cwIo.h/cpp/test : Added initial audio implemetation.

This commit is contained in:
kpl 2020-02-13 11:30:46 -05:00
parent f15e06695b
commit 7db4474dd5
3 changed files with 80 additions and 2 deletions

View File

@ -15,6 +15,10 @@
#include "cwSerialPort.h" #include "cwSerialPort.h"
#include "cwSerialPortSrv.h" #include "cwSerialPortSrv.h"
#include "cwAudioDevice.h"
#include "cwAudioBuf.h"
#include "cwAudioDeviceAlsa.h"
namespace cw namespace cw
{ {
@ -42,6 +46,10 @@ namespace cw
unsigned serialN; unsigned serialN;
midi::device::handle_t midiH; midi::device::handle_t midiH;
audio::device::handle_t audioH;
audio::device::alsa::handle_t alsaH;
} io_t; } io_t;
@ -215,6 +223,59 @@ namespace cw
return rc; return rc;
} }
void _audioDeviceCallback( void* cbArg, audio::device::audioPacket_t* inPktArray, unsigned inPktCnt, audio::device::audioPacket_t* outPktArray, unsigned outPktCnt )
{
}
rc_t _audioDeviceConfig( io_t* p, const object_t* c )
{
rc_t rc = kOkRC;
return rc;
}
rc_t _audioDeviceCreate( io_t* p, const object_t*& c )
{
rc_t rc = kOkRC;
audio::device::driver_t* audioDrv = nullptr;
// initialize the audio device interface
if((rc = audio::device::create(p->audioH)) != kOkRC )
{
cwLogInfo("Initialize failed.");
goto errLabel;
}
// initialize the ALSA device driver interface
if((rc = audio::device::alsa::create(p->alsaH, audioDrv )) != kOkRC )
{
cwLogInfo("ALSA initialize failed.");
goto errLabel;
}
// register the ALSA device driver with the audio interface
if((rc = audio::device::registerDriver( p->audioH, audioDrv )) != kOkRC )
{
cwLogInfo("ALSA driver registration failed.");
goto errLabel;
}
//
if((rc = _audioDeviceConfig( p, c )) != kOkRC )
{
cwLogInfo("Audio device configuration failed.");
goto errLabel;
}
errLabel:
return rc;
}
} }
} }
@ -254,6 +315,10 @@ cw::rc_t cw::io::create( handle_t& h, const char* cfgStr, cbFunc_t cbFunc, void*
if((rc = _midiPortCreate(p,o)) != kOkRC ) if((rc = _midiPortCreate(p,o)) != kOkRC )
goto errLabel; goto errLabel;
// create the Audio device interface
if((rc = _audioDeviceCreate(p,o)) != kOkRC )
goto errLabel;
// create the the thread // create the the thread
if((rc = thread::create( p->threadH, _mainThreadFunc, p)) != kOkRC ) if((rc = thread::create( p->threadH, _mainThreadFunc, p)) != kOkRC )
goto errLabel; goto errLabel;

6
cwIo.h
View File

@ -43,7 +43,7 @@ namespace cw
rc_t create( rc_t create(
handle_t& h, handle_t& h,
const char* cfgStr, const char* cfgStr, // configuration information as text
cbFunc_t cbFunc, cbFunc_t cbFunc,
void* cbArg, void* cbArg,
const char* cfgLabel="io" ); const char* cfgLabel="io" );
@ -66,6 +66,10 @@ namespace cw
unsigned midiDevicePortIndex( handle_t h, unsigned devIdx, bool inputFl, const char* portName ); unsigned midiDevicePortIndex( handle_t h, unsigned devIdx, bool inputFl, const char* portName );
rc_t midiDeviceSend( handle_t h, unsigned devIdx, unsigned portIdx, midi::byte_t status, midi::byte_t d0, midi::byte_t d1 ); rc_t midiDeviceSend( handle_t h, unsigned devIdx, unsigned portIdx, midi::byte_t status, midi::byte_t d0, midi::byte_t d1 );
} }
} }

View File

@ -38,6 +38,15 @@ cw::rc_t cw::io::test()
midi: { midi: {
parserBufByteN: 1024, parserBufByteN: 1024,
} }
audio: [
{
name: "default",
device: "HDA Intel PCH CS4208 Analog",
srate: 48000,
framesPerCycle: 64
}
]
} }
})"; })";