소스 검색

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

master
kevin 8 년 전
부모
커밋
48a582c012
6개의 변경된 파일241개의 추가작업 그리고 10개의 파일을 삭제
  1. 29
    3
      cmProc5.c
  2. 4
    4
      cmProc5.h
  3. 1
    0
      dsp/cmDspBuiltIn.c
  4. 157
    0
      dsp/cmDspKr.c
  5. 1
    0
      dsp/cmDspKr.h
  6. 49
    3
      dsp/cmDspPgm.c

+ 29
- 3
cmProc5.c 파일 보기

@@ -680,14 +680,14 @@ cmReflectCalc_t* cmReflectCalcAlloc( cmCtx* ctx, cmReflectCalc_t* p, const cmGol
680 680
   cmRC_t rc = cmOkRC;
681 681
   
682 682
   // allocate the Gold code signal generator
683
-  if( (p->gs = cmGoldSigAlloc(ctx,NULL,NULL)) == NULL )
683
+  if( (op->gs = cmGoldSigAlloc(ctx,NULL,NULL)) == NULL )
684 684
   {
685 685
     rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"Gold sig allocate failed.");
686 686
     goto errLabel;
687 687
   }
688 688
 
689 689
   // allocate the PHAT object
690
-  if( (p->phat = cmPhatAlloc(ctx,NULL,0,0,0,0,0)) == NULL )
690
+  if( (op->phat = cmPhatAlloc(ctx,NULL,0,0,0,0,0)) == NULL )
691 691
   {
692 692
     rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"PHAT allocate failed.");
693 693
     goto errLabel;
@@ -718,6 +718,8 @@ cmRC_t cmReflectCalcFree( cmReflectCalc_t** pp )
718 718
 
719 719
   cmReflectCalc_t* p = *pp;
720 720
 
721
+  cmReflectCalcWrite(p,"/home/kevin/temp/cmkc");
722
+  
721 723
   if((rc = cmReflectCalcFinal(p)) != cmOkRC )
722 724
     return rc;
723 725
 
@@ -779,9 +781,12 @@ cmRC_t cmReflectCalcFinal( cmReflectCalc_t* p )
779 781
   return cmOkRC;
780 782
 }
781 783
 
782
-cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* yV, unsigned xyN )
784
+cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN )
783 785
 {
784 786
   unsigned i;
787
+
788
+  // feed audio into the PHAT's buffer
789
+  cmPhatExec(p->phat,xV,xyN);
785 790
   
786 791
   for(i=0; i<xyN; ++i,++p->xi)
787 792
   {
@@ -790,12 +795,16 @@ cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* y
790 795
     else
791 796
       yV[i] = 0;
792 797
 
798
+    // if the PHAT has a complete buffer
793 799
     if( p->xi == p->phat->fhN )
794 800
     {
795 801
       p->xi = 0;
796 802
 
803
+      // execute the correlation
797 804
       cmPhatChExec(p->phat,0,0,0);
798 805
 
806
+      // p->phat->xV now holds the correlation result
807
+      
799 808
       if( p->va != NULL )
800 809
         cmVectArrayAppendS(p->va,p->phat->xV,p->phat->fhN );
801 810
     }
@@ -805,3 +814,20 @@ cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* y
805 814
   return cmOkRC;
806 815
   
807 816
 }
817
+
818
+cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr )
819
+{
820
+  cmRC_t rc = cmOkRC;
821
+  
822
+  if( p->va != NULL) 
823
+  {
824
+    const char* path = NULL;
825
+
826
+    if((rc = cmVectArrayWrite(p->va, path = cmFsMakeFn(path,"reflect_calc","va",dirStr,NULL) )) != cmOkRC )
827
+        rc = cmCtxRtCondition(&p->obj,cmSubSysFailRC,"Reflect calc file write failed.");
828
+    
829
+    cmFsFreeFn(path);
830
+  }
831
+  
832
+  return rc;
833
+}

+ 4
- 4
cmProc5.h 파일 보기

