Browse Source

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

addition of cmXFaderJumpToDestinationGain().
master
kevin 11 years ago
parent
commit
29c10b0a88
2 changed files with 20 additions and 3 deletions
  1. 17
    1
      cmProc3.c
  2. 3
    2
      cmProc3.h

+ 17
- 1
cmProc3.c View File

2057
     if( cp->gateFl )
2057
     if( cp->gateFl )
2058
     {
2058
     {
2059
       cp->gain = cmMin(cp->gain + i_dgain,1.0); 
2059
       cp->gain = cmMin(cp->gain + i_dgain,1.0); 
2060
-      cp->ep_gain = sqrt(0.5 + 0.5 * cos(3.14159*cp->gain));
2060
+      cp->ep_gain = sqrt(0.5 - 0.5 * cos(3.14159*cp->gain));
2061
     }
2061
     }
2062
     else
2062
     else
2063
     {
2063
     {
2133
     p->chArray[i].gateFl = false;
2133
     p->chArray[i].gateFl = false;
2134
 }
2134
 }
2135
 
2135
 
2136
+void      cmXfaderJumpToDestinationGain( cmXfader* p )
2137
+{
2138
+  unsigned i = 0;
2139
+  for(i=0; i<p->chCnt; ++i)
2140
+  {
2141
+    if( p->chArray[i].gateFl )
2142
+      p->chArray[i].gain = 1.0;
2143
+    else
2144
+      p->chArray[i].gain = 0.0;
2145
+
2146
+    p->chArray[i].onFl = false;
2147
+    p->chArray[i].offFl = false;
2148
+    p->chArray[i].ep_gain = p->chArray[i].gain;
2149
+  }
2150
+}
2151
+
2136
 //==========================================================================================================================================
2152
 //==========================================================================================================================================
2137
 cmFader*  cmFaderAlloc( cmCtx*c, cmFader* p, cmReal_t srate, cmReal_t fadeTimeMs  )
2153
 cmFader*  cmFaderAlloc( cmCtx*c, cmFader* p, cmReal_t srate, cmReal_t fadeTimeMs  )
2138
 {
2154
 {

+ 3
- 2
cmProc3.h View File

299
   // to the audio signal - unless you use cmXfaderExecAudio()
299
   // to the audio signal - unless you use cmXfaderExecAudio()
300
   typedef struct
300
   typedef struct
301
   {
301
   {
302
-    cmReal_t ep_gain;
303
-    cmReal_t gain;
302
+    cmReal_t ep_gain; // equal power xfade gain
303
+    cmReal_t gain;    // linear gain
304
     bool     gateFl; // true if channel is on
304
     bool     gateFl; // true if channel is on
305
     bool     onFl;   // true if gateFl transitioned to true on this cycle  
305
     bool     onFl;   // true if gateFl transitioned to true on this cycle  
306
     bool     offFl;  // true if gateFl transitioned to false on this cycle
306
     bool     offFl;  // true if gateFl transitioned to false on this cycle
333
   // Set all gates to false except chIdx.
333
   // Set all gates to false except chIdx.
334
   void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
334
   void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
335
   void      cmXfaderAllOff( cmXfader* p );
335
   void      cmXfaderAllOff( cmXfader* p );
336
+  void      cmXfaderJumpToDestinationGain( cmXfader* p ); // jump to dest. gain based on gate state
336
 
337
 
337
   //=======================================================================================================================
338
   //=======================================================================================================================
338
   // This fader object accepts a gate signal. When the gate is high it increments
339
   // This fader object accepts a gate signal. When the gate is high it increments

Loading…
Cancel
Save