浏览代码

Many documentation string additions and updates.

master
kevin 4 年前
父节点
当前提交
7b32da2c04

+ 12
- 0
src/app/cmMidiScoreFollow.h 查看文件

@@ -5,6 +5,17 @@
5 5
 #ifdef __cplusplus
6 6
 extern "C" {
7 7
 #endif
8
+  
9
+  //( { file_desc:"Score follow a MIDI files." kw[score] }
10
+  //
11
+  // This function uses a CSV score file generated from cmXScoreTest() to score follow a MIDI file.
12
+  // Output filesL
13
+  // - MIDI file with velocities from the score applied to the associated notes in the MIDI file.
14
+  // - A text file, for use with cmTimeLine, which describes the bar positions as absolute times into the score.
15
+  // - An SVG file which shows the score match results over time for each note in the score.
16
+  // - A report file which lists the score match status over time.
17
+  
18
+  
8 19
 
9 20
   enum
10 21
   {
@@ -24,6 +35,7 @@ extern "C" {
24 35
     const cmChar_t* midiOutFn,       // (optional) midiFn with apply sostenuto and velocities from the score to the MIDI file
25 36
     const cmChar_t* tlBarOutFn       // (optional) bar positions sutiable for use in a cmTimeLine description file.
26 37
                                   );
38
+  //)
27 39
   
28 40
 #ifdef __cplusplus
29 41
 }

+ 4
- 0
src/app/cmScoreMatchGraphic.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Implements the functionality of cmMidiScoreFollowMain()." kw[score] }
9
+
8 10
   enum
9 11
   {
10 12
     kOkSmgRC = cmOkRC,
@@ -34,6 +36,8 @@ extern "C" {
34 36
   // from from score into MIDI file and then write the updated MIDI
35 37
   // file to 'newMidiFn'.
36 38
   cmSmgRC_t cmScoreMatchGraphicUpdateMidiFromScore( cmCtx_t* ctx, cmSmgH_t h, const cmChar_t* newMidiFn );
39
+
40
+  //)
37 41
   
38 42
 #ifdef __cplusplus
39 43
 }

+ 13
- 0
src/app/cmXScore.h 查看文件

@@ -5,6 +5,17 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Process a Music XML score in a variety of ways." kw[score] }
9
+
10
+  //$
11
+  // cmScoreTest() performs a the following functions:
12
+  // - Parses Music XML files into a text (edit) file.
13
+  // - The 'edit' file can then be manually edited to modify and add information to the score.
14
+  // - The modified 'edit' file can then be used to generate a CSV file
15
+  // suitable for use with cmScore(), a MIDI file which can render the modified score,
16
+  // and a SVG file which will display the score as a piano roll.
17
+  //
18
+  
8 19
   enum
9 20
   {
10 21
     kOkXsRC = cmOkRC,
@@ -73,6 +84,8 @@ extern "C" {
73 84
   // Set begMeasNumb to the first measure the to be written to the output csv, MIDI and SVG files.
74 85
   // Set begBPM to 0 to use the tempo from the score otherwise set it to the tempo at begMeasNumb.
75 86
   cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* xmlFn, const cmChar_t* reorderFn, const cmChar_t* csvOutFn, const cmChar_t* midiOutFn, const cmChar_t* svgOutFn, bool reportFl, int begMeasNumb, int begBPM, bool svgStandAloneFl, bool svgPanZoomFl, bool damperRptFl );
87
+
88
+  //)
76 89
   
77 90
 #ifdef __cplusplus
78 91
 }

+ 8
- 2
src/cmApBuf.c 查看文件

@@ -1071,7 +1071,12 @@ void cmApBufReport( cmRpt_t* rpt )
1071 1071
   }
1072 1072
 }
1073 1073
 
1074
-/// [cmApBufExample]
1074
+//{ { label:cmApBufExample }
1075
+//(
1076
+// cmApBufTest() demonstrates the audio buffer usage.
1077
+//)
1078
+
1079
+//(
1075 1080
 
1076 1081
 void cmApBufTest( cmRpt_t* rpt )
1077 1082
 {
@@ -1172,6 +1177,7 @@ void cmApBufTest( cmRpt_t* rpt )
1172 1177
   cmApBufFinalize();
1173 1178
 }
1174 1179
 
1175
-/// [cmApBufExample]
1180
+//)
1181
+//}
1176 1182
 
1177 1183
 

+ 1
- 1
src/cmAudioPort.h 查看文件

@@ -1,4 +1,4 @@
1
-//( { file_desc: "Cross platform audio device interface." kw:[audio rt] }
1
+//( { file_desc: "Cross platform audio device interface." kw:[audio rt devices] }
2 2
 //
3 3
 // This interface provides data declarations for platform dependent 
4 4
 // audio I/O functions. The implementation for the functions are

+ 9
- 3
src/cmAudioSys.c 查看文件

@@ -1157,11 +1157,16 @@ unsigned cmAudioSysSubSystemCount( cmAudioSysH_t h )
1157 1157
 
1158 1158
 //===========================================================================================================================
1159 1159
 //
1160
-//  cmAsTest()
1160
+//  cmAudioSysTest()
1161 1161
 //
1162 1162
 
1163
-/// [cmAudioSysTest]
1163
+//{ { label:cmAudioSysTest }
1164
+//(
1165
+// cmAudioSysTest() demonstrates the audio system usage.
1166
+//)
1164 1167
 
1168
+//(
1169
+ 
1165 1170
 typedef struct 
1166 1171
 {
1167 1172
   double   hz;       // current synth frq
@@ -1463,4 +1468,5 @@ void cmAudioSysTest( cmRpt_t* rpt, int argc, const char* argv[] )
1463 1468
 
1464 1469
 }
1465 1470
 
1466
-/// [cmAudioSysTest]
1471
+//)
1472
+//}

+ 3
- 2
src/cmJson.c 查看文件

@@ -3994,7 +3994,8 @@ void _cmJsonTestPrint( void* userPtr, const cmChar_t* text )
3994 3994
 //(
3995 3995
 // cmJsonTest() demonstrates some JSON tree operations.
3996 3996
 //)
3997
-//[
3997
+
3998
+//(
3998 3999
 cmJsRC_t cmJsonTest( const char* fn, cmCtx_t* ctx )
3999 4000
 {
4000 4001
   cmJsRC_t      rc  = kOkJsRC;
@@ -4076,5 +4077,5 @@ cmJsRC_t cmJsonTest( const char* fn, cmCtx_t* ctx )
4076 4077
 
4077 4078
   return rc == kOkJsRC ? rc1 : rc;
4078 4079
 }
4079
-//]
4080
+//)
4080 4081
 //}

+ 1
- 1
src/cmKeyboard.h 查看文件

@@ -5,7 +5,7 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
-  //( { file_desc:"Query and get keypresses directly from the console." kw:[system] }
8
+  //( { file_desc:"Query and get keypresses directly from the console." kw:[system devices] }
9 9
   
10 10
   enum
11 11
   {

+ 1
- 1
src/cmMidiPort.h 查看文件

@@ -5,7 +5,7 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
-  //(  { file_desc:"Device independent MIDI port related code." kw:[midi]}
8
+  //(  { file_desc:"Device independent MIDI port related code." kw:[midi devices]}
9 9
 
10 10
   typedef unsigned cmMpRC_t;
11 11
 

+ 4
- 1
src/cmPP_NARG.h 查看文件

@@ -1,7 +1,8 @@
1 1
 #ifndef cmPP_NARG_H
2 2
 #define cmPP_NARG_H
3 3
 
4
-
4
+//( { file_desc:"Var-args argument counter. " kw:[base] }
5
+//
5 6
 // Taken from here:
6 7
 // https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
7 8
 // and here:
@@ -43,3 +44,5 @@
43 44
          9,8,7,6,5,4,3,2,1,0
44 45
 
45 46
 #endif
47
+
48
+//)

+ 2
- 1
src/cmPrefix.h 查看文件

@@ -5,8 +5,9 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Global prefix header for the 'cm' library. Currently empty." kw:[base] }
8 9
 
9
-
10
+  //)
10 11
 
11 12
 #ifdef __cplusplus
12 13
 }

+ 0
- 1
src/cmProcTest.c 查看文件

@@ -28,7 +28,6 @@
28 28
 #include <time.h> // time()
29 29
 
30 30
 
31
-
32 31
 void cmTestPrint( cmRpt_t* rpt, const char* fmt, ... )
33 32
 {
34 33
   va_list vl;

+ 4
- 0
src/cmProcTest.h 查看文件

@@ -5,10 +5,14 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc: "Some obsolete test stub functions. See the cmtools project for a complete set of test and example functions." kw:[proc]}
9
+  
8 10
   void cmProcTestNoInit( cmCtx_t* ctx );
9 11
   void cmProcTestGnuPlot( cmCtx_t* ctx );
10 12
   void cmProcTest( cmCtx_t* ctx );
11 13
 
14
+  //)
15
+  
12 16
 #ifdef __cplusplus
13 17
 }
14 18
 #endif

+ 4
- 0
src/cmRptFile.h 查看文件

@@ -4,6 +4,8 @@
4 4
 #ifdef __cplusplus
5 5
 extern "C" {
6 6
 #endif
7
+  
8
+  //( { file_desc: "The cmRptFile provides a cmRpt class which outputs to a file." kw:[base]}
7 9
 
8 10
   enum
9 11
   {
@@ -23,6 +25,8 @@ extern "C" {
23 25
     
24 26
   cmRpt_t* cmRptFileRpt( cmRptFileH_t h );
25 27
 
28
+  //)
29
+  
26 30
 #ifdef __cplusplus
27 31
 }
28 32
 #endif

+ 4
- 0
src/cmSerialPort.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Serial port interface." kw[system devices rt] }
9
+  
8 10
   typedef unsigned cmSeRC_t;
9 11
 
10 12
   enum
@@ -86,6 +88,8 @@ extern "C" {
86 88
 
87 89
   cmSeRC_t cmSePortTest(cmCtx_t* ctx);
88 90
 
91
+  //)
92
+  
89 93
 #ifdef __cplusplus
90 94
 }
91 95
 #endif

+ 5
- 0
src/cmSvgWriter.h 查看文件

@@ -5,6 +5,9 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"SVG file writer." kw[file plot] }
9
+  
10
+
8 11
 enum
9 12
 {
10 13
   kOkSvgRC = cmOkRC,
@@ -31,6 +34,8 @@ enum
31 34
   // Both the CSS file and svg-pan-zoom.min.js should therefore be in the same directory
32 35
   // as the output HTML file.
33 36
   cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn, bool standaloneFl, bool panZoomFl );
37
+
38
+  //)
34 39
   
35 40
 #ifdef __cplusplus
36 41
 }

+ 4
- 1
src/cmSyncRecd.h 查看文件

@@ -4,6 +4,8 @@
4 4
 #ifdef __cplusplus
