Pārlūkot izejas kodu

Merge branch 'master' of klarke.webfactional.com:webapps/gitweb/repos/libcm

master
kevin 7 gadus atpakaļ
vecāks
revīzija
98cef5668f
7 mainītis faili ar 679 papildinājumiem un 6 dzēšanām
  1. 6
    1
      app/cmScore.c
  2. 200
    3
      cmProc2.c
  3. 38
    0
      cmProc2.h
  4. 2
    1
      dsp/cmDspBuiltIn.c
  5. 246
    0
      dsp/cmDspKr.c
  6. 1
    0
      dsp/cmDspKr.h
  7. 186
    1
      dsp/cmDspPgmKrChain.c

+ 6
- 1
app/cmScore.c Parādīt failu

@@ -764,7 +764,12 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned
764 764
     return cmErrMsg(&p->err,kSyntaxErrScRC,"Unable to convert the scientific pitch '%s' to a MIDI value. ");
765 765
 
766 766
   if((midiVel = cmCsvCellUInt( p->cH,rowIdx,kD1ColScIdx)) >= kInvalidMidiVelocity )
767
-    return cmErrMsg(&p->err,kSyntaxErrScRC,"An invalid MIDI velocity (%i) was encountered.",midiVel);
767
+  {
768
+    //return cmErrMsg(&p->err,kSyntaxErrScRC,"An invalid MIDI velocity (%i) was encountered.",midiVel);
769
+    midiVel = 64;
770
+    cmErrWarnMsg(&p->err,kSyntaxErrScRC,"An invalilid MIDI velocity (%i) was encountered.",midiVel);
771
+  }
772
+    
768 773
   
769 774
   // get the sec's field - or DBL_MAX if it is not set
770 775
   if((secs =  cmCsvCellDouble(p->cH, rowIdx, kSecsColScIdx )) == DBL_MAX) // Returns DBL_MAX on error.

+ 200
- 3
cmProc2.c Parādīt failu

@@ -2498,10 +2498,10 @@ cmRC_t  cmPvSynDoIt( cmPvSyn* p, const cmSample_t* v )
2498 2498
   return cmOkRC;
2499 2499
 }
2500 2500
 
2501
-
2502 2501
 const cmSample_t* cmPvSynExecOut(cmPvSyn* p )
2503 2502
 { return cmOlaExecOut(&p->ola); }
2504 2503
 
2504
+
2505 2505
 //------------------------------------------------------------------------------------------------------------
2506 2506
 cmMidiSynth* cmMidiSynthAlloc( cmCtx* ctx, cmMidiSynth* ap, const cmMidiSynthPgm* pgmArray, unsigned pgmCnt, unsigned voiceCnt, unsigned procSmpCnt, unsigned outChCnt, cmReal_t srate  )
