|
@@ -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
|