5 5
 extern "C" {
6 6
 #endif
7
+  
8
+  //( { file_desc:"Generate time-alignment data between an audio and MIDI file. See cmDspSyncRecd_t." kw[proc] }
7 9
 
8 10
   enum
9 11
   {
@@ -27,7 +29,8 @@ extern "C" {
27 29
   
28 30
 
29 31
   cmSyRC_t cmSyncRecdTest( cmCtx_t* ctx );
30
-
32
+  //)
33
+  
31 34
 #ifdef __cplusplus
32 35
 }
33 36
 #endif

+ 990
- 0
src/cmVectOpsDocOut.h 查看文件

@@ -0,0 +1,990 @@
1
+//( { file_desc:"Math vector operations." kw:[vop math] }
2
+//)
3
+//( { label:misc desc:"Miscellaneous vector operations." kw:[vop] }
4
+
5
+// Compute the cummulative sum of sbp[dn]. Equivalent to Matlab cumsum().
6
+T_t* cmVOT_CumSum(T_t* dbp, unsigned dn, const T_t* sbp ); 
7
+
8
+// Returns true if all values in each vector are equal.
9
+bool          cmVOT_Equal(    const T_t* s0p, const T_t* s1p, unsigned sn );
10
+
11
+// Same as Matlab linspace() v[i] = i * (limit-1)/n
12
+T_t*  cmVOT_LinSpace( T_t* dbp, unsigned dn, T_t base, T_t limit );
13
+
14
+//======================================================================================================================
15
+//)
16
+
17
+
18
+//( { label:Print desc:"Vector printing functions." kw:[vop] }
19
+// Setting fieldWidth or decPltCnt to to negative values result in fieldWidth == 10 or decPlCnt == 4
20
+//
21
+void          cmVOT_Printf( cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp, int fieldWidth, int decPlCnt, const char* fmt, unsigned flags );
22
+void          cmVOT_Print(  cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp );
23
+void          cmVOT_PrintE( cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp );
24
+
25
+void          cmVOT_PrintLf( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp, unsigned fieldWidth, unsigned decPlCnt, const char* fmt );
26
+void          cmVOT_PrintL(  const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp );
27
+void          cmVOT_PrintLE( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const T_t* dbp );
28
+//======================================================================================================================
29
+//)
30
+
31
+
32
+//( { label:Normalization desc:"Normalization and standardization functions." kw:[vop] }
33
+
34
+// Normalize the vector of proabilities by dividing through by the sum.
35
+// This leaves the relative proportions of each value unchanged while producing a total probability of 1.0.
36
+//
37
+T_t* cmVOT_NormalizeProbabilityVV(T_t* dbp, unsigned dn, const T_t* sbp);
38
+T_t* cmVOT_NormalizeProbability(T_t* dbp, unsigned dn);
39
+T_t* cmVOT_NormalizeProbabilityN(T_t* dbp, unsigned dn, unsigned stride);
40
+//
41
+// Standardize the columns of the matrix by subtracting the mean and dividing by the standard deviation.
42
+// uV[dcn] returns the mean of the data and is optional.
43
+// sdV[dcn] return the standard deviation of the data and is optional.
44
+T_t* cmVOT_StandardizeRows( T_t* dbp, unsigned drn, unsigned dcn, T_t* uV, T_t* sdV );
45
+T_t* cmVOT_StandardizeCols( T_t* dbp, unsigned drn, unsigned dcn, T_t* uV, T_t* sdV );
46
+//
47
+// Normalize by dividing through by the max. value.
48
+// dp[] ./= max(dp). Returns the index of the max value.
49
+unsigned  cmVOT_NormToMax(    T_t* dp, unsigned dn );
50
+//
51
+// Normalize by dividing through by the max. absolute value.
52
+// db[] .*= fact / abs(max(dp));
53
+unsigned cmVOT_NormToAbsMax(   T_t* dp, unsigned dn, T_t fact );
54
+//======================================================================================================================
55
+//)
56
+
57
+
58
+//( { label:"Mean and variance" desc:"Compute mean and variance." kw:[vop] }
59
+
60
+T_t  cmVOT_Mean(     const T_t* sp, unsigned sn );
61
+T_t  cmVOT_MeanN(    const T_t* sp, unsigned sn, unsigned stride  );
62
+//
63
+// Take the mean of each column/row of a matrix.
64
+// Set 'dim' to 0 to return mean of columns else return mean of rows.
65
+T_t*  cmVOT_MeanM(    T_t* dp, const T_t* sp, unsigned srn, unsigned scn, unsigned dim );
66
+//
67
+// Take the mean of the first 'cnt' element of each column/row of a matrix.
68
+// Set 'dim' to 0 to return mean of columns else return mean of rows.
69
+// If 'cnt' is greater than the number of elements in the column/row then 'cnt' is
70
+// reduced to the number of elements in the column/row.
71
+T_t*  cmVOT_MeanM2(    T_t* dp, const T_t* sp, unsigned srn, unsigned scn, unsigned dim, unsigned cnt );
72
+//
73
+// Find the mean of the  data points returned by srcFuncPtr(argPtr,i) and return it in dp[dim].
74
+// 'dim' is both the size of dp[] and the length of each data point returned by srcFuncPtr().
75
+// srcFuncPtr() will be called 'cnt' times but it may return NULL on some calls if the associated
76
+// data point should not be included in the mean calculation.
77
+T_t*  cmVOT_Mean2(   T_t* dp, const T_t* (*srcFuncPtr)(void* arg, unsigned idx ), unsigned dim, unsigned cnt, void* argPtr );
78
+//
79
+// avgPtr is optional - set to NULL to compute the average
80
+T_t  cmVOT_Variance( const T_t* sp, unsigned sn, const T_t* avgPtr );
81
+T_t  cmVOT_VarianceN(const T_t* sp, unsigned sn, unsigned stride, const T_t* avgPtr );
82
+//
83
+// Set dim=0 to return variance of columns otherwise return variance or rows.
84
+T_t*  cmVOT_VarianceM(T_t* dp,  const T_t* sp, unsigned srn, unsigned scn, const T_t* avgPtr, unsigned dim );
85
+//======================================================================================================================
86
+//)
87
+
88
+
89
+//( { label:"Covariance" desc:"Matrix covariance" kw:[vop] }
90
+
91
+// Calculate the sample covariance matrix from a set of Gaussian distributed multidimensional data.
92
+// sp[dn,scn] is the data set.
93
+// dn is the dimensionality of the data.
94
+// scn is the count of data points
95
+// up[dn] is an optional mean vector. If up == NULL then the mean of the data is calculated internally. 
96
+// selIdxV[scn] can be used to select a subset of datapoints to process.
97
+// If selIdxV[] is non-NULL then only columns where selIdxV[i]==selKey will be processed.
98
+//
99
+// dp[dn,dn] = covar( sp[dn,scn], u[dn] )
100
+void  cmVOT_GaussCovariance(T_t* dp, unsigned dn, const T_t* sp, unsigned scn, const T_t* up, const unsigned* selIdxV, unsigned selKey );
101
+
102
+// Calculate the sample covariance matrix.
103
+// dp[ dn*dn ] - output matrix
104
+// dn - dimensionality of the data
105
+// srcFuncPtr - User defined function which is called to return a pointer to a data vector at index 'idx'.
106
+//          The returned data vector must contain 'dn' elements.  The function should return NULL
107
+//          if the data point associated with 'idx' should not be included in the covariance calculation.
108
+// sn - count of data vectors 
109
+// userPtr - User arg. passed to srcFuncPtr.    
110
+// uV[ dn ] - mean of the data set (optional)
111
+// Note that this function computes the covariance matrix in 2 serial passes (1 if the mean vector is given)
112
+// through the 'sn' data points.  
113
+// The result of this function are identical to the octave cov() function.
114
+void  cmVOT_GaussCovariance2(T_t* dp, unsigned dn, const T_t* (*srcFuncPtr)(void* userPtr, unsigned idx), unsigned sn, void* userPtr, const T_t* uV, const unsigned* selIdxV, unsigned selKey );
115
+//======================================================================================================================
116
+//)
117
+
118
+//( { label:"Float point normal" desc:"Evaluate the 'normalness of floating point values." kw:[vop] }
119
+
120
+// Returns true if all values are 'normal' according the the C macro 'isnormal'.
121
+// This function will return false if any of the values are zero.
122
+bool          cmVOT_IsNormal( const T_t* sp, unsigned sn );
123
+
124
+// Returns true if all values are 'normal' or zero according the the C macro 'isnormal'.
125
+// This function accepts zeros as normal.
126
+bool          cmVOT_IsNormalZ(const T_t* sp, unsigned sn );
127
+
128
+// Set dp[dn] to the indexes of the non-normal numbers in sp[dn].
129
+// Returns the count of indexes stored in dp[].
130
+unsigned      cmVOT_FindNonNormal( unsigned* dp, unsigned dn, const T_t* sp );
131
+unsigned      cmVOT_FindNonNormalZ( unsigned* dp, unsigned dn, const T_t* sp );
132
+//======================================================================================================================
133
+//)
134
+
135
+
136
+//( { label:"Measure" desc:"Measure features of a vector." kw:[vop] }
137
+
138
+// Successive call to to ZeroCrossCount should preserve the value pointed to by delaySmpPtr.
139
+unsigned      cmVOT_ZeroCrossCount( const T_t* sp, unsigned n, T_t* delaySmpPtr);
140
+
141
+// Calculuate the sum of the squares of all elements in bp[bn]. 
142
+T_t cmVOT_SquaredSum( const T_t* bp, unsigned bn );
143
+
144
+// sn must be <= wndSmpCnt. If sn < wndSmpCnt then sp[sn] is treated as a
145
+// a partially filled buffer padded with wndSmpCnt-sn zeros.
146
+// rms = sqrt( sum(sp[1:sn] .* sp[1:sn]) / wndSmpCnt )
147
+T_t  cmVOT_RMS( const T_t* sp, unsigned sn, unsigned wndSmpCnt );
148
+
149
+// This function handles the case were sn is not an integer multiple of 
150
+// wndSmpCnt or hopSmpCnt.  In this case the function computes zero 
151
+// padded RMS values for windows which go past the end of sp[sn].
152
+T_t* cmVOT_RmsV( T_t* dp, unsigned dn, const T_t* sp, unsigned sn, unsigned wndSmpCnt, unsigned hopSmpCnt );
153
+
154
+// Return the magnitude (Euclidean Norm) of a vector.
155
+T_t  cmVOT_EuclidNorm( const T_t* sp, unsigned sn );
156
+
157
+T_t  cmVOT_AlphaNorm(const T_t* sp, unsigned sn, T_t alpha );
158
+
159
+//======================================================================================================================
160
+//)
161
+
162
+
163
+
164
+//( { label:"Distance" desc:"Calculate various vector distances." kw:[vop] }
165
+
166
+// Return the Itakura-Saito distance between a modelled power spectrum (up) and another power spectrum (sp).
167
+T_t cmVOT_ItakuraDistance( const T_t* up, const T_t* sp, unsigned sn );
168
+
169
+// Return the cosine distance between two vectors.
170
+T_t  cmVOT_CosineDistance( const T_t* s0P, const T_t* s1p, unsigned sn );
171
+
172
+// Return the Euclidean distance between two vectors
173
+T_t  cmVOT_EuclidDistance( const T_t* s0p, const T_t* s1p, unsigned sn );
174
+
175
+// Return the Manhattan distance between two vectors
176
+T_t  cmVOT_L1Distance( const T_t* s0p, const T_t* s1p, unsigned sn );
177
+
178
+// Return the Mahalanobis distance between a vector and the mean of the distribution.
179
+// The mean vector could be replaced with another vector drawn from the same distribution in which
180
+// case the returned value would reflect the distance between the two vectors.
181
+// 'sn' is the dimensionality of the data.
182
+// up[D] and invCovM[sn,sn] are the mean and inverse of the covariance matrix of the distribution from 
183
+// which sp[D] is drawn. 
184
+T_t  cmVOT_MahalanobisDistance( const T_t* sp, unsigned sn, const T_t* up, const T_t* invCovM );
185
+
186
+// Return the KL distance between two probability distributions up[sn] and sp[sn].
187
+// Since up[] and sp[] are probability distributions they must sum to 1.0.
188
+T_t cmVOT_KL_Distance( const T_t* up, const T_t* sp, unsigned sn );
189
+
190
+// Return the KL distance between a prototype vector up[sn] and another vector sp[sn].
191
+// This function first normalizes the two vectors to sum to 1.0 before calling
192
+// cmVOT_KL_Distance(up,sp,sn);
193
+T_t cmVOT_KL_Distance2( const T_t* up, const T_t* sp, unsigned sn );
194
+
195
+
196
+// Measure the Euclidean distance between a vector and all the columns in a matrix.
197
+// If dv[scn] is no NULL then return the Euclidean distance from sv[scn] to each column of sm[srn,scn].
198
+// The function returns the index of the closest data point (column) in sm[].
199
+unsigned cmVOT_EuclidDistanceVM( T_t* dv, const T_t* sv, const T_t* sm, unsigned srn, unsigned scn );
200
+
201
+// Measure the distance between each column in s0M[ rn, s0cn ] and 
202
+// each column in s1M[rn, s1cn ]. If dM is non-NULL store the 
203
+// result in dM[s1cn, s0cn]. The difference between s0M[:,0] and s1M[:,0] 
204
+// is stored in dM[0,0], the diff. between s0M[:,1] and s1M[:,1] is stored 
205
+// in dM[1,0], etc.  If mvV[s0cn] is non-NULL then  minV[i] is set with
206
+// the distance from s0M[:,i] to the nearest column in s1M[]. If miV[s0cn]
207
+// is non-NULL then it is set with the column index of s1M[] which is
208
+// closest to s0M[:,i].  In other words mvV[i] gives the distance to column
209
+// miV[i] from column s0M[:,i].
210
+// In those cases where the distane from a prototype (centroid) to the data point
211
+// is not the same as from the data point to the centroid then s1M[] is considered
212
+// to hold the prototypes and s0M[] is considered to hold the data points.
213
+// The distance function returns the distance from a prototype 'cV[dimN]' to
214
+// an datapoint dV[dimN]. 'dimN' is the dimensionality of the data vector
215
+// and is threfore equal to 'rn'.
216
+void cmVOT_DistVMM( 
217
+  T_t*       dM,    // dM[s1cn,s0cn] return distance mtx (optional) 
218
+  T_t*       mvV,   // mvV[s0cn] distance to closest data point in s0M[]. (optional)
219
+  unsigned*           miV,   // miV[s0cn] column index into s1M[] of closest data point to s0M[:,i]. (optional)
220
+  unsigned            rn,    // dimensionality of the data and the row count for s0M[] and s1M[] 
221
+  const T_t* s0M,   // s0M[rn,s0cn] contains one data point per column
222
+  unsigned            s0cn,  // count of data points (count of columns in s0M[]
223
+  const T_t* s1M,   // s1M[rn,s1cn] contains one prototype per column
224
+  unsigned            s1cn,  // count of prototypes (count of columns in s1m[]
225
+  T_t (*distFunc)( void* userPtr, const T_t* cV, const T_t* dV, unsigned dimN ), 
226
+  void*               userPtr );
227
+
228
+//======================================================================================================================
229
+//)
230
+
231
+//( { label:"Select columns" desc:"Select columns based on distance." kw:[vop] }
232
+
233
+// Select 'selIdxN' columns from sM[srn,scn].
234
+// dM[srn,selIdxN] receives copies of the selected columns.
235
+// selIdxV[selIdxN] receives the column indexes of the selected columns.
236
+// Both dM[] and selIdxV[] are optional.
237
+// In each case the first selected point is chosen at random.
238
+// SelectRandom() then selects the following selIdxN-1 points at random.
239
+// SelectMaxDist() selects the next selIdxN-1 points by selecting 
240
+// the point whose combined distance to the previously selected points
241
+// is greatest. SelectMaxAvgDist() selectes the points whose combined
242
+// average distance is greatest relative the the previously selected
243
+// points.
244
+void cmVOT_SelectRandom(     T_t* dM, unsigned* selIdxV, unsigned selIdxN, const T_t* sM, unsigned srn, unsigned scn );
245
+void cmVOT_SelectMaxDist(    T_t* dM, unsigned* selIdxV, unsigned selIdxN, const T_t* sM, unsigned srn, unsigned scn, T_t (*distFunc)( void* userPtr, const T_t* s0V, const T_t* s1V, unsigned sn ), void* distUserPtr );
246
+void cmVOT_SelectMaxAvgDist( T_t* dM, unsigned* selIdxV, unsigned selIdxN, const T_t* sM, unsigned srn, unsigned scn, T_t (*distFunc)( void* userPtr, const T_t* s0V, const T_t* s1V, unsigned sn ), void* distUserPtr ); 
247
+
248
+//======================================================================================================================
249
+//)
250
+
251
+//( { label:"Matrix multiplication" desc:"Various matrix multiplication operations." kw:[vop] }
252
+
253
+// Return the sum of the products (dot product)
254
+T_t cmVOT_MultSumVV(  const T_t* s0p, const T_t* s1p, unsigned sn  );
255
+T_t cmVOT_MultSumVS(  const T_t* s0p, unsigned sn, T_t s );
256
+
257
+// Number of elements in the dest vector is expected to be the same 
258
+// as the number of source matrix rows.
259
+// mcn gives the number of columns in the source matrix which is 
260
+//  expected to match the number of elements in the source vector.
261
+// dbp[dn,1] = mp[dn,mcn] * vp[mcn,1] 
262
+T_t* cmVOT_MultVMV( T_t* dbp, unsigned dn, const T_t* mp, unsigned mcn, const T_t* vp ); 
263
+
264
+// Multiply a row vector with a matrix to produce a row vector. 
265
+// dbp[1,dn] = v[1,vn] * m[vn,dn]
266
+T_t* cmVOT_MultVVM( T_t* dbp, unsigned dn, const T_t* vp, unsigned vn, const T_t* mp ); 
267
+
268
+// Same as MultVMtV() except M is transposed as part of the multiply.  
269
+// mrn gives the number of rows in m[] and number of elements in vp[]
270
+// dpb[dn] = mp[mrn,dn] * vp[mrn]
271
+T_t* cmVOT_MultVMtV( T_t* dbp, unsigned dn, const T_t* mp, unsigned mrn, const T_t* vp ); 
272
+
273
+// Same as MultVMV() but where the matrix is diagonal.
274
+T_t* cmVOT_MultDiagVMV( T_t* dbp, unsigned dn, const T_t* mp, unsigned mcn, const T_t* vp ); 
275
+
276
+// Generalized matrix multiply.
277
+// If transposition is selected for M0 or M1 then the given dimension represent the size of the matrix 'after' the transposion. 
278
+// d[drn,dcn] = alpha * op(m0[drn,m0cn_m1rn]) * op(m1[m0cn_m1rn,dcn]) + beta * d[drn,dcn]
279
+/// See enum { kTranpsoseM0Fl=0x01, kTransposeM1Fl=0x02 } in cmVectOps for flags.
280
+T_t* cmVOT_MultMMM1(T_t* dbp, unsigned drn, unsigned dcn, T_t alpha, const T_t* m0, const T_t* m1, unsigned m0cn_m1rn, T_t beta, unsigned flags );
281
+
282
+// Same a cmVOT_MultMMM1 except allows the operation on a sub-matrix by providing the physical (memory) row count rather than the logical (matrix) row count.
283
+T_t* cmVOT_MultMMM2(T_t* dbp, unsigned drn, unsigned dcn, T_t alpha, const T_t* m0, const T_t* m1, unsigned m0cn_m1rn, T_t beta, unsigned flags, unsigned dprn, unsigned m0prn, unsigned m1prn );
284
+
285
+// d[drn,dcn] = m0[drn,m0cn] * m1[m1rn,dcn] 
286
+T_t* cmVOT_MultMMM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* m0, const T_t* m1, unsigned m0cn_m1rn );
287
+
288
+// same as MultMMM() except second source matrix is transposed prior to the multiply
289
+T_t* cmVOT_MultMMMt(T_t* dbp, unsigned drn, unsigned dcn, const T_t* m0, const T_t* m1, unsigned m0cn_m1rn );
290
+
291
+//======================================================================================================================
292
+//)
293
+
294
+//( { label:"Linear algebra" desc:"Miscellaneous linear algebra operations. Determinant, Inversion, Cholesky decompostion. Linear system solver." kw:[vop] }
295
+
296
+// Initialize dbp[dn,dn] as a square symetric positive definite matrix using values
297
+// from a random uniform distribution. This is useful for initializing random 
298
+// covariance matrices as used by multivariate Gaussian distributions
299
+// If t is non-NULL it must point to a block of scratch memory of t[dn,dn].
300
+// If t is NULL then scratch memory is internally allocated and deallocated.
301
+T_t* cmVOT_RandSymPosDef( T_t* dbp, unsigned dn, T_t* t );
302
+
303
+
304
+// Compute the determinant of any square matrix.
305
+T_t  cmVOT_DetM(    const T_t* sp, unsigned srn );
306
+
307
+// Compute the determinant of a diagonal matrix.
308
+T_t  cmVOT_DetDiagM(    const T_t* sp, unsigned srn);
309
+
310
+// Compute the log determinant of any square matrix.
311
+T_t  cmVOT_LogDetM(    const T_t* sp, unsigned srn );
312
+
313
+// Compute the log determinant of a diagonal matrix.
314
+T_t  cmVOT_LogDetDiagM(    const T_t* sp, unsigned srn);
315
+
316
+
317
+// Compute the inverse of a square matrix.  Returns NULL if the matrix is not invertable.
318
+// 'drn' is the dimensionality of the data.
319
+T_t* cmVOT_InvM(    T_t* dp, unsigned drn );
320
+
321
+// Compute the inverse of a diagonal matrix. Returns NULL if the matrix is not invertable.
322
+T_t* cmVOT_InvDiagM(    T_t* dp, unsigned drn );
323
+
324
+// Solve a linear system of the form AX=B where A[an,an] is square. 
325
+// Since A is square B must have 'an' rows.
326
+// Result is returned in B.
327
+// Returns a pointer to B on success or NULL on fail.
328
+// NOTE: Both A and B are overwritten by this operation.
329
+T_t* cmVOT_SolveLS( T_t* A, unsigned an, T_t* B, unsigned bcn ); 
330
+
331
+// Perform a Cholesky decomposition of the square symetric matrix U[un,un].
332
+// The factorization has the form: A=U'TU.
333
+// If the factorization is successful A is set to U and a pointer to A is returned.
334
+// Note that the lower triangle of A is not overwritten. See CholZ().
335
+// If the factorization fails NULL is returned.
336
+T_t* cmVOT_Chol(T_t* A, unsigned an );
337
+
338
+// Same as Chol() but sets the lower triangle of U to zero. 
339
+// This is equivalent ot the Matlab version.
340
+T_t* cmVOT_CholZ(T_t* U, unsigned un );
341
+
342
+// Calculate the best fit line: b0 + b1*x_i through the points x_i,y_i.
343
+// Set x to NULL if it uses sequential integers [0,1,2,3...]
344
+void cmVOT_Lsq1(const T_t* x, const T_t* y, unsigned n, T_t* b0, T_t* b1 );
345
+
346
+
347
+//======================================================================================================================
348
+//)
349
+
350
+//( { label:"Stretch/Shrink" desc:"Stretch or shrink a vector by resampling." kw:[vop] }
351
+
352
+// Return the average value of the contents of sbp[] between two fractional indexes
353
+T_t  cmVOT_FracAvg( double bi, double ei, const T_t* sbp, unsigned sn );
354
+
355
+// Shrinking function - Decrease the size of sbp[] by averaging blocks of values into single values in dbp[]
356
+T_t* cmVOT_DownSampleAvg( T_t* dbp, unsigned dn, const T_t* sbp, unsigned sn );
357
+
358
+// Stretching function - linear interpolate between points in sbp[] to fill dbp[] ... where dn > sn
359
+T_t* cmVOT_UpSampleInterp( T_t* dbp, unsigned dn, const T_t* sbp, unsigned sn );
360
+
361
+// Stretch or shrink the sbp[] to fit into dbp[]
362
+T_t* cmVOT_FitToSize( T_t* dbp, unsigned dn, const T_t* sbp, unsigned sn );
363
+
364
+// Stretch or shrink sV[] to fit into dV[] using a simple linear mapping.
365
+// When stretching (sn<dn) each source element is repeated dn/sn times
366
+// and the last fraction position is interpolated.  When shrinking 
367
+// (sn>dn) each dest value is formed by the average of sequential segments
368
+// of sn/dn source elements. Fractional values are used at the beginning
369
+// and end of each segment.
370
+T_t* cmVOT_LinearMap(T_t* dV, unsigned dn, T_t* sV, unsigned sn );
371
+
372
+//======================================================================================================================
373
+//)
374
+
375
+//( { label:"Random number generation" desc:"Generate random numbers." kw:[vop] }
376
+
377
+// Generate a vector of uniformly distributed random numbers in the range minVal to maxVal.
378
+T_t* cmVOT_Random( T_t* dbp, unsigned dn, T_t minVal, T_t maxVal );
379
+
380
+// Generate dn random numbers integers between 0 and wn-1 based on a the relative 
381
+// weights in wp[wn].  Note thtat the weights do not have to sum to 1.0.
382
+unsigned*  cmVOT_WeightedRandInt( unsigned* dbp, unsigned dn, const T_t* wp, unsigned wn );
383
+
384
+// Generate a vector of normally distributed univariate random numbers 
385
+T_t* cmVOT_RandomGauss(  T_t* dbp, unsigned dn, T_t mean, T_t var );
386
+
387
+// Generate a vector of normally distributed univariate random numbers where each value has been drawn from a 
388
+// seperately parameterized Gaussian distribution. meanV[] and varV[] must both contain dn velues.
389
+T_t* cmVOT_RandomGaussV( T_t* dbp, unsigned dn, const T_t* meanV, const T_t* varV );
390
+
391
+// Generate a matrix of multi-dimensional random values. Each column represents a single vector value and each row contains a dimension.
392
+// meanV[] and varV[] must both contain drn elements where each meanV[i],varV[i] pair parameterize one dimensions Gaussian distribution.
393
+T_t* cmVOT_RandomGaussM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* meanV, const T_t* varV );
394
+T_t* cmVOT_RandomGaussDiagM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* meanV, const T_t* diagCovarM );
395
+
396
+// Generate a matrix of multivariate random values drawn from a normal distribution.
397
+// The dimensionality of the values are 'drn'.
398
+// The count of returned values is 'dcn'.
399
+// meanV[drn] and covarM[drn,drn] parameterize the normal distribution.
400
+// The covariance matrix must be symetric and positive definite. 
401
+// t[(drn*drn) ] points to scratch memory or is set to NULL if the function should
402
+//   allocate the memory internally.
403
+// Based on octave function mvrnd.m.
404
+T_t* cmVOT_RandomGaussNonDiagM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* meanV, const T_t* covarM, T_t* t );
405
+
406
+// Same as RandomGaussNonDiagM() except requires the upper trianglular 
407
+// Cholesky factor of the covar matrix in 'uM'. 
408
+T_t* cmVOT_RandomGaussNonDiagM2( T_t* dbp, unsigned drn, unsigned dcn, const T_t* meanV, const T_t* uM );
409
+
410
+
411
+// Generate a matrix of N*K multi-dimensional data points.
412
+// Where D is the dimensionality of the data. (D == drn).
413
+// K is the number of multi-dimensional PDF's (clusters).
414
+// N is the number of data points to generate per cluster. 
415
+// dbp[ D, N*K ] contains the returned data point. 
416
+// The first N columns is associated with the cluster 0, 
417
+// the next N columns is associated with cluster 1, ...
418
+// meanM[ D, K ] and varM[D,K] parameterize the generating PDF.s for each cluster
419
+T_t* cmVOT_RandomGaussMM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* meanM, const T_t* varM, unsigned K );
420
+
421
+
422
+// Evaluate the univariate normal distribution defined by 'mean' and 'stdDev'.
423
+T_t* cmVOT_GaussPDF( T_t* dbp, unsigned dn, const T_t* sbp, T_t mean, T_t stdDev );
424
+
425
+// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
426
+// at the data points held in the columns of xM[D,N]. Return the evaluation
427
+// results in the vector yV[N].  D is the dimensionality of the data. N is the number of
428
+// data points to evaluate and values to return in yV[N]. 
429
+// Set diagFl to true if covarM is diagonal.
430
+// The function fails and returns false if the covariance matrix is singular.
431
+bool cmVOT_MultVarGaussPDF( T_t* yV, const T_t* xM, const T_t* meanV, const T_t* covarM, unsigned D, unsigned N, bool diagFl );
432
+
433
+// Same as multVarGaussPDF[] except takes the inverse covar mtx invCovarM[D,D] 
434
+// and log determinant of covar mtx. 
435
+// Always returns yV[].
436
+T_t* cmVOT_MultVarGaussPDF2( T_t* yV, const T_t* xM, const T_t* meanV, const T_t* invCovarM, T_t logDet, unsigned D, unsigned N, bool diagFl );
437
+
438
+// Same as multVarGaussPDF[] except uses a function to obtain the data vectors.
439
+// srcFunc() can filter the data points by returning NULL if the data vector at frmIdx should
440
+// not be evaluated against the PDF. In this case yV[frmIdx] will be set to 0.
441
+T_t* cmVOT_MultVarGaussPDF3( 
442
+  T_t*       yV, 
443
+  const T_t* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
444
+  void*               funcDataPtr,
445
+  const T_t* meanV, 
446
+  const T_t* invCovarM, 
447
+  T_t        logDet, 
448
+  unsigned            D, 
449
+  unsigned            N, 
450
+  bool                diagFl );
451
+
452
+
453
+//======================================================================================================================
454
+//)
455
+
456
+
457
+//( { label:"Signal generators" desc:"Generate periodic signals." kw:[vop] }
458
+
459
+// The following functions all return the phase of the next value. 
460
+unsigned      cmVOT_SynthSine(      T_t* dbp, unsigned dn, unsigned phase, double srate, double hz );
461
+unsigned      cmVOT_SynthCosine(    T_t* dbp, unsigned dn, unsigned phase, double srate, double hz );
462
+unsigned      cmVOT_SynthSquare(    T_t* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
463
+unsigned      cmVOT_SynthTriangle(  T_t* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
464
+unsigned      cmVOT_SynthSawtooth(  T_t* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
465
+unsigned      cmVOT_SynthPulseCos(  T_t* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
466
+unsigned      cmVOT_SynthImpulse(   T_t* dbp, unsigned dn, unsigned phase, double srate, double hz );
467
+unsigned      cmVOT_SynthPhasor(    T_t* dbp, unsigned dn, unsigned phase, double srate, double hz ); 
468
+
469
+
470
+// Return value should be passed back via delaySmp on the next call.
471
+T_t  cmVOT_SynthPinkNoise( T_t* dbp, unsigned dn, T_t delaySmp );
472
+
473
+//======================================================================================================================
474
+//)
475
+
476
+//( { label:"Exponential conversion" desc:"pow() and log() functions." kw:[vop] }
477
+
478
+// Raise dbp[] to the power 'expon'
479
+T_t* cmVOT_PowVS(  T_t* dbp, unsigned dn, T_t expon );
480
+T_t* cmVOT_PowVVS( T_t* dbp, unsigned dn, const T_t* sp, T_t expon );
481
+
482
+// Take the natural log of all values in sbp[dn]. It is allowable for sbp point to the same array as dbp=.
483
+T_t* cmVOT_LogV( T_t* dbp, unsigned dn, const T_t* sbp );
484
+
485
+//======================================================================================================================
486
+//)
487
+
488
+//( { label:"dB Conversions" desc:"Convert vectors between dB,linear and power representations." kw:[vop] }
489
+
490
+// Convert a magnitude (amplitude) spectrum to/from decibels. 
491
+// It is allowable for dbp==sbp.
492
+T_t* cmVOT_AmplToDbVV( T_t* dbp, unsigned dn, const T_t* sbp, T_t minDb );
493
+T_t* cmVOT_DbToAmplVV( T_t* dbp, unsigned dn, const T_t* sbp);
494
+
495
+T_t* cmVOT_PowToDbVV( T_t* dbp, unsigned dn, const T_t* sbp, T_t minDb );
496
+T_t* cmVOT_DbToPowVV( T_t* dbp, unsigned dn, const T_t* sbp);
497
+
498
+T_t* cmVOT_LinearToDb(    T_t* dbp, unsigned dn, const T_t* sp, T_t mult );
499
+T_t* cmVOT_dBToLinear(    T_t* dbp, unsigned dn, const T_t* sp, T_t mult );
500
+T_t* cmVOT_AmplitudeToDb( T_t* dbp, unsigned dn, const T_t* sp );
501
+T_t* cmVOT_PowerToDb(     T_t* dbp, unsigned dn, const T_t* sp );
502
+T_t* cmVOT_dBToAmplitude( T_t* dbp, unsigned dn, const T_t* sp );
503
+T_t* cmVOT_dBToPower(     T_t* dbp, unsigned dn, const T_t* sp );
504
+//======================================================================================================================
505
+//)
506
+
507
+//( { label:"DSP Windows" desc:"DSP windowing functions." kw:[vop] }
508
+
509
+T_t  cmVOT_KaiserBetaFromSidelobeReject(  double sidelobeRejectDb );
510
+T_t  cmVOT_KaiserFreqResolutionFactor( double sidelobeRejectDb );
511
+T_t* cmVOT_Kaiser(  T_t* dbp, unsigned dn, double beta );
512
+T_t*	cmVOT_Gaussian(T_t* dbp, unsigned dn, double mean, double variance );
513
+T_t* cmVOT_Hamming( T_t* dbp, unsigned dn );
514
+T_t* cmVOT_Hann(    T_t* dbp, unsigned dn );
515
+T_t* cmVOT_Triangle(T_t* dbp, unsigned dn );
516
+
517
+// The MATLAB equivalent Hamming and Hann windows.
518
+//T_t* cmVOT_HammingMatlab(T_t* dbp, unsigned dn );
519
+T_t* cmVOT_HannMatlab(   T_t* dbp, unsigned dn );
520
+
521
+// Simulates the MATLAB GaussWin function. Set arg to 2.5 to simulate the default arg
522
+// as used by MATLAB.
523
+T_t*	cmVOT_GaussWin( T_t* dbp, unsigned dn, double arg );
524
+//======================================================================================================================
525
+//)
526
+
527
+//( { label:"DSP Filters" desc:"DSP filtering functions." kw:[vop] }
528
+
529
+// Direct form II algorithm based on the MATLAB implmentation
530
+// http://www.mathworks.com/access/helpdesk/help/techdoc/ref/filter.html#f83-1015962
531
+// The only difference between this function and the equivalent MATLAB filter() function
532
+// is that the first feedforward coeff is given as a seperate value. The first  b coefficient
533
+//  in this function is therefore the same as the second coefficient in the MATLAB function.
534
+//  and the first a[] coefficient (which is generally set to 1.0) is skipped.
535
+//  Example:
536
+//  Matlab:         b=[.5 .4 .3]  a=[1 .2 .1]
537
+//  Equiv:  b0 = .5 b=[   .4 .3]  a=[  .2 .1]; 
538
+//
539
+// y[yn] - output vector 
540
+// x[xn] - input vector. xn must be <= yn. if xn < yn then the end of y[] is set to zero.
541
+// b0 - signal scale. This can also be seen as b[0] (which is not included in b[])
542
+// b[dn] - feedforward coeff's b[1..dn-1]
543
+// a[dn] - feedback coeff's    a[1..dn-1]
544
+// d[dn+1] - delay registers - note that this array must be one element longer than the coeff arrays.
545
+// 
546
+T_t* cmVOT_Filter( T_t* y, unsigned yn, const T_t* x, unsigned xn, cmReal_t b0, const cmReal_t* b, const cmReal_t* a,  cmReal_t* d, unsigned dn );
547
+
548
+struct cmFilter_str;
549
+//typedef cmRC_t (*cmVOT_FiltExecFunc_t)( struct acFilter_str* f,  const T_t* x, unsigned xn, T_t* y, unsigned yn );
550
+T_t* cmVOT_FilterFilter(struct cmFilter_str* f, cmRC_t (*func)( struct cmFilter_str* f,  const T_t* x, unsigned xn, T_t* y, unsigned yn ), const cmReal_t bb[], unsigned bn, const cmReal_t aa[], unsigned an, const T_t* x, unsigned xn, T_t* y, unsigned yn );
551
+
552
+// Compute the coefficients of a low/high pass FIR filter
553
+// wndV[dn] gives the window function used to truncate the ideal low-pass impulse response.
554
+// Set wndV to NULL to use a unity window.
555
+// See enum { kHighPass_LPSincFl=0x01, kNormalize_LPSincFl=0x02 } in cmVectOps.h
556
+T_t* cmVOT_LP_Sinc(T_t* dp, unsigned dn, const T_t* wndV, double srate, double fcHz, unsigned flags );
557
+
558
+
559
+
560
+//======================================================================================================================
561
+//)
562
+
563
+//( { label:"Spectral Masking" desc:"A collection of spectral masking functions." kw:[vop] }
564
+
565
+// Compute a set of filterCnt mel filter masks for wieghting magnitude spectra consisting of binCnt bins.
566
+// The spectrum is divided into bandCnt equal bands in the mel domain
567
+// Each row of the matrix contains the mask for a single filter band consisting of binCnt elements.  
568
+// See enum{ kShiftMelFl=0x01, kNormalizeMelFl=0x02 } in cmVectOps.h
569
+// Set kShiftMelFl to shift the mel bands onto the nearest FFT bin.
570
+// Set kNormalizeMelFl to normalize the combined filters for unity gain.
571
+T_t* cmVOT_MelMask( T_t* maskMtx, unsigned bandCnt, unsigned binCnt, double srate, unsigned flags );
572
+
573
+// Fill binIdxV[bandCnt] and cntV[bandCnt] with a bin to band map.
574
+// binIdx[] contains the first (minimum) bin index for a given band.
575
+// cntV[]   contains the count of bins for each band.
576
+// bandCnt is the number of bark bands to return 
577
+// The function returns the actual number of bands mapped which will always be <= 23.
578
+unsigned cmVOT_BarkMap(unsigned* binIdxV, unsigned* cntV, unsigned bandCnt, unsigned binCnt, double srate );
579
+
580
+// Calc a set of triangle fitler masks into each row of maskMtx.
581
+// maskMtx[ bandCnt, binCnt ] - result matrix
582
+// binHz - freq resolution of the output filters.
583
+// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth. 
584
+//            (Only used if lowHzV or uprHzV are NULL)
585
+// lowHz[ bandCnt ] - set of upper frequency limits for each band.
586
+// ctrHz[ bandCnt ] set to the center value in Hz for each band
587
+// uprHz[ bandCnt ] - set of lower frequency limits for each band.
588
+// Note if lowHz[] and uprHz[] are set to NULL then stSpread is used to set the bandwidth of each band.
589
+T_t* cmVOT_TriangleMask(T_t* maskMtx, unsigned bandCnt, unsigned binCnt, const T_t* ctrHzV, T_t binHz, T_t stSpread, const T_t* lowHzV, const T_t* uprHzV );
590
+
591
+// Calculate a set of Bark band triangle filters into maskMtx.
592
+// Each row of maskMtx contains the filter for one band.
593
+// maskMtx[ bandCnt, binCnt ]
594
+// bandCnt - the number of triangle bankds. If bandCnt is > 24 it will be reduced to 24.
595
+// binCnt - the number of bins in the filters.
596
+// binHz - the width of each bin in Hz.
597
+T_t* cmVOT_BarkMask(T_t* maskMtx, unsigned bandCnt, unsigned binCnt, double binHz );
598
+
599
+// Terhardt 1979 (Calculating virtual pitch, Hearing Research #1, pp 155-182)
600
+// See enum { kNoTtmFlags=0, kModifiedTtmFl=0x01 } in cmVectOps.h
601
+T_t* cmVOT_TerhardtThresholdMask(T_t* maskV, unsigned binCnt,  double srate, unsigned flags);
602
+
603
+//Schroeder et al., 1979, JASA, Optimizing digital speech coders by exploiting masking properties of the human ear
604
+T_t* cmVOT_ShroederSpreadingFunc(T_t* m, unsigned bandCnt, double srate);
605
+
606
+//======================================================================================================================
607
+//)
608
+
609
+//( { label:"Machine learning" desc:"K-means clustering and Viterbi algorithms." kw:[vop] }
610
+
611
+// Assign each data point to one of k clusters using an expectation-maximization algorithm.
612
+// k gives the number of clusters to identify
613
+// Each column of sp[ srn, scn ] contains a multidimensional data point. 
614
+// srn therefore defines the dimensionality of the data.
615
+// Each column of centroidV[ srn, k ] is set to the centroid of each of k clusters.
616
+// classIdxV[ scn ] assigns the index (0 to k-1) of a cluster to each soure data point
617
+// The function returns the number of iterations required for the EM process to converge.
618
+// selIdxV[ scn ] is optional and contains a list of id's assoc'd with each column of sM.
619
+// selKey is a integer value.
620
+// If selIdxV is non-NULL then only columns of sM[] where selIdxV[] == selKey will be clustered.
621
+// All columns of sM[] where the associated column in selIdxV[] do not match will be ignored.
622
+// Set 'initFromCentroidFl' to true if the initial centroids should be taken from centroidM[].
623
+// otherwise the initial centroids are selected from 'k' random data points in sp[].
624
+// The distance function distFunc(cV,dV,dN) is called to determine the distance from a 
625
+// centroid the centroid 'cV[dN]' to a data point 'dV[dN]'. 'dN' is the dimensionality of the
626
+// feature vector and is therefore equal to 'srn'.
627
+unsigned cmVOT_Kmeans( 
628
+  unsigned*           classIdxV, 
629
+  T_t*       centroidM, 
630
+  unsigned            k, 
631
+  const T_t* sp, 
632
+  unsigned            srn, 
633
+  unsigned            scn, 
634
+  const unsigned*     selIdxV, 
635
+  unsigned            selKey, 
636
+  bool                initFromCentroidFl,  
637
+  T_t (*distFunc)( void* userPtr, const T_t* cV, const T_t* dV, unsigned dN ), 
638
+  void*               userDistPtr ); 
639
+
640
+// 'srcFunc() should return NULL if the data point located at 'frmIdx' should not be included in the clustering.
641
+// Clustering is considered to be complete after 'maxIterCnt' iterations or when
642
+// 'deltaStopCnt' or fewer data points change class on a single iteration
643
+unsigned cmVOT_Kmeans2( 
644
+  unsigned*           classIdxV,         // classIdxV[scn] - data point class assignments
645
+  T_t*       centroidM,         // centroidM[srn,K] - cluster centroids
646
+  unsigned            K,                 // count of clusters
647
+  const T_t* (*srcFunc)(void* userPtr, unsigned frmIdx ),
648
+  unsigned            srn,               // dimensionality of each data point
649
+  unsigned            scn,               // count of data points
650
+  void*               userSrcPtr,        // callback data for srcFunc
651
+  T_t (*distFunc)( void* userPtr, const T_t* cV, const T_t* dV, unsigned dN ), 
652
+  void*              userDistPtr,        // arg. to distFunc()
653
+  int                iterCnt,            // max. number of iterations (-1 to ignore)
654
+  int                deltaStopCnt);      // if less than deltaStopCnt data points change classes on a given iteration then convergence occurs.
655
+
656
+// Determine the most likely state sequece stateV[timeN] given a 
657
+// transition matrix a[stateN,stateN], 
658
+// observation probability matrix b[stateN,timeN] and 
659
+// initial state probability vector phi[stateN].  
660
+// a[i,j] is the probability of transitioning from state i to state j.
661
+// b[i,t] is the probability of state i emitting the obj t.
662
+void cmVOT_DiscreteViterbi(unsigned* stateV, unsigned timeN, unsigned stateN, const T_t* phi, const T_t* a, const T_t* b );
663
+
664
+
665
+//======================================================================================================================
666
+//)
667
+
668
+//( { label:"Graphics" desc:"Graphics related algorithms." kw:[vop] }
669
+
670
+// Generate the set of coordinates which describe a circle with a center at x,y.
671
+// dbp[dn,2] must contain 2*dn elements.  The first column holds the x coord and and the second holds the y coord.
672
+T_t* cmVOT_CircleCoords( T_t* dbp, unsigned dn, T_t x, T_t y, T_t varX, T_t varY );
673
+
674
+// Clip the line defined by x0,y0 to x1,y1 into the rect defined by xMin,yMin xMax,yMax.
675
+bool cmVOT_ClipLine( T_t* x0, T_t* y0, T_t* x1, T_t* y1, T_t xMin, T_t yMin, T_t xMax, T_t yMax );
676
+
677
+// Return true if the line defined by x0,y0 to x1,y1 intersects with
678
+// the rectangle formed by xMin,yMin - xMax,yMax
679
+bool cmVOT_IsLineInRect( T_t x0, T_t y0, T_t x1, T_t y1, T_t xMin, T_t yMin, T_t xMax, T_t yMax );
680
+
681
+
682
+// Return the perpendicular distance from the line formed by x0,y0 and x1,y1
683
+// and the point px,py
684
+T_t cmVOT_PtToLineDistance( T_t x0, T_t y0, T_t x1, T_t y1, T_t px, T_t py);                              
685
+
686
+//======================================================================================================================
687
+//)
688
+
689
+//( { label:"Miscellaneous DSP" desc:"Common DSP algorithms." kw:[vop] }
690
+
691
+// Compute the complex transient detection function from successive spectral frames.
692
+// The spectral magntidue mag0V precedes mag1V and the phase (radians) spectrum phs0V precedes the phs1V which precedes phs2V.  
693
+// binCnt gives the length of each of the spectral vectors.
694
+T_t  cmVOT_ComplexDetect(const T_t* mag0V, const T_t* mag1V, const T_t* phs0V, const T_t* phs1V, const T_t* phs2V, unsigned binCnt );
695
+
696
+// Compute a set of DCT-II coefficients. Result dp[ coeffCnt, filtCnt ]
697
+T_t* cmVOT_DctMatrix( T_t* dp, unsigned coeffCnt, unsigned filtCnt );
698
+
699
+
700
+// Set the indexes of local peaks greater than threshold in dbp[].
701
+// Returns the number of peaks in dbp[]
702
+// The maximum number of peaks from n source values is max(0,floor((n-1)/2)).
703
+// Note that peaks will never be found at index 0 or index sn-1.
704
+unsigned cmVOT_PeakIndexes( unsigned* dbp, unsigned dn, const T_t* sbp, unsigned sn, T_t threshold );
705
+
706
+// Return the index of the bin containing v otherwise return kInvalidIdx if v is below sbp[0] or above sbp[ n-1 ]
707
+// The bin limits are contained in sbp[].
708
+// The value in spb[] are therefore expected to be in increasing order.
709
+// The value returned will be in the range 0:sn-1.
710
+unsigned cmVOT_BinIndex( const T_t* sbp, unsigned sn, T_t v );
711
+
712
+
713
+// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
714
+// x1[i].  Note that x0[] and x1[] must be increasing monotonic.
715
+// This function is similar to the octave interp1() function.
716
+void cmVOT_Interp1(T_t* y1, const T_t* x1, unsigned xy1N, const T_t* x0, const T_t* y0, unsigned xy0N );
717
+ 
718
+//======================================================================================================================
719
+//)
720
+
721
+
722
+//( { label:"Matrix ops" desc:"Common 2D matrix operations and accessors." kw:[vop] }
723
+
724
+// 2D matrix accessors
725
+T_t* cmVOT_Col(    T_t* m, unsigned ci, unsigned rn, unsigned cn );
726
+T_t* cmVOT_Row(    T_t* m, unsigned ri, unsigned rn, unsigned cn );
727
+T_t* cmVOT_ElePtr( T_t* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
728
+T_t  cmVOT_Ele(    T_t* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
729
+void          cmVOT_Set(    T_t* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn, T_t v );
730
+
731
+const T_t* cmVOT_CCol(    const T_t* m, unsigned ci, unsigned rn, unsigned cn );
732
+const T_t* cmVOT_CRow(    const T_t* m, unsigned ri, unsigned rn, unsigned cn );
733
+const T_t* cmVOT_CElePtr( const T_t* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
734
+T_t        cmVOT_CEle(    const T_t* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
735
+
736
+
737
+// Set only the diagonal of a square mtx to sbp.
738
+T_t* cmVOT_Diag( T_t* dbp, unsigned n, const T_t* sbp );
739
+
740
+// Set the diagonal of a square mtx to db to sbp and set all other values to zero.
741
+T_t* cmVOT_DiagZ( T_t* dbp, unsigned n, const T_t* sbp ); 
742
+
743
+// Create an identity matrix (only sets 1's not zeros).
744
+T_t* cmVOT_Identity(  T_t* dbp, unsigned rn, unsigned cn );
745
+
746
+// Zero the matrix and then fill it as an identity matrix.
747
+T_t* cmVOT_IdentityZ( T_t* dbp, unsigned rn, unsigned cn );
748
+
749
+// Transpose the matrix sbp[srn,scn] into dbp[scn,srn]
750
+T_t* cmVOT_Transpose(  T_t* dbp, const T_t* sbp, unsigned srn, unsigned scn );
751
+
752
+//======================================================================================================================
753
+//)
754
+
755
+
756
+//( { label:"Fill,move,copy" desc:"Basic data movement and initialization." kw:[vop] }
757
+
758
+// Fill a vector with a value. If value is 0 then the function is accellerated via memset().
759
+T_t* cmVOT_Fill( T_t* dbp, unsigned dn, T_t value  );
760
+
761
+// Fill a vector with zeros
762
+T_t* cmVOT_Zero( T_t* dbp, unsigned dn  );
763
+
764
+// Analogous to memmove()
765
+T_t* cmVOT_Move(  T_t* dbp, unsigned dn, const T_t* sp );
766
+
767
+// Fill the vector from various sources
768
+T_t* cmVOT_Copy(  T_t* dbp, unsigned dn, const T_t* sp );
769
+T_t* cmVOT_CopyN( T_t* dbp, unsigned dn, unsigned d_stride, const T_t* sp, unsigned s_stride );
770
+T_t* cmVOT_CopyU( T_t* dbp, unsigned dn, const unsigned* sp );
771
+T_t* cmVOT_CopyI( T_t* dbp, unsigned dn, const int* sp );
772
+T_t* cmVOT_CopyF( T_t* dbp, unsigned dn, const float* sp );
773
+T_t* cmVOT_CopyD( T_t* dbp, unsigned dn, const double* sp );
774
+T_t* cmVOT_CopyS( T_t* dbp, unsigned dn, const cmSample_t* sp );
775
+T_t* cmVOT_CopyR( T_t* dbp, unsigned dn, const cmReal_t* sp );
776
+
777
+// Fill the the destination vector from a source vector where the source vector contains
778
+// srcStride interleaved elements to be ignored. 
779
+T_t* cmVOT_CopyStride(  T_t* dbp, unsigned dn, const T_t* sp, unsigned srcStride );
780
+
781
+
782
+//======================================================================================================================
783
+//)
784
+
785
+//( { label:"Shrink/Expand/Replace" desc:"Change the size of a vector." kw:[vop] }
786
+
787
+
788
+// Shrink the elemetns of dbp[dn] by copying all elements past t+tn to t.
789
+// This operation results in overwriting the elements in the range t[tn].
790
+// t[tn] must be entirely inside dbp[dn].
791
+T_t* cmVOT_Shrink( T_t* dbp, unsigned dn, const T_t* t, unsigned tn );
792
+
793
+// Expand dbp[[dn] by shifting all elements past t to t+tn.
794
+// This produces a set of empty elements in t[tn].
795
+// t must be inside or at the end of dbp[dn].
796
+// This results in a reallocation of dbp[]. Be sure to call cmMemFree(dbp)
797
+// to release the returned pointer.
798
+T_t* cmVOT_Expand( T_t* dbp, unsigned dn, const T_t* t, unsigned tn );                                                            
799
+
800
+// Replace the elements t[tn] with the elements in u[un]. 
801
+// t must be inside or at the end of dbp[dn].
802
+// This operation may result in a reallocation of dbp[]. Be sure to call cmMemFree(dbp)
803
+// to release the returned pointer.
804
+// IF dbp==NULL and tn==0 then the dbp[un] is allocated and returned 
805
+// with the contents of u[un].
806
+T_t* cmVOT_Replace(T_t* dbp, unsigned* dn, const T_t* t, unsigned tn, const T_t* u, unsigned un );
807
+
808
+//======================================================================================================================
809
+//)
810
+
811
+
812
+
813
+//( { label:"Rotate/Shift/Flip/Sequence" desc:"Modify/generate the vector sequence." kw:[vop] }
814
+
815
+// Assuming a row vector positive shiftCnt rotates right, negative shiftCnt rotates left.
816
+T_t* cmVOT_Rotate( T_t* dbp, unsigned dn, int shiftCnt );
817
+
818
+// Equivalent to Matlab circshift().
819
+T_t* cmVOT_RotateM( T_t* dbp, unsigned drn, unsigned dcn, const T_t* sbp, int rShift, int cShift  );
820
+
821
+// Assuming a row vector positive shiftCnt shifts right, negative shiftCnt shifts left.
822
+T_t* cmVOT_Shift( T_t* dbp, unsigned dn, int shiftCnt, T_t fill );
823
+
824
+// Reverse the contents of the vector.
825
+T_t* cmVOT_Flip(  T_t* dbp, unsigned dn);
826
+
827
+// Fill dbp[] with a sequence of values. Returns next value. 
828
+T_t  cmVOT_Seq( T_t* dbp, unsigned dn, T_t beg, T_t incr );
829
+
830
+
831
+
832
+
833
+//======================================================================================================================
834
+//)
835
+
836
+//( { label:"Arithmetic" desc:"Add,Sub,Mult,Divde" kw:[vop] }
837
+
838
+T_t* cmVOT_SubVS(  T_t* dp, unsigned dn, T_t v );
839
+T_t* cmVOT_SubVV(  T_t* dp, unsigned dn, const T_t* v );
840
+T_t* cmVOT_SubVVS( T_t* dp, unsigned dn, const T_t* v, T_t s );
841
+T_t* cmVOT_SubVVNN(T_t* dp, unsigned dn, unsigned dnn, const T_t* sp, unsigned snn );
842
+T_t* cmVOT_SubVVV( T_t* dp, unsigned dn, const T_t* sb0p, const T_t* sb1p );
843
+T_t* cmVOT_SubVSV( T_t* dp, unsigned dn, const T_t  s0, const T_t* sb1p );
844
+
845
+T_t* cmVOT_AddVS(  T_t* dp, unsigned dn, T_t v );
846
+T_t* cmVOT_AddVV(  T_t* dp, unsigned dn, const T_t* v );
847
+T_t* cmVOT_AddVVS( T_t* dp, unsigned dn, const T_t* v, T_t s );
848
+T_t* cmVOT_AddVVNN(T_t* dp, unsigned dn, unsigned dnn, const T_t* sp, unsigned snn );
849
+T_t* cmVOT_AddVVV( T_t* dp, unsigned dn, const T_t* sb0p, const T_t* sb1p );
850
+
851
+T_t* cmVOT_MultVVV( T_t* dbp, unsigned dn, const T_t* sb0p, const T_t* sb1p );
852
+T_t* cmVOT_MultVV(  T_t* dbp, unsigned dn, const T_t* sbp );
853
+T_t* cmVOT_MultVVNN(T_t* dp,  unsigned dn, unsigned dnn, const T_t* sp, unsigned snn );
854
+T_t* cmVOT_MultVS(  T_t* dbp, unsigned dn, T_t s );
855
+T_t* cmVOT_MultVVS( T_t* dbp, unsigned dn, const T_t* sbp, T_t s );
856
+T_t* cmVOT_MultVaVS( T_t* dbp, unsigned dn, const T_t* sbp, T_t s );
857
+T_t* cmVOT_MultSumVVS(T_t* dbp, unsigned dn, const T_t* sbp, T_t s );
858
+
859
+T_t* cmVOT_DivVVS( T_t* dbp, unsigned dn, const T_t* sb0p, T_t sb1 );
860
+T_t* cmVOT_DivVVV( T_t* dbp, unsigned dn, const T_t* sb0p, const T_t* sb1p );
861
+T_t* cmVOT_DivVV(  T_t* dbp, unsigned dn, const T_t* sb0p );
862
+T_t* cmVOT_DivVVNN(T_t* dp,  unsigned dn, unsigned dnn, const T_t* sp, unsigned snn );
863
+T_t* cmVOT_DivVS(  T_t* dbp, unsigned dn, T_t s );
864
+T_t* cmVOT_DivVSV( T_t* dp,  unsigned dn, const T_t  s0, const T_t* sb1p );
865
+
866
+// Set dest to 0 if denominator is 0.
867
+T_t* cmVOT_DivVVVZ( T_t* dbp, unsigned dn, const T_t* sb0p, const T_t* sb1p );
868
+T_t* cmVOT_DivVVZ(  T_t* dbp, unsigned dn, const T_t* sb0p );
869
+
870
+// Divide columns of dp[:,i] by each value in the source vector sp[i]. 
871
+T_t*  cmVOT_DivMS(    T_t* dp, unsigned drn, unsigned dcn, const T_t* sp ); 
872
+
873
+//======================================================================================================================
874
+//)
875
+
876
+//( { label:"Sum vectors" desc:"Operations which take sum vector elements." kw:[vop] }
877
+
878
+T_t  cmVOT_Sum(      const T_t* sp, unsigned sn );
879
+T_t  cmVOT_SumN(     const T_t* sp, unsigned sn, unsigned stride );
880
+
881
+// Sum the columns of sp[srn,scn] into dp[scn]. 
882
+// dp[] is zeroed prior to computing the sum.
883
+T_t*  cmVOT_SumM(     const T_t* sp, unsigned srn, unsigned scn, T_t* dp );
884
+
885
+// Sum the rows of sp[srn,scn] into dp[srn]
886
+// dp[] is zeroed prior to computing the sum.
887
+T_t*  cmVOT_SumMN(    const T_t* sp, unsigned srn, unsigned scn, T_t* dp );
888
+
889
+//======================================================================================================================
890
+//)
891
+
892
+
893
+//( { label:"Min/max/median/mode" desc:"Simple descriptive statistics." kw:[vop] }
894
+
895
+T_t  cmVOT_Median(   const T_t* sp, unsigned sn );
896
+unsigned      cmVOT_MinIndex( const T_t* sp, unsigned sn, unsigned stride );
897
+unsigned      cmVOT_MaxIndex( const T_t* sp, unsigned sn, unsigned stride );
898
+T_t  cmVOT_Min(      const T_t* sp, unsigned sn, unsigned stride );
899
+T_t  cmVOT_Max(      const T_t* sp, unsigned sn, unsigned stride );
900
+
901
+T_t*  cmVOT_MinVV( T_t* dp, unsigned dn, const T_t* sp );
902
+T_t*  cmVOT_MaxVV( T_t* dp, unsigned dn, const T_t* sp );
903
+
904
+
905
+// Return index of max/min value into dp[scn] of each column of sp[srn,scn]
906
+unsigned*  cmVOT_MinIndexM( unsigned* dp, const T_t* sp, unsigned srn, unsigned scn );
907
+unsigned*  cmVOT_MaxIndexM( unsigned* dp, const T_t* sp, unsigned srn, unsigned scn );
908
+
909
+// Return the most frequently occuring element in sp.
910
+T_t  cmVOT_Mode(     const T_t* sp, unsigned sn );
911
+
912
+//======================================================================================================================
913
+//)
914
+
915
+//( { label:"Compare/Find" desc:"Compare, find, replace and count elements in a vector." kw:[vop] }
916
+
917
+// Return true if s0p[sn] is equal to s1p[sn]
918
+bool       cmVOT_IsEqual( const T_t* s0p, const T_t* s1p, unsigned sn );
919
+
920
+// Return true if all elements of s0p[sn] are within 'eps' of s1p[sn].
921
+// This function is based on cmMath.h:cmIsCloseX()
922
+bool cmVOT_IsClose( const T_t* s0p, const T_t* s1p, unsigned sn, double eps );
923
+
924
+// Replace all values <= lteKeyVal with replaceVal.  sp==dp is legal.
925
+T_t* cmVOT_ReplaceLte( T_t* dp, unsigned dn, const T_t* sp, T_t lteKeyVal, T_t replaceVal );
926
+
927
+// Return the index of 'key' in sp[sn] or cmInvalidIdx if 'key' does not exist.
928
+unsigned cmVOT_Find( const T_t* sp, unsigned sn, T_t key );
929
+
930
+// Count the number of times 'key' occurs in sp[sn].
931
+unsigned cmVOT_Count(const T_t* sp, unsigned sn, T_t key );
932
+
933
+//======================================================================================================================
934
+//)
935
+
936
+
937
+
938
+//( { label:"Absolute value" desc:"Absolute value and signal rectification." kw:[vop] }
939
+
940
+T_t*   cmVOT_Abs(   T_t* dbp, unsigned dn );
941
+
942
+// Half wave rectify the source vector.
943
+// dbp[] = sbp<0 .* sbp 
944
+// Overlapping the source and dest is allowable as long as dbp <= sbp. 
945
+T_t* cmVOT_HalfWaveRectify(T_t* dbp, unsigned dn, const T_t* sp );
946
+
947
+//======================================================================================================================
948
+//)
949
+
950
+
951
+//( { label:"Filter" desc:"Apply filtering to a vector taking into account vector begin/end conditions." kw:[vop] }
952
+
953
+// Apply a median or other filter of order wndN to xV[xN] and store the result in yV[xN].
954
+// When the window goes off either side of the vector the window is shortened.
955
+// This algorithm produces the same result as the fn_thresh function in MATLAB fv codebase.
956
+void cmVOT_FnThresh( const T_t* xV, unsigned xN, unsigned wndN, T_t* yV, unsigned yStride, T_t (*fnPtr)(const T_t*, unsigned) );
957
+
958
+
959
+// Apply a median filter of order wndN  to xV[xN] and store the result in yV[xN].
960
+// When the window goes off either side of the vector the missing elements are considered
961
+// to be 0.
962
+// This algorithm produces the same result as the MATLAB medfilt1() function.
963
+void cmVOT_MedianFilt( const T_t* xV, unsigned xN, unsigned wndN, T_t* yV, unsigned yStride );
964
+//======================================================================================================================
965
+//)
966
+
967
+
968
+//( { label:"Edit distance" desc:"Calculate the Levenshtein edit distance between vectors." kw:[vop] }
969
+
970
+// Allocate and initialize a matrix for use by LevEditDist().
971
+// This matrix can be released with a call to cmMemFree().
972
+unsigned* cmVOT_LevEditDistAllocMtx(unsigned mtxMaxN);
973
+
974
+// Return the Levenshtein edit distance between two vectors.
975
+// m must point to a matrix pre-allocated by cmVOT_InitiLevEditDistMtx(maxN).
976
+double  cmVOT_LevEditDist(unsigned mtxMaxN, unsigned* m, const T_t* s0, int n0, const T_t* s1, int n1, unsigned maxN );
977
+
978
+// Return the Levenshtein edit distance between two vectors.
979
+// Edit distance with a max cost threshold. This version of the algorithm
980
+// will run faster than LevEditDist() because it will stop execution as soon
981
+// as the distance exceeds 'maxCost'.
982
+// 'maxCost' must be between 0.0 and 1.0 or it is forced into this range.
983
+// The maximum distance returned will be 'maxCost'.
984
+// m must point to a matrix pre-allocated by cmVOT_InitiLevEditDistMtx(maxN).
985
+double cmVOT_LevEditDistWithCostThresh( int mtxMaxN, unsigned* m, const T_t* s0, int n0, const T_t* s1, int n1, double maxCost, unsigned maxN );
986
+
987
+//======================================================================================================================
988
+//)
989
+
990
+

+ 4
- 0
src/cmXml.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"XML file reader." kw[file] }
9
+
8 10
   enum
9 11
   {
10 12
     kOkXmlRC = cmOkRC,
@@ -101,6 +103,8 @@ extern "C" {
101 103
   
102 104
   
103 105
   cmXmlRC_t cmXmlTest( cmCtx_t* ctx, const cmChar_t* fn );
106
+
107
+  //)
104 108
   
105 109
 #ifdef __cpluspus
106 110
 }

+ 4
- 0
src/dsp/cmDspBuiltIn.h 查看文件

@@ -6,9 +6,13 @@
6 6
 extern "C" {
7 7
 #endif
8 8
 
9
+  
10
+  //( { file_desc:"Dataflow built-in process interface." kw:[snap] }
11
+
9 12
   // Returns NULL if index is outside of valid range.
10 13
   cmDspClassConsFunc_t cmDspClassGetBuiltIn( unsigned index );
11 14
 
15
+  //)
12 16
 
13 17
 
14 18
 #ifdef __cplusplus

+ 4
- 0
src/dsp/cmDspCtx.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Dataflow global context interface." kw:[snap] }
9
+
8 10
   typedef cmHandle_t cmDspSysH_t;
9 11
   typedef cmHandle_t cmDspStoreH_t;
10 12
   
@@ -34,6 +36,8 @@ extern "C" {
34 36
     unsigned execDurUsecs;
35 37
   } cmDspCtx_t;
36 38
 
39
+  //)
40
+  
37 41
 #ifdef __cplusplus
38 42
 }
39 43
 #endif

+ 4
- 0
src/dsp/cmDspFx.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Large collection of real-time audio processing dataflow class descriptions originally developed for 'fluxo'." kw:[snap fluxo] }
9
+  
8 10
   struct cmDspClass_str* cmDelayClassCons(      cmDspCtx_t* ctx );
9 11
   struct cmDspClass_str* cmPShiftClassCons(     cmDspCtx_t* ctx );
10 12
   struct cmDspClass_str* cmLoopRecdClassCons(   cmDspCtx_t* ctx );
@@ -43,6 +45,8 @@ extern "C" {
43 45
   struct cmDspClass_str* cmBcastSymClassCons(   cmDspCtx_t* ctx );
44 46
   struct cmDspClass_str* cmSegLineClassCons(    cmDspCtx_t* ctx );
45 47
 
48
+  //)
49
+  
46 50
 #ifdef __cplusplus
47 51
 }
48 52
 #endif

+ 3
- 1
src/dsp/cmDspPgm.h 查看文件

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Dataflow program instance interface." kw:[snap] }
9
+  
8 10
   typedef cmDspRC_t (*cmDspPgmFunc_t)( cmDspSysH_t h, void** userPtrPtr );
9 11
 
10 12
   typedef struct
@@ -20,7 +22,7 @@ extern "C" {
20 22
 
21 23
   _cmDspSysPgm_t* _cmDspSysPgmArrayBase();
22 24
   
23
-
25
+  //)
24 26
 
25 27
 #ifdef __cplusplus
26 28
 }

+ 4
- 0
src/dsp/cmDspPgmKr.h 查看文件

@@ -5,11 +5,15 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  //( { file_desc:"Dataflow pgm interfaces for 'GUTIM'." kw:[gutim snap] }
9
+  
8 10
   cmDspRC_t _cmDspSysPgm_TimeLine( cmDspSysH_t h, void** userPtrPtr );
9 11
   cmDspRC_t _cmDspSysPgm_TimeLineLite( cmDspSysH_t h, void** userPtrPtr );
10 12
   cmDspRC_t _cmDspSysPgm_TimeLineLiteAf( cmDspSysH_t h, void** userPtrPtr );
11 13
   cmDspRC_t _cmDspSysPgm_Tksb(cmDspSysH_t h, void** userPtrPtr );
12 14
   cmDspRC_t _cmDspSysPgm_TksbLite(cmDspSysH_t h, void** userPtrPtr );
15
+
16
+  //)
13 17
   
14 18
 #ifdef __cplusplus
15 19
   }

+ 3
- 0
src/dsp/cmDspPgmKrChain.h 查看文件

@@ -6,6 +6,8 @@
6 6
 extern "C" {
7 7
 #endif
8 8
 
9
+  //( { file_desc:"Signal processing chain implementation for 'GUTIM'." kw:[snap gutim] }
10
+
9 11
 typedef struct
10 12
 {
11 13
   const cmChar_t* tlFn;
@@ -44,6 +46,7 @@ void _cmDspSys_TlXformChain(
44 46
   unsigned        ach,
45 47
   unsigned        mch );
46 48
 
49
+  //)
47 50
 
48 51
 #ifdef __cplusplus
49 52
 }

+ 3
- 0
src/dsp/cmDspPgmPPMain.h 查看文件

@@ -1,6 +1,7 @@
1 1
 #ifndef cmDspPgmPPMain_h
2 2
 #define cmDspPgmPPMain_h
3 3
 
4
+//( { file_desc:"'fluxo' implementation header." kw:[fluxo] }
4 5
 
5 6
 cmDspInst_t*  _cmDspSys_PresetMgmt( cmDspSysH_t h, const cmChar_t* preLbl, unsigned presetGroupSymId );
6 7
 
@@ -44,6 +45,8 @@ const _cmDspPP_CircDesc_t* _cmDspPP_CircuitDesc( unsigned idx );
44 45
 cmDspRC_t _cmDspPP_CircuitSwitchAlloc( cmDspSysH_t h, _cmDspPP_Ctx_t* ctx, cmDspPP_CircuitSwitch_t* p, cmDspInst_t* reset, cmDspInst_t** csel, cmDspInst_t** ain, cmDspInst_t** ef );
45 46
 cmDspRC_t _cmDspPP_CircuitSwitchFree(  cmDspSysH_t h, cmDspPP_CircuitSwitch_t* p);
46 47
 
48
+//)
49
+
47 50
 #ifdef __cplusplus
48 51
 extern "C" {
49 52
 #endif

+ 2
- 0
src/dsp/cmDspUi.h 查看文件

@@ -8,7 +8,9 @@
8 8
 extern "C" {
9 9
 #endif
10 10
 
11
+  //( { file_desc:"Dataflow UI interfaces." kw:[snap] }
11 12
 
13
+  //)
12 14
 
13 15
 
14 16
 #ifdef __cplusplus

+ 6
- 7
src/vop/cmVectOpsDoc.h 查看文件

@@ -5,8 +5,9 @@
5 5
 // is generated using the gcc preprocessor.
6 6
 // switches: -E : Stop after preprocess
7 7
 //           -C : Do not strip comments.
8
-//           -P : Do not generate line markers 
9
-// gcc -E -C -P -o cmVectOpsDocOut.h cmVectOpsDoc.h
8
+//           -P : Do not generate line markers
9
+//           -traditional-cpp : preserve white space
10
+// gcc -E -C -P -traditional-cpp -o cmVectOpsDocOut.h cmVectOpsDoc.h
10 11
 
11 12
 
12 13
 #include "cmVectOpsTemplateUndef.h"
@@ -17,11 +18,9 @@
17 18
 #define VECT_OP_MIN        FLT_MIN
18 19
 #define VECT_OP_LAP_FUNC(F)        s##F
19 20
 #define VECT_OP_BLAS_FUNC(F) cblas_s##F
20
-
21
-//{
22
-//[
21
+//end_cut
22
+//( { file_desc:"Math vector operations." kw:[vop math] }
23
+//)
23 24
 #include "cmVectOpsTemplateHdr.h"
24 25
 #include "cmVectOpsRIHdr.h"
25
-//]
26
-//}
27 26
 

+ 105
- 91
src/vop/cmVectOpsRICode.h 查看文件

@@ -46,6 +46,57 @@ VECT_OP_TYPE VECT_OP_FUNC(CEle)( const VECT_OP_TYPE* m, unsigned ri, unsigned ci
46 46
 { return *VECT_OP_FUNC(CElePtr)(m,ri,ci,rn,cn); }
47 47
 
48 48
 
49
+VECT_OP_TYPE* VECT_OP_FUNC(Diag)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp )
50
+{
51
+  unsigned i,j;
52
+  for(i=0,j=0; i<n && j<n; ++i,++j)
53
+    dbp[ (i*n) + j ] = sbp[i];
54
+
55
+  return dbp;  
56
+}
57
+
58
+
59
+VECT_OP_TYPE* VECT_OP_FUNC(DiagZ)(VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp )
60
+{
61
+  VECT_OP_FUNC(Fill)(dbp,n*n,0);
62
+  return VECT_OP_FUNC(Diag)(dbp,n,sbp);
63
+}
64
+
65
+
66
+VECT_OP_TYPE* VECT_OP_FUNC(Identity)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn )
67
+{
68
+  unsigned i,j;
69
+  for(i=0,j=0; i<cn && j<rn; ++i,++j)
70
+      dbp[ (i*rn) + j ] = 1;
71
+
72
+  return dbp;
73
+}
74
+
75
+
76
+VECT_OP_TYPE* VECT_OP_FUNC(IdentityZ)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn )
77
+{
78
+  VECT_OP_FUNC(Fill)(dbp,rn*cn,0);
79
+  return VECT_OP_FUNC(Identity)(dbp,rn,cn);
80
+}
81
+
82
+
83
+VECT_OP_TYPE* VECT_OP_FUNC(Transpose)( VECT_OP_TYPE* dbp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn )
84
+{
85
+  VECT_OP_TYPE*       dp  = dbp;
86
+  const VECT_OP_TYPE* dep = dbp + (srn*scn);
87
+
88
+  while( dbp < dep )
89
+  {
90
+    const VECT_OP_TYPE* sbp = sp++;
91
+    const VECT_OP_TYPE* sep = sbp + (srn*scn);
92
+
93
+    for(; sbp < sep; sbp+=srn )
94
+      *dbp++ = *sbp;
95
+  }
96
+
97
+  return dp;
98
+}
99
+
49 100
 
50 101
 
51 102
 VECT_OP_TYPE* VECT_OP_FUNC(Fill)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE value  )
@@ -364,6 +415,17 @@ VECT_OP_TYPE* VECT_OP_FUNC(Flip)(  VECT_OP_TYPE* dbp, unsigned dn)
364 415
   return dbp;
365 416
 }
366 417
 
418
+VECT_OP_TYPE VECT_OP_FUNC(Seq)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE beg, VECT_OP_TYPE incr )
419
+{
420
+  const VECT_OP_TYPE* dep = dbp + dn;
421
+  unsigned i = 0;
422
+  for(; dbp<dep; ++i)
423
+    *dbp++ = beg + (incr*i);
424
+  return beg + (incr*i);
425
+}
426
+
427
+
428
+
367 429
 
368 430
 VECT_OP_TYPE* VECT_OP_FUNC(SubVS)( VECT_OP_TYPE* bp, unsigned n, VECT_OP_TYPE v )
369 431
 {
@@ -660,15 +722,6 @@ VECT_OP_TYPE*  VECT_OP_FUNC(SumMN)(const VECT_OP_TYPE* sp, unsigned srn, unsigne
660 722
   return dp;
661 723
 }
662 724
 
663
-VECT_OP_TYPE*   VECT_OP_FUNC(Abs)(   VECT_OP_TYPE* dbp, unsigned dn )
664
-{
665
-  unsigned i;
666
-  for(i=0; i<dn; ++i)
667
-    if( dbp[i]<0 )     
668
-      dbp[i] = -dbp[i];
669
-
670
-  return dbp;  
671
-}
672 725
 
673 726
 // mi is a target value - it holds the number of elements in ap[an] which must be be less than the median value.
674 727
 // If the initial array contains an even number of values then the median value is formed by averaging the two center values.
@@ -880,27 +933,6 @@ unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsign
880 933
   return dp;
881 934
 }
882 935
 
883
-bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
884
-{
885
-  const VECT_OP_TYPE* ep = s0p + sn;
886
-  for(; s0p < ep; ++s0p,++s1p )
887
-    if( *s0p != *s1p )
888
-      return false;
889
-  return true;
890
-}
891
-
892
-bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps )
893
-{
894
-  const VECT_OP_TYPE* ep = s0p + sn;
895
-  for(; s0p < ep; ++s0p,++s1p )
896
-  {
897
-    if( !cmIsClose(*s0p,*s1p,eps) )
898
-      return false;
899
-  }
900
-  return true;
901
-}
902
-
903
-
904 936
 VECT_OP_TYPE  VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn )
905 937
 {
906 938
   unsigned     n[sn];
@@ -965,6 +997,49 @@ VECT_OP_TYPE  VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn )
965 997
   return v[j];
966 998
 }
967 999
 
1000
+VECT_OP_TYPE*   VECT_OP_FUNC(Abs)(   VECT_OP_TYPE* dbp, unsigned dn )
1001
+{
1002
+  unsigned i;
1003
+  for(i=0; i<dn; ++i)
1004
+    if( dbp[i]<0 )     
1005
+      dbp[i] = -dbp[i];
1006
+
1007
+  return dbp;  
1008
+}
1009
+
1010
+VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp )
1011
+{
1012
+  VECT_OP_TYPE* dp = dbp;
1013
+  VECT_OP_TYPE* ep = dbp + dn;
1014
+  for(; dp < ep; ++dp,++sp )
1015
+    *dp = *sp < 0 ? 0 : *sp;
1016
+
1017
+  return dbp;
1018
+}
1019
+
1020
+
1021
+
1022
+bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
1023
+{
1024
+  const VECT_OP_TYPE* ep = s0p + sn;
1025
+  for(; s0p < ep; ++s0p,++s1p )
1026
+    if( *s0p != *s1p )
1027
+      return false;
1028
+  return true;
1029
+}
1030
+
1031
+bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps )
1032
+{
1033
+  const VECT_OP_TYPE* ep = s0p + sn;
1034
+  for(; s0p < ep; ++s0p,++s1p )
1035
+  {
1036
+    if( !cmIsClose(*s0p,*s1p,eps) )
1037
+      return false;
1038
+  }
1039
+  return true;
1040
+}
1041
+
1042
+
968 1043
 unsigned VECT_OP_FUNC(Find)( const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE key )
