Ver código fonte

cmDspBuiltIn.c : Added cmDspBinEnc and cmDsp2d.

master
Kevin Larke 9 anos atrás
pai
commit
aab1940eb5
1 arquivos alterados com 223 adições e 0 exclusões
  1. 223
    0
      dsp/cmDspBuiltIn.c

+ 223
- 0
dsp/cmDspBuiltIn.c Ver arquivo

@@ -44,6 +44,8 @@
44 44
 #include "cmVectOpsTemplateMain.h"
45 45
 #include "cmMidiPort.h"
46 46
 
47
+#include "sa/cmSaProc.h"
48
+
47 49
 /*
48 50
 About variables:
49 51
 1) Variables represent data fields within a DSP object.
@@ -5515,6 +5517,225 @@ struct cmDspClass_str* cmRsrcWrClassCons( cmDspCtx_t* ctx )
5515 5517
 }
5516 5518
 
5517 5519
 //==========================================================================================================================================
5520
+enum
5521
+{
5522
+  kModeBeId,
5523
+  kAzimBeId,
5524
+  kElevBeId,
5525
+  kDistBeId,
5526
+  kAudioInBeId,
5527
+  kAudioOut0BeId,
5528
+  kAudioOut1BeId
5529
+};
5530
+
5531
+typedef struct
5532
+{
5533
+  cmDspInst_t inst;
5534
+  cmBinEnc*   bep;
5535
+} cmDspBinEnc_t;
5536
+ 
5537
+cmDspClass_t _cmBeDC;
5538
+
5539
+cmDspInst_t*  _cmDspBinEncAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
5540
+{
5541
+  cmDspVarArg_t args[] =
5542
+  {
5543
+    { "mode",    kModeBeId,        0, 0,   kInDsvFl  | kUIntDsvFl | kReqArgDsvFl, "Mode" },
5544
+    { "azim",    kAzimBeId,        0, 0,   kInDsvFl  | kDoubleDsvFl,              "Azimuth" },
5545
+    { "elev",    kElevBeId,        0, 0,   kInDsvFl  | kDoubleDsvFl,              "Elevation" },
5546
+    { "dist",    kDistBeId,        0, 0,   kInDsvFl  | kDoubleDsvFl,              "Distance" },
5547
+    { "in",      kAudioInBeId,     0, 0,   kInDsvFl  | kAudioBufDsvFl,            "Audio Input" },
5548
+    { "out0",    kAudioOut0BeId,   0, 1,   kOutDsvFl | kAudioBufDsvFl,            "Audio Output 0" },
5549
+    { "out1",    kAudioOut1BeId,   0, 1,   kOutDsvFl | kAudioBufDsvFl,            "Audio Output 1" },
5550
+    { NULL, 0, 0, 0, 0 }
5551
+  };
5552
+
5553
+  cmDspBinEnc_t* p = cmDspInstAlloc(cmDspBinEnc_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
5554
+  
5555
+  cmDspSetDefaultUInt(   ctx,&p->inst, kModeBeId, 0, 0.0 );
5556
+  cmDspSetDefaultDouble( ctx,&p->inst, kAzimBeId, 0, 0.0 );
5557
+  cmDspSetDefaultDouble( ctx,&p->inst, kElevBeId, 0, 0.0 );
5558
+  cmDspSetDefaultDouble( ctx,&p->inst, kDistBeId, 0, 0.0 );
5559
+
5560
+  return &p->inst;
5561
+}
5562
+
5563
+cmDspRC_t _cmDspBinEncFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5564
+{
5565
+  cmDspRC_t      rc = kOkDspRC;
5566
+  cmDspBinEnc_t* p  = (cmDspBinEnc_t*)inst;
5567
+
5568
+  cmBinEncFree(&p->bep);
5569
+
5570
+  return rc;
5571
+}
5572
+
5573
+cmDspRC_t _cmDspBinEncSetup(cmDspCtx_t* ctx, cmDspBinEnc_t* p )
5574
+{
5575
+  cmDspRC_t rc           = kOkDspRC;
5576
+
5577
+  cmBinEncFree(&p->bep);
5578
+
5579
+  p->bep = cmBinEncAlloc(ctx->cmProcCtx,NULL,cmDspSampleRate(ctx), cmDspSamplesPerCycle(ctx));
5580
+
5581
+  return rc;
5582
+}
5583
+
5584
+cmDspRC_t _cmDspBinEncReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5585
+{
5586
+  cmDspBinEnc_t*   p  = (cmDspBinEnc_t*)inst;
5587
+  cmDspRC_t    rc;
5588
+
5589
+  if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
5590
+    return rc;
5591
+
5592
+  return _cmDspBinEncSetup(ctx,p);
5593
+}
5594
+
5595
+cmDspRC_t _cmDspBinEncExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5596
+{
5597
+  cmDspBinEnc_t* p  = (cmDspBinEnc_t*)inst;
5598
+  cmDspRC_t      rc = kOkDspRC;
5599
+
5600
+  unsigned          iChIdx  = 0;
5601
+  const cmSample_t* ip      = cmDspAudioBuf(ctx,inst,kAudioInBeId,iChIdx);
5602
+  unsigned          iSmpCnt = cmDspVarRows(inst,kAudioInBeId);
5603
+
5604
+  // if no connected
5605
+  if( iSmpCnt == 0 )
5606
+    return rc;
5607
+  
5608
+  unsigned          oChIdx   = 0;
5609
+  cmSample_t*       o0p      = cmDspAudioBuf(ctx,inst,kAudioOut0BeId,oChIdx);
5610
+  unsigned          oSmp0Cnt = cmDspVarRows(inst,kAudioOut0BeId);
5611
+  cmSample_t*       o1p      = cmDspAudioBuf(ctx,inst,kAudioOut1BeId,oChIdx);
5612
+  unsigned          oSmp1Cnt = cmDspVarRows(inst,kAudioOut0BeId);
5613
+
5614
+  assert( iSmpCnt==oSmp0Cnt && iSmpCnt==oSmp1Cnt );
5615
+
5616
+  cmBinEncExec( p->bep, ip, o0p, o1p, iSmpCnt );
5617
+
5618
+  return rc;
5619
+}
5620
+
5621
+cmDspRC_t _cmDspBinEncRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5622
+{
5623
+  cmDspBinEnc_t* p  = (cmDspBinEnc_t*)inst;
5624
+  cmDspRC_t      rc = kOkDspRC;
5625
+
5626
+  cmDspSetEvent(ctx,inst,evt);
5627
+
5628
+  switch( evt->dstVarId )
5629
+  {
5630
+    case kModeBeId:
5631
+      cmBinEncSetMode(p->bep, cmDspUInt(inst,kModeBeId));
5632
+      break;
5633
+
5634
+    case kAzimBeId:
5635
+    case kElevBeId:
5636
+    case kDistBeId:
5637
+      {
5638
+        float azim = cmDspDouble(inst,kAzimBeId);
5639
+        float elev = cmDspDouble(inst,kElevBeId);
5640
+        float dist = cmDspDouble(inst,kDistBeId);
5641
+        cmBinEncSetLoc(p->bep, azim, elev, dist );
5642
+      }
5643
+      break;
5644
+
5645
+    default:
5646
+      { assert(0); }
5647
+  }
5648
+
5649
+  return rc;
5650
+}
5651
+
5652
+struct cmDspClass_str* cmBinEncClassCons( cmDspCtx_t* ctx )
5653
+{
5654
+  cmDspClassSetup(&_cmBeDC,ctx,"BinauralEnc",
5655
+    NULL,
5656
+    _cmDspBinEncAlloc,
5657
+    _cmDspBinEncFree,
5658
+    _cmDspBinEncReset,
5659
+    _cmDspBinEncExec,
5660
+    _cmDspBinEncRecv,
5661
+    NULL,NULL,
5662
+    "Binaural filter.");
5663
+
5664
+  return &_cmBeDC;
5665
+}
5666
+
5667
+//==========================================================================================================================================
5668
+enum
5669
+{
5670
+  kX2dId,
5671
+  kY2dId,
5672
+  kRadius2dId,
5673
+  kAngle2dId
5674
+};
5675
+
5676
+cmDspClass_t _cm2dDC;
5677
+
5678
+typedef struct
5679
+{
5680
+  cmDspInst_t inst;
5681
+} cmDsp2d_t;
5682
+
5683
+cmDspInst_t*  _cmDsp2dAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
5684
+{
5685
+  cmDspVarArg_t args[] =
5686
+  {
5687
+    { "x",     kX2dId,      0, 0, kOutDsvFl  | kDoubleDsvFl,  "X coordinate" },
5688
+    { "y",     kY2dId,      0, 0, kOutDsvFl  | kDoubleDsvFl,  "Y coordinate"},
5689
+    { "radius",kRadius2dId, 0, 0, kOutDsvFl  | kDoubleDsvFl,  "Radius"},
5690
+    { "angle", kAngle2dId,  0, 0, kOutDsvFl  | kDoubleDsvFl,  "Angle"},
5691
+    { NULL, 0, 0, 0, 0 }
5692
+  };
5693
+
5694
+  cmDsp2d_t* p = cmDspInstAlloc(cmDsp2d_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
5695
+
5696
+  cmDspSetDefaultDouble(ctx, &p->inst, kX2dId,       0.0, 0.0);
5697
+  cmDspSetDefaultDouble(ctx, &p->inst, kY2dId,       0.0, 0.0);
5698
+  cmDspSetDefaultDouble(ctx, &p->inst, kRadius2dId,  0.0, 0.0);
5699
+  cmDspSetDefaultDouble(ctx, &p->inst, kAngle2dId,   0.0, 0.0);
5700
+
5701
+  // create the UI control
5702
+  cmDspUi2dCreate(ctx,&p->inst,kX2dId,kY2dId,kRadius2dId,kAngle2dId);
5703
+
5704
+  return &p->inst;
5705
+}
5706
+
5707
+cmDspRC_t _cmDsp2dReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5708
+{
5709
+  cmDspApplyAllDefaults(ctx,inst);
5710
+  return kOkDspRC;
5711
+}
5712
+
5713
+cmDspRC_t _cmDsp2dRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5714
+{
5715
+  cmDspSetEvent(ctx,inst,evt);
5716
+
5717
+  return kOkDspRC;
5718
+}
5719
+
5720
+
5721
+struct cmDspClass_str* cm2dClassCons( cmDspCtx_t* ctx )
5722
+{
5723
+  cmDspClassSetup(&_cm2dDC,ctx,"twod",
5724
+    NULL,
5725
+    _cmDsp2dAlloc,
5726
+    NULL,
5727
+    _cmDsp2dReset,
5728
+    NULL,
5729
+    _cmDsp2dRecv,
5730
+    NULL,
5731
+    NULL,
5732
+    "2d value control.");
5733
+
5734
+  return &_cm2dDC;
5735
+}
5736
+
5737
+
5738
+//==========================================================================================================================================
5518 5739
 
5519 5740
 //==========================================================================================================================================
5520 5741
 
@@ -5556,6 +5777,8 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
5556 5777
   cmShiftBufClassCons,
5557 5778
   cmNetSendClassCons,
5558 5779
   cmRsrcWrClassCons,
5780
+  cmBinEncClassCons,
5781
+  cm2dClassCons,
5559 5782
 
5560 5783
   cmDelayClassCons,
5561 5784
   cmPShiftClassCons,

Carregando…
Cancelar
Salvar