Browse Source

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

master
kevin 11 years ago
parent
commit
7a08ab4793
3 changed files with 40 additions and 9 deletions
  1. 16
    3
      cmProc3.c
  2. 6
    1
      cmProc3.h
  3. 18
    5
      dsp/cmDspFx.c

+ 16
- 3
cmProc3.c View File

2033
   bool gateFl = false;
2033
   bool gateFl = false;
2034
 
2034
 
2035
   // gain change associated with procSmpCnt
2035
   // gain change associated with procSmpCnt
2036
-  cmReal_t dgain = (cmReal_t)procSmpCnt / p->fadeSmpCnt; 
2036
+  //cmReal_t dgain   = (cmReal_t)procSmpCnt / p->fadeSmpCnt; 
2037
+  cmReal_t i_dgain = (cmReal_t)procSmpCnt / p->fadeInSmpCnt; 
2038
+  cmReal_t o_dgain = (cmReal_t)procSmpCnt / p->fadeOutSmpCnt;
2037
 
2039
 
2038
   unsigned i;
2040
   unsigned i;
2039
   // for each channel
2041
   // for each channel
2053
     cmReal_t g = cp->gain;
2055
     cmReal_t g = cp->gain;
2054
 
2056
 
2055
     if( cp->gateFl )
2057
     if( cp->gateFl )
2056
-      cp->gain = cmMin(cp->gain + dgain,1.0); 
2058
+      cp->gain = cmMin(cp->gain + i_dgain,1.0); 
2057
     else
2059
     else
2058
     {
2060
     {
2059
-      cp->gain = cmMax(cp->gain - dgain,0.0); 
2061
+      cp->gain = cmMax(cp->gain - o_dgain,0.0); 
2060
       cp->offFl = g>0.0 && cp->gain==0.0; // notice fade-out transition end
2062
       cp->offFl = g>0.0 && cp->gain==0.0; // notice fade-out transition end
2061
     }
2063
     }
2062
 
2064
 
2100
 void      cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs )
2102
 void      cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs )
2101
 {
2103
 {
2102
    p->fadeSmpCnt = floor(fadeTimeMs * p->srate /1000.0); 
2104
    p->fadeSmpCnt = floor(fadeTimeMs * p->srate /1000.0); 
2105
+   p->fadeInSmpCnt = p->fadeSmpCnt;
2106
+   p->fadeOutSmpCnt = p->fadeSmpCnt;
2107
+}
2108
+
2109
+void      cmXfaderSetXfadeInTime( cmXfader* p, cmReal_t fadeTimeMs )
2110
+{
2111
+   p->fadeInSmpCnt = floor(fadeTimeMs * p->srate /1000.0); 
2112
+}
2113
+void      cmXfaderSetXfadeOutTime( cmXfader* p, cmReal_t fadeTimeMs )
2114
+{
2115
+   p->fadeOutSmpCnt = floor(fadeTimeMs * p->srate /1000.0); 
2103
 }
2116
 }
2104
 
2117
 
2105
 void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx )
2118
 void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx )

+ 6
- 1
cmProc3.h View File

310
     cmObj       obj;
310
     cmObj       obj;
311
     unsigned    chCnt;
311
     unsigned    chCnt;
312
     cmXfaderCh* chArray;
312
     cmXfaderCh* chArray;
313
-    unsigned    fadeSmpCnt;    
313
+    unsigned    fadeSmpCnt;  
314
+    unsigned    fadeInSmpCnt;
315
+    unsigned    fadeOutSmpCnt;
314
     cmReal_t    srate;
316
     cmReal_t    srate;
315
     bool        gateFl;  // true if any channels are on
317
     bool        gateFl;  // true if any channels are on
316
     bool        onFl;    // true on cycle where gate transitions to 'on'.
318
     bool        onFl;    // true on cycle where gate transitions to 'on'.
324
   cmRC_t    cmXfaderExec(  cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt );
326
   cmRC_t    cmXfaderExec(  cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt );
325
   cmRC_t    cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt, const cmSample_t* x[], cmSample_t* y );
327
   cmRC_t    cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt, const cmSample_t* x[], cmSample_t* y );
