diff --git a/src/cmAudDsp.c b/src/cmAudDsp.c index 4b97570..213a7dd 100644 --- a/src/cmAudDsp.c +++ b/src/cmAudDsp.c @@ -354,10 +354,15 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p ) { cmAudioSysArgs_t* asap = &p->asCfgArray[i].cfg.ssArray[j].args; const cmJsonNode_t* argsNodePtr = cmJsonArrayElementC(ssArrayNodePtr,j); + + asap->inDevIdx = cmInvalidIdx; + asap->outDevIdx = cmInvalidIdx; + asap->inDevLabel = NULL; + asap->outDevLabel = NULL; if((jsRC = cmJsonMemberValues( argsNodePtr, &errLabelPtr, - "inDevIdx", kIntTId, &asap->inDevIdx, - "outDevIdx", kIntTId, &asap->outDevIdx, + "inDevLabel", kStringTId, &asap->inDevLabel, + "outDevLabel", kStringTId, &asap->outDevLabel, "syncToInputFl", kTrueTId, &asap->syncInputFl, "msgQueueByteCnt", kIntTId, &asap->msgQueueByteCnt, "devFramesPerCycle", kIntTId, &asap->devFramesPerCycle, @@ -443,6 +448,35 @@ cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p ) return rc; } +cmAdRC_t _cmAdResolveDeviceLabels( cmAd_t* p ) +{ + cmAdRC_t rc = kOkAdRC; + unsigned i,j; + + // for each cmAsAudioSysCfg record in audioSysCfgArray[] + for(i=0; iasCfgCnt; ++i) + { + // for each audio system sub-subsystem + for(j=0; jasCfgArray[i].cfg.ssCnt; ++j) + { + cmAudioSysArgs_t* asap = &p->asCfgArray[i].cfg.ssArray[j].args; + if((asap->inDevIdx = cmApDeviceLabelToIndex( asap->inDevLabel )) == cmInvalidId ) + { + rc = cmErrMsg(&p->err,kInvalidAudioDevIdxAdRC,"The audio input device '%s' could not be found.", cmStringNullGuard(asap->inDevLabel)); + goto errLabel; + } + + if((asap->outDevIdx = cmApDeviceLabelToIndex( asap->outDevLabel )) == cmInvalidId ) + { + rc = cmErrMsg(&p->err,kInvalidAudioDevIdxAdRC,"The audio input device '%s' could not be found.", cmStringNullGuard(asap->inDevLabel)); + goto errLabel; + } + } + } + errLabel: + return rc; +} + cmAdRC_t _cmAdCreateNrtDevices( cmAd_t* p ) { cmAdRC_t rc = kOkAdRC; @@ -721,10 +755,11 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo if((rc = _cmAdParseSysJsonTree(p)) != kOkAdRC ) goto errLabel; + // create the aggregate device if( _cmAdCreateAggDevices(p) != kOkAdRC ) goto errLabel; - + // create the non-real-time devices if( _cmAdCreateNrtDevices(p) != kOkAdRC ) goto errLabel; @@ -740,6 +775,12 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo goto errLabel; } + if( _cmAdResolveDeviceLabels(p) != kOkApRC ) + { + rc = cmErrMsg(&p->err,kAudioPortFailAdRC,"Audio device labels could not be resolved.."); + goto errLabel; + } + // initialize the audio buffer if( cmApBufInitialize( cmApDeviceCount(), p->meterMs ) != kOkApRC ) { diff --git a/src/cmAudDsp.h b/src/cmAudDsp.h index 152c94e..6e0c88b 100644 --- a/src/cmAudDsp.h +++ b/src/cmAudDsp.h @@ -27,7 +27,8 @@ extern "C" { kAggDevCreateFailAdRC, kNrtDevSysFailAdRC, kAfpDevSysFailAdRC, - kNetSysFailAdRC + kNetSysFailAdRC, + kInvalidAudioDevIdxAdRC }; diff --git a/src/cmAudioNrtDev.c b/src/cmAudioNrtDev.c index c22f770..1408df3 100644 --- a/src/cmAudioNrtDev.c +++ b/src/cmAudioNrtDev.c @@ -189,6 +189,10 @@ cmApRC_t cmApNrtAllocate( cmRpt_t* rpt ) cmApRC_t cmApNrtFree() { cmApRC_t rc = kOkApRC; + + if( _cmNrt == NULL ) + return rc; + cmApNrtDev_t* dp = _cmNrt->devs; while( dp != NULL ) { diff --git a/src/cmAudioSys.h b/src/cmAudioSys.h index 9a5b28e..7fc5c8d 100644 --- a/src/cmAudioSys.h +++ b/src/cmAudioSys.h @@ -130,16 +130,18 @@ extern "C" { // Audio device sub-sytem configuration record typedef struct cmAudioSysArgs_str { - cmRpt_t* rpt; // system console object - unsigned inDevIdx; // input audio device - unsigned outDevIdx; // output audio device - bool syncInputFl; // true/false sync the DSP update callbacks with audio input/output - unsigned msgQueueByteCnt; // Size of the internal msg queue used to buffer msgs arriving via cmAudioSysDeliverMsg(). - unsigned devFramesPerCycle; // (512) Audio device samples per channel per device update buffer. - unsigned dspFramesPerCycle; // (64) Audio samples per channel per DSP cycle. - unsigned audioBufCnt; // (3) Audio device buffers. - double srate; // Audio sample rate. - int srateMult; // Sample rate multiplication factor (negative for divide) + cmRpt_t* rpt; // system console object + const cmChar_t* inDevLabel; // input audio device text label + const cmChar_t* outDevLabel; // output audio device text label + unsigned inDevIdx; // input audio device index + unsigned outDevIdx; // output audio device index + bool syncInputFl; // true/false sync the DSP update callbacks with audio input/output + unsigned msgQueueByteCnt; // Size of the internal msg queue used to buffer msgs arriving via cmAudioSysDeliverMsg(). + unsigned devFramesPerCycle; // (512) Audio device samples per channel per device update buffer. + unsigned dspFramesPerCycle; // (64) Audio samples per channel per DSP cycle. + unsigned audioBufCnt; // (3) Audio device buffers. + double srate; // Audio sample rate. + int srateMult; // Sample rate multiplication factor (negative for divide) } cmAudioSysArgs_t; // Audio sub-system configuration record.