Pārlūkot izejas kodu

cmProc2.h/c : Added frequency suppression filter to cmFrqTrk.

Added cmFrqTrk to cmSpecDist and did initial real-time testing.
master
Kevin Larke 9 gadus atpakaļ
vecāks
revīzija
634225d803
2 mainītis faili ar 231 papildinājumiem un 27 dzēšanām
  1. 204
    24
      cmProc2.c
  2. 27
    3
      cmProc2.h

+ 204
- 24
cmProc2.c Parādīt failu

@@ -4076,6 +4076,35 @@ cmRC_t cmVectArrayWriteMatrixS( cmCtx* ctx, const char* fn, const cmSample_t* m,
4076 4076
 
4077 4077
 }
4078 4078
 
4079
+cmRC_t cmVectArrayWriteMatrixR( cmCtx* ctx, const char* fn, const cmReal_t* m, unsigned  rn, unsigned cn )
4080
+{
4081
+  cmRC_t        rc = cmOkRC;
4082
+  cmVectArray_t* p;
4083
+  unsigned       i;
4084
+
4085
+  if((p = cmVectArrayAlloc(ctx,kRealVaFl)) == NULL )
4086
+    return cmCtxRtCondition(&ctx->obj,cmSubSysFailRC,"Unable to allocate an cmVectArray_t in cmVectArrayWriteVectorR().");
4087
+
4088
+  for(i=0; i<cn; ++i)
4089
+  {
4090
+    if((rc = cmVectArrayAppendR(p,m + (i*rn), rn)) != cmOkRC )
4091
+    {
4092
+      rc = cmCtxRtCondition(&p->obj,rc,"Vector append failed in cmVectArrayWriteVectorR().");
4093
+      goto errLabel;
4094
+    }
4095
+    
4096
+  }
4097
+
4098
+  if((rc = cmVectArrayWrite(p,fn)) != cmOkRC )
4099
+    rc = cmCtxRtCondition(&p->obj,rc,"Vector array write failed in cmVectArrayWriteVectorR().");
4100
+
4101
+ errLabel:
4102
+  if((rc = cmVectArrayFree(&p)) != cmOkRC )
4103
+    rc = cmCtxRtCondition(&ctx->obj,rc,"Free failed on cmVectArrayFree() in cmVectArrayWriteVectorR().");
4104
+
4105
+  return rc;
4106
+
4107
+}
4079 4108
 
4080 4109
 cmRC_t cmVectArrayWriteVectorI( cmCtx* ctx, const char* fn, const int* v,        unsigned  vn )
