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 "cwSerialPortSrv.h"
#include "cwAudioDevice.h"
#include "cwAudioBuf.h"
#include "cwAudioDeviceAlsa.h"
namespace cw
{
@ -41,7 +45,11 @@ namespace cw
serialPort_t* serialA;
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;
@ -215,6 +223,59 @@ namespace cw
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;
}
}
}
@ -253,6 +314,10 @@ cw::rc_t cw::io::create( handle_t& h, const char* cfgStr, cbFunc_t cbFunc, void*
// create the MIDI port device
if((rc = _midiPortCreate(p,o)) != kOkRC )
goto errLabel;
// create the Audio device interface
if((rc = _audioDeviceCreate(p,o)) != kOkRC )
goto errLabel;
// create the the thread
if((rc = thread::create( p->threadH, _mainThreadFunc, p)) != kOkRC )

6
cwIo.h
View File

@ -43,7 +43,7 @@ namespace cw
rc_t create(
handle_t& h,
const char* cfgStr,
const char* cfgStr, // configuration information as text
cbFunc_t cbFunc,
void* cbArg,
const char* cfgLabel="io" );
@ -65,6 +65,10 @@ namespace cw
const char* midiDevicePortName( handle_t h, unsigned devIdx, bool inputFl, unsigned portIdx );
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 );
}
}

View File

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