Procházet zdrojové kódy

cmProc4.h/c,cmProc5.h/c,Makefiile.am : Moved cmGoertzel from cmProc4.h/c into new file (cmProc5.h/c).

master
kevin před 10 roky
rodič
revize
d8d63d7e29
5 změnil soubory, kde provedl 174 přidání a 136 odebrání
  1. 2
    2
      Makefile.am
  2. 0
    102
      cmProc4.c
  3. 0
    32
      cmProc4.h
  4. 125
    0
      cmProc5.c
  5. 47
    0
      cmProc5.h

+ 2
- 2
Makefile.am Zobrazit soubor

@@ -67,8 +67,8 @@ cmHDR += src/libcm/vop/cmVectOps.h src/libcm/vop/cmProcTemplate.h
67 67
 
68 68
 cmSRC += src/libcm/vop/cmVectOps.c src/libcm/vop/cmProcTemplate.c
69 69
 
70
-cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/cmProc3.h src/libcm/cmProc4.h src/libcm/cmProcTest.h
71
-cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProcTest.c
70
+cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/cmProc3.h src/libcm/cmProc4.h src/libcm/cmProc5.h src/libcm/cmProcTest.h
71
+cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProc5.c src/libcm/cmProcTest.c
72 72
 
73 73
 
74 74
 cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h 

+ 0
- 102
cmProc4.c Zobrazit soubor

@@ -24,7 +24,6 @@
24 24
 #include "cmTimeLine.h"
25 25
 #include "cmScore.h"
26 26
 #include "cmProc4.h"
27
-#include "cmTime.h"
28 27
 
29 28
 
30 29
 cmScFol* cmScFolAlloc( cmCtx* c, cmScFol* p, cmReal_t srate, cmScH_t scH, unsigned bufN, unsigned minWndLookAhead, unsigned maxWndCnt, unsigned minVel )
@@ -4547,104 +4546,3 @@ cmRC_t         cmRecdPlayExec( cmRecdPlay* p, const cmSample_t** iChs, cmSample_
4547 4546
   return cmOkRC;
4548 4547
 }
4549 4548
 
4550
-//=======================================================================================================================
4551
-cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt )
4552
-{
4553
-  cmGoertzel* op = cmObjAlloc(cmGoertzel,c,p);
4554
-  
4555
-  op->shb = cmShiftBufAlloc(c,NULL,0,0,0);
4556
-
4557
-  if( srate > 0 )  
4558
-    if( cmGoertzelInit(op,srate,fcHzV,chCnt,procSmpCnt,wndSmpCnt,hopSmpCnt) != cmOkRC )
4559
-      cmGoertzelFree(&op);
4560
-
4561
-  return op;
4562
-}
4563
-
4564
-cmRC_t cmGoertzelFree( cmGoertzel** pp )
4565
-{
4566
-  cmRC_t rc = cmOkRC;
4567
-  if( pp==NULL || *pp==NULL )
4568
-    return rc;
4569
-
4570
-  cmGoertzel* p = *pp;
4571
-  if((rc = cmGoertzelFinal(p)) != cmOkRC )
4572
-    return rc;
4573
-
4574
-  cmShiftBufFree(&p->shb);
4575
-  cmMemFree(p->ch);
4576
-  cmMemFree(p->wnd);
4577
-  cmObjFree(pp);
4578
-  return rc;
4579
-
4580
-}
4581
-
4582
-cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt )
4583
-{
4584
-  cmRC_t rc;
4585
-  unsigned i;
4586
-
4587
-  if((rc = cmGoertzelFinal(p)) != cmOkRC )
4588
-    return rc;
4589
-
4590
-  p->ch    = cmMemResizeZ(cmGoertzelCh,p->ch,chCnt);
4591
-  p->chCnt = chCnt;
4592
-  p->srate = srate;
4593
-  p->wnd   = cmMemResizeZ(cmSample_t,p->wnd,wndSmpCnt);
4594
-
4595
-  cmVOS_Hann(p->wnd,wndSmpCnt);
4596
-
4597
-  cmShiftBufInit(p->shb,procSmpCnt,wndSmpCnt,hopSmpCnt);
4598
-
4599
-  for(i=0; i<p->chCnt; ++i)
4600
-  {
4601
-    cmGoertzelSetFcHz(p,i,fcHzV[i]);
4602
-  }
4603
-
4604
-  return rc;
4605
-}
4606
-
4607
-cmRC_t cmGoertzelFinal( cmGoertzel* p )
4608
-{ return cmOkRC; }
4609
-
4610
-cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz )
4611
-{
4612
-  assert( chIdx < p->chCnt );
4613
-  p->ch[chIdx].hz   = hz;
4614
-  p->ch[chIdx].coeff = 2*cos(2*M_PI*hz/p->srate);
4615
-  
4616
-  return cmOkRC;
4617
-}
4618
-
4619
-cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* inpV, unsigned procSmpCnt, double* outV, unsigned chCnt )
4620
-{
4621
-  unsigned i,j;
4622
-
4623
-  while( cmShiftBufExec(p->shb,inpV,procSmpCnt) )
4624
-  {
4625
-    unsigned   xn = p->shb->wndSmpCnt;
4626
-    cmSample_t x[ xn ];
4627
-
4628
-    cmVOS_MultVVV(x,xn,p->wnd,p->shb->outV);
4629
-
4630
-    for(i=0; i<chCnt; ++i)
4631
-    {
4632
-      cmGoertzelCh* ch = p->ch + i;
4633
-    
4634
-      ch->s2 = x[0];
4635
-      ch->s1 = x[1] + 2 * x[0] * ch->coeff;
4636
-      for(j=2; j<xn; ++j)
4637
-      {
4638
-        ch->s0 = x[j] + ch->coeff * ch->s1 - ch->s2;
4639
-        ch->s2 = ch->s1;
4640
-        ch->s1 = ch->s0;
4641
-      }
4642
-    
4643
-      outV[i] = ch->s2*ch->s2 + ch->s1*ch->s1 - ch->coeff * ch->s2 * ch->s1;
4644
-    }
4645
-  }
4646
-
4647
-  return cmOkRC;
4648
-}
4649
-
4650
-