@@ -209,11 +209,11 @@ extern "C" {
209 209
 
210 210
   
211 211
   cmReflectCalc_t* cmReflectCalcAlloc( cmCtx* ctx, cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult );
212
-  cmRC_t cmReflectCalcFree( cmReflectCalc_t** pp );
213
-  cmRC_t cmReflectCalcInit( cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult );
212
+  cmRC_t cmReflectCalcFree(  cmReflectCalc_t** pp );
213
+  cmRC_t cmReflectCalcInit(  cmReflectCalc_t* p, const cmGoldSigArg_t* gsa, float phat_alpha, unsigned phat_mult );
214 214
   cmRC_t cmReflectCalcFinal( cmReflectCalc_t* p );
215
-  cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t xV, cmSample_t* yV, unsigned xyN );
216
-
215
+  cmRC_t cmReflectCalcExec(  cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN );
216
+  cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr );
217 217
   
218 218
   
219 219
 #ifdef __cplusplus

+ 1
- 0
dsp/cmDspBuiltIn.c 파일 보기

@@ -5837,6 +5837,7 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
5837 5837
   cmSyncRecdClassCons,
5838 5838
   cmTakeSeqBldrClassCons,
5839 5839
   cmTakeSeqRendClassCons,
5840
+  cmReflectCalcClassCons,
5840 5841
   NULL,
5841 5842
 };
5842 5843
 

+ 157
- 0
dsp/cmDspKr.c 파일 보기

@@ -3587,3 +3587,160 @@ struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx )
3587 3587
   return &_cmTakeSeqRendDC;
3588 3588
 }
3589 3589
 
