Merge branch 'master' of klarke.webfactional.com:webapps/git/repos/libcm

This commit is contained in:
kevin 2015-08-07 18:32:29 -04:00
commit 48a582c012
6 changed files with 241 additions and 10 deletions

View File

@ -680,14 +680,14 @@ cmReflectCalc_t* cmReflectCalcAlloc( cmCtx* ctx, cmReflectCalc_t* p, const cmGol
cmRC_t rc = cmOkRC; cmRC_t rc = cmOkRC;
// allocate the Gold code signal generator // allocate the Gold code signal generator
if( (p->gs = cmGoldSigAlloc(ctx,NULL,NULL)) == NULL ) if( (op->gs = cmGoldSigAlloc(ctx,NULL,NULL)) == NULL )
{ {
rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"Gold sig allocate failed."); rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"Gold sig allocate failed.");
goto errLabel; goto errLabel;
} }
// allocate the PHAT object // allocate the PHAT object
if( (p->phat = cmPhatAlloc(ctx,NULL,0,0,0,0,0)) == NULL ) if( (op->phat = cmPhatAlloc(ctx,NULL,0,0,0,0,0)) == NULL )
{ {
rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"PHAT allocate failed."); rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"PHAT allocate failed.");
goto errLabel; goto errLabel;
@ -718,6 +718,8 @@ cmRC_t cmReflectCalcFree( cmReflectCalc_t** pp )
cmReflectCalc_t* p = *pp; cmReflectCalc_t* p = *pp;
cmReflectCalcWrite(p,"/home/kevin/temp/cmkc");
if((rc = cmReflectCalcFinal(p)) != cmOkRC ) if((rc = cmReflectCalcFinal(p)) != cmOkRC )
return rc; return rc;
@ -779,9 +781,12 @@ cmRC_t cmReflectCalcFinal( cmReflectCalc_t* p )
return cmOkRC; return cmOkRC;
} }
cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* yV, unsigned xyN ) cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN )
{ {
unsigned i; unsigned i;
// feed audio into the PHAT's buffer
cmPhatExec(p->phat,xV,xyN);
for(i=0; i<xyN; ++i,++p->xi) for(i=0; i<xyN; ++i,++p->xi)
{ {
@ -790,12 +795,16 @@ cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* y
else else
yV[i] = 0; yV[i] = 0;
// if the PHAT has a complete buffer
if( p->xi == p->phat->fhN ) if( p->xi == p->phat->fhN )
{ {
p->xi = 0; p->xi = 0;
// execute the correlation
cmPhatChExec(p->phat,0,0,0); cmPhatChExec(p->phat,0,0,0);
// p->phat->xV now holds the correlation result
if( p->va != NULL ) if( p->va != NULL )
cmVectArrayAppendS(p->va,p->phat->xV,p->phat->fhN ); cmVectArrayAppendS(p->va,p->phat->xV,p->phat->fhN );
} }
@ -805,3 +814,20 @@ cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* y
return cmOkRC; return cmOkRC;
} }
cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr )
{
cmRC_t rc = cmOkRC;
if( p->va != NULL)
{
const char* path = NULL;
if((rc = cmVectArrayWrite(p->va, path = cmFsMakeFn(path,"reflect_calc","va",dirStr,NULL) )) != cmOkRC )
rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"Reflect calc file write failed.");
cmFsFreeFn(path);
}
return rc;
}

View File

@ -209,11 +209,11 @@ extern "C" {
cmReflectCalc_t* cmReflectCalcAlloc( cmCtx* ctx, cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult ); cmReflectCalc_t* cmReflectCalcAlloc( cmCtx* ctx, cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult );
cmRC_t cmReflectCalcFree( cmReflectCalc_t** pp ); cmRC_t cmReflectCalcFree( cmReflectCalc_t** pp );
cmRC_t cmReflectCalcInit( cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult ); cmRC_t cmReflectCalcInit( cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult );
cmRC_t cmReflectCalcFinal( cmReflectCalc_t* p ); cmRC_t cmReflectCalcFinal( cmReflectCalc_t* p );
cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* yV, unsigned xyN ); cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN );
cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -5837,6 +5837,7 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
cmSyncRecdClassCons, cmSyncRecdClassCons,
cmTakeSeqBldrClassCons, cmTakeSeqBldrClassCons,
cmTakeSeqRendClassCons, cmTakeSeqRendClassCons,
cmReflectCalcClassCons,
NULL, NULL,
}; };

