cmProc3.h/c : Changes to cmXFader to implement equal power cross-fade and

addition of cmXFaderJumpToDestinationGain().
This commit is contained in:
kevin 2013-11-03 11:50:03 -08:00
parent a690102601
commit 29c10b0a88
2 changed files with 20 additions and 3 deletions

View File

@ -2057,7 +2057,7 @@ cmRC_t cmXfaderExec( cmXfader* p, unsigned procSmpCnt, const bool* chGateV,
if( cp->gateFl )
{
cp->gain = cmMin(cp->gain + i_dgain,1.0);
cp->ep_gain = sqrt(0.5 + 0.5 * cos(3.14159*cp->gain));
cp->ep_gain = sqrt(0.5 - 0.5 * cos(3.14159*cp->gain));
}
else
{
@ -2133,6 +2133,22 @@ void cmXfaderAllOff( cmXfader* p )
p->chArray[i].gateFl = false;
}
void cmXfaderJumpToDestinationGain( cmXfader* p )
{
unsigned i = 0;
for(i=0; i<p->chCnt; ++i)
{
if( p->chArray[i].gateFl )
p->chArray[i].gain = 1.0;
else
p->chArray[i].gain = 0.0;
p->chArray[i].onFl = false;
p->chArray[i].offFl = false;
p->chArray[i].ep_gain = p->chArray[i].gain;
}
}
//==========================================================================================================================================
cmFader* cmFaderAlloc( cmCtx*c, cmFader* p, cmReal_t srate, cmReal_t fadeTimeMs )
{

View File

@ -299,8 +299,8 @@ extern "C" {
// to the audio signal - unless you use cmXfaderExecAudio()
typedef struct
{
cmReal_t ep_gain;
cmReal_t gain;
cmReal_t ep_gain; // equal power xfade gain
cmReal_t gain; // linear gain
bool gateFl; // true if channel is on
bool onFl; // true if gateFl transitioned to true on this cycle
bool offFl; // true if gateFl transitioned to false on this cycle
@ -333,6 +333,7 @@ extern "C" {
// Set all gates to false except chIdx.
void cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
void cmXfaderAllOff( cmXfader* p );
void cmXfaderJumpToDestinationGain( cmXfader* p ); // jump to dest. gain based on gate state
//=======================================================================================================================
// This fader object accepts a gate signal. When the gate is high it increments