326
   void      cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs );
328
   void      cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs );
329
+  void      cmXfaderSetXfadeInTime( cmXfader* p, cmReal_t fadeTimeMs );
330
+  void      cmXfaderSetXfadeOutTime( cmXfader* p, cmReal_t fadeTimeMs );
331
+
327
   // Set all gates to false except chIdx.
332
   // Set all gates to false except chIdx.
328
   void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
333
   void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
329
   void      cmXfaderAllOff( cmXfader* p );
334
   void      cmXfaderAllOff( cmXfader* p );

+ 18
- 5
dsp/cmDspFx.c View File

1417
   kChCntXfId,
1417
   kChCntXfId,
1418
   kFadeTimeMsXfId,
1418
   kFadeTimeMsXfId,
1419
   kMstrGateXfId,
1419
   kMstrGateXfId,
1420
+  kFadeInTimeMsXfId,
1421
+  kFadeOutTimeMsXfId,
1420
   kOnXfId,
1422
   kOnXfId,
1421
   kOffXfId,
1423
   kOffXfId,
1422
   kGateBaseXfId,
1424
   kGateBaseXfId,
1442
 {
1444
 {
1443
   cmDspVarArg_t args[] =
1445
   cmDspVarArg_t args[] =
1444
   {
1446
   {
1445
-    { "chs",   kChCntXfId,      0, 0,               kUIntDsvFl   | kReqArgDsvFl, "Input and Output channel count"},
1446
-    { "ms",    kFadeTimeMsXfId, 0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl, "Fade time in milliseonds."},
1447
-    { "mgate", kMstrGateXfId,   0, 0,   kInDsvFl  | kBoolDsvFl   | kOptArgDsvFl, "Master gate - can be used to set all gates."},
1448
-    { "on",    kOnXfId,         0, 0,   kOutDsvFl | kSymDsvFl,                   "Send 'on' when all ch's transition from off to on."},
1449
-    { "off",   kOffXfId,        0, 0,   kOutDsvFl | kSymDsvFl,                   "Send 'off' when all ch's transition from on to off."},
1447
+    { "chs",   kChCntXfId,         0, 0,               kUIntDsvFl   | kReqArgDsvFl, "Input and Output channel count"},
1448
+    { "ms",    kFadeTimeMsXfId,    0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl, "Fade time in milliseonds."},
1449
+    { "mgate", kMstrGateXfId,      0, 0,   kInDsvFl  | kBoolDsvFl   | kOptArgDsvFl, "Master gate - can be used to set all gates."},
1450
+    { "ims",   kFadeInTimeMsXfId,  0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl, "Fade in time in milliseonds."},
1451
+    { "oms",   kFadeOutTimeMsXfId, 0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl, "Fade out time in milliseonds."},
1452
+    { "on",    kOnXfId,            0, 0,   kOutDsvFl | kSymDsvFl,                   "Send 'on' when all ch's transition from off to on."},
1453
+    { "off",   kOffXfId,           0, 0,   kOutDsvFl | kSymDsvFl,                   "Send 'off' when all ch's transition from on to off."},
1450
   };
1454
   };
1451
 
1455
 
1452
   if( va_cnt < 1 )
1456
   if( va_cnt < 1 )
1592
           p->chGateV[i] = fl;
1596
           p->chGateV[i] = fl;
1593
       }
1597
       }
1594
       break;
1598
       break;
1599
+
1600
+    case kFadeInTimeMsXfId:
1601
+      cmXfaderSetXfadeInTime(p->xfdp,cmDspDouble(inst,kFadeInTimeMsXfId));
1602
+      break;
1603
+
1604
+    case kFadeOutTimeMsXfId:
1605
+      cmXfaderSetXfadeOutTime(p->xfdp,cmDspDouble(inst,kFadeOutTimeMsXfId));
1606
+      break;
1607
+
1595
   }
1608
   }
1596
   
1609
   
1597
   // record gate changes into p->chGateV[] for later use in _cmDspXfaderExec().
1610
   // record gate changes into p->chGateV[] for later use in _cmDspXfaderExec().

Loading…
Cancel
Save