4081 4110
 {
@@ -4602,6 +4631,7 @@ cmRC_t    cmWhFiltInit( cmWhFilt* p, unsigned binCnt, cmReal_t binHz, cmReal_t c
4602 4631
   cmMemFree(tM);
4603 4632
 
4604 4633
   //cmVOR_PrintL("whM",NULL,p->bandCnt,p->binCnt,p->whM);
4634
+  //cmVectArrayWriteMatrixR(p->obj.ctx, "/home/kevin/temp/frqtrk/whM.va", p->whM, p->binCnt, p->bandCnt );
4605 4635
 
4606 4636
   unsigned whiN = p->bandCnt+2;
4607 4637
   p->whiV = cmMemResizeZ(cmReal_t,p->whiV,whiN);
@@ -4618,6 +4648,7 @@ cmRC_t    cmWhFiltInit( cmWhFilt* p, unsigned binCnt, cmReal_t binHz, cmReal_t c
4618 4648
   }
4619 4649
 
4620 4650
   //cmVOR_PrintL("whiV",NULL,1,whiN,p->whiV);
4651
+  //cmVectArrayWriteMatrixR(p->obj.ctx, "/home/kevin/temp/frqtrk/whiV.va", p->whiV, whiN, 1 );
4621 4652
   
4622 4653
   return rc;
4623 4654
 }
@@ -4641,8 +4672,14 @@ cmRC_t    cmWhFiltExec( cmWhFilt* p, const cmReal_t* xV, cmReal_t* yV, unsigned
4641 4672
 
4642 4673
   //cmVOR_PrintL("b0V",NULL,1,p->bandCnt,b0V);
4643 4674
 
4675
+  // BEWARE: zeros in b0V will generate Inf's when sent 
4676
+  // through the cmVOR_PowVS() function.
4677
+  int i;
4678
+  for(i=0; i<p->bandCnt; ++i)
4679
+    if( b0V[i] < 0.000001 )
4680
+      b0V[i] =  0.000001;
4681
+
4644 4682
   // apply a non-linear expansion function to each band
4645
-  // (BEWARE: zeros in b0V will generate Inf's)
4646 4683
   cmVOR_PowVS(b0V,p->bandCnt,p->coeff-1);
4647 4684
 
4648 4685
   //cmVOR_PrintL("b0V",NULL,1,p->bandCnt,b0V);
@@ -4673,6 +4710,7 @@ cmFrqTrk* cmFrqTrkAlloc( cmCtx* c, cmFrqTrk* p, const cmFrqTrkArgs_t* a )
4673 4710
   op->logVa   = cmVectArrayAlloc(c,kRealVaFl);
4674 4711
   op->levelVa = cmVectArrayAlloc(c,kRealVaFl);
4675 4712
   op->specVa  = cmVectArrayAlloc(c,kRealVaFl);
4713
+  op->attenVa = cmVectArrayAlloc(c,kRealVaFl);
4676 4714
 
4677 4715
   op->wf  = cmWhFiltAlloc(c,NULL,0,0,0,0);
4678 4716
 
@@ -4706,9 +4744,11 @@ cmRC_t    cmFrqTrkFree( cmFrqTrk** pp )
4706 4744
   cmMemFree(p->dbM);
4707 4745
   cmMemFree(p->pkiV);
4708 4746
   cmMemFree(p->dbV);
4747
+  cmMemFree(p->aV);
4709 4748
   cmVectArrayFree(&p->logVa);
4710 4749
   cmVectArrayFree(&p->levelVa);
4711 4750
   cmVectArrayFree(&p->specVa);
4751
+  cmVectArrayFree(&p->attenVa);
4712 4752
   cmWhFiltFree(&p->wf);
4713 4753
   cmMemFree(p->logFn);
4714 4754
   cmMemFree(p->levelFn);
@@ -4727,8 +4767,9 @@ cmRC_t    cmFrqTrkInit( cmFrqTrk* p, const cmFrqTrkArgs_t* a )
4727 4767
   p->a         = *a;
4728 4768
   p->ch        = cmMemResizeZ(cmFrqTrkCh_t,p->ch,a->chCnt );
4729 4769
   p->hN        = cmMax(1,a->wndSecs * a->srate / a->hopSmpCnt );
4730
-  p->sN        = p->hN;
4731
-  p->bN        = p->a.binCnt;
4770
+  p->sN        = 4*p->hN;
4771
+  p->binHz       = a->srate / ((p->a.binCnt-1)*2);
4772
+  p->bN        = cmMin( p->a.binCnt, ceil(p->a.pkMaxHz / p->binHz ));
4732 4773
   p->dbM       = cmMemResizeZ(cmReal_t,p->dbM,p->hN*p->bN);
4733 4774
   p->hi        = 0;
4734 4775
   p->fN        = 0;
@@ -4737,7 +4778,9 @@ cmRC_t    cmFrqTrkInit( cmFrqTrk* p, const cmFrqTrkArgs_t* a )
4737 4778
   p->deadN_max = a->maxTrkDeadSec * a->srate / a->hopSmpCnt;
4738 4779
   p->minTrkN   = a->minTrkSec * a->srate / a->hopSmpCnt;
4739 4780
   p->nextTrkId = 1;
4740
-
4781
+  p->aV        = cmMemResizeZ(cmReal_t,p->aV,p->a.binCnt);
4782
+  p->attenPhsMax    = cmMax(3,a->attenAtkSec * a->srate / a->hopSmpCnt );
4783
+  
4741 4784
   if( a->logFn != NULL )
4742 4785
     p->logFn = cmMemResizeStr(p->logFn,a->logFn);
4743 4786
 
@@ -4747,10 +4790,11 @@ cmRC_t    cmFrqTrkInit( cmFrqTrk* p, const cmFrqTrkArgs_t* a )
4747 4790
   if( a->specFn != NULL )
4748 4791
     p->specFn = cmMemResizeStr(p->specFn,a->specFn);
4749 4792
 
4750
-  p->binHz       = a->srate / ((p->a.binCnt-1)*2);
4793
+  if( a->attenFn != NULL )
4794
+    p->attenFn = cmMemResizeStr(p->attenFn,a->attenFn);
4751 4795
 
4752
-  cmReal_t whFiltCoeff = 0.33;
4753
-  if(cmWhFiltInit(p->wf,p->a.binCnt,p->binHz,whFiltCoeff,a->srate/2) != cmOkRC )
4796
+
4797
+  if(cmWhFiltInit(p->wf,p->bN,p->binHz,p->a.whFiltCoeff,p->a.pkMaxHz) != cmOkRC )
4754 4798
     cmCtxRtCondition(&p->obj, cmSubSysFailRC, "Whitening filter intitialization failed.");
4755 4799
 
4756 4800
   unsigned i;
@@ -4776,6 +4820,9 @@ cmRC_t    cmFrqTrkFinal( cmFrqTrk* p )
4776 4820
   if( p->specFn != NULL )
4777 4821
     cmVectArrayWrite(p->specVa,p->specFn);
4778 4822
 
4823
+  if( p->attenFn != NULL )
4824
+    cmVectArrayWrite(p->attenVa,p->attenFn);
4825
+
4779 4826
   cmWhFiltFinal(p->wf);
4780 4827
   return rc;
4781 4828
 }
@@ -4792,7 +4839,7 @@ cmFrqTrkCh_t* _cmFrqTrkFindAvailCh( cmFrqTrk* p )
4792 4839
 }
