From 7a08ab4793c96f97dcdb0e9bbedd1880657ca951 Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 13 Aug 2013 15:21:42 -0700 Subject: [PATCH] cmProc3.h/c,cmDspFx.c:Added fade in/out times to xfader. --- cmProc3.c | 19 ++++++++++++++++--- cmProc3.h | 7 ++++++- dsp/cmDspFx.c | 23 ++++++++++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cmProc3.c b/cmProc3.c index 38468be..e4dbf80 100644 --- a/cmProc3.c +++ b/cmProc3.c @@ -2033,7 +2033,9 @@ cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* chGateV, bool gateFl = false; // gain change associated with procSmpCnt - cmReal_t dgain = (cmReal_t)procSmpCnt / p->fadeSmpCnt; + //cmReal_t dgain = (cmReal_t)procSmpCnt / p->fadeSmpCnt; + cmReal_t i_dgain = (cmReal_t)procSmpCnt / p->fadeInSmpCnt; + cmReal_t o_dgain = (cmReal_t)procSmpCnt / p->fadeOutSmpCnt; unsigned i; // for each channel @@ -2053,10 +2055,10 @@ cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* chGateV, cmReal_t g = cp->gain; if( cp->gateFl ) - cp->gain = cmMin(cp->gain + dgain,1.0); + cp->gain = cmMin(cp->gain + i_dgain,1.0); else { - cp->gain = cmMax(cp->gain - dgain,0.0); + cp->gain = cmMax(cp->gain - o_dgain,0.0); cp->offFl = g>0.0 && cp->gain==0.0; // notice fade-out transition end } @@ -2100,6 +2102,17 @@ cmRC_t cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV void cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs ) { p->fadeSmpCnt = floor(fadeTimeMs * p->srate /1000.0); + p->fadeInSmpCnt = p->fadeSmpCnt; + p->fadeOutSmpCnt = p->fadeSmpCnt; +} + +void cmXfaderSetXfadeInTime( cmXfader* p, cmReal_t fadeTimeMs ) +{ + p->fadeInSmpCnt = floor(fadeTimeMs * p->srate /1000.0); +} +void cmXfaderSetXfadeOutTime( cmXfader* p, cmReal_t fadeTimeMs ) +{ + p->fadeOutSmpCnt = floor(fadeTimeMs * p->srate /1000.0); } void cmXfaderSelectOne( cmXfader* p, unsigned chIdx ) diff --git a/cmProc3.h b/cmProc3.h index ab2739c..07525b2 100644 --- a/cmProc3.h +++ b/cmProc3.h @@ -310,7 +310,9 @@ extern "C" { cmObj obj; unsigned chCnt; cmXfaderCh* chArray; - unsigned fadeSmpCnt; + unsigned fadeSmpCnt; + unsigned fadeInSmpCnt; + unsigned fadeOutSmpCnt; cmReal_t srate; bool gateFl; // true if any channels are on bool onFl; // true on cycle where gate transitions to 'on'. @@ -324,6 +326,9 @@ extern "C" { cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt ); cmRC_t cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt, const cmSample_t* x[], cmSample_t* y ); void cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs ); + void cmXfaderSetXfadeInTime( cmXfader* p, cmReal_t fadeTimeMs ); + void cmXfaderSetXfadeOutTime( cmXfader* p, cmReal_t fadeTimeMs ); + // Set all gates to false except chIdx. void cmXfaderSelectOne( cmXfader* p, unsigned chIdx ); void cmXfaderAllOff( cmXfader* p ); diff --git a/dsp/cmDspFx.c b/dsp/cmDspFx.c index 3115d96..a41539d 100644 --- a/dsp/cmDspFx.c +++ b/dsp/cmDspFx.c @@ -1417,6 +1417,8 @@ enum kChCntXfId, kFadeTimeMsXfId, kMstrGateXfId, + kFadeInTimeMsXfId, + kFadeOutTimeMsXfId, kOnXfId, kOffXfId, kGateBaseXfId, @@ -1442,11 +1444,13 @@ cmDspInst_t* _cmDspXfaderAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigne { cmDspVarArg_t args[] = { - { "chs", kChCntXfId, 0, 0, kUIntDsvFl | kReqArgDsvFl, "Input and Output channel count"}, - { "ms", kFadeTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade time in milliseonds."}, - { "mgate", kMstrGateXfId, 0, 0, kInDsvFl | kBoolDsvFl | kOptArgDsvFl, "Master gate - can be used to set all gates."}, - { "on", kOnXfId, 0, 0, kOutDsvFl | kSymDsvFl, "Send 'on' when all ch's transition from off to on."}, - { "off", kOffXfId, 0, 0, kOutDsvFl | kSymDsvFl, "Send 'off' when all ch's transition from on to off."}, + { "chs", kChCntXfId, 0, 0, kUIntDsvFl | kReqArgDsvFl, "Input and Output channel count"}, + { "ms", kFadeTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade time in milliseonds."}, + { "mgate", kMstrGateXfId, 0, 0, kInDsvFl | kBoolDsvFl | kOptArgDsvFl, "Master gate - can be used to set all gates."}, + { "ims", kFadeInTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade in time in milliseonds."}, + { "oms", kFadeOutTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade out time in milliseonds."}, + { "on", kOnXfId, 0, 0, kOutDsvFl | kSymDsvFl, "Send 'on' when all ch's transition from off to on."}, + { "off", kOffXfId, 0, 0, kOutDsvFl | kSymDsvFl, "Send 'off' when all ch's transition from on to off."}, }; if( va_cnt < 1 ) @@ -1592,6 +1596,15 @@ cmDspRC_t _cmDspXfaderRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* p->chGateV[i] = fl; } break; + + case kFadeInTimeMsXfId: + cmXfaderSetXfadeInTime(p->xfdp,cmDspDouble(inst,kFadeInTimeMsXfId)); + break; + + case kFadeOutTimeMsXfId: + cmXfaderSetXfadeOutTime(p->xfdp,cmDspDouble(inst,kFadeOutTimeMsXfId)); + break; + } // record gate changes into p->chGateV[] for later use in _cmDspXfaderExec().