View File

@ -3587,3 +3587,160 @@ struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx )
return &_cmTakeSeqRendDC; return &_cmTakeSeqRendDC;
} }
//==========================================================================================================================================
enum
{
kLfsrN_RcId,
kMlsCoeff0RcId,
kMlsCoeff1RcId,
kSmpPerChipRcId,
kRcosBetaRcId,
kRcosOS_RcId,
kCarrierHzRcId,
kAtkDcyMsRcId,
kPhatAlphaRcId,
kPhatMultRcId,
kInRcId,
kOutRcId,
};
cmDspClass_t _cmReflectCalcDC;
typedef struct
{
cmDspInst_t inst;
cmReflectCalc_t* r;
} cmDspReflectCalc_t;
cmDspInst_t* _cmDspReflectCalcAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
{
/*
if( va_cnt !=3 )
{
cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'ReflectCalc' constructor must have two arguments: a channel count and frequency array.");
return NULL;
}
*/
cmDspReflectCalc_t* p = cmDspInstAllocV(cmDspReflectCalc_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl,
1, "lfsrN", kLfsrN_RcId, 0,0, kInDsvFl | kUIntDsvFl, "Gold code generator LFSR length",
1, "mlsc0", kMlsCoeff0RcId, 0,0, kInDsvFl | kUIntDsvFl, "LFSR coefficient 0",
1, "mlsc1", kMlsCoeff1RcId, 0,0, kInDsvFl | kUIntDsvFl, "LFSR coefficient 0",
1, "spchip",kSmpPerChipRcId,0,0, kInDsvFl | kUIntDsvFl, "Samples per spreading code bit.",
1, "rcosb", kRcosBetaRcId, 0,0, kInDsvFl | kDoubleDsvFl, "Raised cosine beta",
1, "rcosos",kRcosOS_RcId, 0,0, kInDsvFl | kUIntDsvFl, "Raised cosine oversample factor.",
1, "carhz", kCarrierHzRcId, 0,0, kInDsvFl | kDoubleDsvFl, "Carrier frequency in Hertz.",
1, "envms", kAtkDcyMsRcId, 0,0, kInDsvFl | kDoubleDsvFl, "Signal Attack/Decay milliseconds.",
1, "alpha", kPhatAlphaRcId, 0,0, kInDsvFl | kDoubleDsvFl, "PHAT alpha coefficient.",
1, "mult", kPhatMultRcId, 0,0, kInDsvFl | kUIntDsvFl, "PHAT multiplier coefficient.",
1, "in", kInRcId, 0,1, kInDsvFl | kAudioBufDsvFl,"Audio input",
1, "out", kOutRcId, 0,1, kOutDsvFl | kAudioBufDsvFl,"Audio output",
0 );
p->r = cmReflectCalcAlloc(ctx->cmProcCtx, NULL, NULL, 0, 0 );
cmDspSetDefaultUInt( ctx, &p->inst, kLfsrN_RcId, 0, 8);
cmDspSetDefaultUInt( ctx, &p->inst, kMlsCoeff0RcId, 0, 0x8e);
cmDspSetDefaultUInt( ctx, &p->inst, kMlsCoeff1RcId, 0, 0x96);
cmDspSetDefaultUInt( ctx, &p->inst, kSmpPerChipRcId, 0, 64);
cmDspSetDefaultDouble( ctx, &p->inst, kRcosBetaRcId, 0, 0.5);
cmDspSetDefaultUInt( ctx, &p->inst, kRcosOS_RcId, 0, 4);
cmDspSetDefaultDouble( ctx, &p->inst, kCarrierHzRcId, 0, 2500.0);
cmDspSetDefaultDouble( ctx, &p->inst, kAtkDcyMsRcId, 0, 50.0);
cmDspSetDefaultDouble( ctx, &p->inst, kPhatAlphaRcId, 0, 0.5);
cmDspSetDefaultUInt( ctx, &p->inst, kPhatMultRcId, 0, 4);
return &p->inst;
}
cmDspRC_t _cmDspReflectCalcSetup( cmDspCtx_t* ctx, cmDspInst_t* inst )
{
cmDspRC_t rc = kOkDspRC;
cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
cmGoldSigArg_t gsa;
gsa.chN = 1;
gsa.srate = cmDspSampleRate(ctx);
gsa.lfsrN = cmDspUInt(inst,kLfsrN_RcId);
gsa.mlsCoeff0 = cmDspUInt(inst,kMlsCoeff0RcId);
gsa.mlsCoeff1 = cmDspUInt(inst,kMlsCoeff1RcId);
gsa.samplesPerChip = cmDspUInt(inst,kSmpPerChipRcId);
gsa.rcosBeta = cmDspDouble(inst,kRcosBetaRcId);
gsa.rcosOSFact = cmDspUInt(inst,kRcosOS_RcId);
gsa.carrierHz = cmDspDouble(inst,kCarrierHzRcId);
gsa.envMs = cmDspDouble(inst,kAtkDcyMsRcId);
double phatAlpha = cmDspDouble(inst,kPhatAlphaRcId);
unsigned phatMult = cmDspUInt(inst,kPhatMultRcId);
if( cmReflectCalcInit(p->r,&gsa,phatAlpha,phatMult) != cmOkRC )
rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to initialize the internal ReflectCalc detector.");
return rc;
}
cmDspRC_t _cmDspReflectCalcFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
{
cmDspRC_t rc = kOkDspRC;
cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
cmReflectCalcFree(&p->r);
return rc;
}
cmDspRC_t _cmDspReflectCalcReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
{
//cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
cmDspApplyAllDefaults(ctx,inst);
return _cmDspReflectCalcSetup(ctx, inst );
}
cmDspRC_t _cmDspReflectCalcExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
{
cmDspRC_t rc = kOkDspRC;
cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
const cmSample_t* xV = cmDspAudioBuf(ctx,inst,kInRcId,0);
unsigned xN = cmDspAudioBufSmpCount(ctx,inst,kInRcId,0);
cmSample_t* yV = cmDspAudioBuf(ctx,inst,kOutRcId,0);
unsigned yN = cmDspAudioBufSmpCount(ctx,inst,kOutRcId,0);
if( xV != NULL && yV != NULL )
{
assert( xN == yN );
cmReflectCalcExec(p->r,xV,yV,xN);
}
return rc;
}
cmDspRC_t _cmDspReflectCalcRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
{
//cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
cmDspSetEvent(ctx,inst,evt);
return kOkDspRC;
}
struct cmDspClass_str* cmReflectCalcClassCons( cmDspCtx_t* ctx )
{
cmDspClassSetup(&_cmReflectCalcDC,ctx,"ReflectCalc",
NULL,
_cmDspReflectCalcAlloc,
_cmDspReflectCalcFree,
_cmDspReflectCalcReset,
_cmDspReflectCalcExec,
_cmDspReflectCalcRecv,
NULL,
NULL,
"Reflecttion time calculator");
return &_cmReflectCalcDC;
}

