cmProc3.h/c,cmDspFx.c:Added fade in/out times to xfader.

This commit is contained in:
kevin 2013-08-13 15:21:42 -07:00
parent 13f8d89142
commit 7a08ab4793
3 changed files with 40 additions and 9 deletions

View File

@ -2033,7 +2033,9 @@ cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* chGateV,
bool gateFl = false; bool gateFl = false;
// gain change associated with procSmpCnt // 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; unsigned i;
// for each channel // for each channel
@ -2053,10 +2055,10 @@ cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* chGateV,
cmReal_t g = cp->gain; cmReal_t g = cp->gain;
if( cp->gateFl ) if( cp->gateFl )
cp->gain = cmMin(cp->gain + dgain,1.0); cp->gain = cmMin(cp->gain + i_dgain,1.0);
else 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 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 ) void cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs )
{ {
p->fadeSmpCnt = floor(fadeTimeMs * p->srate /1000.0); 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 ) void cmXfaderSelectOne( cmXfader* p, unsigned chIdx )

View File

@ -311,6 +311,8 @@ extern "C" {
unsigned chCnt; unsigned chCnt;
cmXfaderCh* chArray; cmXfaderCh* chArray;
unsigned fadeSmpCnt; unsigned fadeSmpCnt;
unsigned fadeInSmpCnt;
unsigned fadeOutSmpCnt;
cmReal_t srate; cmReal_t srate;
bool gateFl; // true if any channels are on bool gateFl; // true if any channels are on
bool onFl; // true on cycle where gate transitions to '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 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 ); 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 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. // Set all gates to false except chIdx.
void cmXfaderSelectOne( cmXfader* p, unsigned chIdx ); void cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
void cmXfaderAllOff( cmXfader* p ); void cmXfaderAllOff( cmXfader* p );

View File

@ -1417,6 +1417,8 @@ enum
kChCntXfId, kChCntXfId,
kFadeTimeMsXfId, kFadeTimeMsXfId,
kMstrGateXfId, kMstrGateXfId,
kFadeInTimeMsXfId,
kFadeOutTimeMsXfId,
kOnXfId, kOnXfId,
kOffXfId, kOffXfId,
kGateBaseXfId, kGateBaseXfId,
@ -1442,11 +1444,13 @@ cmDspInst_t* _cmDspXfaderAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigne
{ {
cmDspVarArg_t args[] = cmDspVarArg_t args[] =
{ {
{ "chs", kChCntXfId, 0, 0, kUIntDsvFl | kReqArgDsvFl, "Input and Output channel count"}, { "chs", kChCntXfId, 0, 0, kUIntDsvFl | kReqArgDsvFl, "Input and Output channel count"},
{ "ms", kFadeTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade time in milliseonds."}, { "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."}, { "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."}, { "ims", kFadeInTimeMsXfId, 0, 0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Fade in time in milliseonds."},
{ "off", kOffXfId, 0, 0, kOutDsvFl | kSymDsvFl, "Send 'off' when all ch's transition from on to off."}, { "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 ) if( va_cnt < 1 )
@ -1592,6 +1596,15 @@ cmDspRC_t _cmDspXfaderRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
p->chGateV[i] = fl; p->chGateV[i] = fl;
} }
break; 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(). // record gate changes into p->chGateV[] for later use in _cmDspXfaderExec().