4793 4840
 
4794 4841
 
4795
-// Estimate the peak frequency by parabolic interpolotion into hzV[p->a.binCnt]
4842
+// Estimate the peak frequency by parabolic interpolotion into hzV[p->bN]
4796 4843
 void _cmFrqTrkMagnToHz( cmFrqTrk* p, const cmReal_t* dbV, unsigned* pkiV, unsigned pkN, cmReal_t* hzV )
4797 4844
 {
4798 4845
   unsigned i;
@@ -4802,10 +4849,15 @@ void _cmFrqTrkMagnToHz( cmFrqTrk* p, const cmReal_t* dbV, unsigned* pkiV, unsign
4802 4849
       unsigned pki  = pkiV[i];
4803 4850
       cmReal_t y0   = pki>0             ? dbV[ pki-1 ] : dbV[pki];
4804 4851
       cmReal_t y1   =                     dbV[ pki   ];
4805
-      cmReal_t y2   = pki<p->a.binCnt-1 ? dbV[ pki+1 ] : dbV[pki];
4852
+      cmReal_t y2   = pki<p->bN-1       ? dbV[ pki+1 ] : dbV[pki];
4806 4853
       cmReal_t den  = y0 - (2.*y1) + y2;
4807 4854
       cmReal_t offs = den==0 ? 0 : 0.5 * ((y0 - y2) / den);
4808 4855
       hzV[pki] = p->binHz * (pki+offs);
4856
+
4857
+      //if( hzV[pki] < 0 )
4858
+      //{
4859
+      //  printf("%f : %f %f %f : %f %f\n",hzV[pki],y0,y1,y2,den,offs);
4860
+      //}
4809 4861
     }
4810 4862
 }
4811 4863
 