3590
+
3591
+//==========================================================================================================================================
3592
+enum
3593
+{
3594
+  kLfsrN_RcId,
3595
+  kMlsCoeff0RcId,
3596
+  kMlsCoeff1RcId,
3597
+  kSmpPerChipRcId,
3598
+  kRcosBetaRcId,
3599
+  kRcosOS_RcId,
3600
+  kCarrierHzRcId,
3601
+  kAtkDcyMsRcId,
3602
+  kPhatAlphaRcId,
3603
+  kPhatMultRcId,
3604
+  kInRcId,
3605
+  kOutRcId,
3606
+};
3607
+
3608
+cmDspClass_t _cmReflectCalcDC;
3609
+
3610
+typedef struct
3611
+{
3612
+  cmDspInst_t    inst;
3613
+  cmReflectCalc_t* r;
3614
+} cmDspReflectCalc_t;
3615
+
3616
+
3617
+cmDspInst_t*  _cmDspReflectCalcAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
3618
+{
3619
+
3620
+  /*
3621
+  if( va_cnt !=3 )
3622
+  {
3623
+    cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'ReflectCalc' constructor must have two arguments: a channel count and frequency array.");
3624
+    return NULL;
3625
+  }
3626
+  */
3627
+
3628
+  cmDspReflectCalc_t* p = cmDspInstAllocV(cmDspReflectCalc_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl,
3629
+    1,         "lfsrN", kLfsrN_RcId,    0,0, kInDsvFl   | kUIntDsvFl,    "Gold code generator LFSR length",
3630
+    1,         "mlsc0", kMlsCoeff0RcId, 0,0, kInDsvFl   | kUIntDsvFl,    "LFSR coefficient 0",
3631
+    1,         "mlsc1", kMlsCoeff1RcId, 0,0, kInDsvFl   | kUIntDsvFl,    "LFSR coefficient 0",
3632
+    1,         "spchip",kSmpPerChipRcId,0,0, kInDsvFl   | kUIntDsvFl,    "Samples per spreading code bit.",
3633
+    1,         "rcosb", kRcosBetaRcId,  0,0, kInDsvFl   | kDoubleDsvFl,  "Raised cosine beta",
3634
+    1,         "rcosos",kRcosOS_RcId,   0,0, kInDsvFl   | kUIntDsvFl,    "Raised cosine oversample factor.",
3635
+    1,         "carhz", kCarrierHzRcId, 0,0, kInDsvFl   | kDoubleDsvFl,  "Carrier frequency in Hertz.",
3636
+    1,         "envms", kAtkDcyMsRcId,  0,0, kInDsvFl   | kDoubleDsvFl,  "Signal Attack/Decay milliseconds.",
3637
+    1,         "alpha", kPhatAlphaRcId, 0,0, kInDsvFl   | kDoubleDsvFl,  "PHAT alpha coefficient.",
3638
+    1,         "mult",  kPhatMultRcId,  0,0, kInDsvFl   | kUIntDsvFl,    "PHAT multiplier coefficient.",
3639
+    1,          "in",   kInRcId,        0,1, kInDsvFl   | kAudioBufDsvFl,"Audio input",
3640
+    1,          "out",  kOutRcId,       0,1, kOutDsvFl  | kAudioBufDsvFl,"Audio output",
3641
+    0 );
3642
+
3643
+
3644
+p->r = cmReflectCalcAlloc(ctx->cmProcCtx, NULL, NULL, 0, 0 );
3645
+  
3646
+  cmDspSetDefaultUInt(   ctx, &p->inst, kLfsrN_RcId,     0,  8);
3647
+  cmDspSetDefaultUInt(   ctx, &p->inst, kMlsCoeff0RcId,  0, 0x8e);
3648
+  cmDspSetDefaultUInt(   ctx, &p->inst, kMlsCoeff1RcId,  0, 0x96);
3649
+  cmDspSetDefaultUInt(   ctx, &p->inst, kSmpPerChipRcId, 0, 64);
3650
+  cmDspSetDefaultDouble( ctx, &p->inst, kRcosBetaRcId,   0, 0.5);
3651
+  cmDspSetDefaultUInt(   ctx, &p->inst, kRcosOS_RcId,    0, 4);
3652
+  cmDspSetDefaultDouble( ctx, &p->inst, kCarrierHzRcId,  0, 2500.0);
3653
+  cmDspSetDefaultDouble( ctx, &p->inst, kAtkDcyMsRcId,   0, 50.0);
3654
+  cmDspSetDefaultDouble( ctx, &p->inst, kPhatAlphaRcId,  0, 0.5);
3655
+  cmDspSetDefaultUInt(   ctx, &p->inst, kPhatMultRcId,   0, 4);
3656
+
3657
+  return &p->inst;
3658
+}
3659
+
3660
+cmDspRC_t _cmDspReflectCalcSetup( cmDspCtx_t* ctx, cmDspInst_t* inst )
3661
+{
3662
+  cmDspRC_t   rc = kOkDspRC;
3663
+  cmDspReflectCalc_t* p  = (cmDspReflectCalc_t*)inst;
3664
+  cmGoldSigArg_t gsa;
3665
+
3666
+  gsa.chN            = 1;
3667
+  gsa.srate          = cmDspSampleRate(ctx);
3668
+  gsa.lfsrN          = cmDspUInt(inst,kLfsrN_RcId);
3669
+  gsa.mlsCoeff0      = cmDspUInt(inst,kMlsCoeff0RcId);
3670
+  gsa.mlsCoeff1      = cmDspUInt(inst,kMlsCoeff1RcId);
3671
+  gsa.samplesPerChip = cmDspUInt(inst,kSmpPerChipRcId);
3672
+  gsa.rcosBeta       = cmDspDouble(inst,kRcosBetaRcId);
3673
+  gsa.rcosOSFact     = cmDspUInt(inst,kRcosOS_RcId);
3674
+  gsa.carrierHz      = cmDspDouble(inst,kCarrierHzRcId);
3675
+  gsa.envMs          = cmDspDouble(inst,kAtkDcyMsRcId);
3676
+
3677
+  double   phatAlpha = cmDspDouble(inst,kPhatAlphaRcId);
3678
+  unsigned phatMult  = cmDspUInt(inst,kPhatMultRcId);
3679
+
3680
+  if( cmReflectCalcInit(p->r,&gsa,phatAlpha,phatMult) != cmOkRC )
3681
+    rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to initialize the internal ReflectCalc detector.");
3682
+
3683
+  return rc;
3684
+}
3685
+
3686
+cmDspRC_t _cmDspReflectCalcFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3687
+{
3688
+  cmDspRC_t           rc = kOkDspRC;
3689
+  cmDspReflectCalc_t* p  = (cmDspReflectCalc_t*)inst;
3690
+
3691
+  cmReflectCalcFree(&p->r);
3692
+
3693
+  return rc;
3694
+}
3695
+
3696
+cmDspRC_t _cmDspReflectCalcReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3697
+{
3698
+//cmDspReflectCalc_t* p = (cmDspReflectCalc_t*)inst;
3699
+
3700
+  cmDspApplyAllDefaults(ctx,inst);
3701
+
3702
+  return _cmDspReflectCalcSetup(ctx, inst );
3703
+} 
3704
+
3705
+cmDspRC_t _cmDspReflectCalcExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3706
+{
3707
+  cmDspRC_t           rc = kOkDspRC;
3708
+  cmDspReflectCalc_t* p  = (cmDspReflectCalc_t*)inst;
3709
+  const cmSample_t*   xV = cmDspAudioBuf(ctx,inst,kInRcId,0);
3710
+  unsigned            xN = cmDspAudioBufSmpCount(ctx,inst,kInRcId,0);
3711
+  cmSample_t*         yV = cmDspAudioBuf(ctx,inst,kOutRcId,0);
3712
+  unsigned            yN = cmDspAudioBufSmpCount(ctx,inst,kOutRcId,0);
3713
+
3714
+  if( xV != NULL && yV != NULL )
3715
+  {
3716
+    assert( xN == yN );
3717
+    cmReflectCalcExec(p->r,xV,yV,xN);
3718
+  }
3719
+  
3720
+  return rc;
3721
+}
3722
+
3723
+cmDspRC_t _cmDspReflectCalcRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3724
+{
3725
+//cmDspReflectCalc_t*  p         = (cmDspReflectCalc_t*)inst;
3726
+
3727
+  cmDspSetEvent(ctx,inst,evt);
3728
+
3729
+  return kOkDspRC;
3730
+}
3731
+
3732
+struct cmDspClass_str* cmReflectCalcClassCons( cmDspCtx_t* ctx )
3733
+{
3734
+  cmDspClassSetup(&_cmReflectCalcDC,ctx,"ReflectCalc",
3735
+    NULL,
3736
+    _cmDspReflectCalcAlloc,
3737
+    _cmDspReflectCalcFree,
3738
+    _cmDspReflectCalcReset,
3739
+    _cmDspReflectCalcExec,
3740
+    _cmDspReflectCalcRecv,
3741
+    NULL,
3742
+    NULL,
3743
+    "Reflecttion time calculator");
3744
+
3745
+  return &_cmReflectCalcDC;
3746
+}