View File

@ -21,6 +21,7 @@ extern "C" {
struct cmDspClass_str* cmSyncRecdClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmSyncRecdClassCons( cmDspCtx_t* ctx );
struct cmDspClass_str* cmTakeSeqBldrClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmTakeSeqBldrClassCons( cmDspCtx_t* ctx );
struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx ); struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx );
struct cmDspClass_str* cmReflectCalcClassCons( cmDspCtx_t* ctx );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,51 @@
#include "cmDspPgmPP.h" #include "cmDspPgmPP.h"
#include "cmDspPgmKr.h" #include "cmDspPgmKr.h"
cmDspRC_t _cmDspSysPgm_ReflectCalc( cmDspSysH_t h, void** userPtrPtr )
{
// audio inputs
cmDspInst_t* ai0 = cmDspSysAllocInst(h,"AudioIn", NULL, 1, 0 );
cmDspInst_t* ai1 = cmDspSysAllocInst(h,"AudioIn", NULL, 1, 1 );
cmDspInst_t* rc0 = cmDspSysAllocInst(h,"ReflectCalc", NULL, 0 );
//cmDspInst_t* rc1 = cmDspSysAllocInst(h,"ReflectCalc", NULL, 0 );
// audio outputs
cmDspInst_t* ao0 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 0 );
cmDspInst_t* ao1 = cmDspSysAllocInst(h,"AudioOut",NULL, 1, 1 );
// input meters
cmDspInst_t* im0 = cmDspSysAllocInst(h,"AMeter","In 0", 0);
cmDspInst_t* im1 = cmDspSysAllocInst(h,"AMeter","In 1", 0);
// output meters
//cmDspInst_t* om0 = cmDspSysAllocInst(h,"AMeter","Out 0", 0);
//cmDspInst_t* om1 = cmDspSysAllocInst(h,"AMeter","Out 1",0);
// gain controls
cmDspInst_t* igain = cmDspSysAllocInst( h,"Scalar", "In Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
cmDspInst_t* ogain = cmDspSysAllocInst( h,"Scalar", "Out Gain", 5, kNumberDuiId, 0.0, 4.0, 0.01, 1.0);
cmDspSysConnectAudio(h, ai0, "out", im0, "in"); // ain0 -> imtr0
cmDspSysConnectAudio(h, ai1, "out", im1, "in"); // ain1 -> imtr1
cmDspSysInstallCb( h, igain,"val", ai0, "gain", NULL); // igain -> ain0
cmDspSysInstallCb( h, igain,"val", ai1, "gain", NULL); // igain -> ain0
cmDspSysInstallCb( h, ogain,"val", ao0, "gain", NULL); // igain -> ain0
cmDspSysInstallCb( h, ogain,"val", ao1, "gain", NULL); // igain -> ain0
cmDspSysConnectAudio(h, ai0,"out", rc0, "in" );
cmDspSysConnectAudio(h, rc0,"out", ao0, "in" );
cmDspSysConnectAudio(h, ai1,"out", ao1, "in" );
return kOkDspRC;
}
cmDspRC_t _cmDspSysPgm_SyncRecd( cmDspSysH_t h, void** userPtrPtr ) cmDspRC_t _cmDspSysPgm_SyncRecd( cmDspSysH_t h, void** userPtrPtr )
{ {
cmDspRC_t rc = kOkDspRC; cmDspRC_t rc = kOkDspRC;
@ -2834,7 +2879,7 @@ cmDspRC_t _cmDspSysPgm_BinEnc( cmDspSysH_t h, void** userPtrPtr )
double maxDurMs = 60000.0; double maxDurMs = 60000.0;
double azimBeg = 0.0; double azimBeg = 0.0;
double azimEnd = 360.0; double azimEnd = 360.0;
const char* fn1 = "media/audio/sourcetone/Jazz/Ella & Louis - Under A Blanket Of Blue"; //const char* fn1 = "media/audio/sourcetone/Jazz/Ella & Louis - Under A Blanket Of Blue";
const char* fn0 = "temp/comhear/drw/monty.wav"; const char* fn0 = "temp/comhear/drw/monty.wav";
cmDspInst_t* twod = cmDspSysAllocInst( h, "twod", NULL, 0); cmDspInst_t* twod = cmDspSysAllocInst( h, "twod", NULL, 0);
@ -2901,8 +2946,7 @@ cmDspRC_t _cmDspSysPgm_BinEnc( cmDspSysH_t h, void** userPtrPtr )
_cmDspSysPgm_t _cmDspSysPgmArray[] = _cmDspSysPgm_t _cmDspSysPgmArray[] =
{ {
{ "two-d", _cmDspSysPgm_TwoD, NULL, NULL }, { "reflect", _cmDspSysPgm_ReflectCalc, NULL, NULL },
{ "bin-enc", _cmDspSysPgm_BinEnc, NULL, NULL },
{ "tksb", _cmDspSysPgm_Tksb, NULL, NULL }, { "tksb", _cmDspSysPgm_Tksb, NULL, NULL },
{ "time_line", _cmDspSysPgm_TimeLine, NULL, NULL }, { "time_line", _cmDspSysPgm_TimeLine, NULL, NULL },
{ "seq-bldr", _cmDspSysPgm_TakeSeqBldr, NULL, NULL }, { "seq-bldr", _cmDspSysPgm_TakeSeqBldr, NULL, NULL },
@ -2951,6 +2995,8 @@ _cmDspSysPgm_t _cmDspSysPgmArray[] =
{ "scalar op", _cmDspSysPgm_ScalarOp, NULL, NULL }, { "scalar op", _cmDspSysPgm_ScalarOp, NULL, NULL },
{ "seg_line", _cmDspSysPgm_SegLine, NULL, NULL }, { "seg_line", _cmDspSysPgm_SegLine, NULL, NULL },
{ "avail_ch", _cmDspSysPgm_AvailCh, NULL, NULL }, { "avail_ch", _cmDspSysPgm_AvailCh, NULL, NULL },
{ "two-d", _cmDspSysPgm_TwoD, NULL, NULL },
{ "bin-enc", _cmDspSysPgm_BinEnc, NULL, NULL },
{ NULL , NULL, NULL, NULL } { NULL , NULL, NULL, NULL }
}; };