@@ -4853,15 +4905,15 @@ void _cmFrqTrkWriteLog( cmFrqTrk* p )
4853 4905
     // sn = count of elements in the summary sub-vector
4854 4906
     unsigned  sn  = 3;
4855 4907
 
4856
-    // each active channel will emit 6 values
4857
-    unsigned  nn  = 1 + n*6 + sn;
4908
+    // each active channel will emit 7 values
4909
+    unsigned  nn  = 1 + n*7 + sn;
4858 4910
 
4859 4911
     // allocate the row vector
4860 4912
     vb   = cmMemResize(cmReal_t,vb,nn);
4861 4913
 
4862 4914
     // row format
4863 4915
     // [ nn idV[n] hzV[n] ... hsV[n] smV[sn]  ]
4864
-    // n = (nn - (1 + sn)) / 6
4916
+    // n = (nn - (1 + sn)) / 7
4865 4917
 
4866 4918
     *vb = nn; // the first element in the vector contains the length of the row
4867 4919
 
@@ -4874,7 +4926,8 @@ void _cmFrqTrkWriteLog( cmFrqTrk* p )
4874 4926
     cmReal_t* stV = v + n * 3;
4875 4927
     cmReal_t* dsV = v + n * 4;
4876 4928
     cmReal_t* hsV = v + n * 5;
4877
-    cmReal_t* smV = v + n * 6; // summary information
4929
+    cmReal_t* agV = v + n * 6;
4930
+    cmReal_t* smV = v + n * 7; // summary information
4878 4931
 
4879 4932
     smV[0] = p->newTrkCnt;
4880 4933
     smV[1] = p->curTrkCnt;
@@ -4895,6 +4948,7 @@ void _cmFrqTrkWriteLog( cmFrqTrk* p )
4895 4948
         stV[j] = p->ch[i].dN;
4896 4949
         dsV[j] = p->ch[i].db_std;
4897 4950
         hsV[j] = p->ch[i].hz_std;
4951
+        agV[j] = p->ch[i].attenGain;
4898 4952
         ++j;
4899 4953
       }
4900 4954
     
@@ -4964,7 +5018,92 @@ void _cmFrqTrkScoreChs( cmFrqTrk* p )
4964 5018
       c->db_std  = sqrt(cmVOR_Variance( c->dbV,n,&c->db_mean));
4965 5019
       c->hz_mean = cmVOR_Mean(c->hzV,n);
4966 5020
       c->hz_std  = sqrt(cmVOR_Variance( c->hzV,n,&c->hz_mean));