+ 0
- 32
cmProc4.h Zobrazit soubor

@@ -698,38 +698,6 @@ extern "C" {
698 698
 
699 699
   cmRC_t         cmRecdPlayExec(        cmRecdPlay* p, const cmSample_t** iChs, cmSample_t** oChs, unsigned chCnt, unsigned smpCnt );
700 700
 
701
-  //=======================================================================================================================
702
-  // Goertzel Filter
703
-  //
704
-
705
-  typedef struct
706
-  {
707
-    double s0;
708
-    double s1;
709
-    double s2;
710
-    double coeff;
711
-    double hz;
712
-  } cmGoertzelCh;
713
-
714
-  struct cmShiftBuf_str;
715
-
716
-  typedef struct cmGoertzel_str
717
-  {
718
-    cmObj                  obj;
719
-    cmGoertzelCh*          ch;
720
-    unsigned               chCnt;
721
-    double                 srate;
722
-    struct cmShiftBuf_str* shb;
723
-    cmSample_t*            wnd;
724
-  } cmGoertzel;
725
-
726
-  cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
727
-  cmRC_t cmGoertzelFree( cmGoertzel** pp );
728
-  cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
729
-  cmRC_t cmGoertzelFinal( cmGoertzel* p );
730
-  cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz );
731
-  cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* in, unsigned procSmpCnt,  double* outV, unsigned chCnt );
732
-
733 701
 
734 702
 #ifdef __cplusplus
735 703
 }

+ 125
- 0
cmProc5.c Zobrazit soubor

