From 744da472189b30423c11f35473d8cb0b1ba26f0f Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 16 Jan 2014 16:05:11 -0500 Subject: [PATCH 1/2] cmProc4.h/c : Added cmRecdPlayInsertRecord() to the cmRecdPlay object. --- cmProc4.c | 40 ++++++++++++++++++++++++++++++++++++++++ cmProc4.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/cmProc4.c b/cmProc4.c index a7d0cba..475c79e 100644 --- a/cmProc4.c +++ b/cmProc4.c @@ -4352,6 +4352,46 @@ cmRC_t cmRecdPlayEndRecord( cmRecdPlay* p, unsigned labelSymId ) return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'end record'.",labelSymId); } +cmRC_t cmRecdPlayInsertRecord(cmRecdPlay* p, unsigned labelSymId, const cmChar_t* wavFn ) +{ + cmRC_t rc = cmOkRC; + unsigned i; + + for(i=0; ifragCnt; ++i) + if( p->frags[i].labelSymId == labelSymId ) + { + cmAudioFileH_t afH = cmNullAudioFileH; + cmAudioFileInfo_t afInfo; + cmRC_t afRC = kOkAfRC; + + // open the audio file + if( cmAudioFileIsValid( afH = cmAudioFileNewOpen(wavFn, &afInfo, &afRC, p->obj.err.rpt )) == false ) + return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The audio file '%s' could not be opened'.",cmStringNullGuard(wavFn)); + + // ignore blank + if( afInfo.frameCnt == 0 ) + return cmOkRC; + + // allocate buffer space + unsigned j; + for(j=0; jchCnt; ++j) + p->frags[i].chArray[j] = cmMemResize(cmSample_t,p->frags[i].chArray[j],afInfo.frameCnt); + + p->frags[i].allocCnt = afInfo.frameCnt; + + // read samples into the buffer space + unsigned chIdx = 0; + unsigned chCnt = cmMin(p->chCnt,afInfo.chCnt); + unsigned actFrmCnt = 0; + if( cmAudioFileReadSample(afH,afInfo.frameCnt,chIdx,chCnt,&p->frags[i].chArray, &actFrmCnt) != kOkAfRC ) + return cmCtxRtCondition(&p->obj, cmSubSysFailRC, "Read failed on the audio file '%s'.",cmStringNullGuard(wavFn)); + + } + + return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'begin record'.",labelSymId); +} + + cmRC_t cmRecdPlayBeginPlay( cmRecdPlay* p, unsigned labelSymId ) { unsigned i; diff --git a/cmProc4.h b/cmProc4.h index eaabff7..82cc243 100644 --- a/cmProc4.h +++ b/cmProc4.h @@ -688,6 +688,8 @@ extern "C" { cmRC_t cmRecdPlayBeginRecord( cmRecdPlay* p, unsigned labelSymId ); cmRC_t cmRecdPlayEndRecord( cmRecdPlay* p, unsigned labelSymId ); + cmRC_t cmRecdPlayInsertRecord(cmRecdPlay* p, unsigned labelSymId, const cmChar_t* wavFn ); + cmRC_t cmRecdPlayBeginPlay( cmRecdPlay* p, unsigned labelSymId ); cmRC_t cmRecdPlayEndPlay( cmRecdPlay* p, unsigned labelSymId ); From a19d93b2653a993f28aa2cb9253b2436c910e5a0 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 16 Jan 2014 16:05:45 -0500 Subject: [PATCH 2/2] cmDspKr.c : Added ability to preload a cmRecdPlay segment from an audio file. --- dsp/cmDspKr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dsp/cmDspKr.c b/dsp/cmDspKr.c index 9a14f8f..1e6c7ef 100644 --- a/dsp/cmDspKr.c +++ b/dsp/cmDspKr.c @@ -2485,6 +2485,8 @@ enum kMaxLaSecsPrId, kCurLaSecsPrId, kFadeRatePrId, + kSegFnPrId, + kSegLblPrId, kScLocIdxPrId, kCmdPrId, kInAudioBasePrId @@ -2537,6 +2539,15 @@ cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst ) for(i=0; ircdply,i, cmScoreMarkerLabelSymbolId(p->scH,i )); + const cmChar_t* segFn = cmDspStrcz(inst,kSegFnPrId); + const cmChar_t* segLbl= cmDspStrcz(inst,kSegLblPrId); + + if( cmTextLength(segFn)>0 && cmTextLength(segLbl)>0 ) + { + unsigned segSymId = cmSymTblRegisterSymbol(ctx->stH,segLbl); + cmRecdPlayInsertRecord(p->rcdply,segSymId,segFn); + } + } return rc; @@ -2565,6 +2576,8 @@ cmDspInst_t* _cmDspRecdPlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig 1, "maxla", kMaxLaSecsPrId, 0,0, kInDsvFl | kDoubleDsvFl | kReqArgDsvFl, "Maximum look-ahead buffer in seconds.", 1, "curla", kCurLaSecsPrId, 0,0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Current look-head buffer in seconds.", 1, "frate", kFadeRatePrId, 0,0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade rate in dB per second.", + 1, "segFn", kSegFnPrId, 0,0, kInDsvFl | kStrzDsvFl | kOptArgDsvFl, "Preload an audio segment.", + 1, "segLbl", kSegLblPrId, 0,0, kInDsvFl | kStrzDsvFl | kOptArgDsvFl, "Score symbol of preloaded audio segment.", 1, "index", kScLocIdxPrId, 0,0, kInDsvFl | kUIntDsvFl, "Score follower location index.", 1, "cmd", kCmdPrId, 0,0, kInDsvFl | kSymDsvFl, "on=reset off=stop.", chCnt, "in", kInAudioBasePrId,0,1, kInDsvFl | kAudioBufDsvFl, "Audio input", @@ -2589,6 +2602,8 @@ cmDspInst_t* _cmDspRecdPlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig printf("1 max la secs:%f\n",cmDspDouble(&p->inst,kMaxLaSecsPrId)); + + return &p->inst; }