cmAudDsp,cmAudioFileDev,cmAudioPortFile,cmAudioSys: Changes to support audio port file devices.

This commit is contained in:
kevin 2013-03-01 17:20:01 -08:00
parent d7b64b882b
commit 0efe33d6e0
9 changed files with 139 additions and 16 deletions

View File

@ -14,6 +14,7 @@
#include "cmAudioPort.h" #include "cmAudioPort.h"
#include "cmAudioAggDev.h" #include "cmAudioAggDev.h"
#include "cmAudioNrtDev.h" #include "cmAudioNrtDev.h"
#include "cmAudioPortFile.h"
#include "cmApBuf.h" #include "cmApBuf.h"
#include "cmMidi.h" #include "cmMidi.h"
#include "cmMidiPort.h" #include "cmMidiPort.h"
@ -62,6 +63,15 @@ typedef struct
unsigned cbPeriodMs; unsigned cbPeriodMs;
} cmAdNrtDev_t; } cmAdNrtDev_t;
typedef struct
{
const cmChar_t* label;
const cmChar_t* inAudioFn;
const cmChar_t* outAudioFn;
unsigned oBits;
unsigned oChCnt;
} cmAdAfpDev_t;
typedef struct typedef struct
{ {
cmErr_t err; cmErr_t err;
@ -84,6 +94,9 @@ typedef struct
cmAdNrtDev_t* nrtDevArray; cmAdNrtDev_t* nrtDevArray;
unsigned nrtDevCnt; unsigned nrtDevCnt;
cmAdAfpDev_t* afpDevArray;
unsigned afpDevCnt;
cmAdAsCfg_t* asCfgArray; cmAdAsCfg_t* asCfgArray;
unsigned asCfgCnt; unsigned asCfgCnt;
@ -151,6 +164,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
cmJsonNode_t* asCfgArrNodePtr = NULL; cmJsonNode_t* asCfgArrNodePtr = NULL;
cmJsonNode_t* aggDevArrNodePtr = NULL; cmJsonNode_t* aggDevArrNodePtr = NULL;
cmJsonNode_t* nrtDevArrNodePtr = NULL; cmJsonNode_t* nrtDevArrNodePtr = NULL;
cmJsonNode_t* afpDevArrNodePtr = NULL;
cmJsonNode_t* audDspNodePtr = NULL; cmJsonNode_t* audDspNodePtr = NULL;
const cmChar_t* errLabelPtr = NULL; const cmChar_t* errLabelPtr = NULL;
unsigned i; unsigned i;
@ -171,6 +185,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
"audioSysCfgArray", kArrayTId, &asCfgArrNodePtr, "audioSysCfgArray", kArrayTId, &asCfgArrNodePtr,
"aggDevArray", kArrayTId | kOptArgJsFl, &aggDevArrNodePtr, "aggDevArray", kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
"nrtDevArray", kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr, "nrtDevArray", kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
"afpDevArray", kArrayTId | kOptArgJsFl, &afpDevArrNodePtr,
NULL )) != kOkJsRC ) NULL )) != kOkJsRC )
{ {
rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" ); rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
@ -242,6 +257,34 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
} }
} }
}
// parse the audio file device specifications into p->afpDevArray[].
if( afpDevArrNodePtr != NULL && (p->afpDevCnt = cmJsonChildCount(afpDevArrNodePtr)) > 0)
{
// alloc the non-real-time spec. array
p->afpDevArray = cmMemResizeZ( cmAdAfpDev_t, p->afpDevArray, p->afpDevCnt );
// for each afp. device spec. recd
for(i=0; i<p->afpDevCnt; ++i)
{
const cmJsonNode_t* np = cmJsonArrayElementC(afpDevArrNodePtr,i);
// read afpDevArray record values
if(( jsRC = cmJsonMemberValues( np, &errLabelPtr,
"label", kStringTId, &p->afpDevArray[i].label,
"iAudioFn", kStringTId | kOptArgJsFl, &p->afpDevArray[i].inAudioFn,
"oAudioFn", kStringTId | kOptArgJsFl, &p->afpDevArray[i].outAudioFn,
"oBits", kIntTId | kOptArgJsFl, &p->afpDevArray[i].oBits,
"oChCnt", kIntTId | kOptArgJsFl, &p->afpDevArray[i].oChCnt,
NULL )) != kOkJsRC )
{
rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, cmStringNullGuard(p->afpDevArray[i].label) );
goto errLabel;
}
}
} }
@ -368,6 +411,26 @@ cmAdRC_t _cmAdCreateNrtDevices( cmAd_t* p )
return rc; return rc;
} }
cmAdRC_t _cmAdCreateAfpDevices( cmAd_t* p )
{
cmAdRC_t rc = kOkAdRC;
if( cmApFileAllocate(p->err.rpt) != kOkApRC )
return cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device system allocation failed.");
unsigned i;
// create the audio file devices
for(i=0; i<p->afpDevCnt; ++i)
{
//const cmAudioSysFilePort_t* afp = cfg->afpArray + i;
cmAdAfpDev_t* afp = p->afpDevArray + i;
if( cmApFileDeviceCreate( afp->label, afp->inAudioFn, afp->outAudioFn, afp->oBits, afp->oChCnt ) != kOkApRC )
rc = cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device '%s' creation failed.",cmStringNullGuard(afp->label));
}
return rc;
}
cmAdRC_t _cmAdSendAudioSysCfgLabels( cmAd_t* p) cmAdRC_t _cmAdSendAudioSysCfgLabels( cmAd_t* p)
{ {
cmAdRC_t rc = kOkAdRC; cmAdRC_t rc = kOkAdRC;
@ -480,9 +543,15 @@ cmAdRC_t _cmAudDspFree( cmAd_t* p )
goto errLabel; goto errLabel;
} }
if( cmApFileFree() != kOkApRC )
{
rc = cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device system release failed.");
goto errLabel;
}
if( cmApNrtFree() != kOkAgRC ) if( cmApNrtFree() != kOkAgRC )
{ {
rc = cmErrMsg(&p->err,kNrtDevSysFailAdRC,"The non-real-time device system realease failed."); rc = cmErrMsg(&p->err,kNrtDevSysFailAdRC,"The non-real-time device system release failed.");
goto errLabel; goto errLabel;
} }
@ -562,6 +631,10 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
if( _cmAdCreateNrtDevices(p) != kOkAdRC ) if( _cmAdCreateNrtDevices(p) != kOkAdRC )
goto errLabel; goto errLabel;
// create the audio file devices
if( _cmAdCreateAfpDevices(p) != kOkAdRC )
goto errLabel;
// initialize the audio device system // initialize the audio device system
if( cmApInitialize(&ctx->rpt) != kOkApRC ) if( cmApInitialize(&ctx->rpt) != kOkApRC )
{ {

View File

@ -25,6 +25,7 @@ extern "C" {
kAggDevSysFailAdRC, kAggDevSysFailAdRC,
kAggDevCreateFailAdRC, kAggDevCreateFailAdRC,
kNrtDevSysFailAdRC, kNrtDevSysFailAdRC,
kAfpDevSysFailAdRC,
kNetSysFailAdRC kNetSysFailAdRC
}; };

View File

@ -220,8 +220,6 @@ cmAfdRC_t cmAudioFileDevInitialize(
goto errLabel; goto errLabel;
} }
p->iPkt.devIdx = devIdx; p->iPkt.devIdx = devIdx;
p->iPkt.begChIdx = 0; p->iPkt.begChIdx = 0;
p->iPkt.chCnt = afInfo.chCnt; // setting iPkt.chCnt to a non-zero value marks the input file as active p->iPkt.chCnt = afInfo.chCnt; // setting iPkt.chCnt to a non-zero value marks the input file as active
@ -294,6 +292,7 @@ bool cmAudioFileDevIsValid( cmAfdH_t h )
cmAfdRC_t cmAudioFileDevSetup( cmAfdRC_t cmAudioFileDevSetup(
cmAfdH_t h, cmAfdH_t h,
unsigned baseDevIdx,
double srate, double srate,
unsigned framesPerCycle, unsigned framesPerCycle,
cmApCallbackPtr_t callbackPtr, cmApCallbackPtr_t callbackPtr,
@ -344,13 +343,14 @@ cmAfdRC_t cmAudioFileDevSetup(
cmApSample_t* bp = (cmApSample_t*)p->oPkt.audioBytesPtr; cmApSample_t* bp = (cmApSample_t*)p->oPkt.audioBytesPtr;
p->oPkt.devIdx = p->devIdx; p->oPkt.devIdx = p->devIdx + baseDevIdx;
p->oPkt.begChIdx = 0; p->oPkt.begChIdx = 0;
p->oPkt.chCnt = p->oChCnt; p->oPkt.chCnt = p->oChCnt;
p->oPkt.audioFramesCnt = framesPerCycle; p->oPkt.audioFramesCnt = framesPerCycle;
p->oPkt.bitsPerSample = p->oBits; p->oPkt.bitsPerSample = p->oBits;
p->oPkt.flags = kFloatApFl; p->oPkt.flags = kFloatApFl;
p->oPkt.audioBytesPtr = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->oChCnt ); p->oPkt.audioBytesPtr = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->oChCnt );
p->oPkt.userCbPtr = cbDataPtr;
p->oChArray = cmMemResizeZ( cmApSample_t*, p->oChArray, p->oChCnt ); p->oChArray = cmMemResizeZ( cmApSample_t*, p->oChArray, p->oChCnt );
for(i=0; i<p->oChCnt; ++i) for(i=0; i<p->oChCnt; ++i)
@ -362,8 +362,10 @@ cmAfdRC_t cmAudioFileDevSetup(
{ {
cmApSample_t* bp = (cmApSample_t*)p->iPkt.audioBytesPtr; cmApSample_t* bp = (cmApSample_t*)p->iPkt.audioBytesPtr;
p->iPkt.devIdx = p->devIdx + baseDevIdx;
p->iPkt.audioFramesCnt = framesPerCycle; p->iPkt.audioFramesCnt = framesPerCycle;
p->iPkt.audioBytesPtr = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->iPkt.chCnt ); ; p->iPkt.audioBytesPtr = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->iPkt.chCnt ); ;
p->iPkt.userCbPtr = cbDataPtr;
for(i=0; i<p->iPkt.chCnt; ++i) for(i=0; i<p->iPkt.chCnt; ++i)
p->iChArray[i] = bp + (i*framesPerCycle); p->iChArray[i] = bp + (i*framesPerCycle);
} }
@ -534,7 +536,7 @@ void cmAudioFileDevTest( cmRpt_t* rpt )
if( cmAudioFileDevInitialize(&afdH,"file",devIdx,iFn,oFn,oBits,oChCnt,rpt) != kOkAfdRC ) if( cmAudioFileDevInitialize(&afdH,"file",devIdx,iFn,oFn,oBits,oChCnt,rpt) != kOkAfdRC )
goto errLabel; goto errLabel;
if( cmAudioFileDevSetup(afdH,srate,framesPerCycle,_cmAfdCallback,cbDataPtr) != kOkAfdRC ) if( cmAudioFileDevSetup(afdH,0,srate,framesPerCycle,_cmAfdCallback,cbDataPtr) != kOkAfdRC )
goto errLabel; goto errLabel;
char c; char c;

