Browse Source

cmProc5.h/c : Added history buffer to cmReflectCalc to allow evaluating correlation stability.

master
kevin 8 years ago
parent
commit
a720bd8d30
2 changed files with 84 additions and 5 deletions
  1. 75
    3
      cmProc5.c
  2. 9
    2
      cmProc5.h

+ 75
- 3
cmProc5.c View File

726
   if((rc = cmReflectCalcFinal(p)) != cmOkRC )
726
   if((rc = cmReflectCalcFinal(p)) != cmOkRC )
727
     return rc;
727
     return rc;
728
 
728
 
729
+  cmMemFree(p->t0V);
730
+  cmMemFree(p->t1V);
729
   cmVectArrayFree(&p->phVa);
731
   cmVectArrayFree(&p->phVa);
730
   cmVectArrayFree(&p->xVa);
732
   cmVectArrayFree(&p->xVa);
731
   cmVectArrayFree(&p->yVa);
733
   cmVectArrayFree(&p->yVa);
770
     goto errLabel;
772
     goto errLabel;
771
   }
773
   }
772
 
774
 
773
-  
774
   p->xi     = 0;
775
   p->xi     = 0;
775
-  p->zeroFl = false;
776
 
776
 
777
+  p->tN     = 5;
778
+  p->t0V    = cmMemResizeZ(unsigned,p->t0V,p->tN);
779
+  p->t1V    = cmMemResizeZ(unsigned,p->t1V,p->tN);
780
+  p->ti     = 0;
781
+  p->t      = 0;
782
+  
777
  errLabel:
783
  errLabel:
778
   
784
   
779
   return rc;
785
   return rc;
786
   return cmOkRC;
792
   return cmOkRC;
787
 }
793
 }
788
 
794
 
795
+/*
789
 cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN )
796
 cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN )
790
 {
797
 {
791
   unsigned i;
798
   unsigned i;
792
 
799
 
793
   // feed audio into the PHAT's buffer
800
   // feed audio into the PHAT's buffer
794
   cmPhatExec(p->phat,xV,xyN);
801
   cmPhatExec(p->phat,xV,xyN);
795
-  
802
+
803
+  // fill the output buffer
796
   for(i=0; i<xyN; ++i,++p->xi)
804
   for(i=0; i<xyN; ++i,++p->xi)
797
   {
805
   {
798
     if( p->xi < p->gs->sigN )
806
     if( p->xi < p->gs->sigN )
820
   cmVectArrayAppendS(p->yVa,yV,xyN);
828
   cmVectArrayAppendS(p->yVa,yV,xyN);
821
 
829
 
822
   return cmOkRC;
830
   return cmOkRC;
831
+}
832
+*/
833
+
834
+cmRC_t cmReflectCalcExec( cmReflectCalc_t* p, const cmSample_t* xV, cmSample_t* yV, unsigned xyN )
835
+{
836
+  unsigned i;
837
+
838
+  unsigned xyN0 = xyN;
839
+
840
+  while(xyN0)
841
+  {
842
+    // feed audio into the PHAT's buffer
843
+    unsigned di = p->phat->di;
844
+    unsigned n  = cmMin(xyN0,p->phat->fhN - di );
845
+    
846
+    cmPhatExec(p->phat,xV,n);
847
+
848
+    if( di + n == p->phat->fhN )
849
+    {
850
+      // execute the correlation
851
+      cmPhatChExec(p->phat,0,0,0);
852
+      
853
+      // p->phat->xV[fhN] now holds the correlation result
854
+
855
+      // get the peak index
856
+      p->t1V[p->ti] = cmVOS_MaxIndex(p->phat->xV,p->phat->fhN,1);
857
+
858
+      printf("%i %i\n",p->t,p->t1V[p->ti]);
859
+
860
+      p->ti = (p->ti + 1) % p->tN;
861
+
862
+      
863
+      // store the correlation result
864
+      if( p->phVa != NULL )
865
+        cmVectArrayAppendS(p->phVa,p->phat->xV,p->phat->fhN );
866
+      
867
+    }
868
+
869
+    xyN0 -= n;
870
+
871
+  }
823
   
872
   
873
+  // fill the output buffer
874
+  for(i=0; i<xyN; ++i)
875
+  {
876
+    if( p->xi == 0 )
877
+      p->t0V[p->ti] = p->t + i;
878
+    
879
+    if( p->xi < p->gs->sigN )
880
+      yV[i] = p->gs->ch[0].mdV[p->xi];
881
+    else
882
+      yV[i] = 0;
883
+
884
+    p->xi = (p->xi+1) % p->phat->fhN;
885
+  }
886
+
887
+  p->t += xyN;
888
+  
889
+  if( p->xVa != NULL )
890
+    cmVectArrayAppendS(p->xVa,xV,xyN);
891
+
892
+  if( p->yVa != NULL )
893
+    cmVectArrayAppendS(p->yVa,yV,xyN);
894
+
895
+  return cmOkRC;
824
 }
896
 }
825
 
897
 
826
 cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr )
898
 cmRC_t cmReflectCalcWrite( cmReflectCalc_t* p, const char* dirStr )

+ 9
- 2
cmProc5.h View File

196
   // 
196
   // 
197
   //
197
   //
198
 
198
 
199
+
199
   typedef struct
200
   typedef struct
200
   {
201
   {
201
     cmObj obj;
202
     cmObj obj;
202
 
203
 
203
     cmGoldSig_t*     gs;
204
     cmGoldSig_t*     gs;
204
-    unsigned         xi;  // index into gs->ch[0].mdV[] of the next sample to output
205
-    bool             zeroFl;
206
     cmPhat_t*        phat;
205
     cmPhat_t*        phat;
207
     
206
     
207
+    unsigned         xi;     // index into xV[] of the next sample to output
208
+    
209
+    unsigned         t;
210
+    unsigned*        t0V;    // t0V[tN] - last tN signal start times 
211
+    unsigned*        t1V;    // t1V[tN] - last tN signal detection times 
212
+    unsigned         tN;
213
+    unsigned         ti;
214
+    
208
     cmVectArray_t*   phVa;
215
     cmVectArray_t*   phVa;
209
     cmVectArray_t*   xVa;
216
     cmVectArray_t*   xVa;
210
     cmVectArray_t*   yVa;
217
     cmVectArray_t*   yVa;

Loading…
Cancel
Save