2507 2507
 {
@@ -5947,9 +5947,9 @@ cmRC_t      cmExpanderBankExecD( cmExpanderBank* p, double* x, unsigned bandN )
5947 5947
 cmSpecDist_t* cmSpecDistAlloc( cmCtx* ctx,cmSpecDist_t* ap, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId  )
5948 5948
 {
5949 5949
   cmSpecDist_t* p = cmObjAlloc( cmSpecDist_t, ctx, ap );
5950
-
5950
+  
5951 5951
   //p->iSpecVa   = cmVectArrayAlloc(ctx,kRealVaFl);
5952
-  //p->oSpecVa   = cmVectArrayAlloc(ctx,kRealVaFl);
5952
+  //p->oSpecVa   = cmVectArrayAlloc(ctx,kRealVaFl);  
5953 5953
   p->statVa     = cmVectArrayAlloc(ctx,kDoubleVaFl);
5954 5954
   
5955 5955
   if( procSmpCnt != 0 )
@@ -6459,6 +6459,203 @@ const cmSample_t* cmSpecDistOut(  cmSpecDist_t* p )
6459 6459
   return cmPvSynExecOut(p->pvs); 
6460 6460
 }
6461 6461
 
6462
+
6463
+//------------------------------------------------------------------------------------------------------------
6464
+cmSpecDist2_t* cmSpecDist2Alloc( cmCtx* ctx,cmSpecDist2_t* ap, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId  )
6465
+{
6466
+  cmSpecDist2_t* p = cmObjAlloc( cmSpecDist2_t, ctx, ap );
6467
+
6468
+  if( procSmpCnt != 0 )
6469
+  {
6470
+    if( cmSpecDist2Init( p, procSmpCnt, srate, wndSmpCnt, hopFcmt, olaWndTypeId ) != cmOkRC )
6471
+      cmSpecDist2Free(&p);
6472
+  }
6473
+
6474
+  return p;
6475
+
6476
+}
6477
+
6478
+cmRC_t cmSpecDist2Free( cmSpecDist2_t** pp )
6479
+{
6480
+  if( pp == NULL || *pp == NULL )
6481
+    return cmOkRC;
6482
+
6483
+  cmSpecDist2_t* p = *pp;
6484
+  
6485
+  cmSpecDist2Final(p);
6486
+  cmObjFree(pp);
6487
+  return cmOkRC;
6488
+
6489
+}
6490
+
6491
+cmRC_t cmSpecDist2Init( cmSpecDist2_t* p, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId  )
6492
+{
6493
+  cmRC_t rc;
6494
+  if((rc = cmSpecDist2Final(p)) != cmOkRC )
6495
+    return rc;
6496
+
6497
+  unsigned flags = 0;
6498
+
6499
+
6500
+  p->srate        = srate;
6501
+  p->wndSmpCnt    = wndSmpCnt;
6502
+  p->hopSmpCnt    = (unsigned)floor(wndSmpCnt/hopFcmt);
6503
+  p->procSmpCnt   = procSmpCnt;
6504
+
6505
+  p->ceiling      = 30;
6506
+  p->expo         = 2.0;
6507
+    
6508
+  p->thresh       = 60;
6509
+  p->uprSlope     = 0.0;
6510
+  p->lwrSlope     = 2.0;
6511
+
6512
+  p->mix          = 0.0;
6513
+
6514
+  p->pva = cmPvAnlAlloc(  p->obj.ctx, NULL, procSmpCnt, srate, wndSmpCnt, p->hopSmpCnt, flags );
6515
+  p->pvs = cmPvSynAlloc(  p->obj.ctx, NULL, procSmpCnt, srate, wndSmpCnt, p->hopSmpCnt, olaWndTypeId );
6516
+
6517
+
6518
+  return rc;
6519
+}
6520
+
6521
+cmRC_t cmSpecDist2Final(cmSpecDist2_t* p )
6522
+{
6523
+  cmRC_t rc = cmOkRC;
6524
+
6525
+  
6526
+  cmPvAnlFree(&p->pva);
6527
+  cmPvSynFree(&p->pvs);
6528
+  return rc;
6529
+}
6530
+
6531
+void _cmSpecDist2Bump( cmSpecDist2_t* p, cmReal_t* x, unsigned binCnt, double thresh, double expo)
6532
+{
6533
+  unsigned i     = 0;  
6534
+  double   minDb = -100.0;
6535
+  
6536
+  thresh = -fabs(thresh);
6537
+
6538
+  for(i=0; i<binCnt; ++i)
6539
+  {
6540
+    double y;
6541
+
6542
+    if( x[i] < minDb )
6543
+      x[i] = minDb;
6544
+
6545
+    if( x[i] > thresh )
6546
+      y = 1;
6547
+    else
6548
+    {
6549
+      y  = (minDb - x[i])/(minDb - thresh);  
6550
+      y += y - pow(y,expo);
6551
+    }
6552
+
6553
+    x[i] = minDb + (-minDb) * y;
6554
+
6555
+  }  
6556
+}
6557
+
6558
+void _cmSpecDist2BasicMode(cmSpecDist2_t* p, cmReal_t* X1m, unsigned binCnt, cmReal_t thresh, double upr, double lwr )
6559
+{
6560
+
6561
+  unsigned i=0;
6562
+
6563
+  if( lwr < 0.3 )
6564
+    lwr = 0.3;
6565
+
6566
+  for(i=0; i<binCnt; ++i)
6567
+  {
6568
+    cmReal_t a = fabs(X1m[i]);
6569
+    cmReal_t d = a - thresh;
6570
+
6571
+    X1m[i] = -thresh;
6572
+
6573
+    if( d > 0 )
6574
+      X1m[i] -= (lwr*d);
6575
+    else
6576
+      X1m[i] -= (upr*d);
6577
+  }
6578
+
6579
+}
6580
+
6581
+cmRC_t  cmSpecDist2Exec( cmSpecDist2_t* p, const cmSample_t* sp, unsigned sn )
6582
+{
6583
+
6584
+  assert( sn == p->procSmpCnt );
6585
+
6586
+  unsigned binN = p->pva->binCnt;
6587
+
6588
+  // cmPvAnlExec() returns true when it calc's a new spectral output frame
6589
+  if( cmPvAnlExec( p->pva, sp, sn ) )
6590
+  {
6591
+    cmReal_t X0m[binN];
6592
+    cmReal_t X1m[binN]; 
6593
+
6594
+    // take the mean of the the input magntitude spectrum
6595
+    cmReal_t u0 = cmVOR_Mean(p->pva->magV,binN);
6596
+
6597
+    // convert magnitude to db (range=-1000.0 to 0.0)
6598
+    cmVOR_AmplToDbVV(X0m, binN, p->pva->magV, -1000.0 );
6599
+    cmVOR_Copy(X1m,binN,X0m);
6600
+
6601
+    // bump transform X0m
6602
+    _cmSpecDist2Bump(p,X0m, binN, p->ceiling, p->expo);
6603
+
6604
+    // xfade bump output with raw input: X1m = (X0m*mix) + (X1m*(1.0-mix))
6605
+    cmVOR_MultVS(X0m,binN,p->mix);
6606
+    cmVOR_MultVS(X1m,binN,1.0 - p->mix );
6607
+    cmVOR_AddVV(X1m,binN,X0m);
6608
+
6609
+    // basic transform 
6610
+    _cmSpecDist2BasicMode(p,X1m,binN,p->thresh,p->uprSlope,p->lwrSlope);
6611
+    
6612
+    // convert db back to magnitude
6613
+    cmVOR_DbToAmplVV(X1m, binN, X1m );
6614
+
6615
+
6616
+    // convert the mean input magnitude to db
6617
+    cmReal_t idb = 20*log10(u0);
6618
+    
6619
+    // get the mean output magnitude spectra
6620
+    cmReal_t u1 = cmVOR_Mean(X1m,binN);
6621
+
6622
+    if( idb > -150.0 )
6623
+    {
6624
+      // set the output gain such that the mean output magnitude
6625
+      // will match the mean input magnitude
6626
+      p->ogain = u0/u1;  
6627
+    }
6628
+    else
6629
+    {
6630
+      cmReal_t a0 = 0.9;
6631
+      p->ogain *= a0;
6632
+    }
6633
+
6634
+    // apply the output gain
6635
+    cmVOR_MultVS(X1m,binN,cmMin(4.0,p->ogain));
6636
+
6637
+
6638
+    // convert back to time domain
6639
+    cmPvSynExec(p->pvs, X1m, p->pva->phsV );
6640
+  
6641
+    p->fi += 1;
6642
+  }
6643
+ 
6644
+  return cmOkRC;
6645
+}
6646
+
6647
+
6648
+const cmSample_t* cmSpecDist2Out(  cmSpecDist2_t* p )
6649
+{ 
6650
+  return cmPvSynExecOut(p->pvs); 
6651
+}
6652
+
6653
+void  cmSpecDist2Report( cmSpecDist2_t* p )
6654
+{
6655
+  printf("ceil:%f expo:%f mix:%f thresh:%f upr:%f lwr:%f\n", p->ceiling,p->expo,p->mix,p->thresh,p->lwrSlope,p->uprSlope);
6656
+}
6657
+
6658
+
6462 6659
 //------------------------------------------------------------------------------------------------------------
6463 6660
 
6464 6661
 cmRC_t _cmBinMtxFileWriteHdr( cmBinMtxFile_t* p )

+ 38
- 0
cmProc2.h Parādīt failu

@@ -1313,6 +1313,44 @@ extern "C" {
1313 1313
 
1314 1314
   //------------------------------------------------------------------------------------------------------------
1315 1315
   //)
1316
+
1317
+  //( { label:cmSpecDist file_desc:"Spectral distortion 2 algorithm based on non-linear transform." kw:[proc]}    
1318
+
1319
+  typedef struct
1320
+  {
1321
+    cmObj    obj;
1322
+    double   srate;
1323
+    unsigned wndSmpCnt;
1324
+    unsigned hopFcmt;
1325
+    unsigned hopSmpCnt;
1326
+    unsigned procSmpCnt;
1327
+    
1328
+    cmPvAnl* pva;
1329
+    cmPvSyn* pvs;
1330
+
1331
+    double   ceiling;
1332
+    double   expo;    
1333
+    double   mix;
1334
+    double   thresh;
1335
+    double   uprSlope;
1336
+    double   lwrSlope;
1337
+
1338
+    cmReal_t ogain;
1339
+
1340
+    unsigned       fi;          // total count of frames processed by cmSpecDistExec()
1341
+
1342
+  } cmSpecDist2_t;
1343
+
1344
+  cmSpecDist2_t*    cmSpecDist2Alloc( cmCtx* ctx,cmSpecDist2_t* ap, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId  ); 
1345
+  cmRC_t            cmSpecDist2Free( cmSpecDist2_t** pp );
1346
+  cmRC_t            cmSpecDist2Init( cmSpecDist2_t* p, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId  );
1347
+  cmRC_t            cmSpecDist2Final(cmSpecDist2_t* p );
1348
+  cmRC_t            cmSpecDist2Exec( cmSpecDist2_t* p, const cmSample_t* sp, unsigned sn );
1349
+  const cmSample_t* cmSpecDist2Out(  cmSpecDist2_t* p );
1350
+  void              cmSpecDist2Report( cmSpecDist2_t* p );
1351
+  
1352
+  //------------------------------------------------------------------------------------------------------------
1353
+  //)
1316 1354
   
1317 1355
   //( { label:cmBinMtxFile file_desc:"Write a binary matrix which can be read by readBinFile.m." kw:[proc]}
1318 1356
   

+ 2
- 1
dsp/cmDspBuiltIn.c Parādīt failu

@@ -5481,7 +5481,8 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
5481 5481
   cmBcastSymClassCons,
5482 5482
   cmSegLineClassCons,
5483 5483
 
5484
-  cmKrClassCons,  
5484
+  cmKrClassCons,
5485
+  cmKr2ClassCons,
5485 5486
   cmTimeLineClassCons,
5486 5487
   cmScoreClassCons,
5487 5488
   cmMidiFilePlayClassCons,

+ 246
- 0
dsp/cmDspKr.c Parādīt failu

@@ -283,6 +283,252 @@ cmDspClass_t* cmKrClassCons( cmDspCtx_t* ctx )
283 283
 
284 284
 //------------------------------------------------------------------------------------------------------------
285 285
 //)
286
+//( { label:cmDspKr2 file_desc:"Spectral non-linear distortion effect." kw:[sunit] }
287
+
288
+enum
289
+{
290
+  kWndSmpCntKr2Id,
291
+  kHopFactKr2Id,
292
+  
293
+  kCeilKr2Id,
294
+  kExpoKr2Id,
295
+  
296
+  kThreshKr2Id,
297
+  kLwrSlopeKr2Id,
298
+  kUprSlopeKr2Id,
299
+
300
+  kMixKr2Id,
301
+
302
+  kWetKr2Id,
303
+  kAudioInKr2Id,
304
+  kAudioOutKr2Id
305
+};
306
+
307
+typedef struct
308
+{
309
+  cmDspInst_t   inst;
310
+  cmCtx*        ctx;
311
+  cmSpecDist2_t* sdp;
312
+} cmDspKr2_t;
313
+ 
314
+cmDspClass_t _cmKr2DC;
315
+
316
+
317
+cmDspInst_t*  _cmDspKr2Alloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
318
+{
319
+  cmDspVarArg_t args[] =
320
+  {
321
+    { "wndn",    kWndSmpCntKr2Id,   0, 0,   kInDsvFl  | kUIntDsvFl   | kReqArgDsvFl,   "Window sample count"   },
322
+    { "hopf",    kHopFactKr2Id,     0, 0,   kInDsvFl  | kUIntDsvFl   | kOptArgDsvFl,   "Hop factor" },
323
+    
324
+    { "ceil",    kCeilKr2Id,     0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Ceiling" },
325
+    { "expo",    kExpoKr2Id,        0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Exponent" },
326
+    
327
+    { "thrh",    kThreshKr2Id,      0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Threshold" },
328
+    { "lwrs",    kLwrSlopeKr2Id,    0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Lower Slope"},
329
+    { "uprs",    kUprSlopeKr2Id,    0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Upper Slope"},
330
+
331
+    { "mix",     kMixKr2Id,         0, 0,   kInDsvFl  | kDoubleDsvFl | kOptArgDsvFl,   "Mix"},
332
+    
333
+    { "wet",     kWetKr2Id,         0, 0,   kInDsvFl  | kSampleDsvFl,                  "Wet mix level."},
334
+    { "in",      kAudioInKr2Id,     0, 0,   kInDsvFl  | kAudioBufDsvFl, "Audio Input" },
335
+    { "out",     kAudioOutKr2Id,    0, 1,   kOutDsvFl | kAudioBufDsvFl, "Audio Output" },
336
+    { NULL, 0, 0, 0, 0 }
337
+  };
338
+
339
+  cmDspKr2_t* p           = cmDspInstAlloc(cmDspKr2_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
340
+  unsigned   defWndSmpCnt = cmDspDefaultUInt(&p->inst,kWndSmpCntKr2Id);
341
+  unsigned   wndSmpCnt    = cmNextPowerOfTwo( defWndSmpCnt );
342
+  
343
+  cmDspSetDefaultUInt(   ctx,&p->inst, kWndSmpCntKr2Id, defWndSmpCnt, wndSmpCnt );
344
+  cmDspSetDefaultUInt(   ctx,&p->inst, kHopFactKr2Id,  0, 4 );
345
+  
346
+  cmDspSetDefaultDouble( ctx,&p->inst, kCeilKr2Id,  0, 20.0 );
347
+  cmDspSetDefaultDouble( ctx,&p->inst, kExpoKr2Id,     0,  2.0 );
348
+
349
+  cmDspSetDefaultDouble( ctx,&p->inst, kThreshKr2Id,   0, 60.0 );
350
+  cmDspSetDefaultDouble( ctx,&p->inst, kLwrSlopeKr2Id, 0, 2.0 );
351
+  cmDspSetDefaultDouble( ctx,&p->inst, kUprSlopeKr2Id, 0, 0.0 );
352
+  
353
+  cmDspSetDefaultDouble( ctx,&p->inst, kMixKr2Id,      0, 0.0 );
354
+  
355
+  cmDspSetDefaultSample( ctx,&p->inst, kWetKr2Id,      0, 1.0);
356
+
357
+  //_cmDspKr2CmInit(ctx,p); // initialize the cm library
358
+
359
+  p->ctx = cmCtxAlloc(NULL,ctx->rpt,ctx->lhH,ctx->stH);
360
+
361
+  return &p->inst;
362
+}
363
+
364
+cmDspRC_t _cmDspKr2Free(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
365
+{
366
+  cmDspRC_t rc = kOkDspRC;
367
+  cmDspKr2_t* p = (cmDspKr2_t*)inst;
368
+
369
+  cmSpecDist2Free(&p->sdp);
370
+
371
+  cmCtxFree(&p->ctx);
372
+  //_cmDspKr2CmFinal(ctx,p);  // finalize the cm library
373
+
374
+  return rc;
375
+}
376
+
377
+
378
+cmDspRC_t _cmDspKr2Setup(cmDspCtx_t* ctx, cmDspKr2_t* p )
379
+{
380
+  cmDspRC_t rc           = kOkDspRC;
381
+  unsigned  wndSmpCnt    = cmDspUInt(&p->inst,kWndSmpCntKr2Id);
382
+  unsigned  hopFact      = cmDspUInt(&p->inst,kHopFactKr2Id);
383
+  unsigned  olaWndTypeId =kHannWndId;
384
+
385
+  cmSpecDist2Free(&p->sdp);
386
+
387
+  p->sdp = cmSpecDist2Alloc(p->ctx, NULL, cmDspSamplesPerCycle(ctx), cmDspSampleRate(ctx), wndSmpCnt, hopFact, olaWndTypeId);
388
+
389
+  assert(p->sdp != NULL );
390
+
391
+  if((rc = cmDspZeroAudioBuf(ctx,&p->inst,kAudioOutKr2Id)) != kOkDspRC )
392
+    return rc;
393
+  
394
+  return rc;
395
+}
396
+
397
+
398
+cmDspRC_t _cmDspKr2Reset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
399
+{
400
+  cmDspKr2_t*   p  = (cmDspKr2_t*)inst;
401
+  cmDspRC_t    rc;
402
+
403
+  if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
404
+    return rc;
405
+
406
+  return _cmDspKr2Setup(ctx,p);
407
+}
408
+
409
+cmDspRC_t _cmDspKr2Exec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
410
+{
411
+  cmDspKr2_t* p = (cmDspKr2_t*)inst;
412
+  cmDspRC_t rc = kOkDspRC;
413
+
414
+  unsigned          iChIdx  = 0;
415
+  const cmSample_t* ip      = cmDspAudioBuf(ctx,inst,kAudioInKr2Id,iChIdx);
416
+  unsigned          iSmpCnt = cmDspVarRows(inst,kAudioInKr2Id);
417
+
418
+  // if no connected
419
+  if( iSmpCnt == 0 )
420
+    return rc;
421
+  
422
+  unsigned          oChIdx  = 0;
423
+  cmSample_t*       op      = cmDspAudioBuf(ctx,inst,kAudioOutKr2Id,oChIdx);
424
+  unsigned          oSmpCnt = cmDspVarRows(inst,kAudioOutKr2Id);
425
+  const cmSample_t* sp;
426
+
427
+  cmSample_t wet = cmDspSample(inst,kWetKr2Id);
428
+
429
+  cmSpecDist2Exec(p->sdp,ip,iSmpCnt);
430
+  
431
+  if((sp = cmSpecDist2Out(p->sdp)) != NULL )
432
+  {
433
+    cmVOS_MultVVS(op,oSmpCnt,sp,wet);
434
+  }
435
+
436
+  if( wet<1.0 )
437
+    cmVOS_MultSumVVS(op,oSmpCnt,ip,1.0-wet);
438
+
439
+  return rc;
440
+}
441
+
442
+cmDspRC_t _cmDspKr2Recv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
443
+{
444
+  cmDspKr2_t* p = (cmDspKr2_t*)inst;
445
+  cmDspRC_t rc = kOkDspRC;
446
+
447
+
448
+  cmDspSetEvent(ctx,inst,evt);
449
+
450
+  switch( evt->dstVarId )
451
+  {
452
+    case kWndSmpCntKr2Id:
453
+    case kHopFactKr2Id:
454
+      _cmDspKr2Setup(ctx,p);
455
+
456
+      // THIS IS A HACK
457
+      // WHEN WND OR HOP CHANGE THE RESULTING CHANGES
458
+      // SHOULD BE ISOLATED IN cmSpecDist() AND THE
459
+      // CURRENT STATE OF THE PARAMETERS SHOULD NOT BE
460
+      // LOST - IF THE CHANGES WERE ISOLATED WITHIN PVANL 
461
+      // AND PVSYN IT MIGHT BE POSSIBLE TO DO WITH 
462
+      // MINIMAL AUDIO INTERUPTION.
463
+
464
+
465
+      p->sdp->ceiling   = cmDspDouble(inst,kCeilKr2Id);   
466
+      p->sdp->expo      = cmDspDouble(inst,kExpoKr2Id);   
467
+      
468
+      p->sdp->thresh   = cmDspDouble(inst,kThreshKr2Id);   
469
+      p->sdp->uprSlope = cmDspDouble(inst,kUprSlopeKr2Id); 
470
+      p->sdp->lwrSlope = cmDspDouble(inst,kLwrSlopeKr2Id); 
471
+
472
+      p->sdp->mix      = cmDspDouble(inst,kMixKr2Id);
473
+      
474
+      printf("wsn:%i hsn:%i\n",p->sdp->wndSmpCnt,p->sdp->hopSmpCnt);
475
+      break;
476
+
477
+    case kCeilKr2Id:     
478
+      p->sdp->ceiling  = cmDspDouble(inst,kCeilKr2Id);   
479
+      break;
480
+    
481
+    case kExpoKr2Id:     
482
+      p->sdp->expo  = cmDspDouble(inst,kExpoKr2Id);   
483
+      break;
484
+      
485
+    case kThreshKr2Id:     
486
+      p->sdp->thresh   = cmDspDouble(inst,kThreshKr2Id);   
487
+      break;
488
+
489
+    case kUprSlopeKr2Id:   
490
+      p->sdp->uprSlope = cmDspDouble(inst,kUprSlopeKr2Id); 
491
+      break;
492
+
493
+    case kLwrSlopeKr2Id:   
494
+      p->sdp->lwrSlope = cmDspDouble(inst,kLwrSlopeKr2Id); 
495
+      break;
496
+
497
+    case kMixKr2Id:   
498
+      p->sdp->mix = cmDspDouble(inst,kMixKr2Id); 
499
+      break;
500
+
501
+      
502
+    case kWetKr2Id:
503
+      break;
504
+
505
+    default:
506
+      { assert(0); }
507
+  }
508
+
509
+  cmSpecDist2Report(p->sdp);
510
+  
511
+  return rc;
512
+}
513
+
514
+cmDspClass_t* cmKr2ClassCons( cmDspCtx_t* ctx )
515
+{
516
+  cmDspClassSetup(&_cmKr2DC,ctx,"Kr2",
517
+    NULL,
518
+    _cmDspKr2Alloc,
519
+    _cmDspKr2Free,
520
+    _cmDspKr2Reset,
521
+    _cmDspKr2Exec,
522
+    _cmDspKr2Recv,
523
+    NULL,NULL,
524
+    "Fourier based non-linear transformer two.");
525
+
526
+  return &_cmKr2DC;
527
+}
528
+
529
+
530
+//------------------------------------------------------------------------------------------------------------
531
+//)
286 532
 //( { label:cmDspTimeLine file_desc:"Time line user interface unit." kw:[sunit] }
287 533
 
288 534
 enum

+ 1
- 0
dsp/cmDspKr.h Parādīt failu

@@ -6,6 +6,7 @@ extern "C" {
6 6
 #endif
7 7
 
8 8
   struct cmDspClass_str* cmKrClassCons( cmDspCtx_t* ctx );
9
+  struct cmDspClass_str* cmKr2ClassCons( cmDspCtx_t* ctx );
9 10
   struct cmDspClass_str* cmTimeLineClassCons( cmDspCtx_t* ctx );
10 11
   struct cmDspClass_str* cmScoreClassCons( cmDspCtx_t* ctx );
11 12
   struct cmDspClass_str* cmMidiFilePlayClassCons( cmDspCtx_t* ctx );

+ 186
- 1
dsp/cmDspPgmKrChain.c Parādīt failu

@@ -36,6 +36,9 @@
36 36
 
37 37
 #include "cmDspPgmKrChain.h"
38 38
 
39
+#undef KR2
40
+
41
+
39 42
 cmDspRC_t krLoadRsrc(cmDspSysH_t h, cmErr_t* err, krRsrc_t* r)
40 43
 {
41 44
   cmDspRC_t rc;
@@ -71,7 +74,7 @@ const cmChar_t* _mlbl(const cmChar_t* prefix, unsigned ch )
71 74
 #define mlbl(a)  _mlbl(a,mch)
72 75
 #define lbl(a) cmDspSysPrintLabel(a,ach)
73 76
 
74
-
77
+#ifndef KR2
75 78
 void _cmDspSys_TlXformChain( cmDspSysH_t h, cmDspTlXform_t* c,  unsigned preGrpSymId, unsigned cmpPreGrpSymId, cmDspInst_t* modp, unsigned ach, unsigned mch )
76 79
 {
77 80
   unsigned        measRtrChCnt = 6; // note: router channel 6 is not connected
@@ -361,4 +364,186 @@ void _cmDspSys_TlXformChain( cmDspSysH_t h, cmDspTlXform_t* c,  unsigned preGrpS
361 364
   c->cmp   = cmp; 
362 365
 
363 366
 }
367
+#endif
368
+
369
+//=======================================================================================================================
370
+//=======================================================================================================================
371
+//  KR2 Modeless Transform based on cmDspKr2 and cmSpecDist2
372
+//=======================================================================================================================
373
+//=======================================================================================================================
374
+
375
+#ifdef KR2
376
+void _cmDspSys_TlXformChain( cmDspSysH_t h, cmDspTlXform_t* c,  unsigned preGrpSymId, unsigned cmpPreGrpSymId, cmDspInst_t* modp, unsigned ach, unsigned mch )
377
+{
378
+  unsigned        measRtrChCnt = 6; // note: router channel 6 is not connected
379
+    
380
+  int             krWndSmpCnt = 2048;
381
+  int             krHopFact   = 4;
382
+
383
+  unsigned        xfadeChCnt  = 2;
384
+  double          xfadeMs     = 50;
385
+  bool            xfadeInitFl = true;
386
+  double          mixGain     = 1.0;
387
+
388
+  bool            cmpBypassFl  = false;
389
+  double          cmpInGain    = 3.0;
390
+  double          cmpThreshDb  = -40.0;
391
+  double          cmpRatio_num = 5.0;
392
+  double          cmpAtkMs     = 20.0;
393
+  double          cmpRlsMs     = 100.0;
394
+  double          cmpMakeup    = 1.0;
395
+  double          cmpWndMaxMs  = 1000.0;
396
+  double          cmpWndMs     = 200.0;
397
+
398
+  cmDspInst_t* achan = cmDspSysAllocInst(h, "AvailCh",     NULL, 1, xfadeChCnt );
399
+
400
+ 
401
+  // Parameter-> kr routers (routers used to cross-fade between the two kr units)
402
+  unsigned paramRtChCnt = 2;
403
+  cmDspInst_t* wnd_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
404
+  cmDspInst_t* hop_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
405
+  cmDspInst_t* ceil_rt  = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
406
+  cmDspInst_t* expo_rt  = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
407
+  cmDspInst_t* mix_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
408
+  cmDspInst_t* thr_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
409
+  cmDspInst_t* upr_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
410
+  cmDspInst_t* lwr_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
411
+  cmDspInst_t* wet_rt   = cmDspSysAllocInst(h, "Router",      NULL,  2,  paramRtChCnt, paramRtChCnt-1 );
412
+
413
+  // Audio processors
414
+  cmDspInst_t* kr0  = cmDspSysAllocInst(h, "Kr2",        NULL,   2, krWndSmpCnt, krHopFact );
415
+  cmDspInst_t* kr1  = cmDspSysAllocInst(h, "Kr2",        NULL,   2, krWndSmpCnt, krHopFact );
416
+  cmDspInst_t* xfad = cmDspSysAllocInst(h, "Xfader",     NULL,   3, xfadeChCnt,  xfadeMs, xfadeInitFl ); 
417
+  cmDspInst_t* mix  = cmDspSysAllocInst(h, "AMix",       NULL,   3, xfadeChCnt,  mixGain, mixGain );
418
+  cmDspInst_t* cmp  = cmDspSysAllocInst(h, "Compressor", NULL,   8, cmpBypassFl, cmpThreshDb, cmpRatio_num, cmpAtkMs, cmpRlsMs, cmpMakeup, cmpWndMs, cmpWndMaxMs ); 
419
+
420
+  // Internal audio connections
421
+  cmDspSysConnectAudio(h, kr0,  "out",   xfad, "in-0");
422
+  cmDspSysConnectAudio(h, kr1,  "out",   xfad, "in-1");
423
+  cmDspSysConnectAudio(h, xfad, "out-0", mix,  "in-0");
424
+  cmDspSysConnectAudio(h, xfad, "out-1", mix,  "in-1");
425
+  cmDspSysConnectAudio(h, mix,  "out",   cmp,  "in" );
426
+
427
+  // active channel <-> cross-fade connections
428
+  cmDspSysInstallCb(h, achan,  "reset",   xfad, "reset", NULL);
429
+  cmDspSysInstallCb(h, achan,  "gate-0",  xfad, "gate-0", NULL );
430
+  cmDspSysInstallCb(h, achan,  "gate-1",  xfad, "gate-1", NULL );
431
+  cmDspSysInstallCb(h, xfad,   "state-0", achan, "dis-0",  NULL );
432
+  cmDspSysInstallCb(h, xfad,   "state-1", achan, "dis-1",  NULL );
433
+
434
+  
435
+  // Parameter number controls 
436
+  cmDspInst_t* wnd_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("WndSmpCnt"), NULL, "wndSmpCnt", 2);
437
+  cmDspInst_t* hop_ctl = cmDspSysAllocMsgListP(h,preGrpSymId,NULL, lbl("HopFact"),   NULL, "hopFact",   2);
438
+  cmDspInst_t* ceil_ctl= cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Ceiling"),     0.0, 100.0, 0.1,  30.0 );
439
+  cmDspInst_t* expo_ctl= cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Expo"),      -10.0,  10.0, 0.01,  2.0 );
440
+  cmDspInst_t* mix_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Mix"),         0.0,   1.0, 0.01,  0.0 );
441
+  cmDspInst_t* thr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Threshold"),   0.0, 100.0, 0.1,  60.0 );
442
+  cmDspInst_t* upr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Upr slope"), -10.0,  10.0, 0.01,  0.0 ); 
443
+  cmDspInst_t* lwr_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Lwr slope"), -10.0,  10.0, 0.01,  2.0 );
444
+  cmDspInst_t* wet_ctl = cmDspSysAllocScalarP( h,preGrpSymId,NULL, lbl("Wet Dry"),     0.0,   1.0, 0.001, 1.0 );
445
+
446
+  cmDspSysInstallCb(h, wnd_ctl, "out",         wnd_rt, "f-in",    NULL );
447
+  cmDspSysInstallCb(h, achan,   "ch",          wnd_rt, "sel",     NULL );   // ach->rt sel
448
+  cmDspSysInstallCb(h, wnd_rt,  "f-out-0",     kr0,    "wndn",    NULL );   // wndn->kr
449
+  cmDspSysInstallCb(h, wnd_rt,  "f-out-1",     kr1,    "wndn",    NULL );   // wndn->kr
450
+
451
+  cmDspSysInstallCb(h, hop_ctl, "out",         hop_rt, "f-in",    NULL );
452
+  cmDspSysInstallCb(h, achan,   "ch",          hop_rt, "sel",     NULL );   // ach->rt sel
453
+  cmDspSysInstallCb(h, hop_rt,  "f-out-0",     kr0,    "hopf",    NULL );   // hopf->kr
454
+  cmDspSysInstallCb(h, hop_rt,  "f-out-1",     kr1,    "hopf",    NULL );   // hopf->kr
455
+
456
+  cmDspSysInstallCb(h, ceil_ctl,     "val",     ceil_rt, "f-in",  NULL );
457
+  cmDspSysInstallCb(h, achan,        "ch",      ceil_rt, "sel",   NULL );   // ach->rt sel
458
+  cmDspSysInstallCb(h, ceil_rt,      "f-out-0", kr0,     "ceil",  NULL );   // ceil->kr
459
+  cmDspSysInstallCb(h, ceil_rt,      "f-out-1", kr1,     "ceil",  NULL );   // ceil->kr
460
+
461
+  cmDspSysInstallCb(h, expo_ctl,     "val",     expo_rt, "f-in",  NULL );
462
+  cmDspSysInstallCb(h, achan,        "ch",      expo_rt, "sel",   NULL );   // ach->rt sel
463
+  cmDspSysInstallCb(h, expo_rt,      "f-out-0", kr0,     "expo",  NULL );   // expo->kr
464
+  cmDspSysInstallCb(h, expo_rt,      "f-out-1", kr1,     "expo",  NULL );   // expo->kr
465
+
466
+  cmDspSysInstallCb(h, mix_ctl,     "val",     mix_rt,  "f-in",   NULL );
467
+  cmDspSysInstallCb(h, achan,       "ch",      mix_rt,  "sel",    NULL );   // ach->rt sel
468
+  cmDspSysInstallCb(h, mix_rt,      "f-out-0", kr0,     "mix",    NULL );   // mix->kr
469
+  cmDspSysInstallCb(h, mix_rt,      "f-out-1", kr1,     "mix",    NULL );   // mix->kr
470
+  
471
+  
472
+  cmDspSysInstallCb(h, thr_ctl,     "val",     thr_rt, "f-in",    NULL );
473
+  cmDspSysInstallCb(h, achan,       "ch",      thr_rt, "sel",     NULL );   // ach->rt sel
474
+  cmDspSysInstallCb(h, thr_rt,      "f-out-0", kr0,    "thrh",    NULL );   // thr->kr
475
+  cmDspSysInstallCb(h, thr_rt,      "f-out-1", kr1,    "thrh",    NULL );   // thr->kr
476
+
477
+  cmDspSysInstallCb(h, upr_ctl,     "val",     upr_rt, "f-in",    NULL );
478
+  cmDspSysInstallCb(h, achan,       "ch",      upr_rt, "sel",     NULL );   // ach->rt sel
479
+  cmDspSysInstallCb(h, upr_rt,      "f-out-0", kr0,    "uprs",    NULL );   // upr->kr
480
+  cmDspSysInstallCb(h, upr_rt,      "f-out-1", kr1,    "uprs",    NULL );   // upr->kr
481
+
482
+  cmDspSysInstallCb(h, lwr_ctl,     "val",     lwr_rt, "f-in",    NULL );
483
+  cmDspSysInstallCb(h, achan,       "ch",      lwr_rt, "sel",     NULL );   // ach->rt sel
484
+  cmDspSysInstallCb(h, lwr_rt,      "f-out-0", kr0,    "lwrs",    NULL );   // lwr->kr
485
+  cmDspSysInstallCb(h, lwr_rt,      "f-out-1", kr1,    "lwrs",    NULL );   // lwr->kr
486
+
487
+  
488
+  cmDspSysInstallCb(h, wet_ctl,     "val",     wet_rt, "f-in",    NULL );
489
+  cmDspSysInstallCb(h, achan,       "ch",      wet_rt, "sel",     NULL );   // ach->rt sel
490
+  cmDspSysInstallCb(h, wet_rt,      "f-out-0", kr0,    "wet",     NULL );   // wet->kr
491
+  cmDspSysInstallCb(h, wet_rt,      "f-out-1", kr1,    "wet",     NULL );   // wet->kr
492
+  
493
+
494
+  cmDspSysNewColumn(h,0);
495
+  cmDspInst_t* cmp_byp   = cmDspSysAllocCheckP(  h, cmpPreGrpSymId, NULL, lbl("Bypass"), 1.0 );
496
+  cmDspInst_t* cmp_igain = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("In Gain"),  0.0,   10.0, 0.1, cmpInGain);
497
+  cmDspInst_t* cmp_thr   = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("ThreshDb"), -100.0, 0.0, 0.1, cmpThreshDb);
498
+  cmDspInst_t* cmp_rat   = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Ratio"),    0.1, 100, 0.1, cmpRatio_num);
499
+  cmDspInst_t* cmp_atk   = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Atk Ms"),   0.0, 1000.0, 0.1, cmpAtkMs);
500
+  cmDspInst_t* cmp_rls   = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Rls Ms"),   0.0, 1000.0, 0.1, cmpRlsMs);
501
+  cmDspInst_t* cmp_mkup  = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Makeup"),   0.0, 10.0,   0.01, cmpMakeup);
502
+  cmDspInst_t* cmp_wnd   = cmDspSysAllocScalarP( h, cmpPreGrpSymId, NULL, lbl("Wnd Ms"),   1.0, cmpWndMaxMs, 1.0, cmpWndMs );
503
+  cmDspInst_t* cmp_mtr   = cmDspSysAllocInst(h,"Meter",lbl("Env"), 3, 0.0, 0.0, 1.0);
504
+
505
+  cmDspSysInstallCb(h, cmp_byp,  "out", cmp, "bypass", NULL );
506
+  cmDspSysInstallCb(h, cmp_igain,"val", cmp, "igain", NULL );
507
+  cmDspSysInstallCb(h, cmp_thr,  "val", cmp, "thr", NULL );
508
+  cmDspSysInstallCb(h, cmp_rat,  "val", cmp, "ratio", NULL );
509
+  cmDspSysInstallCb(h, cmp_atk,  "val", cmp, "atk", NULL );
510
+  cmDspSysInstallCb(h, cmp_rls,  "val", cmp, "rls", NULL );
511
+  cmDspSysInstallCb(h, cmp_mkup, "val", cmp, "ogain", NULL );
512
+  cmDspSysInstallCb(h, cmp_wnd,  "val", cmp, "wnd", NULL );
513
+  cmDspSysInstallCb(h, cmp,      "env", cmp_mtr, "in", NULL );
514
+
515
+  cmDspSysInstallCb(h, modp, mlbl("cbyp"),    cmp_byp,  "in", NULL );
516
+  cmDspSysInstallCb(h, modp, mlbl("cigain"),  cmp_igain,"val", NULL );
517
+  cmDspSysInstallCb(h, modp, mlbl("cthrsh"),  cmp_thr,  "val", NULL );
518
+  cmDspSysInstallCb(h, modp, mlbl("cratio"),  cmp_rat,  "val", NULL );
519
+  cmDspSysInstallCb(h, modp, mlbl("catkms"),  cmp_atk,  "val", NULL );
520
+  cmDspSysInstallCb(h, modp, mlbl("crlsms"),  cmp_rls,  "val", NULL );
521
+  cmDspSysInstallCb(h, modp, mlbl("cmakeup"), cmp_mkup, "val", NULL );
522
+  cmDspSysInstallCb(h, modp, mlbl("cwndms"),  cmp_wnd,  "val", NULL );
523
+
524
+  // 
525
+  cmDspInst_t* xfadMs = cmDspSysAllocInst(h,"Scalar", lbl("Xfade Ms"),     5, kNumberDuiId, 0.0,   1000.0,0.01, 50.0 );  
526
+  cmDspSysInstallCb(h, xfadMs, "val", xfad, "ms", NULL );
527
+  cmDspSysInstallCb(h, modp, mlbl("xfad"), xfadMs,  "val", NULL);
528
+
529
+  cmDspSysInstallCb(h, modp, mlbl("win"),  wnd_ctl, "sel",  NULL );
530
+  cmDspSysInstallCb(h, modp, mlbl("hop"),  hop_ctl, "sel",  NULL );
531
+  cmDspSysInstallCb(h, modp, mlbl("ceil"), ceil_ctl, "val", NULL );
532
+  cmDspSysInstallCb(h, modp, mlbl("expo"), expo_ctl, "val", NULL );
533
+  cmDspSysInstallCb(h, modp, mlbl("mix"),  mix_ctl,  "val", NULL );
534
+  cmDspSysInstallCb(h, modp, mlbl("thr"),  thr_ctl, "val",  NULL );
535
+  cmDspSysInstallCb(h, modp, mlbl("upr"),  upr_ctl, "val",  NULL );
536
+  cmDspSysInstallCb(h, modp, mlbl("lwr"),  lwr_ctl, "val",  NULL );
537
+  cmDspSysInstallCb(h, modp, mlbl("wet"),  wet_ctl, "val",  NULL );
538
+
539
+  cmDspSysInstallCb(h, modp, mlbl("sw"),   achan,       "trig", NULL ); // See also: amp.sfloc->achan.trig
540
+
541
+  
542
+  c->achan = achan; 
543
+  c->kr0   = kr0; 
544
+  c->kr1   = kr1;
545
+  c->cmp   = cmp; 
546
+
547
+}
364 548
 
549
+#endif

Notiek ielāde…
Atcelt
Saglabāt