+ 1
- 0
dsp/cmDspKr.h 파일 보기

@@ -21,6 +21,7 @@ extern "C" {
21 21
   struct cmDspClass_str* cmSyncRecdClassCons( cmDspCtx_t* ctx );
22 22
   struct cmDspClass_str* cmTakeSeqBldrClassCons( cmDspCtx_t* ctx );
23 23
   struct cmDspClass_str* cmTakeSeqRendClassCons( cmDspCtx_t* ctx );
24
+  struct cmDspClass_str* cmReflectCalcClassCons( cmDspCtx_t* ctx );
24 25
 
25 26
 #ifdef __cplusplus
26 27
 }

+ 49
- 3
dsp/cmDspPgm.c 파일 보기

@@ -26,6 +26,51 @@
26 26
 #include "cmDspPgmPP.h"
27 27
 #include "cmDspPgmKr.h"
28 28
 
29
+
30
+cmDspRC_t _cmDspSysPgm_ReflectCalc( cmDspSysH_t h, void** userPtrPtr )
31
+{
32
+
33
+  // audio inputs
34
+  cmDspInst_t* ai0  = cmDspSysAllocInst(h,"AudioIn", NULL,   1, 0 );
35
+  cmDspInst_t* ai1  = cmDspSysAllocInst(h,"AudioIn", NULL,   1, 1 );
36
+
37
+  cmDspInst_t* rc0   = cmDspSysAllocInst(h,"ReflectCalc", NULL, 0 );
38
+  //cmDspInst_t* rc1   = cmDspSysAllocInst(h,"ReflectCalc", NULL, 0 );
39
+  
40
+  // audio outputs
41
+  cmDspInst_t* ao0 = cmDspSysAllocInst(h,"AudioOut",NULL,   1, 0 );
42
+  cmDspInst_t* ao1 = cmDspSysAllocInst(h,"AudioOut",NULL,   1, 1 );
43
+
44
+  // input meters
45
+  cmDspInst_t* im0 = cmDspSysAllocInst(h,"AMeter","In 0",  0);
46
+  cmDspInst_t* im1 = cmDspSysAllocInst(h,"AMeter","In 1",  0);
47
+
48
+  // output meters
49
+  //cmDspInst_t* om0 = cmDspSysAllocInst(h,"AMeter","Out 0", 0);
50
+  //cmDspInst_t* om1 = cmDspSysAllocInst(h,"AMeter","Out 1",0);
51
+
52
+    // gain controls
53
+  cmDspInst_t* igain = cmDspSysAllocInst( h,"Scalar", "In Gain",  5, kNumberDuiId, 0.0,  4.0, 0.01,  1.0);
54
+  cmDspInst_t* ogain = cmDspSysAllocInst( h,"Scalar", "Out Gain", 5, kNumberDuiId, 0.0,  4.0, 0.01,  1.0);
55
+
56
+  cmDspSysConnectAudio(h, ai0, "out", im0, "in");           // ain0 -> imtr0
57
+  cmDspSysConnectAudio(h, ai1, "out", im1, "in");           // ain1 -> imtr1
58
+  
59
+  cmDspSysInstallCb(   h, igain,"val", ai0, "gain", NULL);  // igain -> ain0
60
+  cmDspSysInstallCb(   h, igain,"val", ai1, "gain", NULL);  // igain -> ain0
61
+  
62
+  cmDspSysInstallCb(   h, ogain,"val", ao0, "gain", NULL);  // igain -> ain0
63
+  cmDspSysInstallCb(   h, ogain,"val", ao1, "gain", NULL);  // igain -> ain0
64
+  
65
+
66
+  cmDspSysConnectAudio(h, ai0,"out", rc0, "in" );  
67
+  cmDspSysConnectAudio(h, rc0,"out", ao0, "in" );
68
+  
69
+  cmDspSysConnectAudio(h, ai1,"out", ao1, "in" );
70
+  
71
+  return kOkDspRC;
72
+}
73
+
29 74
 cmDspRC_t _cmDspSysPgm_SyncRecd(  cmDspSysH_t h, void** userPtrPtr )
