#include "cwCommon.h" #include "cwLog.h" #include "cwCommonImpl.h" #include "cwMem.h" #include "cwTime.h" #include "cwTextBuf.h" #include "cwAudioDevice.h" #include "cwAudioBuf.h" #include "cwAudioDeviceAlsa.h" #include "cwAudioDeviceTest.h" namespace cw { namespace audio { namespace device { /// [cmAudioPortExample] // See test() below for the main point of entry. // Data structure used to hold the parameters for cpApPortTest() // and the user defined data record passed to the host from the // audio port callback functions. typedef struct { unsigned bufCnt; // 2=double buffering 3=triple buffering unsigned chIdx; // first test channel //unsigned chCnt; // count of channels to test unsigned framesPerCycle; // DSP frames per cycle unsigned bufFrmCnt; // count of DSP frames used by the audio buffer (bufCnt * framesPerCycle) unsigned bufSmpCnt; // count of samples used by the audio buffer (chCnt * bufFrmCnt) unsigned inDevIdx; // input device index unsigned outDevIdx; // output device index double srate; // audio sample rate unsigned meterMs; // audio meter buffer length unsigned iCbCnt; // count the callback unsigned oCbCnt; buf::handle_t audioBufH; } cmApPortTestRecd; // print the usage message for cmAudioPortTest.c void _cmApPrintUsage() { char msg[] = "cmApPortTest() command switches\n" "-r -c -b -f -i -o -t -p -h \n" "\n" "-r = sample rate\n" "-a = first channel\n" "-c = audio channels\n" "-b = count of buffers\n" "-f = count of samples per buffer\n" "-i = input device index\n" "-o = output device index\n" "-p = print report but do not start audio devices\n" "-h = print this usage message\n"; cwLogInfo(msg); } // Get a command line option. Note that if 'boolFl' is set to 'true' then the function simply // returns '1'. This is used to handle arguments whose presense indicates a positive boolean // flag. For example -h (help) indicates that the usage data should be printed - it needs no other argument. int _cmApGetOpt( int argc, const char* argv[], const char* label, int defaultVal, bool boolFl=false ) { int i = 0; for(; i(arg); for(unsigned i=0; i(inPktArray[i].cbArg)->iCbCnt++; for(unsigned i=0; i(outPktArray[i].cbArg)->oCbCnt++; buf::inputToOutput( p->audioBufH, _cmGlobalInDevIdx, _cmGlobalOutDevIdx ); buf::update( p->audioBufH, inPktArray, inPktCnt, outPktArray, outPktCnt ); } } } } // Audio Port testing function cw::rc_t cw::audio::device::test( int argc, const char** argv ) { cmApPortTestRecd r; unsigned i; rc_t rc; driver_t* drv = nullptr; handle_t h; alsa::handle_t alsaH; bool runFl = true; if( _cmApGetOpt(argc,argv,"-h",0,true) ) _cmApPrintUsage(); runFl = _cmApGetOpt(argc,argv,"-p",0,true)?false:true; r.srate = _cmApGetOpt(argc,argv,"-r",44100); //r.chIdx = _cmApGetOpt(argc,argv,"-a",0); //r.chCnt = _cmApGetOpt(argc,argv,"-c",2); r.bufCnt = _cmApGetOpt(argc,argv,"-b",3); r.framesPerCycle = _cmApGetOpt(argc,argv,"-f",512); //r.bufFrmCnt = (r.bufCnt*r.framesPerCycle); //r.bufSmpCnt = (r.chCnt * r.bufFrmCnt); //r.logCnt = 100; r.meterMs = 50; r.inDevIdx = _cmGlobalInDevIdx = _cmApGetOpt(argc,argv,"-i",0); r.outDevIdx = _cmGlobalOutDevIdx = _cmApGetOpt(argc,argv,"-o",0); r.iCbCnt = 0; r.oCbCnt = 0; //cwLogInfo("Program cfg: %s in:%i out:%i chidx:%i chs:%i bufs=%i frm=%i rate=%f",runFl?"exec":"rpt",r.inDevIdx,r.outDevIdx,r.chIdx,r.chCnt,r.bufCnt,r.framesPerCycle,r.srate); // initialize the audio device interface if((rc = create(h)) != kOkRC ) { cwLogInfo("Initialize failed."); goto errLabel; } // initialize the ALSA device driver interface if((rc = alsa::create(alsaH, drv )) != kOkRC ) { cwLogInfo("ALSA initialize failed."); goto errLabel; } // register the ALSA device driver with the audio interface if((rc = registerDriver( h, drv )) != kOkRC ) { cwLogInfo("ALSA driver registration failed."); goto errLabel; } // report the current audio device configuration for(i=0; i