969 1044
 {
970 1045
   const VECT_OP_TYPE* sbp = sp;
@@ -1003,67 +1078,6 @@ VECT_OP_TYPE* VECT_OP_FUNC(ReplaceLte)( VECT_OP_TYPE* dp, unsigned dn, const VEC
1003 1078
   return rp;
1004 1079
 }
1005 1080
 
1006
-VECT_OP_TYPE* VECT_OP_FUNC(Diag)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp )
1007
-{
1008
-  unsigned i,j;
1009
-  for(i=0,j=0; i<n && j<n; ++i,++j)
1010
-    dbp[ (i*n) + j ] = sbp[i];
1011
-
1012
-  return dbp;  
1013
-}
1014
-
1015
-
1016
-VECT_OP_TYPE* VECT_OP_FUNC(DiagZ)(VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp )
1017
-{
1018
-  VECT_OP_FUNC(Fill)(dbp,n*n,0);
1019
-  return VECT_OP_FUNC(Diag)(dbp,n,sbp);
1020
-}
1021
-
1022
-
1023
-VECT_OP_TYPE* VECT_OP_FUNC(Identity)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn )
1024
-{
1025
-  unsigned i,j;
1026
-  for(i=0,j=0; i<cn && j<rn; ++i,++j)
1027
-      dbp[ (i*rn) + j ] = 1;
1028
-
1029
-  return dbp;
1030
-}
1031
-
1032
-
1033
-VECT_OP_TYPE* VECT_OP_FUNC(IdentityZ)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn )
1034
-{
1035
-  VECT_OP_FUNC(Fill)(dbp,rn*cn,0);
1036
-  return VECT_OP_FUNC(Identity)(dbp,rn,cn);
1037
-}
1038
-
1039
-
1040
-VECT_OP_TYPE* VECT_OP_FUNC(Transpose)( VECT_OP_TYPE* dbp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn )
1041
-{
1042
-  VECT_OP_TYPE*       dp  = dbp;
1043
-  const VECT_OP_TYPE* dep = dbp + (srn*scn);
1044
-
1045
-  while( dbp < dep )
1046
-  {
1047
-    const VECT_OP_TYPE* sbp = sp++;
1048
-    const VECT_OP_TYPE* sep = sbp + (srn*scn);
1049
-
1050
-    for(; sbp < sep; sbp+=srn )
1051
-      *dbp++ = *sbp;
1052
-  }
1053
-
1054
-  return dp;
1055
-}
1056
-
1057
-VECT_OP_TYPE VECT_OP_FUNC(Seq)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE beg, VECT_OP_TYPE incr )
1058
-{
1059
-  const VECT_OP_TYPE* dep = dbp + dn;
1060
-  unsigned i = 0;
1061
-  for(; dbp<dep; ++i)
1062
-    *dbp++ = beg + (incr*i);
1063
-  return beg + (incr*i);
1064
-}
1065
-
1066
-
1067 1081
 void VECT_OP_FUNC(FnThresh)( const VECT_OP_TYPE* xV, unsigned xN, unsigned wndN, VECT_OP_TYPE* yV, unsigned yStride, VECT_OP_TYPE (*fnPtr)(const VECT_OP_TYPE*, unsigned) )