30 75
 {
31 76
   cmDspRC_t rc = kOkDspRC;
@@ -2834,7 +2879,7 @@ cmDspRC_t _cmDspSysPgm_BinEnc( cmDspSysH_t h, void** userPtrPtr )
2834 2879
   double maxDurMs = 60000.0;
2835 2880
   double azimBeg  =     0.0;
2836 2881
   double azimEnd  =   360.0;
2837
-  const char* fn1 = "media/audio/sourcetone/Jazz/Ella & Louis - Under A Blanket Of Blue";
2882
+  //const char* fn1 = "media/audio/sourcetone/Jazz/Ella & Louis - Under A Blanket Of Blue";
2838 2883
   const char* fn0 = "temp/comhear/drw/monty.wav";
2839 2884
   
2840 2885
   cmDspInst_t* twod = cmDspSysAllocInst( h, "twod",       NULL, 0);
@@ -2901,8 +2946,7 @@ cmDspRC_t _cmDspSysPgm_BinEnc( cmDspSysH_t h, void** userPtrPtr )
2901 2946
 
2902 2947
 _cmDspSysPgm_t _cmDspSysPgmArray[] = 
2903 2948
 {
2904
-  { "two-d",         _cmDspSysPgm_TwoD,         NULL, NULL },
2905
-  { "bin-enc",       _cmDspSysPgm_BinEnc,       NULL, NULL },
2949
+  { "reflect",       _cmDspSysPgm_ReflectCalc,  NULL, NULL },
2906 2950
   { "tksb",          _cmDspSysPgm_Tksb,         NULL, NULL },
2907 2951
   { "time_line",     _cmDspSysPgm_TimeLine,     NULL, NULL },
2908 2952
   { "seq-bldr",      _cmDspSysPgm_TakeSeqBldr,  NULL, NULL },
@@ -2951,6 +2995,8 @@ _cmDspSysPgm_t _cmDspSysPgmArray[] =
2951 2995
   { "scalar op",   _cmDspSysPgm_ScalarOp,       NULL, NULL },
2952 2996
   { "seg_line",    _cmDspSysPgm_SegLine,        NULL, NULL },
2953 2997
   { "avail_ch",    _cmDspSysPgm_AvailCh,        NULL, NULL },
2998
+  { "two-d",         _cmDspSysPgm_TwoD,         NULL, NULL },
2999
+  { "bin-enc",       _cmDspSysPgm_BinEnc,       NULL, NULL },
2954 3000
   { NULL , NULL, NULL, NULL }
2955 3001
 };
2956 3002
 

Loading…
취소
저장