added midi support, untested

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14831 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-11-10 16:45:45 +00:00
parent 53ea108855
commit 0bb683fa19
6 changed files with 200 additions and 1 deletions

View File

@ -46,6 +46,7 @@ KernelAddon echo24 : kernel drivers bin :
kernel_cpp.cpp
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
$(echo_files)
@ -68,6 +69,7 @@ SEARCH on [ FGristFiles
SEARCH on [ FGristFiles
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
] = [ FDirName $(HAIKU_TOP) src add-ons kernel drivers audio echo ] ;

View File

@ -39,6 +39,7 @@ KernelAddon echo3g : kernel drivers bin :
kernel_cpp.cpp
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
$(echo_files)
@ -61,6 +62,7 @@ SEARCH on [ FGristFiles
SEARCH on [ FGristFiles
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
] = [ FDirName $(HAIKU_TOP) src add-ons kernel drivers audio echo ] ;

View File

@ -52,6 +52,9 @@ int32 num_names;
char * names[NUM_CARDS*20+1];
extern device_hooks multi_hooks;
#ifdef MIDI_SUPPORT
extern device_hooks midi_hooks;
#endif
int32 echo_int(void *arg);
status_t init_hardware(void);
@ -380,6 +383,11 @@ int32 echo_int(void *arg)
return B_UNHANDLED_INTERRUPT;
}
#ifdef MIDI_SUPPORT
if (midiReceived)
release_sem(card->midi.midi_ready_sem);
#endif
LIST_FOREACH(stream, &card->streams, next) {
if ((stream->state & ECHO_STATE_STARTED) == 0 ||
(stream->inth == NULL))
@ -547,6 +555,11 @@ static void
make_device_names(
echo_dev * card)
{
#ifdef MIDI_SUPPORT
sprintf(card->midi.name, "midi/"DRIVER_NAME"/%ld", card-cards+1);
names[num_names++] = card->midi.name;
#endif
sprintf(card->name, "audio/multi/"DRIVER_NAME"/%ld", card-cards+1);
names[num_names++] = card->name;
@ -670,6 +683,10 @@ echo_setup(echo_dev * card)
/* Init mems list */
LIST_INIT(&(card->mems));
#ifdef MIDI_SUPPORT
card->midi.midi_ready_sem = create_sem(0, "midi sem");
#endif
PRINT(("installing interrupt : %x\n", card->irq));
install_io_interrupt_handler(card->irq, echo_int, card, 0);
@ -701,6 +718,10 @@ echo_shutdown(echo_dev *card)
PRINT(("echo_shutdown: error when CloseMixer\n"));
remove_io_interrupt_handler(card->irq, echo_int, card);
#ifdef MIDI_SUPPORT
delete_sem(card->midi.midi_ready_sem);
#endif
delete card->pEG;
delete card->pOSS;
@ -747,6 +768,11 @@ find_device(const char * name)
PRINT(("find_device(%s)\n", name));
for (ix=0; ix<num_cards; ix++) {
#ifdef MIDI_SUPPORT
if (!strcmp(cards[ix].midi.name, name)) {
return &midi_hooks;
}
#endif
if (!strcmp(cards[ix].name, name)) {
return &multi_hooks;
}

View File

@ -35,6 +35,18 @@
#define DEVNAME 32
#define NUM_CARDS 3
/*
* Echo midi
*/
typedef struct _midi_dev {
int32 count;
char name[64];
sem_id midi_ready_sem;
ECHOGALS_MIDI_IN_CONTEXT context;
} midi_dev;
#define ECHO_USE_PLAY (1 << 0)
#define ECHO_USE_RECORD (1 << 1)
#define ECHO_STATE_STARTED (1 << 0)
@ -103,7 +115,10 @@ typedef struct _echo_dev {
echo_stream *rstream;
/* multi_audio */
multi_dev multi;
multi_dev multi;
#ifdef MIDI_SUPPORT
midi_dev midi;
#endif
} echo_dev;
extern int32 num_cards;

View File

@ -44,6 +44,7 @@ KernelAddon echogals : kernel drivers bin :
kernel_cpp.cpp
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
$(echo_files)
@ -66,6 +67,7 @@ SEARCH on [ FGristFiles
SEARCH on [ FGristFiles
debug.c
echo.cpp
midi.cpp
multi.cpp
util.c
] = [ FDirName $(HAIKU_TOP) src add-ons kernel drivers audio echo ] ;

View File

@ -0,0 +1,152 @@
//------------------------------------------------------------------------------
//
// EchoGals/Echo24 BeOS Driver for Echo audio cards
//
// Copyright (c) 2005, Jérôme Duval
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#include "echo.h"
#include "debug.h"
#include "midi_driver.h"
static status_t midi_open(const char *name, uint32 flags, void **cookie);
static status_t midi_close(void *cookie);
static status_t midi_free(void *cookie);
static status_t midi_control(void *cookie, uint32 op, void *data, size_t len);
static status_t midi_read(void *cookie, off_t pos, void *data, size_t *len);
static status_t midi_write(void *cookie, off_t pos, const void *data, size_t *len);
device_hooks midi_hooks = {
&midi_open,
&midi_close,
&midi_free,
&midi_control,
&midi_read,
&midi_write,
NULL, /* select */
NULL, /* deselect */
NULL, /* readv */
NULL /* writev */
};
static status_t
midi_open(
const char * name,
uint32 flags,
void ** cookie)
{
int ix;
LOG(("midi_open()\n"));
*cookie = NULL;
for (ix=0; ix<num_cards; ix++) {
if (!strcmp(name, cards[ix].midi.name)) {
break;
}
}
if (ix >= num_cards) {
LOG(("bad device\n"));
return ENODEV;
}
*cookie = &cards[ix];
atomic_add(&cards[ix].midi.count, 1);
memset(&cards[ix].midi.context, 0, sizeof(cards[ix].midi.context));
cards[ix].pEG->OpenMidiInput(&cards[ix].midi.context);
return B_OK;
}
static status_t
midi_close(
void * cookie)
{
LOG(("midi_close()\n"));
return B_OK;
}
static status_t
midi_free(
void * cookie)
{
echo_dev *card = (echo_dev *) cookie;
LOG(("midi_free()\n"));
card->pEG->CloseMidiInput(&card->midi.context);
atomic_add(&card->midi.count, -1);
LOG(("midi_free() done\n"));
return B_OK;
}
static status_t
midi_control(
void * cookie,
uint32 iop,
void * data,
size_t len)
{
return B_ERROR;
}
static status_t
midi_read(
void * cookie,
off_t pos,
void * ptr,
size_t * nread)
{
echo_dev *card = (echo_dev *) cookie;
ECHOSTATUS err;
DWORD midiData;
LONGLONG timestamp;
if (acquire_sem(card->midi.midi_ready_sem) != B_OK)
return B_ERROR;
err = card->pEG->ReadMidiByte(&card->midi.context, midiData, timestamp);
if (err == ECHOSTATUS_OK) {
*nread = 1;
*(PDWORD)ptr = midiData;
}
return B_ERROR;
}
static status_t
midi_write(
void * cookie,
off_t pos,
const void * ptr,
size_t * nwritten)
{
echo_dev *card = (echo_dev *) cookie;
ECHOSTATUS err;
err = card->pEG->WriteMidi(*nwritten, (PBYTE)ptr, nwritten);
return (err != ECHOSTATUS_OK) ? B_ERROR : B_OK;
}