5021
+
5022
+      c->score = c->db / ((cmMin(0.1,c->db_std) + cmMin(0.1,c->hz_std))/2);
5023
+    }
5024
+}
5025
+
5026
+void _cmFrqTrkApplyAtten( cmFrqTrk* p, cmReal_t* aV, cmReal_t gain, cmReal_t hz )
5027
+{
5028
+  int       cbi = cmMin(p->a.binCnt,cmMax(0,round(hz/p->binHz)));
5029
+  cmReal_t  map[] = { .25, .5, 1, .5, .25 };
5030
+  int       mapN = sizeof(map)/sizeof(map[0]);
5031
+  int       j;
5032
+
5033
+  int ai = cbi - mapN/2;
5034
+
5035
+  for(j=0; j<mapN; ++j,++ai)
5036
+    if( 0 <= ai && ai < p->a.binCnt )
5037
+      aV[ai] *=  1.0 - (map[j] * gain);
5038
+    
5039
+}
5040
+
5041
+void _cmFrqTrkUpdateFilter( cmFrqTrk* p )
5042
+{
5043
+  unsigned i;
5044
+  cmVOR_Fill(p->aV,p->a.binCnt,1.0);
5045
+  
5046
+  for(i=0; i<p->a.chCnt; ++i)
5047
+    if( p->ch[i].activeFl )
5048
+    {
5049
+      cmFrqTrkCh_t* c = p->ch + i;
5050
+      // 
5051
+      if( c->score >= p->a.attenThresh && c->state == kNoStateFrqTrkId )
5052
+      {
5053
+        c->attenPhsIdx = 0;
5054
+        c->state  = kAtkFrqTrkId;        
5055
+      }
5056
+
5057
+      switch( c->state )
5058
+      {
5059
+        case kNoStateFrqTrkId:
5060
+          break;
5061
+
5062
+        case kAtkFrqTrkId:
5063
+          if( c->attenPhsIdx < p->attenPhsMax )
5064
+          {
5065
+            _cmFrqTrkApplyAtten(p, p->aV, c->attenGain, c->hz);
5066
+          }
5067
+
5068
+          c->attenPhsIdx += 1;
5069
+          if( c->attenPhsIdx >= p->attenPhsMax )
5070
+            c->state = kSusFrqTrkId;
5071
+          break;
5072
+
5073
+        case kSusFrqTrkId:
5074
+
5075
+          if( c->dN > 0 )
5076
+          {
5077
+            if( c->attenPhsIdx > 0 )
5078
+            {
5079
+              c->attenPhsIdx -= 1;
5080
+              c->attenGain = cmMin(1.0,p->a.attenGain * c->attenPhsIdx / p->attenPhsMax);
5081
+            }
5082
+          }
5083
+
5084
+          _cmFrqTrkApplyAtten(p,p->aV, c->attenGain, c->hz);   
5085
+
5086
+          if( c->dN >= p->deadN_max )
5087
+            c->state = kDcyFrqTrkId;
5088
+
5089
+          break;
5090
+
5091
+        case kDcyFrqTrkId:
5092
+          if( c->attenPhsIdx > 0 )
5093
+          {
5094
+            c->attenPhsIdx -= 1;
5095
+            c->attenGain = cmMin(1.0,p->a.attenGain * c->attenPhsIdx / p->attenPhsMax);
5096
+            _cmFrqTrkApplyAtten(p,p->aV, c->attenGain, c->hz);   
5097
+          }          
5098
+          
5099
+          if( c->attenPhsIdx == 0 )
5100
+            c->activeFl = false;
5101
+
5102
+          break;
5103
+      }
4967 5104
     }
5105
+  
5106
+
4968 5107
 }
4969 5108
 
4970 5109
 // Extend the existing trackers
@@ -4996,7 +5135,9 @@ void _cmFrqTrkExtendChs( cmFrqTrk* p, const cmReal_t* dbV, const cmReal_t* hzV,
4996 5135
 
4997 5136
         if( c->dN >= p->deadN_max )
4998 5137
         {
4999
-          c->activeFl = false;
5138
+          if( c->attenPhsIdx == 0 )
5139
+            c->activeFl = false;
5140
+
5000 5141
           p->deadTrkCnt += 1;
5001 5142
         }
5002 5143
       }