@@ -0,0 +1,125 @@
1
+#include "cmPrefix.h"
2
+#include "cmGlobal.h"
3
+#include "cmRpt.h"
4
+#include "cmErr.h"
5
+#include "cmCtx.h"
6
+#include "cmMem.h"
7
+#include "cmMallocDebug.h"
8
+#include "cmLinkedHeap.h"
9
+#include "cmFloatTypes.h"
10
+#include "cmComplexTypes.h"
11
+#include "cmFileSys.h"
12
+#include "cmJson.h"
13
+#include "cmSymTbl.h"
14
+#include "cmAudioFile.h"
15
+#include "cmText.h"
16
+#include "cmProcObj.h"
17
+#include "cmProcTemplate.h"
18
+#include "cmMath.h"
19
+#include "cmProc.h"
20
+#include "cmProc5.h"
21
+
22
+#include "cmVectOps.h"
23
+
24
+
25
+//=======================================================================================================================
26
+cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt )
27
+{
28
+  cmGoertzel* op = cmObjAlloc(cmGoertzel,c,p);
29
+  
30
+  op->shb = cmShiftBufAlloc(c,NULL,0,0,0);
31
+
32
+  if( srate > 0 )  
33
+    if( cmGoertzelInit(op,srate,fcHzV,chCnt,procSmpCnt,wndSmpCnt,hopSmpCnt) != cmOkRC )
34
+      cmGoertzelFree(&op);
35
+
36
+  return op;
37
+}
38
+
39
+cmRC_t cmGoertzelFree( cmGoertzel** pp )
40
+{
41
+  cmRC_t rc = cmOkRC;
42
+  if( pp==NULL || *pp==NULL )
43
+    return rc;
44
+
45
+  cmGoertzel* p = *pp;
46
+  if((rc = cmGoertzelFinal(p)) != cmOkRC )
47
+    return rc;
48
+
49
+  cmShiftBufFree(&p->shb);
50
+  cmMemFree(p->ch);
51
+  cmMemFree(p->wnd);
52
+  cmObjFree(pp);
53
+  return rc;
54
+
55
+}
56
+
57
+cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt )
58
+{
59
+  cmRC_t rc;
60
+  unsigned i;
61
+
62
+  if((rc = cmGoertzelFinal(p)) != cmOkRC )
63
+    return rc;
64
+
65
+  p->ch    = cmMemResizeZ(cmGoertzelCh,p->ch,chCnt);
66
+  p->chCnt = chCnt;
67
+  p->srate = srate;
68
+  p->wnd   = cmMemResizeZ(cmSample_t,p->wnd,wndSmpCnt);
69
+
70
+  cmVOS_Hann(p->wnd,wndSmpCnt);
71
+
72
+  cmShiftBufInit(p->shb,procSmpCnt,wndSmpCnt,hopSmpCnt);
73
+
74
+  for(i=0; i<p->chCnt; ++i)
75
+  {
76
+    cmGoertzelSetFcHz(p,i,fcHzV[i]);
77
+  }
78
+
79
+  return rc;
80
+}
81
+
82
+cmRC_t cmGoertzelFinal( cmGoertzel* p )
83
+{ return cmOkRC; }
84
+
85
+cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz )
86
+{
87
+  assert( chIdx < p->chCnt );
88
+  p->ch[chIdx].hz   = hz;
89
+  p->ch[chIdx].coeff = 2*cos(2*M_PI*hz/p->srate);
90
+  
91
+  return cmOkRC;
92
+}
93
+
94
+cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* inpV, unsigned procSmpCnt, double* outV, unsigned chCnt )
95
+{
96
+  unsigned i,j;
97
+
98
+  while( cmShiftBufExec(p->shb,inpV,procSmpCnt) )
99
+  {
100
+    unsigned   xn = p->shb->wndSmpCnt;
101
+    cmSample_t x[ xn ];
102
+
103
+    cmVOS_MultVVV(x,xn,p->wnd,p->shb->outV);
104
+
105
+    for(i=0; i<chCnt; ++i)
106
+    {
107
+      cmGoertzelCh* ch = p->ch + i;
108
+    
109
+      ch->s2 = x[0];
110
+      ch->s1 = x[1] + 2 * x[0] * ch->coeff;
111
+      for(j=2; j<xn; ++j)
112
+      {
113
+        ch->s0 = x[j] + ch->coeff * ch->s1 - ch->s2;
114
+        ch->s2 = ch->s1;
115
+        ch->s1 = ch->s0;
116
+      }
117
+    
118
+      outV[i] = ch->s2*ch->s2 + ch->s1*ch->s1 - ch->coeff * ch->s2 * ch->s1;
119
+    }
120
+  }
121
+
122
+  return cmOkRC;
123
+}
124
+
125
+

+ 47
- 0
cmProc5.h Zobrazit soubor

@@ -0,0 +1,47 @@
1
+#ifndef cmProc5_h
2
+#define cmProc5_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+
9
+  //=======================================================================================================================
10
+  // Goertzel Filter
11
+  //
12
+
13
+  typedef struct
14
+  {
15
+    double s0;
16
+    double s1;
17
+    double s2;
18
+    double coeff;
19
+    double hz;
20
+  } cmGoertzelCh;
21
+
22
+  struct cmShiftBuf_str;
23
+
24
+  typedef struct cmGoertzel_str
25
+  {
26
+    cmObj                  obj;
27
+    cmGoertzelCh*          ch;
28
+    unsigned               chCnt;
29
+    double                 srate;
30
+    struct cmShiftBuf_str* shb;
31
+    cmSample_t*            wnd;
32
+  } cmGoertzel;
33
+
34
+  cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
35
+  cmRC_t cmGoertzelFree( cmGoertzel** pp );
36
+  cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
37
+  cmRC_t cmGoertzelFinal( cmGoertzel* p );
38
+  cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz );
39
+  cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* in, unsigned procSmpCnt,  double* outV, unsigned chCnt );
40
+
41
+
42
+
43
+#ifdef __cplusplus
44
+}
45
+#endif
46
+
47
+#endif

Načítá se…
Zrušit
Uložit