View File

@ -37,6 +37,7 @@ bool cmAudioFileDevIsValid( cmAfdH_t h );
/// Setup the device. This function must be called prior to cmAudioFileDevStart(). /// Setup the device. This function must be called prior to cmAudioFileDevStart().
cmAfdRC_t cmAudioFileDevSetup( cmAfdRC_t cmAudioFileDevSetup(
cmAfdH_t h, cmAfdH_t h,
unsigned baseApDevIdx,
double srate, double srate,
unsigned framesPerCycle, unsigned framesPerCycle,
cmApCallbackPtr_t callbackPtr, cmApCallbackPtr_t callbackPtr,

View File

@ -25,7 +25,7 @@ typedef struct
typedef struct cmApNrtDev_str typedef struct cmApNrtDev_str
{ {
unsigned flags; unsigned flags;
unsigned devIdx; // nrt device index unsigned devIdx; // nrt device index
unsigned baseApDevIdx; // global audio device index for first nrt device unsigned baseApDevIdx; // global audio device index for first nrt device
cmChar_t* label; cmChar_t* label;
unsigned iChCnt; unsigned iChCnt;

View File

@ -11,6 +11,8 @@
typedef struct typedef struct
{ {
cmAfdH_t devH; cmAfdH_t devH;
unsigned devIdx; // afp dev idx
unsigned baseApDevIdx; // global audio device index for first afp device
} cmApDev_t; } cmApDev_t;
typedef struct typedef struct
@ -18,19 +20,53 @@ typedef struct
cmErr_t err; cmErr_t err;
cmApDev_t* devArray; cmApDev_t* devArray;
unsigned devCnt; unsigned devCnt;
unsigned baseApDevIdx;
} cmApf_t; } cmApf_t;
cmApf_t* _cmApf = NULL; cmApf_t* _cmApf = NULL;
cmApRC_t cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx ) cmApRC_t cmApFileAllocate( cmRpt_t* rpt )
{ {
cmApRC_t rc; cmApRC_t rc = kOkApRC;
if((rc = cmApFileFinalize()) != kOkApRC )
return rc; if( _cmApf != NULL )
cmApFileFree();
_cmApf = cmMemAllocZ(cmApf_t,1); _cmApf = cmMemAllocZ(cmApf_t,1);
cmErrSetup(&_cmApf->err,rpt,"Audio Port File"); cmErrSetup(&_cmApf->err,rpt,"Audio Port File");
_cmApf->devArray = NULL;
_cmApf->devCnt = 0;
_cmApf->baseApDevIdx = 0;
return rc;
}
cmApRC_t cmApFileFree()
{
cmApRC_t rc = kOkApRC;
if( _cmApf == NULL )
return rc;
if((rc = cmApFileFinalize()) != kOkApRC )
return rc;
cmMemFree(_cmApf);
_cmApf = NULL;
return rc;
}
cmApRC_t cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx )
{
cmApRC_t rc = kOkApRC;
unsigned i = 0;
for(; i<_cmApf->devCnt; ++i)
_cmApf->devArray[i].baseApDevIdx = baseApDevIdx;
_cmApf->baseApDevIdx = baseApDevIdx;
return rc; return rc;
} }
@ -85,7 +121,12 @@ unsigned cmApFileDeviceCreate(
{ {
cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device initialization failed."); cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device initialization failed.");
i = cmInvalidIdx; i = cmInvalidIdx;
goto errLabel;
} }
_cmApf->devArray[i].devIdx = i;
errLabel:
return i; return i;
} }
@ -134,7 +175,7 @@ cmApRC_t cmApFileDeviceSetup(
{ {
assert( devIdx < cmApFileDeviceCount()); assert( devIdx < cmApFileDeviceCount());
if( cmAudioFileDevSetup( _cmApf->devArray[devIdx].devH,srate,framesPerCycle,callbackPtr,userCbPtr) != kOkAfdRC ) if( cmAudioFileDevSetup( _cmApf->devArray[devIdx].devH,_cmApf->baseApDevIdx,srate,framesPerCycle,callbackPtr,userCbPtr) != kOkAfdRC )
return cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device setup failed."); return cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device setup failed.");
return kOkApRC; return kOkApRC;

View File

@ -5,6 +5,8 @@
extern "C" { extern "C" {
#endif #endif
cmApRC_t cmApFileAllocate( cmRpt_t* rpt );
cmApRC_t cmApFileFree();
cmApRC_t cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx ); cmApRC_t cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx );
cmApRC_t cmApFileFinalize(); cmApRC_t cmApFileFinalize();

View File

@ -729,11 +729,13 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
return rc; return rc;
// create the audio file devices // create the audio file devices
/*
for(i=0; i<cfg->afpCnt; ++i) for(i=0; i<cfg->afpCnt; ++i)
{ {
const cmAudioSysFilePort_t* afp = cfg->afpArray + i; const cmAudioSysFilePort_t* afp = cfg->afpArray + i;
cmApFileDeviceCreate( afp->devLabel, afp->inAudioFn, afp->outAudioFn, afp->oBits, afp->oChCnt ); cmApFileDeviceCreate( afp->devLabel, afp->inAudioFn, afp->outAudioFn, afp->oBits, afp->oChCnt );
} }
*/
p->ssArray = cmMemAllocZ( _cmAsCfg_t, cfg->ssCnt ); p->ssArray = cmMemAllocZ( _cmAsCfg_t, cfg->ssCnt );
p->ssCnt = cfg->ssCnt; p->ssCnt = cfg->ssCnt;
@ -1281,8 +1283,8 @@ void cmAudioSysTest( cmRpt_t* rpt, int argc, const char* argv[] )
cfg.ssArray = &ss; cfg.ssArray = &ss;
cfg.ssCnt = 1; cfg.ssCnt = 1;
cfg.afpArray= NULL; //cfg.afpArray= NULL;
cfg.afpCnt = 0; //cfg.afpCnt = 0;
cfg.meterMs = 50; cfg.meterMs = 50;
if(_cmAsGetBoolOpt(argc,argv,"-h",false)) if(_cmAsGetBoolOpt(argc,argv,"-h",false))

View File

@ -172,6 +172,7 @@ extern "C" {
} cmAudioSysCtx_t; } cmAudioSysCtx_t;
/*
typedef struct typedef struct
{ {
const cmChar_t* devLabel; const cmChar_t* devLabel;
@ -180,15 +181,15 @@ extern "C" {
unsigned oBits; unsigned oBits;
unsigned oChCnt; unsigned oChCnt;
} cmAudioSysFilePort_t; } cmAudioSysFilePort_t;
*/
/// Audio system configuration record used by cmAudioSysAllocate(). /// Audio system configuration record used by cmAudioSysAllocate().
typedef struct cmAudioSysCfg_str typedef struct cmAudioSysCfg_str
{ {
cmAudioSysSubSys_t* ssArray; ///< sub-system cfg record array cmAudioSysSubSys_t* ssArray; ///< sub-system cfg record array
unsigned ssCnt; ///< count of sub-systems unsigned ssCnt; ///< count of sub-systems
cmAudioSysFilePort_t* afpArray; ///< audio port file cfg recd array //cmAudioSysFilePort_t* afpArray; ///< audio port file cfg recd array
unsigned afpCnt; ///< audio port file cnt //unsigned afpCnt; ///< audio port file cnt
unsigned meterMs; ///< Meter sample period in milliseconds unsigned meterMs; ///< Meter sample period in milliseconds
void* clientCbData; ///< User arg. for clientCbFunc(). void* clientCbData; ///< User arg. for clientCbFunc().
cmTsQueueCb_t clientCbFunc; ///< Called by cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. cmTsQueueCb_t clientCbFunc; ///< Called by cmAudioSysReceiveMsg() to deliver internally generated msg's to the host.