cmAudDsp.h/c, cmAudioNrtDev.c,cmAudioSys.h : Audio devices are now set in aud_dsp.js by their name rather than their index.

This commit is contained in:
kevin 2020-07-27 17:36:43 -04:00
parent 4d5e88e766
commit 186f815636
4 changed files with 62 additions and 14 deletions

View File

@ -355,9 +355,14 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
cmAudioSysArgs_t* asap = &p->asCfgArray[i].cfg.ssArray[j].args; cmAudioSysArgs_t* asap = &p->asCfgArray[i].cfg.ssArray[j].args;
const cmJsonNode_t* argsNodePtr = cmJsonArrayElementC(ssArrayNodePtr,j); const cmJsonNode_t* argsNodePtr = cmJsonArrayElementC(ssArrayNodePtr,j);
asap->inDevIdx = cmInvalidIdx;
asap->outDevIdx = cmInvalidIdx;
asap->inDevLabel = NULL;
asap->outDevLabel = NULL;
if((jsRC = cmJsonMemberValues( argsNodePtr, &errLabelPtr, if((jsRC = cmJsonMemberValues( argsNodePtr, &errLabelPtr,
"inDevIdx", kIntTId, &asap->inDevIdx, "inDevLabel", kStringTId, &asap->inDevLabel,
"outDevIdx", kIntTId, &asap->outDevIdx, "outDevLabel", kStringTId, &asap->outDevLabel,
"syncToInputFl", kTrueTId, &asap->syncInputFl, "syncToInputFl", kTrueTId, &asap->syncInputFl,
"msgQueueByteCnt", kIntTId, &asap->msgQueueByteCnt, "msgQueueByteCnt", kIntTId, &asap->msgQueueByteCnt,
"devFramesPerCycle", kIntTId, &asap->devFramesPerCycle, "devFramesPerCycle", kIntTId, &asap->devFramesPerCycle,
@ -443,6 +448,35 @@ cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
return rc; return rc;
} }
cmAdRC_t _cmAdResolveDeviceLabels( cmAd_t* p )
{
cmAdRC_t rc = kOkAdRC;
unsigned i,j;
// for each cmAsAudioSysCfg record in audioSysCfgArray[]
for(i=0; i<p->asCfgCnt; ++i)
{
// for each audio system sub-subsystem
for(j=0; j<p->asCfgArray[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 _cmAdCreateNrtDevices( cmAd_t* p )
{ {
cmAdRC_t rc = kOkAdRC; cmAdRC_t rc = kOkAdRC;
@ -721,6 +755,7 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
if((rc = _cmAdParseSysJsonTree(p)) != kOkAdRC ) if((rc = _cmAdParseSysJsonTree(p)) != kOkAdRC )
goto errLabel; goto errLabel;
// create the aggregate device // create the aggregate device
if( _cmAdCreateAggDevices(p) != kOkAdRC ) if( _cmAdCreateAggDevices(p) != kOkAdRC )
goto errLabel; goto errLabel;
@ -740,6 +775,12 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
goto errLabel; goto errLabel;
} }
if( _cmAdResolveDeviceLabels(p) != kOkApRC )
{
rc = cmErrMsg(&p->err,kAudioPortFailAdRC,"Audio device labels could not be resolved..");
goto errLabel;
}
// initialize the audio buffer // initialize the audio buffer
if( cmApBufInitialize( cmApDeviceCount(), p->meterMs ) != kOkApRC ) if( cmApBufInitialize( cmApDeviceCount(), p->meterMs ) != kOkApRC )
{ {

View File

@ -27,7 +27,8 @@ extern "C" {
kAggDevCreateFailAdRC, kAggDevCreateFailAdRC,
kNrtDevSysFailAdRC, kNrtDevSysFailAdRC,
kAfpDevSysFailAdRC, kAfpDevSysFailAdRC,
kNetSysFailAdRC kNetSysFailAdRC,
kInvalidAudioDevIdxAdRC
}; };

View File

@ -189,6 +189,10 @@ cmApRC_t cmApNrtAllocate( cmRpt_t* rpt )
cmApRC_t cmApNrtFree() cmApRC_t cmApNrtFree()
{ {
cmApRC_t rc = kOkApRC; cmApRC_t rc = kOkApRC;
if( _cmNrt == NULL )
return rc;
cmApNrtDev_t* dp = _cmNrt->devs; cmApNrtDev_t* dp = _cmNrt->devs;
while( dp != NULL ) while( dp != NULL )
{ {

View File

@ -131,8 +131,10 @@ extern "C" {
typedef struct cmAudioSysArgs_str typedef struct cmAudioSysArgs_str
{ {
cmRpt_t* rpt; // system console object cmRpt_t* rpt; // system console object
unsigned inDevIdx; // input audio device const cmChar_t* inDevLabel; // input audio device text label
unsigned outDevIdx; // output audio device 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 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 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 devFramesPerCycle; // (512) Audio device samples per channel per device update buffer.