Procházet zdrojové kódy

cmProc2.h/c: Many changes to cmVectArray. Fixed high-pass generation in cmFIR.

master
Kevin Larke před 9 roky
rodič
revize
962ec25635
2 změnil soubory, kde provedl 494 přidání a 347 odebrání
  1. 404
    311
      cmProc2.c
  2. 90
    36
      cmProc2.h

+ 404
- 311
cmProc2.c
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 90
- 36
cmProc2.h Zobrazit soubor

@@ -176,12 +176,18 @@ extern "C" {
176 176
 
177 177
   enum { kHighPassFIRFl = 0x01 };
178 178
 
179
-  /// Set p to NULL to dynamically allocate the object.
180
-  cmFIR* cmFIRAllocKaiser(cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, double passHz, double stopHz, double passDb, double stopDb );
181
-  cmFIR* cmFIRAllocSinc(  cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz, unsigned flags );
179
+  // Note that the relative values of passHz and stopHz do not matter
180
+  // for low-pass vs high-pass filters.  In practice passHz and
181
+  // stopHz can be swapped with no effect on the filter in either
182
+  // case.  Set p to NULL to dynamically allocate the object.
183
+  cmFIR* cmFIRAllocKaiser(cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, double passHz, double stopHz, double passDb, double stopDb, unsigned flags );
184
+
185
+  // Set wndV[sincSmpCnt] to NULL to use a unity window otherwise set it to a window
186
+  // function of length sincSmpCnt.
187
+  cmFIR* cmFIRAllocSinc(  cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz, unsigned flags, const double* wndV );
182 188
   cmRC_t cmFIRFree(       cmFIR** pp );
183
-  cmRC_t cmFIRInitKaiser( cmFIR* p, unsigned procSmpCnt, double srate, double passHz, double stopHz, double passDb, double stopDb );
184
-  cmRC_t cmFIRInitSinc(   cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz, unsigned flags );
189
+  cmRC_t cmFIRInitKaiser( cmFIR* p, unsigned procSmpCnt, double srate, double passHz,       double stopHz, double passDb, double stopDb, unsigned flags );
190
+  cmRC_t cmFIRInitSinc(   cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz,   unsigned flags, const double* wndV );
185 191
   cmRC_t cmFIRFinal(      cmFIR* p );
186 192
   cmRC_t cmFIRExec(       cmFIR* p, const cmSample_t* sp, unsigned sn );
187 193
   void   cmFIRTest();
@@ -783,6 +789,8 @@ extern "C" {
783 789
       double*     dV;  // dV[n] vector of doubles  
784 790
       float*      fV;  // fV[n] vecotr of floats
785 791
       cmSample_t* sV;  // sV[n] vector of cmSample_t
792
+      int*        iV;
793
+      unsigned*   uV;
786 794
     } u;
787 795
 
788 796
     struct cmVectArrayVect_str* link; // link to next element record
@@ -791,23 +799,24 @@ extern "C" {
791 799
 
792 800
   enum
793 801
   {
794
-    kFloatVaFl  = 0x01,
795
-    kDoubleVaFl = 0x02,
796
-    kSampleVaFl = 0x04,
797
-    kRealVaFl   = 0x08,
798
-    kIntVaFl    = 0x02,  // int and uint is converted to double
799
-    kUIntVaFl   = 0x02   // 
802
+    kDoubleVaFl = 0x01,
803
+    kRealVaFl   = 0x01,
804
+    kFloatVaFl  = 0x02,
805
+    kSampleVaFl = 0x02,
806
+    kIntVaFl    = 0x04,
807
+    kUIntVaFl   = 0x08,
808
+    kVaMask     = 0x0f
800 809
   };
801 810
 
802 811
   typedef struct
803 812
   {
804 813
     cmObj              obj;
805
-    cmVectArrayVect_t* bp;         // first list element
806
-    cmVectArrayVect_t* ep;         // last list element
814
+    cmVectArrayVect_t* bp;          // first list element
815
+    cmVectArrayVect_t* ep;          // last list element
807 816
     unsigned           vectCnt;     // count of elements in linked list
808
-    unsigned           flags;      // data vector type (See: kFloatVaFl, kDoubleVaFl, ... )
817
+    unsigned           flags;       // data vector type (See: kFloatVaFl, kDoubleVaFl, ... )
809 818
     unsigned           typeByteCnt; // size of a single data vector value (e.g. 4=float 8=double)
810
-    unsigned           maxEleCnt; // length of the longest data vector
819
+    unsigned           maxEleCnt;   // length of the longest data vector
811 820
     double*            tempV;
812 821
     cmVectArrayVect_t* cur;
813 822
   } cmVectArray_t;
@@ -824,7 +833,13 @@ extern "C" {
824 833
   // Return the count of vectors contained in the vector array.
825 834
   cmRC_t cmVectArrayCount(   const cmVectArray_t* p );
826 835
 
836
+  // Return the maximum element count among all rows.
837
+  unsigned cmVectArrayMaxRowCount( const cmVectArray_t* p );
838
+
827 839
   // Store a new vector by appending it to the end of the internal vector list.
840
+  // Note that the true type of v[] in the call to cmVectArrayAppendV() must match
841
+  // the data type set in p->flags.
842
+  cmRC_t cmVectArrayAppendV( cmVectArray_t* p, const void* v,       unsigned vn );
828 843
   cmRC_t cmVectArrayAppendS( cmVectArray_t* p, const cmSample_t* v, unsigned vn );
829 844
   cmRC_t cmVectArrayAppendR( cmVectArray_t* p, const cmReal_t* v,   unsigned vn );
830 845
   cmRC_t cmVectArrayAppendF( cmVectArray_t* p, const float* v,      unsigned vn );
@@ -835,45 +850,84 @@ extern "C" {
835 850
   // Write a vector array in a format that can be read by readVectArray.m.
836 851
   cmRC_t cmVectArrayWrite(   cmVectArray_t* p, const char* fn );
837 852
 
853
+  // Print the vector array to rpt.
854
+  cmRC_t cmVectArrayPrint( cmVectArray_t* p, cmRpt_t* rpt );
855
+  
838 856
   typedef cmRC_t (*cmVectArrayForEachFuncS_t)( void* arg, unsigned idx, const cmSample_t* xV, unsigned xN );
839 857
   unsigned cmVectArrayForEachS( cmVectArray_t* p, unsigned idx, unsigned cnt, cmVectArrayForEachFuncS_t func, void* arg ); 
840 858
 
859
+  // Write the vector v[vn] in the VectArray file format.
860
+  // Note that the true type of v[] in cmVectArrayWriteVectoV() must match the
861
+  // data type set in the 'flags' parameter.
862
+  cmRC_t cmVectArrayWriteVectorV( cmCtx* ctx, const char* fn, const void*       v, unsigned  vn, unsigned flags );
841 863
   cmRC_t cmVectArrayWriteVectorS( cmCtx* ctx, const char* fn, const cmSample_t* v, unsigned  vn );
842
-  cmRC_t cmVectArrayWriteVectorI( cmCtx* ctx, const char* fn, const int* v,        unsigned  vn );
843
-
844
-  // Write the column-major matrix m[rn,cn] to the file 'fn'. Note that the matrix is transposed as it is 
845
-  // written and therefore will be read back as a 'cn' by 'rn' matrix.
864
+  cmRC_t cmVectArrayWriteVectorR( cmCtx* ctx, const char* fn, const cmReal_t*   v, unsigned  vn );  
865
+  cmRC_t cmVectArrayWriteVectorD( cmCtx* ctx, const char* fn, const double*     v, unsigned  vn );
866
+  cmRC_t cmVectArrayWriteVectorF( cmCtx* ctx, const char* fn, const float*      v, unsigned  vn );
867
+  cmRC_t cmVectArrayWriteVectorI( cmCtx* ctx, const char* fn, const int*        v, unsigned  vn );
868
+  cmRC_t cmVectArrayWriteVectorU( cmCtx* ctx, const char* fn, const unsigned*   v, unsigned  vn );
869
+
870
+  // Write the column-major matrix m[rn,cn] to the file 'fn'.
871
+  // Note that the true type of m[] in cmVectArrayWriteMatrixV() must match the
872
+  // data type set in the 'flags' parameter.
873
+  cmRC_t cmVectArrayWriteMatrixV( cmCtx* ctx, const char* fn, const void*       m, unsigned  rn, unsigned cn, unsigned flags );
846 874
   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 );
875
+  cmRC_t cmVectArrayWriteMatrixR( cmCtx* ctx, const char* fn, const cmReal_t*   m, unsigned  rn, unsigned cn );  
876
+  cmRC_t cmVectArrayWriteMatrixD( cmCtx* ctx, const char* fn, const double*     m, unsigned  rn, unsigned cn );
877
+  cmRC_t cmVectArrayWriteMatrixF( cmCtx* ctx, const char* fn, const float*      m, unsigned  rn, unsigned cn );
848 878
   cmRC_t cmVectArrayWriteMatrixI( cmCtx* ctx, const char* fn, const int*        m, unsigned  rn, unsigned cn );
849
-
879
+  cmRC_t cmVectArrayWriteMatrixU( cmCtx* ctx, const char* fn, const unsigned*   m, unsigned  rn, unsigned cn );
880
+
881
+  // Read a VectArray file and return it as a matrix.
882
+  // The returned memory must be released with a subsequent call to cmMemFree().
883
+  // Note that the true type of the pointer address 'mRef' in the call to 
884
+  // cmVectArrayReadMatrixV() must match the data type of the cmVectArray_t
885
+  // specified by 'fn'.
886
+  cmRC_t cmVectArrayReadMatrixV( cmCtx* ctx, const char* fn, void**       mRef, unsigned* rnRef, unsigned* cnRef );
887
+  cmRC_t cmVectArrayReadMatrixS( cmCtx* ctx, const char* fn, cmSample_t** mRef, unsigned* rnRef, unsigned* cnRef );
888
+  cmRC_t cmVectArrayReadMatrixR( cmCtx* ctx, const char* fn, cmReal_t**   mRef, unsigned* rnRef, unsigned* cnRef );  
889
+  cmRC_t cmVectArrayReadMatrixD( cmCtx* ctx, const char* fn, double**     mRef, unsigned* rnRef, unsigned* cnRef );
890
+  cmRC_t cmVectArrayReadMatrixF( cmCtx* ctx, const char* fn, float**      mRef, unsigned* rnRef, unsigned* cnRef );
891
+  cmRC_t cmVectArrayReadMatrixI( cmCtx* ctx, const char* fn, int**        mRef, unsigned* rnRef, unsigned* cnRef );
892
+  cmRC_t cmVectArrayReadMatrixU( cmCtx* ctx, const char* fn, unsigned**   mRef, unsigned* rnRef, unsigned* cnRef );
893
+
894
+  // Row iteration control functions.
850 895
   cmRC_t   cmVectArrayRewind(   cmVectArray_t* p );
851 896
   cmRC_t   cmVectArrayAdvance(  cmVectArray_t* p, unsigned n );
852 897
   bool     cmVectArrayIsEOL(    const cmVectArray_t* p );
853 898
   unsigned cmVectArrayEleCount( const cmVectArray_t* p );
854
-  cmRC_t   cmVectArrayGetF(     cmVectArray_t* p, float* v,      unsigned* vnRef );
855
-  cmRC_t   cmVectArrayGetD(     cmVectArray_t* p, double* v,     unsigned* vnRef );
856
-  cmRC_t   cmVectArrayGetI(     cmVectArray_t* p, int* v,        unsigned* vnRef );
857
-  cmRC_t   cmVectArrayGetU(     cmVectArray_t* p, unsigned* v,   unsigned* vnRef );
899
+
900
+  // Copy the current row vector to v[].
901
+  // Note that the true type of v[] in cmVectArrayGetV() must match the data type of 'p'.
902
+  cmRC_t  cmVectArrayGetV(     cmVectArray_t* p, void*       v, unsigned* vnRef );
903
+  cmRC_t  cmVectArrayGetS(     cmVectArray_t* p, cmSample_t* v, unsigned* vnRef );  
904
+  cmRC_t  cmVectArrayGetR(     cmVectArray_t* p, cmReal_t*   v, unsigned* vnRef );
905
+  cmRC_t  cmVectArrayGetD(     cmVectArray_t* p, double*     v, unsigned* vnRef );  
906
+  cmRC_t  cmVectArrayGetF(     cmVectArray_t* p, float*      v, unsigned* vnRef );
907
+  cmRC_t  cmVectArrayGetI(     cmVectArray_t* p, int*        v, unsigned* vnRef );
908
+  cmRC_t  cmVectArrayGetU(     cmVectArray_t* p, unsigned*   v, unsigned* vnRef );
909
+
910
+  // Set *resultFlRef to true if m[rn,cn] is equal to the cmVectArray_t specified by 'fn'.
911
+  // Note that the true type of 'm[]' in the call to cmVectArrayMatrixIsEqualV()
912
+  // must match the data type set in 'flags'.
913
+  cmRC_t  cmVectArrayMatrixIsEqualV( cmCtx* ctx, const char* fn, const void*       m, unsigned rn, unsigned cn, bool* resultFlRef, unsigned flags );
914
+  cmRC_t  cmVectArrayMatrixIsEqualS( cmCtx* ctx, const char* fn, const cmSample_t* m, unsigned rn, unsigned cn, bool* resultFlRef );  
915
+  cmRC_t  cmVectArrayMatrixIsEqualR( cmCtx* ctx, const char* fn, const cmReal_t*   m, unsigned rn, unsigned cn, bool* resultFlRef );  
916
+  cmRC_t  cmVectArrayMatrixIsEqualD( cmCtx* ctx, const char* fn, const double*     m, unsigned rn, unsigned cn, bool* resultFlRef );  
917
+  cmRC_t  cmVectArrayMatrixIsEqualF( cmCtx* ctx, const char* fn, const float*      m, unsigned rn, unsigned cn, bool* resultFlRef );  
918
+  cmRC_t  cmVectArrayMatrixIsEqualI( cmCtx* ctx, const char* fn, const int*        m, unsigned rn, unsigned cn, bool* resultFlRef );  
919
+  cmRC_t  cmVectArrayMatrixIsEqualU( cmCtx* ctx, const char* fn, const unsigned*   m, unsigned rn, unsigned cn, bool* resultFlRef );  
858 920
 
859 921
   // If a vector array is composed of repeating blocks of 'groupCnt' sub-vectors 
860 922
   // where the concatenated ith sub-vectors in each group form a single super-vector then
861 923
   // this function will return the super-vector.  Use cmMemFree(*vRef) to release
862 924
   // the returned super-vector.
863
-  cmRC_t   cmVectArrayFormVectF( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, float** vRef, unsigned* vnRef );
925
+  cmRC_t   cmVectArrayFormVectR( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, cmReal_t**   vRef, unsigned* vnRef );
926
+  cmRC_t   cmVectArrayFormVectF( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, float**      vRef, unsigned* vnRef );
864 927
 
865 928
   cmRC_t   cmVectArrayFormVectColF( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, unsigned colIdx, float**    vRef, unsigned* vnRef );
866 929
   cmRC_t   cmVectArrayFormVectColU( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, unsigned colIdx, unsigned** vRef, unsigned* vnRef );
867
-  cmRC_t   cmVectArrayTest( cmCtx* ctx, const char* fn );  
868
-
869
-
870
-#if CM_FLOAT_SMP == 1
871
-#define cmVectArrayGetS cmVectArrayGetF
872
-#define cmVectArrayFormVectS cmVectArrayFormVectF
873
-#else
874
-#define cmVectArrayGetS cmVectArrayGetD
875
-#define cmVectArrayFormVectS cmVectArrayFormVectD
876
-#endif
930
+  cmRC_t   cmVectArrayTest( cmCtx* ctx, const char* fn, bool genFl );  
877 931
 
878 932
   //-----------------------------------------------------------------------------------------------------------------------
879 933
   // Spectral whitening filter.

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