From 9567d9211d1f96418f2af09da589775ebf4893e6 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 28 Sep 2013 12:39:43 -0700 Subject: [PATCH] cmDspBuiltIn.c : The AudioFileOut object no longer creates an output file when the object is created. It now waits until it is sent an 'open' symbol to create the audio output file. If the AudioFileOut object is sent a directory rather than a file then it automatically generates a file name in the given directory. --- dsp/cmDspBuiltIn.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/dsp/cmDspBuiltIn.c b/dsp/cmDspBuiltIn.c index ad98218..133f951 100644 --- a/dsp/cmDspBuiltIn.c +++ b/dsp/cmDspBuiltIn.c @@ -1474,17 +1474,29 @@ typedef struct cmAudioFileH_t afH; unsigned openSymId; unsigned closeSymId; + const cmChar_t* afn; } cmDspAudioFileOut_t; cmDspRC_t _cmDspAudioFileOutCreateFile( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned chCnt ) { - cmDspRC_t rc = kOkDspRC; + cmDspRC_t rc = kOkDspRC; cmDspAudioFileOut_t* p = (cmDspAudioFileOut_t*)inst; const cmChar_t* fn = cmDspStrcz(inst,kFnAofId); if(cmAudioFileIsValid(p->afH) ) cmAudioFileDelete(&p->afH); + // if the supplied audio file name is actually a directory name then generate a file name + if( cmFsIsDir(fn) ) + { + cmMemPtrFree(&p->afn); + + if( cmFsGenFn(fn,"recd","aiff",&p->afn) != kOkFsRC ) + return cmDspInstErr(ctx,&p->inst,kFileSysFailDspRC,"An output audio file name could not be generated."); + + fn = p->afn; + } + if( cmAudioFileIsValid(p->afH = cmAudioFileNewCreate(fn, cmDspSampleRate(ctx), p->bits, chCnt, &rc, ctx->rpt )) == false ) rc = cmDspClassErr(ctx,inst->classPtr,kVarArgParseFailDspRC,"The output audio file '%s' create failed.",fn); @@ -1495,7 +1507,7 @@ cmDspInst_t* _cmDspAudioFileOutAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, u { cmDspVarArg_t args[] = { - { "fn", kFnAofId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Audio file name"}, + { "fn", kFnAofId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "Audio file or directory name"}, { "chs", kChCntAofId, 0, 0, kInDsvFl | kUIntDsvFl | kReqArgDsvFl, "Channel count"}, { "gain0", kGain0AofId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 0 multiplier"}, { "gain1", kGain1AofId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 1 multiplier"}, @@ -1534,7 +1546,7 @@ cmDspRC_t _cmDspAudioFileOutReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDs p->smpCnt = cmDspSamplesPerCycle(ctx) * chCnt; p->smpBuf = cmLhResizeN(ctx->lhH, cmSample_t, p->smpBuf, p->smpCnt); - rc = _cmDspAudioFileOutCreateFile( ctx, inst, chCnt ); + //rc = _cmDspAudioFileOutCreateFile( ctx, inst, chCnt ); return rc; } @@ -1548,6 +1560,10 @@ cmDspRC_t _cmDspAudioFileOutExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp cmSample_t* chArray[chCnt]; unsigned i,j; + if(!cmAudioFileIsValid(p->afH) ) + return rc; + + for(i=0,j=0; iafH) ) cmAudioFileDelete(&p->afH); + cmMemPtrFree(&p->afn); + return kOkDspRC; }