1068 1082
 {
1069 1083
   int i0 = cmIsOddU(wndN) ?  (wndN-1)/2 : wndN/2;

+ 117
- 51
src/vop/cmVectOpsRIHdr.h 查看文件

@@ -1,4 +1,8 @@
1 1
 
2
+
3
+//( { label:"Matrix ops" desc:"Common 2D matrix operations and accessors." kw:[vop] }
4
+
5
+// 2D matrix accessors
2 6
 VECT_OP_TYPE* VECT_OP_FUNC(Col)(    VECT_OP_TYPE* m, unsigned ci, unsigned rn, unsigned cn );
3 7
 VECT_OP_TYPE* VECT_OP_FUNC(Row)(    VECT_OP_TYPE* m, unsigned ri, unsigned rn, unsigned cn );
4 8
 VECT_OP_TYPE* VECT_OP_FUNC(ElePtr)( VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
@@ -11,17 +15,37 @@ const VECT_OP_TYPE* VECT_OP_FUNC(CElePtr)( const VECT_OP_TYPE* m, unsigned ri, u
11 15
 VECT_OP_TYPE        VECT_OP_FUNC(CEle)(    const VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
12 16
 
13 17
 
18
+// Set only the diagonal of a square mtx to sbp.
19
+VECT_OP_TYPE* VECT_OP_FUNC(Diag)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp );
20
+
21
+// Set the diagonal of a square mtx to db to sbp and set all other values to zero.
22
+VECT_OP_TYPE* VECT_OP_FUNC(DiagZ)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp ); 
23
+
24
+// Create an identity matrix (only sets 1's not zeros).
25
+VECT_OP_TYPE* VECT_OP_FUNC(Identity)(  VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
26
+
27
+// Zero the matrix and then fill it as an identity matrix.
28
+VECT_OP_TYPE* VECT_OP_FUNC(IdentityZ)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
29
+
30
+// Transpose the matrix sbp[srn,scn] into dbp[scn,srn]
31
+VECT_OP_TYPE* VECT_OP_FUNC(Transpose)(  VECT_OP_TYPE* dbp, const VECT_OP_TYPE* sbp, unsigned srn, unsigned scn );
32
+
33
+//======================================================================================================================
34
+//)
35
+
36
+
37
+//( { label:"Fill,move,copy" desc:"Basic data movement and initialization." kw:[vop] }
14 38
 
15
-/// Fill a vector with a value. If value is 0 then the function is accellerated via memset().
39
+// Fill a vector with a value. If value is 0 then the function is accellerated via memset().
16 40
 VECT_OP_TYPE* VECT_OP_FUNC(Fill)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE value  );
17 41
 
18 42
 // Fill a vector with zeros
19 43
 VECT_OP_TYPE* VECT_OP_FUNC(Zero)( VECT_OP_TYPE* dbp, unsigned dn  );
20 44
 
21
-// analogous to memmove()
45
+// Analogous to memmove()
22 46
 VECT_OP_TYPE* VECT_OP_FUNC(Move)(  VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
23 47
 
24
-/// Fill the vector from various sources
48
+// Fill the vector from various sources
25 49
 VECT_OP_TYPE* VECT_OP_FUNC(Copy)(  VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
26 50
 VECT_OP_TYPE* VECT_OP_FUNC(CopyN)( VECT_OP_TYPE* dbp, unsigned dn, unsigned d_stride, const VECT_OP_TYPE* sp, unsigned s_stride );
27 51
 VECT_OP_TYPE* VECT_OP_FUNC(CopyU)( VECT_OP_TYPE* dbp, unsigned dn, const unsigned* sp );
@@ -31,6 +55,17 @@ VECT_OP_TYPE* VECT_OP_FUNC(CopyD)( VECT_OP_TYPE* dbp, unsigned dn, const double*
31 55
 VECT_OP_TYPE* VECT_OP_FUNC(CopyS)( VECT_OP_TYPE* dbp, unsigned dn, const cmSample_t* sp );
32 56
 VECT_OP_TYPE* VECT_OP_FUNC(CopyR)( VECT_OP_TYPE* dbp, unsigned dn, const cmReal_t* sp );
33 57
 
58
+// Fill the the destination vector from a source vector where the source vector contains
59
+// srcStride interleaved elements to be ignored. 
60
+VECT_OP_TYPE* VECT_OP_FUNC(CopyStride)(  VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, unsigned srcStride );
61
+
62
+
63
+//======================================================================================================================
64
+//)
65
+
66
+//( { label:"Shrink/Expand/Replace" desc:"Change the size of a vector." kw:[vop] }
67
+
68
+
34 69
 // Shrink the elemetns of dbp[dn] by copying all elements past t+tn to t.
35 70
 // This operation results in overwriting the elements in the range t[tn].
36 71
 // t[tn] must be entirely inside dbp[dn].
@@ -51,24 +86,35 @@ VECT_OP_TYPE* VECT_OP_FUNC(Expand)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_O
51 86
 // with the contents of u[un].
52 87
 VECT_OP_TYPE* VECT_OP_FUNC(Replace)(VECT_OP_TYPE* dbp, unsigned* dn, const VECT_OP_TYPE* t, unsigned tn, const VECT_OP_TYPE* u, unsigned un );
53 88
 
54
-/// Fill the the destination vector from a source vector where the source vector contains
55
-/// srcStride interleaved elements to be ignored. 
56
-VECT_OP_TYPE* VECT_OP_FUNC(CopyStride)(  VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, unsigned srcStride );
89
+//======================================================================================================================
90
+//)
57 91
 
58 92
 
59
-/// Assuming a row vector positive shiftCnt rotates right, negative shiftCnt rotates left.
93
+
94
+//( { label:"Rotate/Shift/Flip/Sequence" desc:"Modify/generate the vector sequence." kw:[vop] }
95
+
96
+// Assuming a row vector positive shiftCnt rotates right, negative shiftCnt rotates left.
60 97
 VECT_OP_TYPE* VECT_OP_FUNC(Rotate)( VECT_OP_TYPE* dbp, unsigned dn, int shiftCnt );
61 98
 
62
-/// Equivalent to Matlab circshift().
99
+// Equivalent to Matlab circshift().
63 100
 VECT_OP_TYPE* VECT_OP_FUNC(RotateM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* sbp, int rShift, int cShift  );
64 101
 
65
-/// Assuming a row vector positive shiftCnt shifts right, negative shiftCnt shifts left.
102
+// Assuming a row vector positive shiftCnt shifts right, negative shiftCnt shifts left.
66 103
 VECT_OP_TYPE* VECT_OP_FUNC(Shift)( VECT_OP_TYPE* dbp, unsigned dn, int shiftCnt, VECT_OP_TYPE fill );
67 104
 
68
-/// Reverse the contents of the vector.
105
+// Reverse the contents of the vector.
69 106
 VECT_OP_TYPE* VECT_OP_FUNC(Flip)(  VECT_OP_TYPE* dbp, unsigned dn);
70 107
 
108
+// Fill dbp[] with a sequence of values. Returns next value. 
109
+VECT_OP_TYPE  VECT_OP_FUNC(Seq)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE beg, VECT_OP_TYPE incr );
110
+
111
+
112
+
71 113
 
114
+//======================================================================================================================
115
+//)
116
+
117
+//( { label:"Arithmetic" desc:"Add,Sub,Mult,Divde" kw:[vop] }
72 118
 
73 119
 VECT_OP_TYPE* VECT_OP_FUNC(SubVS)(  VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE v );
74 120
 VECT_OP_TYPE* VECT_OP_FUNC(SubVV)(  VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* v );
@@ -105,6 +151,10 @@ VECT_OP_TYPE* VECT_OP_FUNC(DivVVZ)(  VECT_OP_TYPE* dbp, unsigned dn, const VECT_
105 151
 // Divide columns of dp[:,i] by each value in the source vector sp[i]. 
106 152
 VECT_OP_TYPE*  VECT_OP_FUNC(DivMS)(    VECT_OP_TYPE* dp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* sp ); 
107 153
 
154
+//======================================================================================================================
155
+//)
156
+
157
+//( { label:"Sum vectors" desc:"Operations which take sum vector elements." kw:[vop] }
108 158
 
109 159
 VECT_OP_TYPE  VECT_OP_FUNC(Sum)(      const VECT_OP_TYPE* sp, unsigned sn );
110 160
 VECT_OP_TYPE  VECT_OP_FUNC(SumN)(     const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
@@ -117,9 +167,12 @@ VECT_OP_TYPE*  VECT_OP_FUNC(SumM)(     const VECT_OP_TYPE* sp, unsigned srn, uns
117 167
 // dp[] is zeroed prior to computing the sum.
118 168
 VECT_OP_TYPE*  VECT_OP_FUNC(SumMN)(    const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, VECT_OP_TYPE* dp );
119 169
 
120
-VECT_OP_TYPE*   VECT_OP_FUNC(Abs)(   VECT_OP_TYPE* dbp, unsigned dn );
170
+//======================================================================================================================
171
+//)
121 172
 
122 173
 
174
+//( { label:"Min/max/median/mode" desc:"Simple descriptive statistics." kw:[vop] }
175
+
123 176
 VECT_OP_TYPE  VECT_OP_FUNC(Median)(   const VECT_OP_TYPE* sp, unsigned sn );
124 177
 unsigned      VECT_OP_FUNC(MinIndex)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
125 178
 unsigned      VECT_OP_FUNC(MaxIndex)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
@@ -130,75 +183,88 @@ VECT_OP_TYPE*  VECT_OP_FUNC(MinVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
130 183
 VECT_OP_TYPE*  VECT_OP_FUNC(MaxVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp );
131 184
 
132 185
 
133
-/// Return index of max/min value into dp[scn] of each column of sp[srn,scn]
186
+// Return index of max/min value into dp[scn] of each column of sp[srn,scn]
134 187
 unsigned*  VECT_OP_FUNC(MinIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
135 188
 unsigned*  VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
136 189
 
137
-/// Return true if s0p[sn] is equal to s1p[sn]
190
+// Return the most frequently occuring element in sp.
191
+VECT_OP_TYPE  VECT_OP_FUNC(Mode)(     const VECT_OP_TYPE* sp, unsigned sn );
192
+
193
+//======================================================================================================================
194
+//)
195
+
196
+//( { label:"Compare/Find" desc:"Compare, find, replace and count elements in a vector." kw:[vop] }
197
+
198
+// Return true if s0p[sn] is equal to s1p[sn]
138 199
 bool       VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
139 200
 
140
-/// Return true if all elements of s0p[sn] are within 'eps' of s1p[sn].
141
-/// This function is based on cmMath.h:cmIsCloseX()
201
+// Return true if all elements of s0p[sn] are within 'eps' of s1p[sn].
202
+// This function is based on cmMath.h:cmIsCloseX()
142 203
 bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps );
143 204
 
144
-/// Return the most frequently occuring element in sp.
145
-VECT_OP_TYPE  VECT_OP_FUNC(Mode)(     const VECT_OP_TYPE* sp, unsigned sn );
146
-
147
-/// Replace all values <= lteKeyVal with replaceVal.  sp==dp is legal.
205
+// Replace all values <= lteKeyVal with replaceVal.  sp==dp is legal.
148 206
 VECT_OP_TYPE* VECT_OP_FUNC(ReplaceLte)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE lteKeyVal, VECT_OP_TYPE replaceVal );
149 207
 
150
-/// Return the index of 'key' in sp[sn] or cmInvalidIdx if 'key' does not exist.
208
+// Return the index of 'key' in sp[sn] or cmInvalidIdx if 'key' does not exist.
151 209
 unsigned VECT_OP_FUNC(Find)( const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE key );
152 210
 
153
-/// Count the number of times 'key' occurs in sp[sn].
211
+// Count the number of times 'key' occurs in sp[sn].
154 212
 unsigned VECT_OP_FUNC(Count)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE key );
155 213
 
156
-/// Set only the diagonal of a square mtx to sbp.
157
-VECT_OP_TYPE* VECT_OP_FUNC(Diag)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp );
214
+//======================================================================================================================
215
+//)
158 216
 
159
-/// Set the diagonal of a square mtx to db to sbp and set all other values to zero.
160
-VECT_OP_TYPE* VECT_OP_FUNC(DiagZ)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp ); 
161 217
 
162
-/// Create an identity matrix (only sets 1's not zeros).
163
-VECT_OP_TYPE* VECT_OP_FUNC(Identity)(  VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
164 218
 
165
-/// Zero the matrix and then fill it as an identity matrix.
166
-VECT_OP_TYPE* VECT_OP_FUNC(IdentityZ)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
219
+//( { label:"Absolute value" desc:"Absolute value and signal rectification." kw:[vop] }
167 220
 
168
-/// Transpose the matrix sbp[srn,scn] into dbp[scn,srn]
169
-VECT_OP_TYPE* VECT_OP_FUNC(Transpose)(  VECT_OP_TYPE* dbp, const VECT_OP_TYPE* sbp, unsigned srn, unsigned scn );
221
+VECT_OP_TYPE*   VECT_OP_FUNC(Abs)(   VECT_OP_TYPE* dbp, unsigned dn );
170 222
 
171
-/// Fill dbp[] with a sequence of values. Returns next value. 
172
-VECT_OP_TYPE  VECT_OP_FUNC(Seq)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE beg, VECT_OP_TYPE incr );
223
+// Half wave rectify the source vector.
224
+// dbp[] = sbp<0 .* sbp 
225
+// Overlapping the source and dest is allowable as long as dbp <= sbp. 
226
+VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
227
+
228
+//======================================================================================================================
229
+//)
173 230
 
174 231
 
175
-/// Apply a median or other filter of order wndN to xV[xN] and store the result in yV[xN].
176
-/// When the window goes off either side of the vector the window is shortened.
177
-/// This algorithm produces the same result as the fn_thresh function in MATLAB fv codebase.
232
+//( { label:"Filter" desc:"Apply filtering to a vector taking into account vector begin/end conditions." kw:[vop] }
233
+
234
+// Apply a median or other filter of order wndN to xV[xN] and store the result in yV[xN].
235
+// When the window goes off either side of the vector the window is shortened.
236
+// This algorithm produces the same result as the fn_thresh function in MATLAB fv codebase.
178 237
 void VECT_OP_FUNC(FnThresh)( const VECT_OP_TYPE* xV, unsigned xN, unsigned wndN, VECT_OP_TYPE* yV, unsigned yStride, VECT_OP_TYPE (*fnPtr)(const VECT_OP_TYPE*, unsigned) );
179 238
 
180 239
 
181
-/// Apply a median filter of order wndN  to xV[xN] and store the result in yV[xN].
182
-/// When the window goes off either side of the vector the missing elements are considered
183
-/// to be 0.
184
-/// This algorithm produces the same result as the MATLAB medfilt1() function.
240
+// Apply a median filter of order wndN  to xV[xN] and store the result in yV[xN].
241
+// When the window goes off either side of the vector the missing elements are considered
242
+// to be 0.
243
+// This algorithm produces the same result as the MATLAB medfilt1() function.
185 244
 void VECT_OP_FUNC(MedianFilt)( const VECT_OP_TYPE* xV, unsigned xN, unsigned wndN, VECT_OP_TYPE* yV, unsigned yStride );
245
+//======================================================================================================================
246
+//)
186 247
 
187 248
 
249
+//( { label:"Edit distance" desc:"Calculate the Levenshtein edit distance between vectors." kw:[vop] }
188 250
 
189
-/// Allocate and initialize a matrix for use by LevEditDist().
190
-/// This matrix can be released with a call to cmMemFree().
251
+// Allocate and initialize a matrix for use by LevEditDist().
252
+// This matrix can be released with a call to cmMemFree().
191 253
 unsigned* VECT_OP_FUNC(LevEditDistAllocMtx)(unsigned mtxMaxN);
192 254
 
193
-/// Return the Levenshtein edit distance between two vectors.
194
-/// m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
255
+// Return the Levenshtein edit distance between two vectors.
256
+// m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
195 257
 double  VECT_OP_FUNC(LevEditDist)(unsigned mtxMaxN, unsigned* m, const VECT_OP_TYPE* s0, int n0, const VECT_OP_TYPE* s1, int n1, unsigned maxN );
196 258
 
197
-/// Return the Levenshtein edit distance between two vectors.
198
-/// Edit distance with a max cost threshold. This version of the algorithm
199
-/// will run faster than LevEditDist() because it will stop execution as soon
200
-/// as the distance exceeds 'maxCost'.
201
-/// 'maxCost' must be between 0.0 and 1.0 or it is forced into this range.
202
-/// The maximum distance returned will be 'maxCost'.
203
-/// m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
259
+// Return the Levenshtein edit distance between two vectors.
260
+// Edit distance with a max cost threshold. This version of the algorithm
261
+// will run faster than LevEditDist() because it will stop execution as soon
262
+// as the distance exceeds 'maxCost'.
263
+// 'maxCost' must be between 0.0 and 1.0 or it is forced into this range.
264
+// The maximum distance returned will be 'maxCost'.
265
+// m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
204 266
 double VECT_OP_FUNC(LevEditDistWithCostThresh)( int mtxMaxN, unsigned* m, const VECT_OP_TYPE* s0, int n0, const VECT_OP_TYPE* s1, int n1, double maxCost, unsigned maxN );
267
+
268
+//======================================================================================================================
269
+//)
270
+

+ 422
- 421
src/vop/cmVectOpsTemplateCode.h 查看文件

@@ -1,5 +1,38 @@
1 1
 #ifdef cmVectOpsTemplateCode_h
2 2
 
3
+VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
4
+{
5
+  VECT_OP_TYPE* dep = dbp + dn;
6
+  VECT_OP_TYPE*  rp = dbp;
7
+  VECT_OP_TYPE sum = 0;
8
+  while( dbp < dep )
9
+  {
10
+    sum += *sbp++;
11
+    *dbp++ = sum;
12
+
13
+  }
14
+  return rp;
15
+}
16
+
17
+bool          VECT_OP_FUNC(Equal)(    const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
18
+{
19
+  const VECT_OP_TYPE* ep = s0p + sn;
20
+  while( s0p < ep )
21
+    if( *s0p++ != *s1p++ )
22
+      return false;
23
+  return true;
24
+}
25
+
26
+VECT_OP_TYPE*  VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit )
27
+{
28
+  unsigned i = 0;
29
+  for(; i<dn; ++i)
30
+    dbp[i] = base + i*(limit-base)/(dn-1);
31
+  return dbp;
32
+}
33
+
34
+
35
+
3 36
 void          VECT_OP_FUNC(VPrint)( cmRpt_t* rpt, const char* fmt, ... )
4 37
 {
5 38
   va_list vl;
@@ -189,31 +222,43 @@ VECT_OP_TYPE* VECT_OP_FUNC(StandardizeCols)( VECT_OP_TYPE* dbp, unsigned drn, un
189 222
   return dbp;
190 223
 }
191 224
 
192
-
193
-VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp )
225
+unsigned  VECT_OP_FUNC(NormToMax)(    VECT_OP_TYPE* dp, unsigned dn )
194 226
 {
195
-  VECT_OP_TYPE* dp = dbp;
196
-  VECT_OP_TYPE* ep = dbp + dn;
197
-  for(; dp < ep; ++dp,++sp )
198
-    *dp = *sp < 0 ? 0 : *sp;
227
+  unsigned i = VECT_OP_FUNC(MaxIndex)(dp,dn,1);
199 228
 
200
-  return dbp;
229
+  if( i != cmInvalidIdx )
230
+  {  
231
+    VECT_OP_TYPE v = dp[i];
232
+    VECT_OP_FUNC(DivVS)(dp,dn,v);
233
+  }
234
+
235
+  return i;
201 236
 }
202 237
 
203
-VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
238
+unsigned VECT_OP_FUNC(NormToAbsMax)(   VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact )
204 239
 {
205
-  VECT_OP_TYPE* dep = dbp + dn;
206
-  VECT_OP_TYPE*  rp = dbp;
207
-  VECT_OP_TYPE sum = 0;
208
-  while( dbp < dep )
209
-  {
210
-    sum += *sbp++;
211
-    *dbp++ = sum;
240
+  if( dn == 0 )
241
+    return cmInvalidIdx;
212 242
 
213
-  }
214
-  return rp;
243
+  unsigned     i  = 0;
244
+  unsigned     mi = 0;
245
+  VECT_OP_TYPE mx = cmAbs(dp[0]);
246
+
247
+  for(i=1; i<dn; ++i)
248
+    if( cmAbs(dp[i])>mx )
249
+    {
250
+      mi = i;
251
+      mx = cmAbs(dp[i]);
252
+    }
253
+
254
+  VECT_OP_FUNC(MultVS)(dp,dn,fact/mx);
255
+  
256
+  return mi;
257
+  
215 258
 }
216 259
 
260
+
261
+
217 262
 VECT_OP_TYPE  VECT_OP_FUNC(Mean)( const VECT_OP_TYPE* bp, unsigned n )
218 263
 {  return VECT_OP_FUNC(Sum)(bp,n)/n; }
219 264
 
@@ -312,52 +357,6 @@ VECT_OP_TYPE*  VECT_OP_FUNC(VarianceM)(VECT_OP_TYPE* dp,  const VECT_OP_TYPE* sp
312 357
   return dp;  
313 358
 }
314 359
 
315
-unsigned  VECT_OP_FUNC(NormToMax)(    VECT_OP_TYPE* dp, unsigned dn )
316
-{
317
-  unsigned i = VECT_OP_FUNC(MaxIndex)(dp,dn,1);
318
-
319
-  if( i != cmInvalidIdx )
320
-  {  
321
-    VECT_OP_TYPE v = dp[i];
322
-    VECT_OP_FUNC(DivVS)(dp,dn,v);
323
-  }
324
-
325
-  return i;
326
-}
327
-
328
-unsigned VECT_OP_FUNC(NormToAbsMax)(   VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact )
329
-{
330
-  if( dn == 0 )
331
-    return cmInvalidIdx;
332
-
333
-  unsigned     i  = 0;
334
-  unsigned     mi = 0;
335
-  VECT_OP_TYPE mx = cmAbs(dp[0]);
336
-
337
-  for(i=1; i<dn; ++i)
338
-    if( cmAbs(dp[i])>mx )
339
-    {
340
-      mi = i;
341
-      mx = cmAbs(dp[i]);
342
-    }
343
-
344
-  VECT_OP_FUNC(MultVS)(dp,dn,fact/mx);
345
-  
346
-  return mi;
347
-  
348
-}
349
-
350
-
351
-VECT_OP_TYPE  VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha )
352
-{
353
-  double sum = 0;
354
-  const VECT_OP_TYPE* bp = sp;
355
-  const VECT_OP_TYPE* ep = sp + sn;
356
-  while( bp < ep )
357
-    sum += pow(fabs(*bp++),alpha);
358
-
359
-  return (VECT_OP_TYPE)pow(sum/sn,1.0/alpha);
360
-}
361 360
 
362 361
 void  VECT_OP_FUNC(GaussCovariance)(VECT_OP_TYPE* yM, unsigned D, const VECT_OP_TYPE* xM, unsigned xN, const VECT_OP_TYPE* uV, const unsigned* selIdxV, unsigned selKey )
363 362
 {
@@ -468,14 +467,6 @@ void  VECT_OP_FUNC(GaussCovariance2)(VECT_OP_TYPE* yM, unsigned D, const VECT_OP
468 467
 }
469 468
 
470 469
 
471
-bool          VECT_OP_FUNC(Equal)(    const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn )
472
-{
473
-  const VECT_OP_TYPE* ep = s0p + sn;
474
-  while( s0p < ep )
475
-    if( *s0p++ != *s1p++ )
476
-      return false;
477
-  return true;
478
-}
479 470
 
480 471
 bool          VECT_OP_FUNC(IsNormal)( const VECT_OP_TYPE* sp, unsigned sn )
481 472
 {
@@ -584,6 +575,19 @@ VECT_OP_TYPE* VECT_OP_FUNC(RmsV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_T
584 575
 VECT_OP_TYPE  VECT_OP_FUNC(EuclidNorm)( const VECT_OP_TYPE* sp, unsigned sn )
585 576
 { return (VECT_OP_TYPE)sqrt( VECT_OP_FUNC(MultSumVV)(sp,sp,sn)); }
586 577
 
578
+
579
+VECT_OP_TYPE  VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha )
580
+{
581
+  double sum = 0;
582
+  const VECT_OP_TYPE* bp = sp;
583
+  const VECT_OP_TYPE* ep = sp + sn;
584
+  while( bp < ep )
585
+    sum += pow(fabs(*bp++),alpha);
586
+
587
+  return (VECT_OP_TYPE)pow(sum/sn,1.0/alpha);
588
+}
589
+
590
+
587 591
 /*
588 592
 From:http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/doc/voicebox/distitpf.html
589 593
 [nf1,p2]=size(pf1);
@@ -1150,47 +1154,6 @@ VECT_OP_TYPE* VECT_OP_FUNC(LogV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_
1150 1154
   return dbp;
1151 1155
 }
1152 1156
 
1153
-VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb )
1154
-{
1155
-  VECT_OP_TYPE  minVal = pow(10.0,minDb/20.0);
1156
-  VECT_OP_TYPE* dp     = dbp;
1157
-  VECT_OP_TYPE* ep     = dp + dn;
1158
-
1159
-  for(; dp<ep; ++dp,++sbp)
1160
-    *dp = *sbp<minVal ? minDb : 20.0 * log10(*sbp);
1161
-  return dbp;
1162
-}
1163
-
1164
-VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
1165
-{
1166
-  VECT_OP_TYPE* dp = dbp;
1167
-  VECT_OP_TYPE* ep = dp + dn;
1168
-  for(; dp<ep; ++dp,++sbp)
1169
-    *dp = pow(10.0,*sbp/20.0);
1170
-  return dbp;
1171
-}
1172
-
1173
-VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb )
1174
-{
1175
-  VECT_OP_TYPE  minVal = pow(10.0,minDb/10.0);
1176
-  VECT_OP_TYPE* dp     = dbp;
1177
-  VECT_OP_TYPE* ep     = dp + dn;
1178
-
1179
-  for(; dp<ep; ++dp,++sbp)
1180
-    *dp = *sbp<minVal ? minDb : 10.0 * log10(*sbp);
1181
-  return dbp;
1182
-}
1183
-
1184
-VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
1185
-{
1186
-  VECT_OP_TYPE* dp = dbp;
1187
-  VECT_OP_TYPE* ep = dp + dn;
1188
-  for(; dp<ep; ++dp,++sbp)
1189
-    *dp = pow(10.0,*sbp/10.0);
1190
-  return dbp;
1191
-}
1192
-
1193
-
1194 1157
 VECT_OP_TYPE* VECT_OP_FUNC(RandSymPosDef)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE* t )
1195 1158
 {
1196 1159
   unsigned i,j;
@@ -1420,6 +1383,43 @@ VECT_OP_TYPE* VECT_OP_FUNC(CholZ)(VECT_OP_TYPE* A, unsigned an )
1420 1383
   return A;
1421 1384
 }
1422 1385
 
1386
+void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 )
1387
+{
1388
+  VECT_OP_TYPE sx = 0;
1389
+  VECT_OP_TYPE sy = 0;
1390
+  VECT_OP_TYPE sx_2 = 0;
1391
+  VECT_OP_TYPE sxy  = 0;
1392
+  unsigned i;  
1393
+
1394
+  if( x == NULL )
1395
+  {
1396
+    for(i=0; i<n; ++i)
1397
+    {
1398
+      VECT_OP_TYPE xx = i;
1399
+      sx   += xx;
1400
+      sx_2 += xx * xx;
1401
+      sxy  += xx * y[i];
1402
+      sy   += y[i];
1403
+    }
1404
+  }
1405
+  else
1406
+  {
1407
+    for(i=0; i<n; ++i)
1408
+    {
1409
+      sx   += x[i];
1410
+      sx_2 += x[i] * x[i];
1411
+      sxy  += x[i] * y[i];
1412
+      sy   += y[i];
1413
+    }
1414
+  }
1415
+
1416
+  *b1 = (sxy * n - sx * sy) / (sx_2 * n - sx*sx);
1417
+  *b0 = (sy - (*b1) * sx) / n;      
1418
+
1419
+}
1420
+
1421
+
1422
+
1423 1423
 VECT_OP_TYPE VECT_OP_FUNC(FracAvg)( double bi, double ei, const VECT_OP_TYPE* sbp, unsigned sn )
1424 1424
 {
1425 1425
   unsigned bii   = cmMax(0,cmMin(sn-1,(unsigned)ceil(bi)));
@@ -1739,34 +1739,150 @@ VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussMM)( VECT_OP_TYPE* dbp, unsigned drn, unsi
1739 1739
   return dbp;
1740 1740
 }
1741 1741
 
1742
-VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY  )
1742
+VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev )
1743 1743
 {
1744
-  unsigned i;
1745
-  for(i=0; i<dn; ++i)
1746
-  {
1747
-    double a = 2.0*M_PI*i/(dn-1);
1744
+  VECT_OP_TYPE*       rp    = dbp;
1745
+  const VECT_OP_TYPE* dep   = dbp + dn;
1746
+  VECT_OP_TYPE        var   = stdDev * stdDev;
1747
+  VECT_OP_TYPE        fact0 = 1.0/sqrt(2*M_PI*var);
1748
+  VECT_OP_TYPE        fact1 = 2.0 * var;
1748 1749
 
1749
-    dbp[ i ]    = (VECT_OP_TYPE)(varX * cos(a) + x);
1750
-    dbp[ i+dn ] = (VECT_OP_TYPE)(varY * sin(a) + y);
1751
-  }
1750
+  for(; dbp < dep; ++sbp )
1751
+    *dbp++ = fact0 * exp( -((*sbp-mean)*(*sbp-mean))/ fact1 );
1752 1752
 
1753
-  return dbp;
1753
+  return rp;
1754 1754
 }
1755 1755
 
1756
-
1757
-unsigned      VECT_OP_FUNC(SynthSine)(      VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz )
1756
+/// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
1757
+/// at the data points held in the columns of xM[D,N]. Return the evaluation
1758
+/// results in the vector yV[N]. 
1759
+bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV,  const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl )
1758 1760
 {
1759
-    const VECT_OP_TYPE* dep = dbp + dn;
1760
-  double rps = 2.0*M_PI*hz/srate;
1761
-
1762
-  while( dbp < dep )
1763
-    *dbp++ = (VECT_OP_TYPE)sin( rps * phase++ );
1764
-
1765
-  return phase;
1766
-}
1761
+  VECT_OP_TYPE det0;
1767 1762
 
1768
-unsigned      VECT_OP_FUNC(SynthCosine)(    VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz )
1769
-{
1763
+  // calc the determinant of the covariance matrix
1764
+  if( diagFl )
1765
+    // kpl 1/16/11 det0  = VECT_OP_FUNC(LogDetDiagM)(covarM,D);
1766
+    det0  = VECT_OP_FUNC(DetDiagM)(covarM,D);
1767
+  else
1768
+    // kpl 1/16/11 det0 = VECT_OP_FUNC(LogDetM)(covarM,D);
1769
+    det0 = VECT_OP_FUNC(DetM)(covarM,D);
1770
+
1771
+  assert(det0 != 0 );
1772
+
1773
+  if( det0 == 0 )
1774
+    return false;
1775
+
1776
+  // calc the inverse of the covariance matrix
1777
+  VECT_OP_TYPE icM[D*D];
1778
+  VECT_OP_FUNC(Copy)(icM,D*D,covarM);
1779
+  
1780
+  VECT_OP_TYPE* r;
1781
+  if( diagFl )
1782
+    r = VECT_OP_FUNC(InvDiagM)(icM,D);
1783
+  else
1784
+    r = VECT_OP_FUNC(InvM)(icM,D);
1785
+
1786
+  if( r == NULL )
1787
+      return false;
1788
+  
1789
+  VECT_OP_FUNC(MultVarGaussPDF2)( yV, xM, meanV, icM, det0, D, N, diagFl );
1790
+
1791
+  return true;
1792
+}
1793
+
1794
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* icM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl )
1795
+{
1796
+  unsigned i;
1797
+
1798
+  double fact = (-(cmReal_t)D/2) * log(2.0*M_PI) - 0.5*logDet;
1799
+
1800
+  for(i=0; i<N; ++i)
1801
+  {
1802
+    VECT_OP_TYPE dx[D];
1803
+    VECT_OP_TYPE t[D];
1804
+
1805
+    // dx[] difference between mean and ith data point
1806
+    VECT_OP_FUNC(SubVVV)(dx,D, xM + (i*D), meanV);
1807
+
1808
+    // t[] = dx[] * inv(covarM);
1809
+    if( diagFl )
1810
+      VECT_OP_FUNC(MultDiagVMV)(t,D,icM,D,dx);
1811
+    else
1812
+      VECT_OP_FUNC(MultVMV)(t,D,icM,D,dx);
1813
+
1814
+    // dist = sum(dx[] * t[])
1815
+    cmReal_t dist = VECT_OP_FUNC(MultSumVV)(t,dx,D);
1816
+
1817
+    yV[i] = exp( fact - (0.5*dist) );
1818
+
1819
+  }
1820
+
1821
+  return yV;
1822
+}
1823
+
1824
+
1825
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)( 
1826
+  VECT_OP_TYPE*       yV, 
1827
+  const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
1828
+  void*               funcDataPtr,
1829
+  const VECT_OP_TYPE* meanV, 
1830
+  const VECT_OP_TYPE* icM, 
1831
+  VECT_OP_TYPE        logDet, 
1832
+  unsigned            D, 
1833
+  unsigned            N, 
1834
+  bool                diagFl )
1835
+{
1836
+  unsigned i;
1837
+
1838
+  double fact = (-(cmReal_t)D/2) * log(2.0*M_PI) - 0.5*logDet;
1839
+
1840
+  for(i=0; i<N; ++i)
1841
+  {
1842
+    VECT_OP_TYPE dx[D];
1843
+    VECT_OP_TYPE t[D];
1844
+
1845
+    const VECT_OP_TYPE* xV = srcFunc( funcDataPtr, i );
1846
+
1847
+    if( xV == NULL )
1848
+      yV[i] = 0;
1849
+    else
1850
+    {
1851
+      // dx[] difference between mean and ith data point
1852
+      VECT_OP_FUNC(SubVVV)(dx, D, xV, meanV);
1853
+
1854
+      // t[] = dx[] * inv(covarM);
1855
+      if( diagFl )
1856
+        VECT_OP_FUNC(MultDiagVMV)(t,D,icM,D,dx);
1857
+      else
1858
+        VECT_OP_FUNC(MultVMV)(t,D,icM,D,dx);
1859
+
1860
+      // dist = sum(dx[] * t[])
1861
+      cmReal_t dist = VECT_OP_FUNC(MultSumVV)(t,dx,D);
1862
+
1863
+      yV[i] = exp( fact - (0.5*dist) );
1864
+    }
1865
+  }
1866
+
1867
+  return yV;
1868
+}
1869
+
1870
+
1871
+
1872
+
1873
+unsigned      VECT_OP_FUNC(SynthSine)(      VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz )
1874
+{
1875
+    const VECT_OP_TYPE* dep = dbp + dn;
1876
+  double rps = 2.0*M_PI*hz/srate;
1877
+
1878
+  while( dbp < dep )
1879
+    *dbp++ = (VECT_OP_TYPE)sin( rps * phase++ );
1880
+
1881
+  return phase;
1882
+}
1883
+
1884
+unsigned      VECT_OP_FUNC(SynthCosine)(    VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz )
1885
+{
1770 1886
   const VECT_OP_TYPE* dep = dbp + dn;
1771 1887
   double rps = 2.0*M_PI*hz/srate;
1772 1888
 
@@ -1929,15 +2045,48 @@ VECT_OP_TYPE VECT_OP_FUNC(SynthPinkNoise)( VECT_OP_TYPE* dbp, unsigned n, VECT_O
1929 2045
   return *sp;
1930 2046
 }
1931 2047
 
1932
-VECT_OP_TYPE*  VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit )
2048
+VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb )
1933 2049
 {
1934
-  unsigned i = 0;
1935
-  for(; i<dn; ++i)
1936
-    dbp[i] = base + i*(limit-base)/(dn-1);
2050
+  VECT_OP_TYPE  minVal = pow(10.0,minDb/20.0);
2051
+  VECT_OP_TYPE* dp     = dbp;
2052
+  VECT_OP_TYPE* ep     = dp + dn;
2053
+
2054
+  for(; dp<ep; ++dp,++sbp)
2055
+    *dp = *sbp<minVal ? minDb : 20.0 * log10(*sbp);
2056
+  return dbp;
2057
+}
2058
+
2059
+VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
2060
+{
2061
+  VECT_OP_TYPE* dp = dbp;
2062
+  VECT_OP_TYPE* ep = dp + dn;
2063
+  for(; dp<ep; ++dp,++sbp)
2064
+    *dp = pow(10.0,*sbp/20.0);
2065
+  return dbp;
2066
+}
2067
+
2068
+VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb )
2069
+{
2070
+  VECT_OP_TYPE  minVal = pow(10.0,minDb/10.0);
2071
+  VECT_OP_TYPE* dp     = dbp;
2072
+  VECT_OP_TYPE* ep     = dp + dn;
2073
+
2074
+  for(; dp<ep; ++dp,++sbp)
2075
+    *dp = *sbp<minVal ? minDb : 10.0 * log10(*sbp);
2076
+  return dbp;
2077
+}
2078
+
2079
+VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp)
2080
+{
2081
+  VECT_OP_TYPE* dp = dbp;
2082
+  VECT_OP_TYPE* ep = dp + dn;
2083
+  for(; dp<ep; ++dp,++sbp)
2084
+    *dp = pow(10.0,*sbp/10.0);
1937 2085
   return dbp;
1938 2086
 }
1939 2087
 
1940 2088
 
2089
+
1941 2090
 VECT_OP_TYPE* VECT_OP_FUNC(LinearToDb)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE mult )
1942 2091
 {
1943 2092
   const VECT_OP_TYPE* dep = dbp + dn;
@@ -2371,41 +2520,6 @@ VECT_OP_TYPE* VECT_OP_FUNC(LP_Sinc)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
2371 2520
   return rp;
2372 2521
 }
2373 2522
 
2374
-VECT_OP_TYPE  VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt )
2375
-{
2376
-  double              sum  = 0;
2377
-  const VECT_OP_TYPE*  ep  = mag0V + binCnt;
2378
-
2379
-  unsigned i = 0;
2380
-
2381
-  for(;  mag0V < ep; ++i )
2382
-  {
2383
-    // calc phase deviation from expected
2384
-    double dev_rads    = *phs0V++ - (2 * *phs1V++) + *phs2V++;   
2385
-
2386
-    // map deviation into range: -pi to pi
2387
-    //double dev_rads1    = mod(dev_rads0 + M_PI, -2*M_PI ) + M_PI;            
2388
-
2389
-    while( dev_rads > M_PI)
2390
-      dev_rads -= 2*M_PI;
2391
-
2392
-    while( dev_rads < -M_PI)
2393
-      dev_rads += 2*M_PI;    
2394
-
2395
-    // convert into rect coord's
2396
-    double m1r =  *mag1V++;
2397
-    double m0r =  *mag0V   * cos(dev_rads);
2398
-    double m0i =  *mag0V++ * sin(dev_rads);
2399
-
2400
-    // calc the combined amplitude and phase deviation 
2401
-    // sum += hypot( m1 - (m0 * e^(-1*dev_rads)));
2402
-
2403
-    sum += hypot( m1r-m0r, -m0i );
2404
-
2405
-  }
2406
-
2407
-  return (VECT_OP_TYPE)sum; 
2408
-}
2409 2523
 
2410 2524
 VECT_OP_TYPE* VECT_OP_FUNC(MelMask)( VECT_OP_TYPE* maskMtx, unsigned filterCnt, unsigned binCnt, double srate, unsigned flags )
2411 2525
 {
@@ -2614,107 +2728,45 @@ VECT_OP_TYPE* VECT_OP_FUNC(ShroederSpreadingFunc)(VECT_OP_TYPE* m, unsigned band
2614 2728
   return m;
2615 2729
 }
2616 2730
 
2617
-
2618
-VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt )
2731
+unsigned VECT_OP_FUNC(Kmeans)( 
2732
+  unsigned*           classIdxV,         // classIdxV[scn] - data point class assignments
2733
+  VECT_OP_TYPE*       centroidM,         // centroidM[srn,K] - cluster centroids
2734
+  unsigned            K,                 // count of clusters
2735
+  const VECT_OP_TYPE* sM,                // sM[srn,scn] source data matrix
2736
+  unsigned            srn,               // dimensionality of each data point
2737
+  unsigned            scn,               // count of data points
2738
+  const unsigned*     selIdxV,           // data subset selection id vector (optional)
2739
+  unsigned            selKey,            // data subset selection key       (optional)
2740
+  bool                initFromCentroidFl,// true if the starting centroids are in centroidM[]
2741
+  VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ),
2742
+  void*               userDistPtr
2743
+) 
2619 2744
 {
2620
-  VECT_OP_TYPE* dbp = dp;
2621
-
2622
-  double c0 = 1.0/sqrt(filtCnt/2); // row 1-coeffCnt factor
2623
-  double c1 = c0 * sqrt(2)/2;      // row 0 factor
2624
-
2625
-  unsigned i,j;
2745
+  unsigned D       = srn;   // data dimensionality
2746
+  unsigned N       = scn;   // count of data points to cluster
2747
+  unsigned iterCnt = 0;
2748
+  unsigned ki;
2749
+  unsigned i       = 0;
2750
+  unsigned selN    = N;
2626 2751
 
2627
-  // for each column
2628
-  for(i=0; i<filtCnt; ++i)
2629
-    // for each row
2630
-    for(j=0; j<coeffCnt; ++j)
2631
-      *dp++ = (j==0 ? c1 : c0) * cos( (0.5 + i) * M_PI * j / filtCnt);
2752
+  // if a data point selection vector was given
2753
+  if( selIdxV != NULL )
2754
+  {
2755
+    selN = 0;
2632 2756
 
2633
-  return dbp;
2634
-}
2757
+    for(i=0; i<N; ++i)
2758
+    {
2759
+      selN        += selIdxV[i]==selKey;
2760
+      classIdxV[i] = K;
2761
+    }
2762
+  }
2635 2763
 
2636
-unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold )
2637
-{
2638
-  unsigned pkCnt = 0;
2639
-  const unsigned*     dep = dbp + dn;
2640
-  const VECT_OP_TYPE* sep = sbp + sn;
2641
-  const VECT_OP_TYPE* s2p = sbp;
2642
-  const VECT_OP_TYPE* s0p = s2p++;
2643
-  const VECT_OP_TYPE* s1p = s2p++;
2644 2764
 
2765
+  assert(K<=selN);
2645 2766
 
2646
-  while( dbp < dep && s2p < sep )
2647
-  {
2648
-    if( (*s0p < *s1p) && (*s1p > *s2p) && (*s1p >= threshold) )
2649
-    {
2650
-      *dbp++ = s1p - sbp;
2651
-      s0p    = s2p++;
2652
-      s1p    = s2p++;
2653
-      ++pkCnt;
2654
-    }
2655
-    else
2656
-    {
2657
-      s0p = s1p;
2658
-      s1p = s2p++;     
2659
-    }
2660
-  }
2661
-  
2662
-  return pkCnt;
2663
-}
2664
-
2665
-unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v )
2666
-{
2667
-  const VECT_OP_TYPE* sep = sbp + sn;
2668
-  const VECT_OP_TYPE* bp = sbp;
2669
-  sep--;
2670
-  for(; sbp < sep; ++sbp  )
2671
-    if( *sbp <= v && v < *(sbp+1) )
2672
-      return sbp - bp;
2673
-      
2674
-  return cmInvalidIdx;
2675
-}
2676
-
2677
-
2678
-
2679
-unsigned VECT_OP_FUNC(Kmeans)( 
2680
-  unsigned*           classIdxV,         // classIdxV[scn] - data point class assignments
2681
-  VECT_OP_TYPE*       centroidM,         // centroidM[srn,K] - cluster centroids
2682
-  unsigned            K,                 // count of clusters
2683
-  const VECT_OP_TYPE* sM,                // sM[srn,scn] source data matrix
2684
-  unsigned            srn,               // dimensionality of each data point
2685
-  unsigned            scn,               // count of data points
2686
-  const unsigned*     selIdxV,           // data subset selection id vector (optional)
2687
-  unsigned            selKey,            // data subset selection key       (optional)
2688
-  bool                initFromCentroidFl,// true if the starting centroids are in centroidM[]
2689
-  VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ),
2690
-  void*               userDistPtr
2691
-) 
2692
-{
2693
-  unsigned D       = srn;   // data dimensionality
2694
-  unsigned N       = scn;   // count of data points to cluster
2695
-  unsigned iterCnt = 0;
2696
-  unsigned ki;
2697
-  unsigned i       = 0;
2698
-  unsigned selN    = N;
2699
-
2700
-  // if a data point selection vector was given
2701
-  if( selIdxV != NULL )
2702
-  {
2703
-    selN = 0;
2704
-
2705
-    for(i=0; i<N; ++i)
2706
-    {
2707
-      selN        += selIdxV[i]==selKey;
2708
-      classIdxV[i] = K;
2709
-    }
2710
-  }
2711
-
2712
-
2713
-  assert(K<=selN);
2714
-
2715
-  // if the numer of datapoints and the number of clusters is the same
2716
-  // make the datapoints the centroids and return
2717
-  if( K == selN )
2767
+  // if the numer of datapoints and the number of clusters is the same
2768
+  // make the datapoints the centroids and return
2769
+  if( K == selN )
2718 2770
   {
2719 2771
     ki = 0;
2720 2772
     for(i=0; i<N; ++i)
@@ -2913,136 +2965,6 @@ unsigned VECT_OP_FUNC(Kmeans2)(
2913 2965
   return iterCnt;
2914 2966
 }
2915 2967
 
2916
-
2917
-VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev )
2918
-{
2919
-  VECT_OP_TYPE*       rp    = dbp;
2920
-  const VECT_OP_TYPE* dep   = dbp + dn;
2921
-  VECT_OP_TYPE        var   = stdDev * stdDev;
2922
-  VECT_OP_TYPE        fact0 = 1.0/sqrt(2*M_PI*var);
2923
-  VECT_OP_TYPE        fact1 = 2.0 * var;
2924
-
2925
-  for(; dbp < dep; ++sbp )
2926
-    *dbp++ = fact0 * exp( -((*sbp-mean)*(*sbp-mean))/ fact1 );
2927
-
2928
-  return rp;
2929
-}
2930
-
2931
-/// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
2932
-/// at the data points held in the columns of xM[D,N]. Return the evaluation
2933
-/// results in the vector yV[N]. 
2934
-bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV,  const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl )
2935
-{
2936
-  VECT_OP_TYPE det0;
2937
-
2938
-  // calc the determinant of the covariance matrix
2939
-  if( diagFl )
2940
-    // kpl 1/16/11 det0  = VECT_OP_FUNC(LogDetDiagM)(covarM,D);
2941
-    det0  = VECT_OP_FUNC(DetDiagM)(covarM,D);
2942
-  else
2943
-    // kpl 1/16/11 det0 = VECT_OP_FUNC(LogDetM)(covarM,D);
2944
-    det0 = VECT_OP_FUNC(DetM)(covarM,D);
2945
-
2946
-  assert(det0 != 0 );
2947
-
2948
-  if( det0 == 0 )
2949
-    return false;
2950
-
2951
-  // calc the inverse of the covariance matrix
2952
-  VECT_OP_TYPE icM[D*D];
2953
-  VECT_OP_FUNC(Copy)(icM,D*D,covarM);
2954
-  
2955
-  VECT_OP_TYPE* r;
2956
-  if( diagFl )
2957
-    r = VECT_OP_FUNC(InvDiagM)(icM,D);
2958
-  else
2959
-    r = VECT_OP_FUNC(InvM)(icM,D);
2960
-
2961
-  if( r == NULL )
2962
-      return false;
2963
-  
2964
-  VECT_OP_FUNC(MultVarGaussPDF2)( yV, xM, meanV, icM, det0, D, N, diagFl );
2965
-
2966
-  return true;
2967
-}
2968
-
2969
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* icM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl )
2970
-{
2971
-  unsigned i;
2972
-
2973
-  double fact = (-(cmReal_t)D/2) * log(2.0*M_PI) - 0.5*logDet;
2974
-
2975
-  for(i=0; i<N; ++i)
2976
-  {
2977
-    VECT_OP_TYPE dx[D];
2978
-    VECT_OP_TYPE t[D];
2979
-
2980
-    // dx[] difference between mean and ith data point
2981
-    VECT_OP_FUNC(SubVVV)(dx,D, xM + (i*D), meanV);
2982
-
2983
-    // t[] = dx[] * inv(covarM);
2984
-    if( diagFl )
2985
-      VECT_OP_FUNC(MultDiagVMV)(t,D,icM,D,dx);
2986
-    else
2987
-      VECT_OP_FUNC(MultVMV)(t,D,icM,D,dx);
2988
-
2989
-    // dist = sum(dx[] * t[])
2990
-    cmReal_t dist = VECT_OP_FUNC(MultSumVV)(t,dx,D);
2991
-
2992
-    yV[i] = exp( fact - (0.5*dist) );
2993
-
2994
-  }
2995
-
2996
-  return yV;
2997
-}
2998
-
2999
-
3000
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)( 
3001
-  VECT_OP_TYPE*       yV, 
3002
-  const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
3003
-  void*               funcDataPtr,
3004
-  const VECT_OP_TYPE* meanV, 
3005
-  const VECT_OP_TYPE* icM, 
3006
-  VECT_OP_TYPE        logDet, 
3007
-  unsigned            D, 
3008
-  unsigned            N, 
3009
-  bool                diagFl )
3010
-{
3011
-  unsigned i;
3012
-
3013
-  double fact = (-(cmReal_t)D/2) * log(2.0*M_PI) - 0.5*logDet;
3014
-
3015
-  for(i=0; i<N; ++i)
3016
-  {
3017
-    VECT_OP_TYPE dx[D];
3018
-    VECT_OP_TYPE t[D];
3019
-
3020
-    const VECT_OP_TYPE* xV = srcFunc( funcDataPtr, i );
3021
-
3022
-    if( xV == NULL )
3023
-      yV[i] = 0;
3024
-    else
3025
-    {
3026
-      // dx[] difference between mean and ith data point
3027
-      VECT_OP_FUNC(SubVVV)(dx, D, xV, meanV);
3028
-
3029
-      // t[] = dx[] * inv(covarM);
3030
-      if( diagFl )
3031
-        VECT_OP_FUNC(MultDiagVMV)(t,D,icM,D,dx);
3032
-      else
3033
-        VECT_OP_FUNC(MultVMV)(t,D,icM,D,dx);
3034
-
3035
-      // dist = sum(dx[] * t[])
3036
-      cmReal_t dist = VECT_OP_FUNC(MultSumVV)(t,dx,D);
3037
-
3038
-      yV[i] = exp( fact - (0.5*dist) );
3039
-    }
3040
-  }
3041
-
3042
-  return yV;
3043
-}
3044
-
3045
-
3046 2968
 /// stateV[timeN]
3047 2969
 /// a[stateN,stateN], 
3048 2970
 /// b[stateN,timeN]
@@ -3117,6 +3039,22 @@ void VECT_OP_FUNC(DiscreteViterbi)(unsigned* stateV, unsigned tN, unsigned sN, c
3117 3039
   cmMemPtrFree( &dV );
3118 3040
 }
3119 3041
 
3042
+
3043
+VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY  )
3044
+{
3045
+  unsigned i;
3046
+  for(i=0; i<dn; ++i)
3047
+  {
3048
+    double a = 2.0*M_PI*i/(dn-1);
3049
+
3050
+    dbp[ i ]    = (VECT_OP_TYPE)(varX * cos(a) + x);
3051
+    dbp[ i+dn ] = (VECT_OP_TYPE)(varY * sin(a) + y);
3052
+  }
3053
+
3054
+  return dbp;
3055
+}
3056
+
3057
+
3120 3058
 bool VECT_OP_FUNC(ClipLine2)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, VECT_OP_TYPE x1, VECT_OP_TYPE y1, VECT_OP_TYPE xMin, VECT_OP_TYPE yMin, VECT_OP_TYPE xMax, VECT_OP_TYPE yMax, VECT_OP_TYPE* t0, VECT_OP_TYPE* t1 )
3121 3059
 {
3122 3060
 
@@ -3226,43 +3164,106 @@ VECT_OP_TYPE VECT_OP_FUNC(PtToLineDistance)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, V
3226 3164
   return (VECT_OP_TYPE)fabs((px - x0) * (y1 - y0) - (py - y0) * (x1 - x0)) / normalLength;
3227 3165
 }                              
3228 3166
 
3229
-void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 )
3167
+
3168
+VECT_OP_TYPE  VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt )
3230 3169
 {
3231
-  VECT_OP_TYPE sx = 0;
3232
-  VECT_OP_TYPE sy = 0;
3233
-  VECT_OP_TYPE sx_2 = 0;
3234
-  VECT_OP_TYPE sxy  = 0;
3235
-  unsigned i;  
3170
+  double              sum  = 0;
3171
+  const VECT_OP_TYPE*  ep  = mag0V + binCnt;
3236 3172
 
3237
-  if( x == NULL )
3173
+  unsigned i = 0;
3174
+
3175
+  for(;  mag0V < ep; ++i )
3238 3176
   {
3239
-    for(i=0; i<n; ++i)
3240
-    {
3241
-      VECT_OP_TYPE xx = i;
3242
-      sx   += xx;
3243
-      sx_2 += xx * xx;
3244
-      sxy  += xx * y[i];
3245
-      sy   += y[i];
3246
-    }
3177
+    // calc phase deviation from expected
3178
+    double dev_rads    = *phs0V++ - (2 * *phs1V++) + *phs2V++;   
3179
+
3180
+    // map deviation into range: -pi to pi
3181
+    //double dev_rads1    = mod(dev_rads0 + M_PI, -2*M_PI ) + M_PI;            
3182
+
3183
+    while( dev_rads > M_PI)
3184
+      dev_rads -= 2*M_PI;
3185
+
3186
+    while( dev_rads < -M_PI)
3187
+      dev_rads += 2*M_PI;    
3188
+
3189
+    // convert into rect coord's
3190
+    double m1r =  *mag1V++;
3191
+    double m0r =  *mag0V   * cos(dev_rads);
3192
+    double m0i =  *mag0V++ * sin(dev_rads);
3193
+
3194
+    // calc the combined amplitude and phase deviation 
3195
+    // sum += hypot( m1 - (m0 * e^(-1*dev_rads)));
3196
+
3197
+    sum += hypot( m1r-m0r, -m0i );
3198
+
3247 3199
   }
3248
-  else
3200
+
3201
+  return (VECT_OP_TYPE)sum; 
3202
+}
3203
+
3204
+VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt )
3205
+{
3206
+  VECT_OP_TYPE* dbp = dp;
3207
+
3208
+  double c0 = 1.0/sqrt(filtCnt/2); // row 1-coeffCnt factor
3209
+  double c1 = c0 * sqrt(2)/2;      // row 0 factor
3210
+
3211
+  unsigned i,j;
3212
+
3213
+  // for each column
3214
+  for(i=0; i<filtCnt; ++i)
3215
+    // for each row
3216
+    for(j=0; j<coeffCnt; ++j)
3217
+      *dp++ = (j==0 ? c1 : c0) * cos( (0.5 + i) * M_PI * j / filtCnt);
3218
+
3219
+  return dbp;
3220
+}
3221
+
3222
+
3223
+unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold )
3224
+{
3225
+  unsigned pkCnt = 0;
3226
+  const unsigned*     dep = dbp + dn;
3227
+  const VECT_OP_TYPE* sep = sbp + sn;
3228
+  const VECT_OP_TYPE* s2p = sbp;
3229
+  const VECT_OP_TYPE* s0p = s2p++;
3230
+  const VECT_OP_TYPE* s1p = s2p++;
3231
+
3232
+
3233
+  while( dbp < dep && s2p < sep )
3249 3234
   {
3250
-    for(i=0; i<n; ++i)
3235
+    if( (*s0p < *s1p) && (*s1p > *s2p) && (*s1p >= threshold) )
3251 3236
     {
3252
-      sx   += x[i];
3253
-      sx_2 += x[i] * x[i];
3254
-      sxy  += x[i] * y[i];
3255
-      sy   += y[i];
3237
+      *dbp++ = s1p - sbp;
3238
+      s0p    = s2p++;
3239
+      s1p    = s2p++;
3240
+      ++pkCnt;
3241
+    }
3242
+    else
3243
+    {
3244
+      s0p = s1p;
3245
+      s1p = s2p++;     
3256 3246
     }
3257 3247
   }
3248
+  
3249
+  return pkCnt;
3250
+}
3258 3251
 
3259
-  *b1 = (sxy * n - sx * sy) / (sx_2 * n - sx*sx);
3260
-  *b0 = (sy - (*b1) * sx) / n;      
3261
-
3252
+unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v )
3253
+{
3254
+  const VECT_OP_TYPE* sep = sbp + sn;
3255
+  const VECT_OP_TYPE* bp = sbp;
3256
+  sep--;
3257
+  for(; sbp < sep; ++sbp  )
3258
+    if( *sbp <= v && v < *(sbp+1) )
3259
+      return sbp - bp;
3260
+      
3261
+  return cmInvalidIdx;
3262 3262
 }
3263 3263
 
3264 3264
 
3265 3265
 
3266
+
3266 3267
 void VECT_OP_FUNC(Interp1)(VECT_OP_TYPE* y1, const VECT_OP_TYPE* x1, unsigned xy1N, const VECT_OP_TYPE* x0, const VECT_OP_TYPE* y0, unsigned xy0N )
3267 3268
 {
3268 3269
   unsigned i,j;

+ 415
- 320
src/vop/cmVectOpsTemplateHdr.h 查看文件

@@ -1,7 +1,21 @@
1
-// \file cmVectOpsTemplateHdr.h
2
-/// Vector operations interface.
1
+//( { label:misc desc:"Miscellaneous vector operations." kw:[vop] }
3 2
 
4
-/// Setting fieldWidth or decPltCnt to to negative values result in fieldWidth == 10 or decPlCnt == 4
3
+// Compute the cummulative sum of sbp[dn]. Equivalent to Matlab cumsum().
4
+VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp ); 
5
+
6
+// Returns true if all values in each vector are equal.
7
+bool          VECT_OP_FUNC(Equal)(    const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
8
+
9
+// Same as Matlab linspace() v[i] = i * (limit-1)/n
10
+VECT_OP_TYPE*  VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit );
11
+
12
+//======================================================================================================================
13
+//)
14
+
15
+
16
+//( { label:Print desc:"Vector printing functions." kw:[vop] }
17
+// Setting fieldWidth or decPltCnt to to negative values result in fieldWidth == 10 or decPlCnt == 4
18
+//
5 19
 void          VECT_OP_FUNC(Printf)( cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp, int fieldWidth, int decPlCnt, const char* fmt, unsigned flags );
6 20
 void          VECT_OP_FUNC(Print)(  cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
7 21
 void          VECT_OP_FUNC(PrintE)( cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
@@ -9,64 +23,68 @@ void          VECT_OP_FUNC(PrintE)( cmRpt_t* rpt, unsigned rn, unsigned cn, cons
9 23
 void          VECT_OP_FUNC(PrintLf)( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp, unsigned fieldWidth, unsigned decPlCnt, const char* fmt );
10 24
 void          VECT_OP_FUNC(PrintL)(  const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
11 25
 void          VECT_OP_FUNC(PrintLE)( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const VECT_OP_TYPE* dbp );
26
+//======================================================================================================================
27
+//)
12 28
 
13 29
 
30
+//( { label:Normalization desc:"Normalization and standardization functions." kw:[vop] }
14 31
 
15
-/// Normalize the vector of proabilities by dividing through by the sum.
16
-/// This leaves the relative proportions of each value unchanged while producing a total probability of 1.0.
32
+// Normalize the vector of proabilities by dividing through by the sum.
33
+// This leaves the relative proportions of each value unchanged while producing a total probability of 1.0.
34
+//
17 35
 VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbabilityVV)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
18 36
 VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbability)(VECT_OP_TYPE* dbp, unsigned dn);
19 37
 VECT_OP_TYPE* VECT_OP_FUNC(NormalizeProbabilityN)(VECT_OP_TYPE* dbp, unsigned dn, unsigned stride);
20
-
21
-/// Standardize the columns of the matrix by subtracting the mean and dividing by the standard deviation.
22
-/// uV[dcn] returns the mean of the data and is optional.
23
-/// sdV[dcn] return the standard deviation of the data and is optional.
38
+//
39
+// Standardize the columns of the matrix by subtracting the mean and dividing by the standard deviation.
40
+// uV[dcn] returns the mean of the data and is optional.
41
+// sdV[dcn] return the standard deviation of the data and is optional.
24 42
 VECT_OP_TYPE* VECT_OP_FUNC(StandardizeRows)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE* uV, VECT_OP_TYPE* sdV );
25 43
 VECT_OP_TYPE* VECT_OP_FUNC(StandardizeCols)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE* uV, VECT_OP_TYPE* sdV );
44
+//
45
+// Normalize by dividing through by the max. value.
46
+// dp[] ./= max(dp). Returns the index of the max value.
47
+unsigned  VECT_OP_FUNC(NormToMax)(    VECT_OP_TYPE* dp, unsigned dn );
48
+//
49
+// Normalize by dividing through by the max. absolute value.
50
+// db[] .*= fact / abs(max(dp));
51
+unsigned VECT_OP_FUNC(NormToAbsMax)(   VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact );
52
+//======================================================================================================================
53
+//)
26 54
 
27
-/// dbp[] = sbp<0 .* sbp 
28
-/// Overlapping the source and dest is allowable as long as dbp <= sbp. 
29
-VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
30 55
 
31
-/// Compute the cummulative sum of sbp[dn]. Equivalent to Matlab cumsum().
32
-VECT_OP_TYPE* VECT_OP_FUNC(CumSum)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp ); 
56
+//( { label:"Mean and variance" desc:"Compute mean and variance." kw:[vop] }
33 57
 
34 58
 VECT_OP_TYPE  VECT_OP_FUNC(Mean)(     const VECT_OP_TYPE* sp, unsigned sn );
35 59
 VECT_OP_TYPE  VECT_OP_FUNC(MeanN)(    const VECT_OP_TYPE* sp, unsigned sn, unsigned stride  );
36
-
60
+//
37 61
 // Take the mean of each column/row of a matrix.
38 62
 // Set 'dim' to 0 to return mean of columns else return mean of rows.
39 63
 VECT_OP_TYPE*  VECT_OP_FUNC(MeanM)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim );
40
-
64
+//
41 65
 // Take the mean of the first 'cnt' element of each column/row of a matrix.
42 66
 // Set 'dim' to 0 to return mean of columns else return mean of rows.
43 67
 // If 'cnt' is greater than the number of elements in the column/row then 'cnt' is
44 68
 // reduced to the number of elements in the column/row.
45 69
 VECT_OP_TYPE*  VECT_OP_FUNC(MeanM2)(    VECT_OP_TYPE* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, unsigned dim, unsigned cnt );
46
-
70
+//
47 71
 // Find the mean of the  data points returned by srcFuncPtr(argPtr,i) and return it in dp[dim].
48 72
 // 'dim' is both the size of dp[] and the length of each data point returned by srcFuncPtr().
49 73
 // srcFuncPtr() will be called 'cnt' times but it may return NULL on some calls if the associated
50 74
 // data point should not be included in the mean calculation.
51 75
 VECT_OP_TYPE*  VECT_OP_FUNC(Mean2)(   VECT_OP_TYPE* dp, const VECT_OP_TYPE* (*srcFuncPtr)(void* arg, unsigned idx ), unsigned dim, unsigned cnt, void* argPtr );
52
-
53
-
76
+//
54 77
 // avgPtr is optional - set to NULL to compute the average
55 78
 VECT_OP_TYPE  VECT_OP_FUNC(Variance)( const VECT_OP_TYPE* sp, unsigned sn, const VECT_OP_TYPE* avgPtr );
56 79
 VECT_OP_TYPE  VECT_OP_FUNC(VarianceN)(const VECT_OP_TYPE* sp, unsigned sn, unsigned stride, const VECT_OP_TYPE* avgPtr );
57
-
80
+//
58 81
 // Set dim=0 to return variance of columns otherwise return variance or rows.
59 82
 VECT_OP_TYPE*  VECT_OP_FUNC(VarianceM)(VECT_OP_TYPE* dp,  const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, const VECT_OP_TYPE* avgPtr, unsigned dim );
83
+//======================================================================================================================
84
+//)
60 85
 
61
-// dp[] ./= max(dp). Returns the index of the max value.
62
-unsigned  VECT_OP_FUNC(NormToMax)(    VECT_OP_TYPE* dp, unsigned dn );
63
-
64
-// db[] .*= fact / abs(max(dp));
65
-unsigned VECT_OP_FUNC(NormToAbsMax)(   VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE fact );
66
-
67
-
68
-VECT_OP_TYPE  VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha );
69 86
 
87
+//( { label:"Covariance" desc:"Matrix covariance" kw:[vop] }
70 88
 
71 89
 // Calculate the sample covariance matrix from a set of Gaussian distributed multidimensional data.
72 90
 // sp[dn,scn] is the data set.
@@ -92,8 +110,10 @@ void  VECT_OP_FUNC(GaussCovariance)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP
92 110
 // through the 'sn' data points.  
93 111
 // The result of this function are identical to the octave cov() function.
94 112
 void  VECT_OP_FUNC(GaussCovariance2)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* (*srcFuncPtr)(void* userPtr, unsigned idx), unsigned sn, void* userPtr, const VECT_OP_TYPE* uV, const unsigned* selIdxV, unsigned selKey );
113
+//======================================================================================================================
114
+//)
95 115
 
96
-bool          VECT_OP_FUNC(Equal)(    const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
116
+//( { label:"Float point normal" desc:"Evaluate the 'normalness of floating point values." kw:[vop] }
97 117
 
98 118
 // Returns true if all values are 'normal' according the the C macro 'isnormal'.
99 119
 // This function will return false if any of the values are zero.
@@ -107,80 +127,90 @@ bool          VECT_OP_FUNC(IsNormalZ)(const VECT_OP_TYPE* sp, unsigned sn );
107 127
 // Returns the count of indexes stored in dp[].
108 128
 unsigned      VECT_OP_FUNC(FindNonNormal)( unsigned* dp, unsigned dn, const VECT_OP_TYPE* sp );
109 129
 unsigned      VECT_OP_FUNC(FindNonNormalZ)( unsigned* dp, unsigned dn, const VECT_OP_TYPE* sp );
130
+//======================================================================================================================
131
+//)
110 132
 
111 133
 
112
-/// Successive call to to ZeroCrossCount should preserve the value pointed to by delaySmpPtr.
134
+//( { label:"Measure" desc:"Measure features of a vector." kw:[vop] }
135
+
136
+// Successive call to to ZeroCrossCount should preserve the value pointed to by delaySmpPtr.
113 137
 unsigned      VECT_OP_FUNC(ZeroCrossCount)( const VECT_OP_TYPE* sp, unsigned n, VECT_OP_TYPE* delaySmpPtr);
114 138
 
115 139
 // Calculuate the sum of the squares of all elements in bp[bn]. 
116 140
 VECT_OP_TYPE VECT_OP_FUNC(SquaredSum)( const VECT_OP_TYPE* bp, unsigned bn );
117 141
 
118
-/// sn must be <= wndSmpCnt. If sn < wndSmpCnt then sp[sn] is treated as a
119
-/// a partially filled buffer padded with wndSmpCnt-sn zeros.
120
-/// rms = sqrt( sum(sp[1:sn] .* sp[1:sn]) / wndSmpCnt )
142
+// sn must be <= wndSmpCnt. If sn < wndSmpCnt then sp[sn] is treated as a
143
+// a partially filled buffer padded with wndSmpCnt-sn zeros.
144
+// rms = sqrt( sum(sp[1:sn] .* sp[1:sn]) / wndSmpCnt )
121 145
 VECT_OP_TYPE  VECT_OP_FUNC(RMS)( const VECT_OP_TYPE* sp, unsigned sn, unsigned wndSmpCnt );
122 146
 
123
-/// This function handles the case were sn is not an integer multiple of 
124
-/// wndSmpCnt or hopSmpCnt.  In this case the function computes zero 
125
-/// padded RMS values for windows which go past the end of sp[sn].
147
+// This function handles the case were sn is not an integer multiple of 
148
+// wndSmpCnt or hopSmpCnt.  In this case the function computes zero 
149
+// padded RMS values for windows which go past the end of sp[sn].
126 150
 VECT_OP_TYPE* VECT_OP_FUNC(RmsV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp, unsigned sn, unsigned wndSmpCnt, unsigned hopSmpCnt );
127 151
 
128
-
129
-/// Return the magnitude (Euclidean Norm) of a vector.
152
+// Return the magnitude (Euclidean Norm) of a vector.
130 153
 VECT_OP_TYPE  VECT_OP_FUNC(EuclidNorm)( const VECT_OP_TYPE* sp, unsigned sn );
131 154
 
155
+VECT_OP_TYPE  VECT_OP_FUNC(AlphaNorm)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE alpha );
156
+
157
+//======================================================================================================================
158
+//)
159
+
160
+
161
+
162
+//( { label:"Distance" desc:"Calculate various vector distances." kw:[vop] }
163
+
132 164
 // Return the Itakura-Saito distance between a modelled power spectrum (up) and another power spectrum (sp).
133 165
 VECT_OP_TYPE VECT_OP_FUNC(ItakuraDistance)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
134 166
 
135
-/// Return the cosine distance between two vectors.
167
+// Return the cosine distance between two vectors.
136 168
 VECT_OP_TYPE  VECT_OP_FUNC(CosineDistance)( const VECT_OP_TYPE* s0P, const VECT_OP_TYPE* s1p, unsigned sn );
137 169
 
138
-/// Return the Euclidean distance between two vectors
170
+// Return the Euclidean distance between two vectors
139 171
 VECT_OP_TYPE  VECT_OP_FUNC(EuclidDistance)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
140 172
 
141
-/// Return the Manhattan distance between two vectors
173
+// Return the Manhattan distance between two vectors
142 174
 VECT_OP_TYPE  VECT_OP_FUNC(L1Distance)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
143 175
 
144
-/// Return the Mahalanobis distance between a vector and the mean of the distribution.
145
-/// The mean vector could be replaced with another vector drawn from the same distribution in which
146
-/// case the returned value would reflect the distance between the two vectors.
147
-/// 'sn' is the dimensionality of the data.
148
-/// up[D] and invCovM[sn,sn] are the mean and inverse of the covariance matrix of the distribution from 
149
-/// which sp[D] is drawn. 
176
+// Return the Mahalanobis distance between a vector and the mean of the distribution.
177
+// The mean vector could be replaced with another vector drawn from the same distribution in which
178
+// case the returned value would reflect the distance between the two vectors.
179
+// 'sn' is the dimensionality of the data.
180
+// up[D] and invCovM[sn,sn] are the mean and inverse of the covariance matrix of the distribution from 
181
+// which sp[D] is drawn. 
150 182
 VECT_OP_TYPE  VECT_OP_FUNC(MahalanobisDistance)( const VECT_OP_TYPE* sp, unsigned sn, const VECT_OP_TYPE* up, const VECT_OP_TYPE* invCovM );
151 183
 
152
-/// Return the KL distance between two probability distributions up[sn] and sp[sn].
153
-/// Since up[] and sp[] are probability distributions they must sum to 1.0.
184
+// Return the KL distance between two probability distributions up[sn] and sp[sn].
185
+// Since up[] and sp[] are probability distributions they must sum to 1.0.
154 186
 VECT_OP_TYPE VECT_OP_FUNC(KL_Distance)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
155 187
 
156
-/// Return the KL distance between a prototype vector up[sn] and another vector sp[sn].
157
-/// This function first normalizes the two vectors to sum to 1.0 before calling
188
+// Return the KL distance between a prototype vector up[sn] and another vector sp[sn].
189
+// This function first normalizes the two vectors to sum to 1.0 before calling
158 190
 // VECT_OP_FUNC(KL_Distance)(up,sp,sn);
159 191
 VECT_OP_TYPE VECT_OP_FUNC(KL_Distance2)( const VECT_OP_TYPE* up, const VECT_OP_TYPE* sp, unsigned sn );
160 192
 
161 193
 
162
-/// Measure the Euclidean distance between a vector and all the columns in a matrix.
163
-/// If dv[scn] is no NULL then return the Euclidean distance from sv[scn] to each column of sm[srn,scn].
164
-/// The function returns the index of the closest data point (column) in sm[].
194
+// Measure the Euclidean distance between a vector and all the columns in a matrix.
195
+// If dv[scn] is no NULL then return the Euclidean distance from sv[scn] to each column of sm[srn,scn].
196
+// The function returns the index of the closest data point (column) in sm[].
165 197
 unsigned VECT_OP_FUNC(EuclidDistanceVM)( VECT_OP_TYPE* dv, const VECT_OP_TYPE* sv, const VECT_OP_TYPE* sm, unsigned srn, unsigned scn );
166 198
 
167
-
168
-
169
-/// Measure the distance between each column in s0M[ rn, s0cn ] and 
170
-/// each column in s1M[rn, s1cn ]. If dM is non-NULL store the 
171
-/// result in dM[s1cn, s0cn]. The difference between s0M[:,0] and s1M[:,0] 
172
-/// is stored in dM[0,0], the diff. between s0M[:,1] and s1M[:,1] is stored 
173
-/// in dM[1,0], etc.  If mvV[s0cn] is non-NULL then  minV[i] is set with
174
-/// the distance from s0M[:,i] to the nearest column in s1M[]. If miV[s0cn]
175
-/// is non-NULL then it is set with the column index of s1M[] which is
176
-/// closest to s0M[:,i].  In other words mvV[i] gives the distance to column
177
-/// miV[i] from column s0M[:,i].
178
-/// In those cases where the distane from a prototype (centroid) to the data point
179
-/// is not the same as from the data point to the centroid then s1M[] is considered
180
-/// to hold the prototypes and s0M[] is considered to hold the data points.
181
-/// The distance function returns the distance from a prototype 'cV[dimN]' to
182
-/// an datapoint dV[dimN]. 'dimN' is the dimensionality of the data vector
183
-/// and is threfore equal to 'rn'.
199
+// Measure the distance between each column in s0M[ rn, s0cn ] and 
200
+// each column in s1M[rn, s1cn ]. If dM is non-NULL store the 
201
+// result in dM[s1cn, s0cn]. The difference between s0M[:,0] and s1M[:,0] 
202
+// is stored in dM[0,0], the diff. between s0M[:,1] and s1M[:,1] is stored 
203
+// in dM[1,0], etc.  If mvV[s0cn] is non-NULL then  minV[i] is set with
204
+// the distance from s0M[:,i] to the nearest column in s1M[]. If miV[s0cn]
205
+// is non-NULL then it is set with the column index of s1M[] which is
206
+// closest to s0M[:,i].  In other words mvV[i] gives the distance to column
207
+// miV[i] from column s0M[:,i].
208
+// In those cases where the distane from a prototype (centroid) to the data point
209
+// is not the same as from the data point to the centroid then s1M[] is considered
210
+// to hold the prototypes and s0M[] is considered to hold the data points.
211
+// The distance function returns the distance from a prototype 'cV[dimN]' to
212
+// an datapoint dV[dimN]. 'dimN' is the dimensionality of the data vector
213
+// and is threfore equal to 'rn'.
184 214
 void VECT_OP_FUNC(DistVMM)( 
185 215
   VECT_OP_TYPE*       dM,    // dM[s1cn,s0cn] return distance mtx (optional) 
186 216
   VECT_OP_TYPE*       mvV,   // mvV[s0cn] distance to closest data point in s0M[]. (optional)
@@ -193,192 +223,238 @@ void VECT_OP_FUNC(DistVMM)(
193 223
   VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* cV, const VECT_OP_TYPE* dV, unsigned dimN ), 
194 224
   void*               userPtr );
195 225
 
196
-/// Select 'selIdxN' columns from sM[srn,scn].
197
-/// dM[srn,selIdxN] receives copies of the selected columns.
198
-/// selIdxV[selIdxN] receives the column indexes of the selected columns.
199
-/// Both dM[] and selIdxV[] are optional.
200
-/// In each case the first selected point is chosen at random.
201
-/// SelectRandom() then selects the following selIdxN-1 points at random.
202
-/// SelectMaxDist() selects the next selIdxN-1 points by selecting 
203
-/// the point whose combined distance to the previously selected points
204
-/// is greatest. SelectMaxAvgDist() selectes the points whose combined
205
-/// average distance is greatest relative the the previously selected
206
-/// points.
226
+//======================================================================================================================
227
+//)
228
+
229
+//( { label:"Select columns" desc:"Select columns based on distance." kw:[vop] }
230
+
231
+// Select 'selIdxN' columns from sM[srn,scn].
232
+// dM[srn,selIdxN] receives copies of the selected columns.
233
+// selIdxV[selIdxN] receives the column indexes of the selected columns.
234
+// Both dM[] and selIdxV[] are optional.
235
+// In each case the first selected point is chosen at random.
236
+// SelectRandom() then selects the following selIdxN-1 points at random.
237
+// SelectMaxDist() selects the next selIdxN-1 points by selecting 
238
+// the point whose combined distance to the previously selected points
239
+// is greatest. SelectMaxAvgDist() selectes the points whose combined
240
+// average distance is greatest relative the the previously selected
241
+// points.
207 242
 void VECT_OP_FUNC(SelectRandom)(     VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn );
208 243
 void VECT_OP_FUNC(SelectMaxDist)(    VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn, VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ), void* distUserPtr );
209 244
 void VECT_OP_FUNC(SelectMaxAvgDist)( VECT_OP_TYPE* dM, unsigned* selIdxV, unsigned selIdxN, const VECT_OP_TYPE* sM, unsigned srn, unsigned scn, VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* s0V, const VECT_OP_TYPE* s1V, unsigned sn ), void* distUserPtr ); 
210 245
 
211
-/// Return the sum of the products (dot product)
246
+//======================================================================================================================
247
+//)
248
+
249
+//( { label:"Matrix multiplication" desc:"Various matrix multiplication operations." kw:[vop] }
250
+
251
+// Return the sum of the products (dot product)
212 252
 VECT_OP_TYPE VECT_OP_FUNC(MultSumVV)(  const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn  );
213 253
 VECT_OP_TYPE VECT_OP_FUNC(MultSumVS)(  const VECT_OP_TYPE* s0p, unsigned sn, VECT_OP_TYPE s );
214 254
 
215
-/// Number of elements in the dest vector is expected to be the same 
216
-/// as the number of source matrix rows.
217
-/// mcn gives the number of columns in the source matrix which is 
255
+// Number of elements in the dest vector is expected to be the same 
256
+// as the number of source matrix rows.
257
+// mcn gives the number of columns in the source matrix which is 
218 258
 //  expected to match the number of elements in the source vector.
219
-/// dbp[dn,1] = mp[dn,mcn] * vp[mcn,1] 
259
+// dbp[dn,1] = mp[dn,mcn] * vp[mcn,1] 
220 260
 VECT_OP_TYPE* VECT_OP_FUNC(MultVMV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mcn, const VECT_OP_TYPE* vp ); 
221 261
 
222
-/// Multiply a row vector with a matrix to produce a row vector. 
223
-/// dbp[1,dn] = v[1,vn] * m[vn,dn]
262
+// Multiply a row vector with a matrix to produce a row vector. 
263
+// dbp[1,dn] = v[1,vn] * m[vn,dn]
224 264
 VECT_OP_TYPE* VECT_OP_FUNC(MultVVM)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* vp, unsigned vn, const VECT_OP_TYPE* mp ); 
225 265
 
226
-/// Same as MultVMtV() except M is transposed as part of the multiply.  
227
-/// mrn gives the number of rows in m[] and number of elements in vp[]
228
-/// dpb[dn] = mp[mrn,dn] * vp[mrn]
266
+// Same as MultVMtV() except M is transposed as part of the multiply.  
267
+// mrn gives the number of rows in m[] and number of elements in vp[]
268
+// dpb[dn] = mp[mrn,dn] * vp[mrn]
229 269
 VECT_OP_TYPE* VECT_OP_FUNC(MultVMtV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mrn, const VECT_OP_TYPE* vp ); 
230 270
 
231
-/// Same as MultVMV() but where the matrix is diagonal.
271
+// Same as MultVMV() but where the matrix is diagonal.
232 272
 VECT_OP_TYPE* VECT_OP_FUNC(MultDiagVMV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* mp, unsigned mcn, const VECT_OP_TYPE* vp ); 
233 273
 
234
-/// Generalized matrix multiply.
235
-/// If transposition is selected for M0 or M1 then the given dimension represent the size of the matrix 'after' the transposion. 
236
-/// d[drn,dcn] = alpha * op(m0[drn,m0cn_m1rn]) * op(m1[m0cn_m1rn,dcn]) + beta * d[drn,dcn]
237
-//// See enum { kTranpsoseM0Fl=0x01, kTransposeM1Fl=0x02 } in cmVectOps for flags.
274
+// Generalized matrix multiply.
275
+// If transposition is selected for M0 or M1 then the given dimension represent the size of the matrix 'after' the transposion. 
276
+// d[drn,dcn] = alpha * op(m0[drn,m0cn_m1rn]) * op(m1[m0cn_m1rn,dcn]) + beta * d[drn,dcn]
277
+/// See enum { kTranpsoseM0Fl=0x01, kTransposeM1Fl=0x02 } in cmVectOps for flags.
238 278
 VECT_OP_TYPE* VECT_OP_FUNC(MultMMM1)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE alpha, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn, VECT_OP_TYPE beta, unsigned flags );
239 279
 
240
-/// Same a VECT_OP_FUNC(MultMMM1) except allows the operation on a sub-matrix by providing the physical (memory) row count rather than the logical (matrix) row count.
280
+// Same a VECT_OP_FUNC(MultMMM1) except allows the operation on a sub-matrix by providing the physical (memory) row count rather than the logical (matrix) row count.
241 281
 VECT_OP_TYPE* VECT_OP_FUNC(MultMMM2)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, VECT_OP_TYPE alpha, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn, VECT_OP_TYPE beta, unsigned flags, unsigned dprn, unsigned m0prn, unsigned m1prn );
242 282
 
243
-/// d[drn,dcn] = m0[drn,m0cn] * m1[m1rn,dcn] 
283
+// d[drn,dcn] = m0[drn,m0cn] * m1[m1rn,dcn] 
244 284
 VECT_OP_TYPE* VECT_OP_FUNC(MultMMM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn );
245 285
 
246
-/// same as MultMMM() except second source matrix is transposed prior to the multiply
286
+// same as MultMMM() except second source matrix is transposed prior to the multiply
247 287
 VECT_OP_TYPE* VECT_OP_FUNC(MultMMMt)(VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* m0, const VECT_OP_TYPE* m1, unsigned m0cn_m1rn );
248
-                                   
249 288
 
250
-// Raise dbp[] to the power 'expon'
251
-VECT_OP_TYPE* VECT_OP_FUNC(PowVS)(  VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE expon );
252
-VECT_OP_TYPE* VECT_OP_FUNC(PowVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE expon );
289
+//======================================================================================================================
290
+//)
253 291
 
254
-// Take the natural log of all values in sbp[dn]. It is allowable for sbp point to the same array as dbp=.
255
-VECT_OP_TYPE* VECT_OP_FUNC(LogV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
292
+//( { label:"Linear algebra" desc:"Miscellaneous linear algebra operations. Determinant, Inversion, Cholesky decompostion. Linear system solver." kw:[vop] }
256 293
 
257
-// Convert a magnitude (amplitude) spectrum to/from decibels. 
258
-// It is allowable for dbp==sbp.
259
-VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
260
-VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
261
-
262
-VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
263
-VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
264
-
265
-/// Initialize dbp[dn,dn] as a square symetric positive definite matrix using values
266
-/// from a random uniform distribution. This is useful for initializing random 
267
-/// covariance matrices as used by multivariate Gaussian distributions
268
-/// If t is non-NULL it must point to a block of scratch memory of t[dn,dn].
269
-/// If t is NULL then scratch memory is internally allocated and deallocated.
294
+// Initialize dbp[dn,dn] as a square symetric positive definite matrix using values
295
+// from a random uniform distribution. This is useful for initializing random 
296
+// covariance matrices as used by multivariate Gaussian distributions
297
+// If t is non-NULL it must point to a block of scratch memory of t[dn,dn].
298
+// If t is NULL then scratch memory is internally allocated and deallocated.
270 299
 VECT_OP_TYPE* VECT_OP_FUNC(RandSymPosDef)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE* t );
271 300
 
272 301
 
273
-
274
-/// Compute the determinant of any square matrix.
302
+// Compute the determinant of any square matrix.
275 303
 VECT_OP_TYPE  VECT_OP_FUNC(DetM)(    const VECT_OP_TYPE* sp, unsigned srn );
276 304
 
277
-/// Compute the determinant of a diagonal matrix.
305
+// Compute the determinant of a diagonal matrix.
278 306
 VECT_OP_TYPE  VECT_OP_FUNC(DetDiagM)(    const VECT_OP_TYPE* sp, unsigned srn);
279 307
 
280
-/// Compute the log determinant of any square matrix.
308
+// Compute the log determinant of any square matrix.
281 309
 VECT_OP_TYPE  VECT_OP_FUNC(LogDetM)(    const VECT_OP_TYPE* sp, unsigned srn );
282 310
 
283
-/// Compute the log determinant of a diagonal matrix.
311
+// Compute the log determinant of a diagonal matrix.
284 312
 VECT_OP_TYPE  VECT_OP_FUNC(LogDetDiagM)(    const VECT_OP_TYPE* sp, unsigned srn);
285 313
 
286 314
 
287
-/// Compute the inverse of a square matrix.  Returns NULL if the matrix is not invertable.
288
-/// 'drn' is the dimensionality of the data.
315
+// Compute the inverse of a square matrix.  Returns NULL if the matrix is not invertable.
316
+// 'drn' is the dimensionality of the data.
289 317
 VECT_OP_TYPE* VECT_OP_FUNC(InvM)(    VECT_OP_TYPE* dp, unsigned drn );
290 318
 
291
-/// Compute the inverse of a diagonal matrix. Returns NULL if the matrix is not invertable.
319
+// Compute the inverse of a diagonal matrix. Returns NULL if the matrix is not invertable.
292 320
 VECT_OP_TYPE* VECT_OP_FUNC(InvDiagM)(    VECT_OP_TYPE* dp, unsigned drn );
293 321
 
294
-/// Solve a linear system of the form AX=B where A[an,an] is square. 
295
-/// Since A is square B must have 'an' rows.
296
-/// Result is returned in B.
297
-/// Returns a pointer to B on success or NULL on fail.
298
-/// NOTE: Both A and B are overwritten by this operation.
322
+// Solve a linear system of the form AX=B where A[an,an] is square. 
323
+// Since A is square B must have 'an' rows.
324
+// Result is returned in B.
325
+// Returns a pointer to B on success or NULL on fail.
326
+// NOTE: Both A and B are overwritten by this operation.
299 327
 VECT_OP_TYPE* VECT_OP_FUNC(SolveLS)( VECT_OP_TYPE* A, unsigned an, VECT_OP_TYPE* B, unsigned bcn ); 
300 328
 
301
-/// Perform a Cholesky decomposition of the square symetric matrix U[un,un].
302
-/// The factorization has the form: A=U'TU.
303
-/// If the factorization is successful A is set to U and a pointer to A is returned.
304
-/// Note that the lower triangle of A is not overwritten. See CholZ().
305
-/// If the factorization fails NULL is returned.
329
+// Perform a Cholesky decomposition of the square symetric matrix U[un,un].
330
+// The factorization has the form: A=U'TU.
331
+// If the factorization is successful A is set to U and a pointer to A is returned.
332
+// Note that the lower triangle of A is not overwritten. See CholZ().
333
+// If the factorization fails NULL is returned.
306 334
 VECT_OP_TYPE* VECT_OP_FUNC(Chol)(VECT_OP_TYPE* A, unsigned an );
307 335
 
308
-/// Same as Chol() but sets the lower triangle of U to zero. 
309
-/// This is equivalent ot the Matlab version.
336
+// Same as Chol() but sets the lower triangle of U to zero. 
337
+// This is equivalent ot the Matlab version.
310 338
 VECT_OP_TYPE* VECT_OP_FUNC(CholZ)(VECT_OP_TYPE* U, unsigned un );
311 339
 
340
+// Calculate the best fit line: b0 + b1*x_i through the points x_i,y_i.
341
+// Set x to NULL if it uses sequential integers [0,1,2,3...]
342
+void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 );
343
+
344
+
345
+//======================================================================================================================
346
+//)
347
+
348
+//( { label:"Stretch/Shrink" desc:"Stretch or shrink a vector by resampling." kw:[vop] }
312 349
 
313
-/// Return the average value of the contents of sbp[] between two fractional indexes
350
+// Return the average value of the contents of sbp[] between two fractional indexes
314 351
 VECT_OP_TYPE  VECT_OP_FUNC(FracAvg)( double bi, double ei, const VECT_OP_TYPE* sbp, unsigned sn );
315 352
 
316
-/// Shrinking function - Decrease the size of sbp[] by averaging blocks of values into single values in dbp[]
353
+// Shrinking function - Decrease the size of sbp[] by averaging blocks of values into single values in dbp[]
317 354
 VECT_OP_TYPE* VECT_OP_FUNC(DownSampleAvg)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
318 355
 
319
-/// Stretching function - linear interpolate between points in sbp[] to fill dbp[] ... where dn > sn
356
+// Stretching function - linear interpolate between points in sbp[] to fill dbp[] ... where dn > sn
320 357
 VECT_OP_TYPE* VECT_OP_FUNC(UpSampleInterp)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
321 358
 
322
-/// Stretch or shrink the sbp[] to fit into dbp[]
359
+// Stretch or shrink the sbp[] to fit into dbp[]
323 360
 VECT_OP_TYPE* VECT_OP_FUNC(FitToSize)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn );
324 361
 
325
-/// Stretch or shrink sV[] to fit into dV[] using a simple linear mapping.
326
-/// When stretching (sn<dn) each source element is repeated dn/sn times
327
-/// and the last fraction position is interpolated.  When shrinking 
328
-/// (sn>dn) each dest value is formed by the average of sequential segments
329
-/// of sn/dn source elements. Fractional values are used at the beginning
330
-/// and end of each segment.
362
+// Stretch or shrink sV[] to fit into dV[] using a simple linear mapping.
363
+// When stretching (sn<dn) each source element is repeated dn/sn times
364
+// and the last fraction position is interpolated.  When shrinking 
365
+// (sn>dn) each dest value is formed by the average of sequential segments
366
+// of sn/dn source elements. Fractional values are used at the beginning
367
+// and end of each segment.
331 368
 VECT_OP_TYPE* VECT_OP_FUNC(LinearMap)(VECT_OP_TYPE* dV, unsigned dn, VECT_OP_TYPE* sV, unsigned sn );
332 369
 
333
-/// Generate a vector of uniformly distributed random numbers in the range minVal to maxVal.
370
+//======================================================================================================================
371
+//)
372
+
373
+//( { label:"Random number generation" desc:"Generate random numbers." kw:[vop] }
374
+
375
+// Generate a vector of uniformly distributed random numbers in the range minVal to maxVal.
334 376
 VECT_OP_TYPE* VECT_OP_FUNC(Random)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE minVal, VECT_OP_TYPE maxVal );
335 377
 
336
-/// Generate dn random numbers integers between 0 and wn-1 based on a the relative 
337
-/// weights in wp[wn].  Note thtat the weights do not have to sum to 1.0.
378
+// Generate dn random numbers integers between 0 and wn-1 based on a the relative 
379
+// weights in wp[wn].  Note thtat the weights do not have to sum to 1.0.
338 380
 unsigned*  VECT_OP_FUNC(WeightedRandInt)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* wp, unsigned wn );
339 381
 
340
-/// Generate a vector of normally distributed univariate random numbers 
382
+// Generate a vector of normally distributed univariate random numbers 
341 383
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGauss)(  VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE mean, VECT_OP_TYPE var );
342 384
 
343
-/// Generate a vector of normally distributed univariate random numbers where each value has been drawn from a 
344
-/// seperately parameterized Gaussian distribution. meanV[] and varV[] must both contain dn velues.
385
+// Generate a vector of normally distributed univariate random numbers where each value has been drawn from a 
386
+// seperately parameterized Gaussian distribution. meanV[] and varV[] must both contain dn velues.
345 387
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* varV );
346 388
 
347
-/// Generate a matrix of multi-dimensional random values. Each column represents a single vector value and each row contains a dimension.
348
-/// meanV[] and varV[] must both contain drn elements where each meanV[i],varV[i] pair parameterize one dimensions Gaussian distribution.
389
+// Generate a matrix of multi-dimensional random values. Each column represents a single vector value and each row contains a dimension.
390
+// meanV[] and varV[] must both contain drn elements where each meanV[i],varV[i] pair parameterize one dimensions Gaussian distribution.
349 391
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* varV );
350 392
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussDiagM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* diagCovarM );
351 393
 
352
-/// Generate a matrix of multivariate random values drawn from a normal distribution.
353
-/// The dimensionality of the values are 'drn'.
354
-/// The count of returned values is 'dcn'.
355
-/// meanV[drn] and covarM[drn,drn] parameterize the normal distribution.
356
-/// The covariance matrix must be symetric and positive definite. 
357
-/// t[(drn*drn) ] points to scratch memory or is set to NULL if the function should
358
-///   allocate the memory internally.
359
-/// Based on octave function mvrnd.m.
394
+// Generate a matrix of multivariate random values drawn from a normal distribution.
395
+// The dimensionality of the values are 'drn'.
396
+// The count of returned values is 'dcn'.
397
+// meanV[drn] and covarM[drn,drn] parameterize the normal distribution.
398
+// The covariance matrix must be symetric and positive definite. 
399
+// t[(drn*drn) ] points to scratch memory or is set to NULL if the function should
400
+//   allocate the memory internally.
401
+// Based on octave function mvrnd.m.
360 402
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussNonDiagM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, VECT_OP_TYPE* t );
361 403
 
362
-/// Same as RandomGaussNonDiagM() except requires the upper trianglular 
363
-/// Cholesky factor of the covar matrix in 'uM'. 
404
+// Same as RandomGaussNonDiagM() except requires the upper trianglular 
405
+// Cholesky factor of the covar matrix in 'uM'. 
364 406
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussNonDiagM2)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* uM );
365 407
 
366 408
 
367
-/// Generate a matrix of N*K multi-dimensional data points.
368
-/// Where D is the dimensionality of the data. (D == drn).
369
-/// K is the number of multi-dimensional PDF's (clusters).
370
-/// N is the number of data points to generate per cluster. 
371
-/// dbp[ D, N*K ] contains the returned data point. 
372
-/// The first N columns is associated with the cluster 0, 
373
-/// the next N columns is associated with cluster 1, ...
374
-/// meanM[ D, K ] and varM[D,K] parameterize the generating PDF.s for each cluster
409
+// Generate a matrix of N*K multi-dimensional data points.
410
+// Where D is the dimensionality of the data. (D == drn).
411
+// K is the number of multi-dimensional PDF's (clusters).
412
+// N is the number of data points to generate per cluster. 
413
+// dbp[ D, N*K ] contains the returned data point. 
414
+// The first N columns is associated with the cluster 0, 
415
+// the next N columns is associated with cluster 1, ...
416
+// meanM[ D, K ] and varM[D,K] parameterize the generating PDF.s for each cluster
375 417
 VECT_OP_TYPE* VECT_OP_FUNC(RandomGaussMM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* meanM, const VECT_OP_TYPE* varM, unsigned K );
376 418
 
377
-/// Generate the set of coordinates which describe a circle with a center at x,y.
378
-/// dbp[dn,2] must contain 2*dn elements.  The first column holds the x coord and and the second holds the y coord.
379
-VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY );
380 419
 
381
-/// The following functions all return the phase of the next value. 
420
+// Evaluate the univariate normal distribution defined by 'mean' and 'stdDev'.
421
+VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev );
422
+
423
+// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
424
+// at the data points held in the columns of xM[D,N]. Return the evaluation
425
+// results in the vector yV[N].  D is the dimensionality of the data. N is the number of
426
+// data points to evaluate and values to return in yV[N]. 
427
+// Set diagFl to true if covarM is diagonal.
428
+// The function fails and returns false if the covariance matrix is singular.
429
+bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl );
430
+
431
+// Same as multVarGaussPDF[] except takes the inverse covar mtx invCovarM[D,D] 
432
+// and log determinant of covar mtx. 
433
+// Always returns yV[].
434
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* invCovarM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl );
435
+
436
+// Same as multVarGaussPDF[] except uses a function to obtain the data vectors.
437
+// srcFunc() can filter the data points by returning NULL if the data vector at frmIdx should
438
+// not be evaluated against the PDF. In this case yV[frmIdx] will be set to 0.
439
+VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)( 
440
+  VECT_OP_TYPE*       yV, 
441
+  const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
442
+  void*               funcDataPtr,
443
+  const VECT_OP_TYPE* meanV, 
444
+  const VECT_OP_TYPE* invCovarM, 
445
+  VECT_OP_TYPE        logDet, 
446
+  unsigned            D, 
447
+  unsigned            N, 
448
+  bool                diagFl );
449
+
450
+
451
+//======================================================================================================================
452
+//)
453
+
454
+
455
+//( { label:"Signal generators" desc:"Generate periodic signals." kw:[vop] }
456
+
457
+// The following functions all return the phase of the next value. 
382 458
 unsigned      VECT_OP_FUNC(SynthSine)(      VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz );
383 459
 unsigned      VECT_OP_FUNC(SynthCosine)(    VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz );
384 460
 unsigned      VECT_OP_FUNC(SynthSquare)(    VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz, unsigned otCnt );
@@ -389,11 +465,33 @@ unsigned      VECT_OP_FUNC(SynthImpulse)(   VECT_OP_TYPE* dbp, unsigned dn, unsi
389 465
 unsigned      VECT_OP_FUNC(SynthPhasor)(    VECT_OP_TYPE* dbp, unsigned dn, unsigned phase, double srate, double hz ); 
390 466
 
391 467
 
392
-/// Return value should be passed back via delaySmp on the next call.
468
+// Return value should be passed back via delaySmp on the next call.
393 469
 VECT_OP_TYPE  VECT_OP_FUNC(SynthPinkNoise)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE delaySmp );
394 470
 
395
-/// Same as Matlab linspace() v[i] = i * (limit-1)/n
396
-VECT_OP_TYPE*  VECT_OP_FUNC(LinSpace)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE base, VECT_OP_TYPE limit );
471
+//======================================================================================================================
472
+//)
473
+
474
+//( { label:"Exponential conversion" desc:"pow() and log() functions." kw:[vop] }
475
+
476
+// Raise dbp[] to the power 'expon'
477
+VECT_OP_TYPE* VECT_OP_FUNC(PowVS)(  VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE expon );
478
+VECT_OP_TYPE* VECT_OP_FUNC(PowVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE expon );
479
+
480
+// Take the natural log of all values in sbp[dn]. It is allowable for sbp point to the same array as dbp=.
481
+VECT_OP_TYPE* VECT_OP_FUNC(LogV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
482
+
483
+//======================================================================================================================
484
+//)
485
+
486
+//( { label:"dB Conversions" desc:"Convert vectors between dB,linear and power representations." kw:[vop] }
487
+
488
+// Convert a magnitude (amplitude) spectrum to/from decibels. 
489
+// It is allowable for dbp==sbp.
490
+VECT_OP_TYPE* VECT_OP_FUNC(AmplToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
491
+VECT_OP_TYPE* VECT_OP_FUNC(DbToAmplVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
492
+
493
+VECT_OP_TYPE* VECT_OP_FUNC(PowToDbVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE minDb );
494
+VECT_OP_TYPE* VECT_OP_FUNC(DbToPowVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp);
397 495
 
398 496
 VECT_OP_TYPE* VECT_OP_FUNC(LinearToDb)(    VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE mult );
399 497
 VECT_OP_TYPE* VECT_OP_FUNC(dBToLinear)(    VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE mult );
@@ -401,6 +499,10 @@ VECT_OP_TYPE* VECT_OP_FUNC(AmplitudeToDb)( VECT_OP_TYPE* dbp, unsigned dn, const
401 499
 VECT_OP_TYPE* VECT_OP_FUNC(PowerToDb)(     VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
402 500
 VECT_OP_TYPE* VECT_OP_FUNC(dBToAmplitude)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
403 501
 VECT_OP_TYPE* VECT_OP_FUNC(dBToPower)(     VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
502
+//======================================================================================================================
503
+//)
504
+
505
+//( { label:"DSP Windows" desc:"DSP windowing functions." kw:[vop] }
404 506
 
405 507
 VECT_OP_TYPE  VECT_OP_FUNC(KaiserBetaFromSidelobeReject)(  double sidelobeRejectDb );
406 508
 VECT_OP_TYPE  VECT_OP_FUNC(KaiserFreqResolutionFactor)( double sidelobeRejectDb );
@@ -410,84 +512,86 @@ VECT_OP_TYPE* VECT_OP_FUNC(Hamming)( VECT_OP_TYPE* dbp, unsigned dn );
410 512
 VECT_OP_TYPE* VECT_OP_FUNC(Hann)(    VECT_OP_TYPE* dbp, unsigned dn );
411 513
 VECT_OP_TYPE* VECT_OP_FUNC(Triangle)(VECT_OP_TYPE* dbp, unsigned dn );
412 514
 
413
-/// The MATLAB equivalent Hamming and Hann windows.
515
+// The MATLAB equivalent Hamming and Hann windows.
414 516
 //VECT_OP_TYPE* VECT_OP_FUNC(HammingMatlab)(VECT_OP_TYPE* dbp, unsigned dn );
415 517
 VECT_OP_TYPE* VECT_OP_FUNC(HannMatlab)(   VECT_OP_TYPE* dbp, unsigned dn );
416 518
 
417
-/// Simulates the MATLAB GaussWin function. Set arg to 2.5 to simulate the default arg
418
-/// as used by MATLAB.
519
+// Simulates the MATLAB GaussWin function. Set arg to 2.5 to simulate the default arg
520
+// as used by MATLAB.
419 521
 VECT_OP_TYPE*	VECT_OP_FUNC(GaussWin)( VECT_OP_TYPE* dbp, unsigned dn, double arg );
420
-
421
-
422
-/// Direct form II algorithm based on the MATLAB implmentation
423
-/// http://www.mathworks.com/access/helpdesk/help/techdoc/ref/filter.html#f83-1015962
424
-/// The only difference between this function and the equivalent MATLAB filter() function
425
-/// is that the first feedforward coeff is given as a seperate value. The first  b coefficient
426
-///  in this function is therefore the same as the second coefficient in the MATLAB function.
427
-///  and the first a[] coefficient (which is generally set to 1.0) is skipped.
428
-///  Example:
429
-///  Matlab:         b=[.5 .4 .3]  a=[1 .2 .1]
430
-///  Equiv:  b0 = .5 b=[   .4 .3]  a=[  .2 .1]; 
431
-///
432
-/// y[yn] - output vector 
433
-/// x[xn] - input vector. xn must be <= yn. if xn < yn then the end of y[] is set to zero.
434
-/// b0 - signal scale. This can also be seen as b[0] (which is not included in b[])
435
-/// b[dn] - feedforward coeff's b[1..dn-1]
436
-/// a[dn] - feedback coeff's    a[1..dn-1]
437
-/// d[dn+1] - delay registers - note that this array must be one element longer than the coeff arrays.
438
-/// 
522
+//======================================================================================================================
523
+//)
524
+
525
+//( { label:"DSP Filters" desc:"DSP filtering functions." kw:[vop] }
526
+
527
+// Direct form II algorithm based on the MATLAB implmentation
528
+// http://www.mathworks.com/access/helpdesk/help/techdoc/ref/filter.html#f83-1015962
529
+// The only difference between this function and the equivalent MATLAB filter() function
530
+// is that the first feedforward coeff is given as a seperate value. The first  b coefficient
531
+//  in this function is therefore the same as the second coefficient in the MATLAB function.
532
+//  and the first a[] coefficient (which is generally set to 1.0) is skipped.
533
+//  Example:
534
+//  Matlab:         b=[.5 .4 .3]  a=[1 .2 .1]
535
+//  Equiv:  b0 = .5 b=[   .4 .3]  a=[  .2 .1]; 
536
+//
537
+// y[yn] - output vector 
538
+// x[xn] - input vector. xn must be <= yn. if xn < yn then the end of y[] is set to zero.
539
+// b0 - signal scale. This can also be seen as b[0] (which is not included in b[])
540
+// b[dn] - feedforward coeff's b[1..dn-1]
541
+// a[dn] - feedback coeff's    a[1..dn-1]
542
+// d[dn+1] - delay registers - note that this array must be one element longer than the coeff arrays.
543
+// 
439 544
 VECT_OP_TYPE* VECT_OP_FUNC(Filter)( VECT_OP_TYPE* y, unsigned yn, const VECT_OP_TYPE* x, unsigned xn, cmReal_t b0, const cmReal_t* b, const cmReal_t* a,  cmReal_t* d, unsigned dn );
440 545
 
441 546
 struct cmFilter_str;
442 547
 //typedef cmRC_t (*VECT_OP_FUNC(FiltExecFunc_t))( struct acFilter_str* f,  const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn );
443 548
 VECT_OP_TYPE* VECT_OP_FUNC(FilterFilter)(struct cmFilter_str* f, cmRC_t (*func)( struct cmFilter_str* f,  const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn ), const cmReal_t bb[], unsigned bn, const cmReal_t aa[], unsigned an, const VECT_OP_TYPE* x, unsigned xn, VECT_OP_TYPE* y, unsigned yn );
444 549
 
445
-/// Compute the coefficients of a low/high pass FIR filter
446
-/// wndV[dn] gives the window function used to truncate the ideal low-pass impulse response.
447
-/// Set wndV to NULL to use a unity window.
448
-/// See enum { kHighPass_LPSincFl=0x01, kNormalize_LPSincFl=0x02 } in cmVectOps.h
550
+// Compute the coefficients of a low/high pass FIR filter
551
+// wndV[dn] gives the window function used to truncate the ideal low-pass impulse response.
552
+// Set wndV to NULL to use a unity window.
553
+// See enum { kHighPass_LPSincFl=0x01, kNormalize_LPSincFl=0x02 } in cmVectOps.h
449 554
 VECT_OP_TYPE* VECT_OP_FUNC(LP_Sinc)(VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* wndV, double srate, double fcHz, unsigned flags );
450 555
 
451
-/// Compute the complex transient detection function from successive spectral frames.
452
-/// The spectral magntidue mag0V precedes mag1V and the phase (radians) spectrum phs0V precedes the phs1V which precedes phs2V.  
453
-/// binCnt gives the length of each of the spectral vectors.
454
-VECT_OP_TYPE  VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt );
455 556
 
456 557
 
457
-/// Compute a set of filterCnt mel filter masks for wieghting magnitude spectra consisting of binCnt bins.
458
-/// The spectrum is divided into bandCnt equal bands in the mel domain
459
-/// Each row of the matrix contains the mask for a single filter band consisting of binCnt elements.  
460
-/// See enum{ kShiftMelFl=0x01, kNormalizeMelFl=0x02 } in cmVectOps.h
461
-/// Set kShiftMelFl to shift the mel bands onto the nearest FFT bin.
462
-/// Set kNormalizeMelFl to normalize the combined filters for unity gain.
463
-VECT_OP_TYPE* VECT_OP_FUNC(MelMask)( VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double srate, unsigned flags );
558
+//======================================================================================================================
559
+//)
464 560
 
561
+//( { label:"Spectral Masking" desc:"A collection of spectral masking functions." kw:[vop] }
465 562
 
563
+// Compute a set of filterCnt mel filter masks for wieghting magnitude spectra consisting of binCnt bins.
564
+// The spectrum is divided into bandCnt equal bands in the mel domain
565
+// Each row of the matrix contains the mask for a single filter band consisting of binCnt elements.  
566
+// See enum{ kShiftMelFl=0x01, kNormalizeMelFl=0x02 } in cmVectOps.h
567
+// Set kShiftMelFl to shift the mel bands onto the nearest FFT bin.
568
+// Set kNormalizeMelFl to normalize the combined filters for unity gain.
569
+VECT_OP_TYPE* VECT_OP_FUNC(MelMask)( VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double srate, unsigned flags );
466 570
 
467
-/// Fill binIdxV[bandCnt] and cntV[bandCnt] with a bin to band map.
468
-/// binIdx[] contains the first (minimum) bin index for a given band.
469
-/// cntV[]   contains the count of bins for each band.
470
-/// bandCnt is the number of bark bands to return 
471
-/// The function returns the actual number of bands mapped which will always be <= 23.
571
+// Fill binIdxV[bandCnt] and cntV[bandCnt] with a bin to band map.
572
+// binIdx[] contains the first (minimum) bin index for a given band.
573
+// cntV[]   contains the count of bins for each band.
574
+// bandCnt is the number of bark bands to return 
575
+// The function returns the actual number of bands mapped which will always be <= 23.
472 576
 unsigned VECT_OP_FUNC(BarkMap)(unsigned* binIdxV, unsigned* cntV, unsigned bandCnt, unsigned binCnt, double srate );
473 577
 
474
-/// Calc a set of triangle fitler masks into each row of maskMtx.
475
-/// maskMtx[ bandCnt, binCnt ] - result matrix
476
-/// binHz - freq resolution of the output filters.
477
-/// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth. 
478
-///            (Only used if lowHzV or uprHzV are NULL)
479
-/// lowHz[ bandCnt ] - set of upper frequency limits for each band.
480
-/// ctrHz[ bandCnt ] set to the center value in Hz for each band
481
-/// uprHz[ bandCnt ] - set of lower frequency limits for each band.
482
-/// Note if lowHz[] and uprHz[] are set to NULL then stSpread is used to set the bandwidth of each band.
578
+// Calc a set of triangle fitler masks into each row of maskMtx.
579
+// maskMtx[ bandCnt, binCnt ] - result matrix
580
+// binHz - freq resolution of the output filters.
581
+// stSpread - Semi-tone spread above and below each center frequency (stSpread*2) is the total bandwidth. 
582
+//            (Only used if lowHzV or uprHzV are NULL)
583
+// lowHz[ bandCnt ] - set of upper frequency limits for each band.
584
+// ctrHz[ bandCnt ] set to the center value in Hz for each band
585
+// uprHz[ bandCnt ] - set of lower frequency limits for each band.
586
+// Note if lowHz[] and uprHz[] are set to NULL then stSpread is used to set the bandwidth of each band.
483 587
 VECT_OP_TYPE* VECT_OP_FUNC(TriangleMask)(VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, const VECT_OP_TYPE* ctrHzV, VECT_OP_TYPE binHz, VECT_OP_TYPE stSpread, const VECT_OP_TYPE* lowHzV, const VECT_OP_TYPE* uprHzV );
484 588
 
485
-/// Calculate a set of Bark band triangle filters into maskMtx.
486
-/// Each row of maskMtx contains the filter for one band.
487
-/// maskMtx[ bandCnt, binCnt ]
488
-/// bandCnt - the number of triangle bankds. If bandCnt is > 24 it will be reduced to 24.
489
-/// binCnt - the number of bins in the filters.
490
-/// binHz - the width of each bin in Hz.
589
+// Calculate a set of Bark band triangle filters into maskMtx.
590
+// Each row of maskMtx contains the filter for one band.
591
+// maskMtx[ bandCnt, binCnt ]
592
+// bandCnt - the number of triangle bankds. If bandCnt is > 24 it will be reduced to 24.
593
+// binCnt - the number of bins in the filters.
594
+// binHz - the width of each bin in Hz.
491 595
 VECT_OP_TYPE* VECT_OP_FUNC(BarkMask)(VECT_OP_TYPE* maskMtx, unsigned bandCnt, unsigned binCnt, double binHz );
492 596
 
493 597
 // Terhardt 1979 (Calculating virtual pitch, Hearing Research #1, pp 155-182)
@@ -497,39 +601,27 @@ VECT_OP_TYPE* VECT_OP_FUNC(TerhardtThresholdMask)(VECT_OP_TYPE* maskV, unsigned
497 601
 //Schroeder et al., 1979, JASA, Optimizing digital speech coders by exploiting masking properties of the human ear
498 602
 VECT_OP_TYPE* VECT_OP_FUNC(ShroederSpreadingFunc)(VECT_OP_TYPE* m, unsigned bandCnt, double srate);
499 603
 
500
-/// Compute a set of DCT-II coefficients. Result dp[ coeffCnt, filtCnt ]
501
-VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt );
502
-
503
-
504
-/// Set the indexes of local peaks greater than threshold in dbp[].
505
-/// Returns the number of peaks in dbp[]
506
-/// The maximum number of peaks from n source values is max(0,floor((n-1)/2)).
507
-/// Note that peaks will never be found at index 0 or index sn-1.
508
-unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold );
509
-
510
-/// Return the index of the bin containing v or acInvalidIdx if v is below sbp[0] or above sbp[ n-1 ]
511
-/// The bin limits are contained in sbp[].
512
-/// The value in spb[] are therefore expected to be in increasing order.
513
-/// The value returned will be in the range 0:sn-1.
514
-unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v );
515
-
516
-
517
-/// Assign each data point to one of k clusters using an expectation-maximization algorithm.
518
-/// k gives the number of clusters to identify
519
-/// Each column of sp[ srn, scn ] contains a multidimensional data point. 
520
-/// srn therefore defines the dimensionality of the data.
521
-/// Each column of centroidV[ srn, k ] is set to the centroid of each of k clusters.
522
-/// classIdxV[ scn ] assigns the index (0 to k-1) of a cluster to each soure data point
523
-/// The function returns the number of iterations required for the EM process to converge.
524
-/// selIdxV[ scn ] is optional and contains a list of id's assoc'd with each column of sM.
525
-/// selKey is a integer value.
526
-/// If selIdxV is non-NULL then only columns of sM[] where selIdxV[] == selKey will be clustered.
527
-/// All columns of sM[] where the associated column in selIdxV[] do not match will be ignored.
528
-/// Set 'initFromCentroidFl' to true if the initial centroids should be taken from centroidM[].
529
-/// otherwise the initial centroids are selected from 'k' random data points in sp[].
530
-/// The distance function distFunc(cV,dV,dN) is called to determine the distance from a 
531
-/// centroid the centroid 'cV[dN]' to a data point 'dV[dN]'. 'dN' is the dimensionality of the
532
-/// feature vector and is therefore equal to 'srn'.
604
+//======================================================================================================================
605
+//)
606
+
607
+//( { label:"Machine learning" desc:"K-means clustering and Viterbi algorithms." kw:[vop] }
608
+
609
+// Assign each data point to one of k clusters using an expectation-maximization algorithm.
610
+// k gives the number of clusters to identify
611
+// Each column of sp[ srn, scn ] contains a multidimensional data point. 
612
+// srn therefore defines the dimensionality of the data.
613
+// Each column of centroidV[ srn, k ] is set to the centroid of each of k clusters.
614
+// classIdxV[ scn ] assigns the index (0 to k-1) of a cluster to each soure data point
615
+// The function returns the number of iterations required for the EM process to converge.
616
+// selIdxV[ scn ] is optional and contains a list of id's assoc'd with each column of sM.
617
+// selKey is a integer value.
618
+// If selIdxV is non-NULL then only columns of sM[] where selIdxV[] == selKey will be clustered.
619
+// All columns of sM[] where the associated column in selIdxV[] do not match will be ignored.
620
+// Set 'initFromCentroidFl' to true if the initial centroids should be taken from centroidM[].
621
+// otherwise the initial centroids are selected from 'k' random data points in sp[].
622
+// The distance function distFunc(cV,dV,dN) is called to determine the distance from a 
623
+// centroid the centroid 'cV[dN]' to a data point 'dV[dN]'. 'dN' is the dimensionality of the
624
+// feature vector and is therefore equal to 'srn'.
533 625
 unsigned VECT_OP_FUNC(Kmeans)( 
534 626
   unsigned*           classIdxV, 
535 627
   VECT_OP_TYPE*       centroidM, 
@@ -543,9 +635,9 @@ unsigned VECT_OP_FUNC(Kmeans)(
543 635
   VECT_OP_TYPE (*distFunc)( void* userPtr, const VECT_OP_TYPE* cV, const VECT_OP_TYPE* dV, unsigned dN ), 
544 636
   void*               userDistPtr ); 
545 637
 
546
-/// 'srcFunc() should return NULL if the data point located at 'frmIdx' should not be included in the clustering.
547
-/// Clustering is considered to be complete after 'maxIterCnt' iterations or when
548
-/// 'deltaStopCnt' or fewer data points change class on a single iteration
638
+// 'srcFunc() should return NULL if the data point located at 'frmIdx' should not be included in the clustering.
639
+// Clustering is considered to be complete after 'maxIterCnt' iterations or when
640
+// 'deltaStopCnt' or fewer data points change class on a single iteration
549 641
 unsigned VECT_OP_FUNC(Kmeans2)( 
550 642
   unsigned*           classIdxV,         // classIdxV[scn] - data point class assignments
551 643
   VECT_OP_TYPE*       centroidM,         // centroidM[srn,K] - cluster centroids
@@ -559,64 +651,67 @@ unsigned VECT_OP_FUNC(Kmeans2)(
559 651
   int                iterCnt,            // max. number of iterations (-1 to ignore)
560 652
   int                deltaStopCnt);      // if less than deltaStopCnt data points change classes on a given iteration then convergence occurs.
561 653
 
562
-/// Evaluate the univariate normal distribution defined by 'mean' and 'stdDev'.
563
-VECT_OP_TYPE* VECT_OP_FUNC(GaussPDF)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE mean, VECT_OP_TYPE stdDev );
564
-
565
-/// Evaluate a multivariate normal distribution defined by meanV[D] and covarM[D,D]
566
-/// at the data points held in the columns of xM[D,N]. Return the evaluation
567
-/// results in the vector yV[N].  D is the dimensionality of the data. N is the number of
568
-/// data points to evaluate and values to return in yV[N]. 
569
-/// Set diagFl to true if covarM is diagonal.
570
-/// The function fails and returns false if the covariance matrix is singular.
571
-bool VECT_OP_FUNC(MultVarGaussPDF)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* covarM, unsigned D, unsigned N, bool diagFl );
654
+// Determine the most likely state sequece stateV[timeN] given a 
655
+// transition matrix a[stateN,stateN], 
656
+// observation probability matrix b[stateN,timeN] and 
657
+// initial state probability vector phi[stateN].  
658
+// a[i,j] is the probability of transitioning from state i to state j.
659
+// b[i,t] is the probability of state i emitting the obj t.
660
+void VECT_OP_FUNC(DiscreteViterbi)(unsigned* stateV, unsigned timeN, unsigned stateN, const VECT_OP_TYPE* phi, const VECT_OP_TYPE* a, const VECT_OP_TYPE* b );
572 661
 
573
-/// Same as multVarGaussPDF[] except takes the inverse covar mtx invCovarM[D,D] 
574
-/// and log determinant of covar mtx. 
575
-/// Always returns yV[].
576
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF2)( VECT_OP_TYPE* yV, const VECT_OP_TYPE* xM, const VECT_OP_TYPE* meanV, const VECT_OP_TYPE* invCovarM, VECT_OP_TYPE logDet, unsigned D, unsigned N, bool diagFl );
577 662
 
578
-/// Same as multVarGaussPDF[] except uses a function to obtain the data vectors.
579
-/// srcFunc() can filter the data points by returning NULL if the data vector at frmIdx should
580
-/// not be evaluated against the PDF. In this case yV[frmIdx] will be set to 0.
581
-VECT_OP_TYPE* VECT_OP_FUNC(MultVarGaussPDF3)( 
582
-  VECT_OP_TYPE*       yV, 
583
-  const VECT_OP_TYPE* (*srcFunc)(void* funcDataPtr, unsigned frmIdx ),
584
-  void*               funcDataPtr,
585
-  const VECT_OP_TYPE* meanV, 
586
-  const VECT_OP_TYPE* invCovarM, 
587
-  VECT_OP_TYPE        logDet, 
588
-  unsigned            D, 
589
-  unsigned            N, 
590
-  bool                diagFl );
663
+//======================================================================================================================
664
+//)
591 665
 
592
-/// Determine the most likely state sequece stateV[timeN] given a 
593
-/// transition matrix a[stateN,stateN], 
594
-/// observation probability matrix b[stateN,timeN] and 
595
-/// initial state probability vector phi[stateN].  
596
-/// a[i,j] is the probability of transitioning from state i to state j.
597
-/// b[i,t] is the probability of state i emitting the obj t.
598
-void VECT_OP_FUNC(DiscreteViterbi)(unsigned* stateV, unsigned timeN, unsigned stateN, const VECT_OP_TYPE* phi, const VECT_OP_TYPE* a, const VECT_OP_TYPE* b );
666
+//( { label:"Graphics" desc:"Graphics related algorithms." kw:[vop] }
599 667
 
668
+// Generate the set of coordinates which describe a circle with a center at x,y.
669
+// dbp[dn,2] must contain 2*dn elements.  The first column holds the x coord and and the second holds the y coord.
670
+VECT_OP_TYPE* VECT_OP_FUNC(CircleCoords)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE x, VECT_OP_TYPE y, VECT_OP_TYPE varX, VECT_OP_TYPE varY );
600 671
 
601
-/// Clip the line defined by x0,y0 to x1,y1 into the rect defined by xMin,yMin xMax,yMax.
672
+// Clip the line defined by x0,y0 to x1,y1 into the rect defined by xMin,yMin xMax,yMax.
602 673
 bool VECT_OP_FUNC(ClipLine)( VECT_OP_TYPE* x0, VECT_OP_TYPE* y0, VECT_OP_TYPE* x1, VECT_OP_TYPE* y1, VECT_OP_TYPE xMin, VECT_OP_TYPE yMin, VECT_OP_TYPE xMax, VECT_OP_TYPE yMax );
603 674
 
604
-/// Return true if the line defined by x0,y0 to x1,y1 intersects with
605
-/// the rectangle formed by xMin,yMin - xMax,yMax
675
+// Return true if the line defined by x0,y0 to x1,y1 intersects with
676
+// the rectangle formed by xMin,yMin - xMax,yMax
606 677
 bool VECT_OP_FUNC(IsLineInRect)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, VECT_OP_TYPE x1, VECT_OP_TYPE y1, VECT_OP_TYPE xMin, VECT_OP_TYPE yMin, VECT_OP_TYPE xMax, VECT_OP_TYPE yMax );
607 678
 
608 679
 
609
-/// Return the perpendicular distance from the line formed by x0,y0 and x1,y1
610
-/// and the point px,py
680
+// Return the perpendicular distance from the line formed by x0,y0 and x1,y1
681
+// and the point px,py
611 682
 VECT_OP_TYPE VECT_OP_FUNC(PtToLineDistance)( VECT_OP_TYPE x0, VECT_OP_TYPE y0, VECT_OP_TYPE x1, VECT_OP_TYPE y1, VECT_OP_TYPE px, VECT_OP_TYPE py);                              
612 683
 
613
-/// Calculate the best fit line: b0 + b1*x_i through the points x_i,y_i.
614
-/// Set x to NULL if it uses sequential integers [0,1,2,3...]
615
-void VECT_OP_FUNC(Lsq1)(const VECT_OP_TYPE* x, const VECT_OP_TYPE* y, unsigned n, VECT_OP_TYPE* b0, VECT_OP_TYPE* b1 );
684
+//======================================================================================================================
685
+//)
686
+
687
+//( { label:"Miscellaneous DSP" desc:"Common DSP algorithms." kw:[vop] }
688
+
689
+// Compute the complex transient detection function from successive spectral frames.
690
+// The spectral magntidue mag0V precedes mag1V and the phase (radians) spectrum phs0V precedes the phs1V which precedes phs2V.  
691
+// binCnt gives the length of each of the spectral vectors.
692
+VECT_OP_TYPE  VECT_OP_FUNC(ComplexDetect)(const VECT_OP_TYPE* mag0V, const VECT_OP_TYPE* mag1V, const VECT_OP_TYPE* phs0V, const VECT_OP_TYPE* phs1V, const VECT_OP_TYPE* phs2V, unsigned binCnt );
693
+
694
+// Compute a set of DCT-II coefficients. Result dp[ coeffCnt, filtCnt ]
695
+VECT_OP_TYPE* VECT_OP_FUNC(DctMatrix)( VECT_OP_TYPE* dp, unsigned coeffCnt, unsigned filtCnt );
696
+
697
+
698
+// Set the indexes of local peaks greater than threshold in dbp[].
699
+// Returns the number of peaks in dbp[]
700
+// The maximum number of peaks from n source values is max(0,floor((n-1)/2)).
701
+// Note that peaks will never be found at index 0 or index sn-1.
702
+unsigned VECT_OP_FUNC(PeakIndexes)( unsigned* dbp, unsigned dn, const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE threshold );
703
+
704
+// Return the index of the bin containing v otherwise return kInvalidIdx if v is below sbp[0] or above sbp[ n-1 ]
705
+// The bin limits are contained in sbp[].
706
+// The value in spb[] are therefore expected to be in increasing order.
707
+// The value returned will be in the range 0:sn-1.
708
+unsigned VECT_OP_FUNC(BinIndex)( const VECT_OP_TYPE* sbp, unsigned sn, VECT_OP_TYPE v );
616 709
 
617 710
 
618
-/// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
619
-/// x1[i].  Note that x0[] and x1[] must be increasing monotonic.
620
-/// This function is similar to the octave interp1() function.
711
+// Given the points x0[xy0N],y0[xy0N] fill y1[i] with the interpolated value of y0[] at
712
+// x1[i].  Note that x0[] and x1[] must be increasing monotonic.
713
+// This function is similar to the octave interp1() function.
621 714
 void VECT_OP_FUNC(Interp1)(VECT_OP_TYPE* y1, const VECT_OP_TYPE* x1, unsigned xy1N, const VECT_OP_TYPE* x0, const VECT_OP_TYPE* y0, unsigned xy0N );
622 715
  
716
+//======================================================================================================================
717
+//)

正在加载...
取消
保存