@@ -5046,7 +5187,7 @@ unsigned _cmFrqTrkMaxEnergyPeakIndex( const cmFrqTrk* p, const cmReal_t* dbV, co
5046 5187
   unsigned i;
5047 5188
 
5048 5189
   for(i=0; i<pkN; ++i)
5049
-    if( pkiV[i] != cmInvalidIdx && dbV[pkiV[i]] >= mv && hzV[pkiV[i]] < p->a.pkAtkMaxHz )
5190
+    if( pkiV[i] != cmInvalidIdx && dbV[pkiV[i]] >= mv && hzV[pkiV[i]] < p->a.pkMaxHz )
5050 5191
     {
5051 5192
       mi = i;
5052 5193
       mv = dbV[pkiV[i]];
@@ -5084,6 +5225,11 @@ void _cmFrqTrkNewChs( cmFrqTrk* p, const cmReal_t* dbV, const cmReal_t* hzV, uns
5084 5225
     c->si       = 0;
5085 5226
     c->sn       = 0;
5086 5227
 
5228
+    c->score       = 0;
5229
+    c->state       = kNoStateFrqTrkId;
5230
+    c->attenPhsIdx = cmInvalidIdx;
5231
+    c->attenGain   = 1.0;
5232
+
5087 5233
     // mark the peak as unavailable
5088 5234
     pkiV[ db_max_idx ] = cmInvalidIdx;    
5089 5235
 
@@ -5111,6 +5257,21 @@ cmRC_t cmFrqTrkExec( cmFrqTrk* p, const cmReal_t* magV, const cmReal_t* phsV, co
5111 5257
   cmVOR_CopyN(p->dbM + p->hi, p->bN, p->hN, p->dbV, 1 );
5112 5258
   //cmVOR_CopyN(p->dbM + p->hi, p->bN, p->hN, whV, 1 );
5113 5259
 
5260
+  if( 1 )
5261
+  {
5262
+    cmReal_t powV[ p->bN ];
5263
+    cmVOR_MultVVV(powV,p->bN,magV,magV);
5264
+    cmWhFiltExec(p->wf,powV,p->dbV,p->bN);
5265
+  }
5266
+  else
5267
+  {
5268
+    // convert magV to Decibels
5269
+    cmVOR_AmplToDbVV(p->dbV,p->bN, magV, -200.0);
5270
+  }
5271
+
5272
+  // copy p->dbV to dbM[hi,:] 
5273
+  cmVOR_CopyN(p->dbM + p->hi, p->bN, p->hN, p->dbV, 1 );
5274
+
5114 5275
   // increment hi
5115 5276
   p->hi = (p->hi + 1) % p->hN;
5116 5277
 
@@ -5124,7 +5285,7 @@ cmRC_t cmFrqTrkExec( cmFrqTrk* p, const cmReal_t* magV, const cmReal_t* phsV, co
5124 5285
     // set the indexes of the peaks above pkThreshDb in i0[]
5125 5286
     unsigned pkN = cmVOR_PeakIndexes(p->pkiV, p->bN, p->dbV, p->bN, p->a.pkThreshDb );
5126 5287
 
5127
-    // 
5288
+    // generate the peak frequencies from the magnitude
5128 5289
     _cmFrqTrkMagnToHz(p, p->dbV, p->pkiV, pkN, hzV );
5129 5290
 
5130 5291
     // extend the existing trackers
@@ -5135,8 +5296,12 @@ cmRC_t cmFrqTrkExec( cmFrqTrk* p, const cmReal_t* magV, const cmReal_t* phsV, co
5135 5296
     // create new trackers
5136 5297
     _cmFrqTrkNewChs(p,p->dbV,hzV,p->pkiV,pkN);
5137 5298
   
5299
+    //
5138 5300
     _cmFrqTrkScoreChs(p);
5139 5301
 
5302
+    // 
5303
+    _cmFrqTrkUpdateFilter(p);
5304
+
5140 5305
     // write the log file
5141 5306
     _cmFrqTrkWriteLog(p);
5142 5307
 
@@ -5144,6 +5309,10 @@ cmRC_t cmFrqTrkExec( cmFrqTrk* p, const cmReal_t* magV, const cmReal_t* phsV, co
5144 5309
     if( p->specFn != NULL )
5145 5310
       cmVectArrayAppendR(p->specVa,p->dbV,p->bN);
5146 5311
 
5312
+    // write the atten output file
5313
+    if( p->attenFn != NULL )
5314
+      cmVectArrayAppendR(p->attenVa,p->aV,p->bN);
5315
+
5147 5316
     // write the the level file
5148 5317
     _cmFrqTrkWriteLevel(p,p->dbV,hzV,p->bN);
5149 5318
   }
@@ -5157,7 +5326,7 @@ void  cmFrqTrkPrint( cmFrqTrk* p )
5157 5326
 {
5158 5327
   printf("srate:         %f\n",p->a.srate);
5159 5328
   printf("chCnt:         %i\n",p->a.chCnt);
5160
-  printf("binCnt:        %i\n",p->a.binCnt);
5329
+  printf("binCnt:        %i (bN=%i)\n",p->a.binCnt,p->bN);
5161 5330
   printf("hopSmpCnt:     %i\n",p->a.hopSmpCnt);
5162 5331
   printf("stRange:       %f\n",p->a.stRange);
5163 5332
   printf("wndSecs:       %f (%i)\n",p->a.wndSecs,p->hN);
@@ -5225,19 +5394,26 @@ cmRC_t cmSpecDistInit( cmSpecDist_t* p, unsigned procSmpCnt, double srate, unsig
5225 5394
   p->pvs = cmPvSynAlloc(  p->obj.ctx, NULL, procSmpCnt, srate, wndSmpCnt, p->hopSmpCnt, olaWndTypeId );
5226 5395
 
5227 5396
   fta.srate         = srate;
5228
-  fta.chCnt         = 20;       
5397
+  fta.chCnt         = 50;       
5229 5398
   fta.binCnt        = p->pva->binCnt;
5230 5399
   fta.hopSmpCnt     = p->pva->hopSmpCnt;
5231 5400
   fta.stRange       = 0.25;
5232
-  fta.wndSecs       = 0.5;
5401
+  fta.wndSecs       = 0.25;
5233 5402
   fta.minTrkSec     = 0.25;
5234 5403
   fta.maxTrkDeadSec = 0.25;
5235
-  fta.pkThreshDb    = 0.2; //-110.0;
5236
-  fta.pkAtkThreshDb = 0.9; //-60.0;
5237
-  fta.pkAtkMaxHz    = 10000;
5404
+  fta.pkThreshDb    = 0.1; //-110.0;
5405
+  fta.pkAtkThreshDb = 0.5; //-60.0;
5406
+  fta.pkMaxHz       = 10000;
5407
+  fta.whFiltCoeff   = 0.33;
5408
+
5409
+  fta.attenThresh = 900.0;
5410
+  fta.attenGain   = 0.9; 
5411
+  fta.attenAtkSec = 0.1;  
5412
+
5238 5413
   fta.logFn         = "/home/kevin/temp/frqtrk/trk_log.va";
5239 5414
   fta.levelFn       = "/home/kevin/temp/frqtrk/level.va";
5240 5415
   fta.specFn        = "/home/kevin/temp/frqtrk/spec.va";
5416
+  fta.attenFn       = "/home/kevin/temp/frqtrk/atten.va";
5241 5417
 
5242 5418
   p->ft  = cmFrqTrkAlloc( p->obj.ctx, NULL, &fta );
5243 5419
   cmFrqTrkPrint(p->ft);
@@ -5462,8 +5638,12 @@ cmRC_t  cmSpecDistExec( cmSpecDist_t* p, const cmSample_t* sp, unsigned sn )
5462 5638
 
5463 5639
     cmFrqTrkExec(p->ft, p->pva->magV, p->pva->phsV, NULL );
5464 5640
 
5465
-    cmVOR_AmplToDbVV(X1m, p->pva->binCnt, p->pva->magV, -1000.0 );
5466
-   
5641
+    // apply the freq track suppression filter
5642
+    cmVOR_MultVVV(X1m, p->pva->binCnt,p->pva->magV,p->ft->aV );
5643
+
5644
+    //cmVOR_AmplToDbVV(X1m, p->pva->binCnt, p->pva->magV, -1000.0 );
5645
+   cmVOR_AmplToDbVV(X1m, p->pva->binCnt, X1m, -1000.0 );
5646
+
5467 5647
     switch( p->mode )
5468 5648
     {
5469 5649
       case kBypassModeSdId:

+ 27
- 3
cmProc2.h Parādīt failu

@@ -844,9 +844,9 @@ extern "C" {
844 844
   // Write the column-major matrix m[rn,cn] to the file 'fn'. Note that the matrix is transposed as it is 
845 845
   // written and therefore will be read back as a 'cn' by 'rn' matrix.
846 846
   cmRC_t cmVectArrayWriteMatrixS( cmCtx* ctx, const char* fn, const cmSample_t* m, unsigned  rn, unsigned cn );
847
+  cmRC_t cmVectArrayWriteMatrixR( cmCtx* ctx, const char* fn, const cmReal_t*   m, unsigned  rn, unsigned cn );
847 848
   cmRC_t cmVectArrayWriteMatrixI( cmCtx* ctx, const char* fn, const int*        m, unsigned  rn, unsigned cn );
848 849
 
849
-
850 850
   cmRC_t   cmVectArrayRewind(   cmVectArray_t* p );
851 851
   cmRC_t   cmVectArrayAdvance(  cmVectArray_t* p, unsigned n );
852 852
   bool     cmVectArrayIsEOL(    const cmVectArray_t* p );
@@ -899,6 +899,13 @@ extern "C" {
899 899
   cmRC_t    cmWhFiltExec( cmWhFilt* p, const cmReal_t* xV, cmReal_t* yV, unsigned xyN );
900 900
 
901 901
   //-----------------------------------------------------------------------------------------------------------------------
902
+  typedef enum
903
+  {
904
+    kNoStateFrqTrkId,
905
+    kAtkFrqTrkId,
906
+    kSusFrqTrkId,
907
+    kDcyFrqTrkId
908
+  } cmFrqTrkAttenStateId_t;
902 909
 
903 910
   typedef struct
904 911
   {
@@ -912,10 +919,17 @@ extern "C" {
912 919
     cmReal_t    maxTrkDeadSec;  // maximum length of time a tracker may fail to connect to a peak before being declared disconnected.
913 920
     cmReal_t    pkThreshDb;     // minimum amplitide in Decibels of a selected spectral peak.
914 921
     cmReal_t    pkAtkThreshDb;  // minimum amplitude in Decibels for the first frame of a new track.
915
-    cmReal_t    pkAtkMaxHz;     // maximum frequency for a new track.
922
+    cmReal_t    pkMaxHz;        // maximum frequency to track
923
+    cmReal_t    whFiltCoeff;
924
+
925
+    cmReal_t    attenThresh;
926
+    cmReal_t    attenGain; 
927
+    cmReal_t    attenAtkSec;   
928
+
916 929
     const char* logFn;          // log file name or NULL if no file is to be written
917 930
     const char* levelFn;        // level file name or NULL if no file is to be written
918 931
     const char* specFn;         // spectrum file name or NULL if no file is to be written
932
+    const char* attenFn;
919 933
 
920 934
   } cmFrqTrkArgs_t;
921 935
 
@@ -938,6 +952,11 @@ extern "C" {
938 952
     cmReal_t hz_mean;
939 953
     cmReal_t hz_std;
940 954
 
955
+    cmReal_t score;
956
+
957
+    cmFrqTrkAttenStateId_t state;
958
+    int      attenPhsIdx;
959
+    cmReal_t attenGain;
941 960
   } cmFrqTrkCh_t;
942 961
 
943 962
   struct cmBinMtxFile_str;
@@ -965,15 +984,20 @@ extern "C" {
965 984
     unsigned      curTrkCnt;
966 985
     unsigned      deadTrkCnt;
967 986
 
987
+    cmReal_t*     aV;
988
+    int           attenPhsMax;
989
+
968 990
     cmWhFilt*      wf;
969 991
 
970 992
     cmVectArray_t* logVa;
971 993
     cmVectArray_t* levelVa;
972 994
     cmVectArray_t* specVa;
973
-    
995
+    cmVectArray_t* attenVa;
996
+
974 997
     cmChar_t*      logFn;
975 998
     cmChar_t*      levelFn;
976 999
     cmChar_t*      specFn;
1000
+    cmChar_t*      attenFn;
977 1001
 
978 1002
   } cmFrqTrk;
979 1003
 

Notiek ielāde…
Atcelt
Saglabāt