Sfoglia il codice sorgente

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

master
kevin 11 anni fa
parent
commit
7a08ab4793
3 ha cambiato i file con 40 aggiunte e 9 eliminazioni
  1. 16
    3
      cmProc3.c
  2. 6
    1
      cmProc3.h
  3. 18
    5
      dsp/cmDspFx.c

+ 16
- 3
cmProc3.c Vedi File

@@ -2033,7 +2033,9 @@ cmRC_t    cmXfaderExec(  cmXfader* p, unsigned procSmpCnt, const bool* chGateV,
2033 2033
   bool gateFl = false;
2034 2034
 
2035 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 2040
   unsigned i;
2039 2041
   // for each channel
@@ -2053,10 +2055,10 @@ cmRC_t    cmXfaderExec(  cmXfader* p, unsigned procSmpCnt, const bool* chGateV,
2053 2055
     cmReal_t g = cp->gain;
2054 2056
 
2055 2057
     if( cp->gateFl )
2056
-      cp->gain = cmMin(cp->gain + dgain,1.0); 
2058
+      cp->gain = cmMin(cp->gain + i_dgain,1.0); 
2057 2059
     else
2058 2060
     {
2059
-      cp->gain = cmMax(cp->gain - dgain,0.0); 
2061
+      cp->gain = cmMax(cp->gain - o_dgain,0.0); 
2060 2062
       cp->offFl = g>0.0 && cp->gain==0.0; // notice fade-out transition end
2061 2063
     }
2062 2064
 
@@ -2100,6 +2102,17 @@ cmRC_t    cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV
2100 2102
 void      cmXfaderSetXfadeTime( cmXfader* p, cmReal_t fadeTimeMs )
2101 2103
 {
2102 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 2118
 void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx )

+ 6
- 1
cmProc3.h Vedi File

@@ -310,7 +310,9 @@ extern "C" {
310 310
     cmObj       obj;
311 311
     unsigned    chCnt;
312 312
     cmXfaderCh* chArray;
313
-    unsigned    fadeSmpCnt;    
313
+    unsigned    fadeSmpCnt;  
314
+    unsigned    fadeInSmpCnt;
315
+    unsigned    fadeOutSmpCnt;
314 316
     cmReal_t    srate;
315 317
     bool        gateFl;  // true if any channels are on
316 318
     bool        onFl;    // true on cycle where gate transitions to 'on'.
@@ -324,6 +326,9 @@ extern "C" {
324 326
   cmRC_t    cmXfaderExec(  cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt );
325 327
   cmRC_t    cmXfaderExecAudio( cmXfader* p, unsigned procSmpCnt, const bool* gateV, unsigned chCnt, const cmSample_t* x[], cmSample_t* y );
326 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 332
   // Set all gates to false except chIdx.
328 333
   void      cmXfaderSelectOne( cmXfader* p, unsigned chIdx );
329 334
   void      cmXfaderAllOff( cmXfader* p );

+ 18
- 5
dsp/cmDspFx.c Vedi File

@@ -1417,6 +1417,8 @@ enum
1417 1417
   kChCntXfId,
1418 1418
   kFadeTimeMsXfId,
1419 1419
   kMstrGateXfId,
1420
+  kFadeInTimeMsXfId,
1421
+  kFadeOutTimeMsXfId,
1420 1422
   kOnXfId,
1421 1423
   kOffXfId,
1422 1424
   kGateBaseXfId,
@@ -1442,11 +1444,13 @@ cmDspInst_t*  _cmDspXfaderAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigne
1442 1444
 {
1443 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 1456
   if( va_cnt < 1 )
@@ -1592,6 +1596,15 @@ cmDspRC_t _cmDspXfaderRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
1592 1596
           p->chGateV[i] = fl;
1593 1597
       }
1594 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 1610
   // record gate changes into p->chGateV[] for later use in _cmDspXfaderExec().

Loading…
Annulla
Salva