libcm is a C development framework with an emphasis on audio signal processing applications.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cmProc2.h 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. #ifndef cmProc2_h
  2. #define cmProc2_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc:"Processor Library 2" kw:[proclib]}
  7. //)
  8. //( { label:cmArray file_desc:"Expandable array designed to work easily with the cmProcObj model" kw:[proc]}
  9. // cmArray is an expandable array designed to work easily with the alloc/init/final/free model
  10. // used by this library. The arrays can be safely used by using the cmArrayAllocXXX macros
  11. // with static cmArray member fields during object allocation. cmArrayResizeXXX macros are then
  12. // used during the object initialization phase to allocate the actual array data space. Notice that
  13. // when used this way there is no need to call cmArrayFinal() prior to cmArrayResizeXXX().
  14. // The data memory used by cmArray's is allocated through the cmAllocData() and cmAllocDataZ()
  15. // macros. The resulting base memory address is therefore guaranteed to be aligned to a
  16. // 16 byte address boundary.
  17. typedef struct
  18. {
  19. cmObj obj;
  20. char* ptr;
  21. unsigned allocByteCnt;
  22. unsigned eleCnt;
  23. unsigned eleByteCnt;
  24. } cmArray;
  25. enum
  26. {
  27. kZeroArrayFl = 0x01
  28. };
  29. cmArray* cmArrayAllocate( cmCtx* c, cmArray* p, unsigned eleCnt, unsigned eleByteCnt, unsigned flags );
  30. cmRC_t cmArrayFree( cmArray** pp );
  31. cmRC_t cmArrayInit( cmArray* p, unsigned eleCnt, unsigned eleByteCnt, unsigned flags );
  32. cmRC_t cmArrayFinal( cmArray* p );
  33. char* cmArrayReallocDestroy( cmArray* p, unsigned newEleCnt, unsigned newEleByteCnt, unsigned flags );
  34. void cmArrayReallocDestroyV(cmArray* p, int eleByteCnt,unsigned flags, ... );
  35. char* cmArrayReallocPreserve(cmArray* p, unsigned newEleCnt, unsigned newEleByteCnt, unsigned flags );
  36. #define cmArrayAlloc( c, p ) cmArrayAllocate(c,p,0,0,0);
  37. #define cmArrayAllocInit( c, p, eleCnt, type ) cmArrayAllocate(c,p,eleCnt,sizeof(type),0)
  38. #define cmArrayAllocInitZ( c, p, eleCnt, type ) cmArrayAllocate(c,p,eleCnt,sizeof(type),kZeroArrayFl)
  39. #define cmArrayResize( c, p, newEleCnt, type ) (type*)cmArrayReallocDestroy(c,p,newEleCnt,sizeof(type), 0 )
  40. #define cmArrayResizeZ( c, p, newEleCnt, type ) (type*)cmArrayReallocDestroy(c,p,newEleCnt,sizeof(type), kZeroArrayFl )
  41. #define cmArrayResizePreserve( c, p, newEleCnt, type ) (type*)cmArrayReallocPreserve(c,p,newEleCnt,sizeof(type), 0 )
  42. #define cmArrayResizePreserveZ(c, p, newEleCnt, type ) (type*)cmArrayReallocPreserve(c,p,newEleCnt,sizeof(type), kZeroArrayFl )
  43. #define cmArrayResizeV( c, p, type, ... ) cmArrayReallocDestroyV(c,p,sizeof(type),0,##__VA_ARGS__)
  44. #define cmArrayResizeVZ( c, p, type, ... ) cmArrayReallocDestroyV(c,p,sizeof(type),kZeroArrayFl,##__VA_ARGS__)
  45. #define cmArrayPtr( type, p ) (type*)(p)->ptr
  46. #define cmArrayCount( p ) (p)->eleCnt
  47. //------------------------------------------------------------------------------------------------------------
  48. //)
  49. //( { label:cmAudioFileWr file_desc:"Audio file writer" kw:[proc]}
  50. typedef struct
  51. {
  52. cmObj obj;
  53. cmAudioFileH_t h;
  54. unsigned chCnt;
  55. unsigned curChCnt;
  56. unsigned procSmpCnt;
  57. char* fn;
  58. cmSample_t* bufV;
  59. } cmAudioFileWr;
  60. cmAudioFileWr* cmAudioFileWrAlloc( cmCtx* c, cmAudioFileWr* p, unsigned procSmpCnt, const char* fn, double srate, unsigned chCnt, unsigned bitsPerSample );
  61. cmRC_t cmAudioFileWrFree( cmAudioFileWr** pp );
  62. cmRC_t cmAudioFileWrInit( cmAudioFileWr* p, unsigned procSmpCnt, const char* fn, double srate, unsigned chCnt, unsigned bitsPerSample );
  63. cmRC_t cmAudioFileWrFinal( cmAudioFileWr* p );
  64. cmRC_t cmAudioFileWrExec( cmAudioFileWr* p, unsigned chIdx, const cmSample_t* sp, unsigned sn );
  65. void cmAudioFileWrTest();
  66. //------------------------------------------------------------------------------------------------------------
  67. //)
  68. //( { label:cmMatrixBuf file_desc:"Store and recall real values in matrix form." kw:[proc]}
  69. typedef struct
  70. {
  71. cmObj obj;
  72. unsigned rn;
  73. unsigned cn;
  74. cmSample_t *bufPtr;
  75. } cmMatrixBuf;
  76. /// Set p to NULL to dynamically allocate the object
  77. cmMatrixBuf* cmMatrixBufAllocFile(cmCtx* c, cmMatrixBuf* p, const char* fn );
  78. cmMatrixBuf* cmMatrixBufAllocCopy(cmCtx* c, cmMatrixBuf* p, unsigned rn, unsigned cn, const cmSample_t* sp );
  79. cmMatrixBuf* cmMatrixBufAlloc( cmCtx* c, cmMatrixBuf* p, unsigned rn, unsigned cn );
  80. cmRC_t cmMatrixBufFree( cmMatrixBuf**p );
  81. cmRC_t cmMatrixBufInitFile( cmMatrixBuf* p, const char* fn );
  82. cmRC_t cmMatrixBufInitCopy( cmMatrixBuf* p, unsigned rn, unsigned cn, const cmSample_t* sp );
  83. cmRC_t cmMatrixBufInit( cmMatrixBuf* p, unsigned rn, unsigned cn );
  84. cmRC_t cmMatrixBufFinal( cmMatrixBuf* p );
  85. cmSample_t* cmMatrixBufColPtr( cmMatrixBuf* p, unsigned ci );
  86. cmSample_t* cmMatrixBufRowPtr( cmMatrixBuf* p, unsigned ri );
  87. void cmMatrixBufTest();
  88. //------------------------------------------------------------------------------------------------------------
  89. //)
  90. //( { label:cmSigGen file_desc:"Generate periodic and noise signals." kw:[proc]}
  91. enum
  92. {
  93. kInvalidWfId,
  94. kSineWfId,
  95. kCosWfId,
  96. kSquareWfId,
  97. kTriangleWfId,
  98. kSawtoothWfId,
  99. kWhiteWfId,
  100. kPinkWfId,
  101. kPulseWfId,
  102. kImpulseWfId,
  103. kSilenceWfId,
  104. kPhasorWfId,
  105. kSeqWfId, // always incrementing integer sequence (srate,frq,otCnt is ignored)
  106. };
  107. typedef struct
  108. {
  109. cmObj obj;
  110. unsigned wfId;
  111. unsigned overToneCnt;
  112. double fundFrqHz;
  113. cmSample_t* outV;
  114. unsigned outN; // outN == procSmpCnt
  115. unsigned phase;
  116. cmSample_t delaySmp;
  117. double srate;
  118. } cmSigGen;
  119. /// Set p to NULL to dynamically allocate the object
  120. /// The last three arguments are optional. Set wfId to kInvalidWfId to allocate the signal generator without initializint it.
  121. cmSigGen* cmSigGenAlloc( cmCtx* c, cmSigGen* p, unsigned procSmpCnt, double srate, unsigned wfId, double fundFrqHz, unsigned overToneCnt );
  122. cmRC_t cmSigGenFree( cmSigGen** p );
  123. cmRC_t cmSigGenInit( cmSigGen* p, unsigned procSmpCnt, double srate, unsigned wfId, double fundFrqHz, unsigned overToneCnt );
  124. cmRC_t cmSigGenFinal( cmSigGen* p );
  125. cmRC_t cmSigGenExec( cmSigGen* p );
  126. //------------------------------------------------------------------------------------------------------------
  127. //)
  128. //( { label:cmDelay file_desc:"Fixed length audio delay." kw:[proc]}
  129. typedef struct
  130. {
  131. cmObj* obj;
  132. cmSample_t* bufPtr;
  133. unsigned bufSmpCnt; // count of samples in the delay line (bufSmpCnt = procSmpCnt+delaySmpCnt)
  134. unsigned procSmpCnt; // maximum legal samples to receive in a single call to cmDelayExec()
  135. unsigned delaySmpCnt; // delay time in samples
  136. int delayInIdx; // index into bufPtr[] of next element to receive an incoming sample
  137. unsigned outCnt; // count of valid buffers in outV[]
  138. cmSample_t* outV[2]; // pointers to output buffers
  139. unsigned outN[2]; // length of output buffers (the sum of the length of both output buffers is always procSmpCnt)
  140. } cmDelay;
  141. cmDelay* cmDelayAlloc( cmCtx* c, cmDelay* p, unsigned procSmpCnt, unsigned delaySmpCnt );
  142. cmRC_t cmDelayFree( cmDelay** p );
  143. cmRC_t cmDelayInit( cmDelay* p, unsigned procSmpCnt, unsigned delaySmpCnt );
  144. cmRC_t cmDelayFinal( cmDelay* p );
  145. cmRC_t cmDelayCopyIn( cmDelay* p, const cmSample_t* sp, unsigned sn );
  146. cmRC_t cmDelayAdvance( cmDelay* p, unsigned sn );
  147. cmRC_t cmDelayExec( cmDelay* p, const cmSample_t* sp, unsigned sn, bool bypassFl );
  148. void cmDelayTest();
  149. //------------------------------------------------------------------------------------------------------------
  150. //)
  151. //( { label:cmFIR file_desc:"Finite impulse response filter." kw:[proc]}
  152. typedef struct
  153. {
  154. cmObj obj;
  155. double* coeffV; // FIR coefficient vector (impulse response)
  156. unsigned coeffCnt; // count of elements in coeffV
  157. double* delayV; // delay vector contains one less elements than the coeff array
  158. cmSample_t* outV; // output signal
  159. unsigned outN; // length of the output signal (outN == ctx.procSmpCnt)
  160. unsigned delayIdx; // current next sample to receive input in the the delay line
  161. } cmFIR;
  162. enum { kHighPassFIRFl = 0x01 };
  163. // Note that the relative values of passHz and stopHz do not matter
  164. // for low-pass vs high-pass filters. In practice passHz and
  165. // stopHz can be swapped with no effect on the filter in either
  166. // case. Set p to NULL to dynamically allocate the object.
  167. cmFIR* cmFIRAllocKaiser(cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, double passHz, double stopHz, double passDb, double stopDb, unsigned flags );
  168. // Set wndV[sincSmpCnt] to NULL to use a unity window otherwise set it to a window
  169. // function of length sincSmpCnt.
  170. cmFIR* cmFIRAllocSinc( cmCtx* c, cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz, unsigned flags, const double* wndV );
  171. cmRC_t cmFIRFree( cmFIR** pp );
  172. cmRC_t cmFIRInitKaiser( cmFIR* p, unsigned procSmpCnt, double srate, double passHz, double stopHz, double passDb, double stopDb, unsigned flags );
  173. cmRC_t cmFIRInitSinc( cmFIR* p, unsigned procSmpCnt, double srate, unsigned sincSmpCnt, double fcHz, unsigned flags, const double* wndV );
  174. cmRC_t cmFIRFinal( cmFIR* p );
  175. cmRC_t cmFIRExec( cmFIR* p, const cmSample_t* sp, unsigned sn );
  176. void cmFIRTest0( cmRpt_t* rpt, cmLHeapH_t lhH, cmSymTblH_t stH );
  177. void cmFIRTest1( cmCtx* ctx );
  178. //------------------------------------------------------------------------------------------------------------
  179. //)
  180. //( { label:cmFuncFilter file_desc:"Apply a generic function to a windowed signal with a one sample hop size.." kw:[proc]}
  181. typedef cmSample_t (*cmFuncFiltPtr_t)( const cmSample_t* sp, unsigned sn, void* userPtr );
  182. typedef struct
  183. {
  184. cmObj obj;
  185. cmFuncFiltPtr_t funcPtr;
  186. cmShiftBuf shiftBuf;
  187. cmSample_t* outV;
  188. unsigned outN; // outN == procSmpCnt
  189. unsigned curWndSmpCnt;
  190. unsigned wndSmpCnt;
  191. void* userPtr;
  192. } cmFuncFilter;
  193. /// Set p to NULL to dynamically allocate the object.
  194. cmFuncFilter* cmFuncFilterAlloc( cmCtx* c, cmFuncFilter* p, unsigned procSmpCnt, cmFuncFiltPtr_t funcPtr, void* userPtr, unsigned wndSmpCnt );
  195. cmRC_t cmFuncFilterFree( cmFuncFilter** pp );
  196. cmRC_t cmFuncFilterInit( cmFuncFilter* p, unsigned procSmpCnt, cmFuncFiltPtr_t funcPtr, void* userPtr, unsigned wndSmpCnt );
  197. cmRC_t cmFuncFilterFinal( cmFuncFilter* p );
  198. cmRC_t cmFuncFilterExec( cmFuncFilter* p, const cmSample_t* sp, unsigned sn );
  199. void cmFuncFilterTest();
  200. //------------------------------------------------------------------------------------------------------------
  201. //)
  202. //( { label:cmDhmm file_desc:"Discrete observation HMM" kw:[proc]}
  203. typedef struct
  204. {
  205. cmObj obj;
  206. unsigned stateN; // count of states
  207. unsigned symN; // count of discrete observation symbols
  208. cmReal_t* initV; // initial state probability vector init[ stateN ]
  209. cmReal_t* transM; // transition probability matrix trans[ stateN (current), stateN (next) ]
  210. cmReal_t* stsM; // state to symbol prob. matrix stsM[ stateN, symN ]
  211. } cmDhmm;
  212. cmDhmm* cmDhmmAlloc( cmCtx* c, cmDhmm* p, unsigned stateN, unsigned symN, cmReal_t* initV, cmReal_t* transM, cmReal_t* stsM );
  213. cmRC_t cmDhmmFree( cmDhmm** pp );
  214. cmRC_t cmDhmmInit( cmDhmm* p, unsigned stateN, unsigned symN, cmReal_t* initV, cmReal_t* transM, cmReal_t* stsM );
  215. cmRC_t cmDhmmFinal( cmDhmm* p );
  216. cmRC_t cmDhmmExec( cmDhmm* p );
  217. cmRC_t cmDhmmGenObsSequence( cmDhmm* p, unsigned* dbp, unsigned dn );
  218. cmRC_t cmDhmmForwardEval( cmDhmm* p, const cmReal_t* statePrV, const unsigned* obsV, unsigned obsN, cmReal_t* alphaM, unsigned flags, cmReal_t* logProbPtr );
  219. cmRC_t cmDhmmReport( cmDhmm* p );
  220. void cmDhmmTest();
  221. //------------------------------------------------------------------------------------------------------------
  222. //)
  223. //( { label:cmConvolve file_desc:"Convolve a signal with an impulse response." kw:[proc]}
  224. typedef struct
  225. {
  226. cmObj obj;
  227. cmFftSR* fft;
  228. cmIFftRS* ifft;
  229. cmComplexR_t* H;
  230. unsigned hn;
  231. cmSample_t* olaV; // olaV[hn-1];
  232. cmSample_t* outV; // outV[procSmpCnt]
  233. unsigned outN; // outN == procSmpCnt
  234. } cmConvolve;
  235. // After cmConvolveExec() outV[outN] contains the first outN samples
  236. // which are complete and can be used by the application.
  237. // The tail of the convolution is held in olaV[hn-1] and will
  238. // be automatically summed with the beginning of the next convolution
  239. // frame.
  240. // BUG BUG BUG
  241. // This code seems to have a problem when hn != procSmpCnt (or maybe hn > procSmpCnt ???).
  242. // See mas/main.c convolve() where procSmpCnt must be set to wndSmpCnt size or
  243. // only the first half of the window is emitted.
  244. // h[hn] is the impulse response to convolve with
  245. cmConvolve* cmConvolveAlloc( cmCtx* c, cmConvolve* p, const cmSample_t* h, unsigned hn, unsigned procSmpCnt );
  246. cmRC_t cmConvolveFree( cmConvolve** pp );
  247. cmRC_t cmConvolveInit( cmConvolve* p, const cmSample_t* h, unsigned hn, unsigned procSmpCnt );
  248. cmRC_t cmConvolveFinal( cmConvolve* p );
  249. // xn must be <= procSmpCnt
  250. cmRC_t cmConvolveExec( cmConvolve* p, const cmSample_t* x, unsigned xn );
  251. cmRC_t cmConvolveSignal( cmCtx* c, const cmSample_t* h, unsigned hn, const cmSample_t* x, unsigned xn, cmSample_t* y, unsigned yn );
  252. cmRC_t cmConvolveTest( cmRpt_t* rpt, cmLHeapH_t lhH, cmSymTblH_t stH );
  253. //------------------------------------------------------------------------------------------------------------
  254. //)
  255. //( { label:cmBfcc file_desc:"Generate Bark Frequency Cepstral Coefficients from STFT frames." kw:[proc]}
  256. typedef struct
  257. {
  258. cmObj obj;
  259. cmReal_t* dctMtx; // dctMtx[ binCnt, bandCnt ]
  260. cmReal_t* filtMask; // filtMask[ bandCnt, bandCnt ]
  261. unsigned binCnt; // bin cnt of input magnitude spectrum
  262. unsigned bandCnt; // must be <= kDefaultBarkBandCnt
  263. cmReal_t* outV; // outV[binCnt]
  264. } cmBfcc;
  265. cmBfcc* cmBfccAlloc( cmCtx* ctx, cmBfcc* p, unsigned bandCnt, unsigned binCnt, double binHz );
  266. cmRC_t cmBfccFree( cmBfcc** pp );
  267. cmRC_t cmBfccInit( cmBfcc* p, unsigned bandCnt, unsigned binCnt, double binHz );
  268. cmRC_t cmBfccFinal( cmBfcc* p );
  269. cmRC_t cmBfccExec( cmBfcc* p, const cmReal_t* magV, unsigned binCnt );
  270. void cmBfccTest( cmRpt_t* rpt, cmLHeapH_t lhH, cmSymTblH_t stH );
  271. //------------------------------------------------------------------------------------------------------------
  272. //)
  273. //( { label:cmCepstrum file_desc:"Generate Cepstral Coefficients from STFT frames." kw:[proc]}
  274. typedef struct
  275. {
  276. cmObj obj;
  277. //cmIFftRR ft;
  278. unsigned dct_cn; // (binCnt-1)*2
  279. cmReal_t* dctM; // dctM[ outN, dct_cn ]
  280. unsigned binCnt; // bin cnt of input magnitude spectrum
  281. unsigned outN; // count of cepstral coeff's
  282. cmReal_t* outV; // outV[outN]
  283. } cmCeps;
  284. // outN is the number of cepstral coeff's in the output vector
  285. cmCeps* cmCepsAlloc( cmCtx* ctx, cmCeps* p, unsigned binCnt, unsigned outN );
  286. cmRC_t cmCepsFree( cmCeps** pp );
  287. cmRC_t cmCepsInit( cmCeps* p, unsigned binCnt, unsigned outN );
  288. cmRC_t cmCepsFinal( cmCeps* p );
  289. cmRC_t cmCepsExec( cmCeps* p, const cmReal_t* magV, const cmReal_t* phsV, unsigned binCnt );
  290. //------------------------------------------------------------------------------------------------------------
  291. //)
  292. //( { label:cmOla file_desc:"Generate a signal from an via overlap-add." kw:[proc]}
  293. //------------------------------------------------------------------------------------------------------------
  294. typedef struct
  295. {
  296. cmObj obj;
  297. cmWndFunc wf;
  298. unsigned wndSmpCnt;
  299. unsigned hopSmpCnt;
  300. unsigned procSmpCnt;
  301. cmSample_t* bufV; // bufV[wndSmpCnt] overlap add buffer
  302. cmSample_t* outV; // outV[hopSmpCnt] output vector
  303. cmSample_t* outPtr; // outPtr[procSmpCnt] output vector
  304. unsigned idx; // idx of next val in bufV[] to be moved to outV[]
  305. } cmOla;
  306. // hopSmpCnt must be <= wndSmpCnt.
  307. // hopSmpCnt must be an even multiple of procSmpCnt.
  308. // Call cmOlaExecR() or cmOlaExecS() at the spectral frame rate.
  309. // Call cmOlaExecOut() at the time domain audio frame rate.
  310. // Set wndTypeId to one of the cmWndFuncXXX enumerated widnow type id's.
  311. cmOla* cmOlaAlloc( cmCtx* ctx, cmOla* p, unsigned wndSmpCnt, unsigned hopSmpCnt, unsigned procSmpCnt, unsigned wndTypeId );
  312. cmRC_t cmOlaFree( cmOla** pp );
  313. cmRC_t cmOlaInit( cmOla* p, unsigned wndSmpCnt, unsigned hopSmpCnt, unsigned procSmpCnt, unsigned wndTypeId );
  314. cmRC_t cmOlaFinal( cmOla* p );
  315. cmRC_t cmOlaExecS( cmOla* p, const cmSample_t* xV, unsigned xN );
  316. cmRC_t cmOlaExecR( cmOla* p, const cmReal_t* xV, unsigned xN );
  317. const cmSample_t* cmOlaExecOut(cmOla* p );
  318. //------------------------------------------------------------------------------------------------------------
  319. //)
  320. //( { label:cmPhsToFrq file_desc:"Given STFT phase spectrum frames return the instantaneous frequency." kw:[proc]}
  321. //------------------------------------------------------------------------------------------------------------
  322. typedef struct
  323. {
  324. cmObj obj;
  325. cmReal_t* hzV; // hzV[binCnt] output vector - frequency in Hertz
  326. cmReal_t* phsV; // phsV[binCnt]
  327. cmReal_t* wV; // bin freq in rads/hop
  328. double srate;
  329. unsigned hopSmpCnt;
  330. unsigned binCnt;
  331. } cmPhsToFrq;
  332. cmPhsToFrq* cmPhsToFrqAlloc( cmCtx* c, cmPhsToFrq* p, double srate, unsigned binCnt, unsigned hopSmpCnt );
  333. cmRC_t cmPhsToFrqFree( cmPhsToFrq** p );
  334. cmRC_t cmPhsToFrqInit( cmPhsToFrq* p, double srate, unsigned binCnt, unsigned hopSmpCnt );
  335. cmRC_t cmPhsToFrqFinal(cmPhsToFrq* p );
  336. cmRC_t cmPhsToFrqExec( cmPhsToFrq* p, const cmReal_t* phsV );
  337. //------------------------------------------------------------------------------------------------------------
  338. //)
  339. //( { label:cmPvAnl file_desc:"Perform the phase-vocoder analysis stage." kw:[proc]}
  340. enum
  341. {
  342. kNoCalcHzPvaFl = 0x00,
  343. kCalcHzPvaFl = 0x01
  344. };
  345. typedef struct
  346. {
  347. cmObj obj;
  348. cmShiftBuf sb;
  349. cmFftSR ft;
  350. cmWndFunc wf;
  351. cmPhsToFrq pf;
  352. unsigned flags;
  353. unsigned procSmpCnt;
  354. double srate;
  355. unsigned wndSmpCnt;
  356. unsigned hopSmpCnt;
  357. unsigned binCnt;
  358. const cmReal_t* magV; // amplitude NOT power
  359. const cmReal_t* phsV;
  360. const cmReal_t* hzV;
  361. } cmPvAnl;
  362. cmPvAnl* cmPvAnlAlloc( cmCtx* ctx, cmPvAnl* p, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopSmpCnt, unsigned flags );
  363. cmRC_t cmPvAnlFree( cmPvAnl** pp );
  364. cmRC_t cmPvAnlInit( cmPvAnl* p, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopSmpCnt, unsigned flags );
  365. cmRC_t cmPvAnlFinal(cmPvAnl* p );
  366. // Returns true when a new spectrum has been computed
  367. bool cmPvAnlExec( cmPvAnl* p, const cmSample_t* x, unsigned xN );
  368. //------------------------------------------------------------------------------------------------------------
  369. //)
  370. //( { label:cmPvSyn file_desc:"Perform the phase-vocoder synthesis stage." kw:[proc]}
  371. typedef struct
  372. {
  373. cmObj obj;
  374. cmIFftRS ft;
  375. cmWndFunc wf;
  376. cmOla ola;
  377. cmReal_t* minRphV;
  378. cmReal_t* maxRphV;
  379. cmReal_t* itrV;
  380. cmReal_t* phs0V;
  381. cmReal_t* mag0V;
  382. cmReal_t* phsV;
  383. cmReal_t* magV;
  384. double outSrate;
  385. unsigned procSmpCnt;
  386. unsigned wndSmpCnt;
  387. unsigned hopSmpCnt;
  388. unsigned binCnt;
  389. } cmPvSyn;
  390. cmPvSyn* cmPvSynAlloc( cmCtx* ctx, cmPvSyn* p, unsigned procSmpCnt, double outSrate, unsigned wndSmpCnt, unsigned hopSmpCnt,unsigned wndTypeId );
  391. cmRC_t cmPvSynFree( cmPvSyn** pp );
  392. cmRC_t cmPvSynInit( cmPvSyn* p, unsigned procSmpCnt, double outSrate, unsigned wndSmpCnt, unsigned hopSmpCnt,unsigned wndTypeId );
  393. cmRC_t cmPvSynFinal(cmPvSyn* p );
  394. cmRC_t cmPvSynExec( cmPvSyn* p, const cmReal_t* magV, const cmReal_t* phsV );
  395. const cmSample_t* cmPvSynExecOut(cmPvSyn* p );
  396. //------------------------------------------------------------------------------------------------------------
  397. //)
  398. //( { label:cmMidiSynth file_desc:"Synthesis independent MIDI synthesizer control structure." kw:[proc]}
  399. // callback selector values
  400. enum
  401. {
  402. kAttackMsId,
  403. kReleaseMsId,
  404. kDspMsId // return 0 if the voice is no longer active
  405. };
  406. // voice flags
  407. enum
  408. {
  409. kActiveMsFl = 0x01, // set if the voice is active
  410. kKeyGateMsFl = 0x02, // set if the key is down for this note
  411. };
  412. struct cmMidiSynth_str;
  413. struct cmMidiSynthCh_str;
  414. struct cmMidiVoice_str;
  415. // voice update callback - use voicePtr->pgm.cbDataPtr to get voice specific data
  416. typedef int (*cmMidiSynthCb_t)( struct cmMidiVoice_str* voicePtr, unsigned sel, cmSample_t* outChArray[], unsigned outChCnt );
  417. typedef struct
  418. {
  419. cmMidiByte_t pgm; // MIDI pgm number
  420. cmMidiSynthCb_t cbPtr; // voice update callback
  421. void* cbDataPtr; // user data pointer
  422. } cmMidiSynthPgm;
  423. typedef struct cmMidiVoice_str
  424. {
  425. unsigned index; // voice index
  426. unsigned flags; // see kXXXMsFl above
  427. cmMidiByte_t pitch; // note-on pitch
  428. cmMidiByte_t velocity; // note-on/off veloctiy
  429. cmMidiSynthPgm pgm; // pgm associated with this voice
  430. struct cmMidiSynthCh_str* chPtr; // pointer to owning ch
  431. struct cmMidiVoice_str* link; // link to next active/avail voice in chain
  432. } cmMidiVoice;
  433. typedef struct cmMidiSynthCh_str
  434. {
  435. cmMidiByte_t midiCtl[ kMidiCtlCnt ]; // current ctl values
  436. short pitchBend; // current pitch bend value
  437. cmMidiByte_t pgm; // last pgm received
  438. cmMidiVoice* active; // first active voice on this channel
  439. struct cmMidiSynth_str* synthPtr; // owning synth
  440. } cmMidiSynthCh;
  441. typedef struct cmMidiSynth_str
  442. {
  443. cmObj obj;
  444. cmMidiSynthCh chArray[ kMidiChCnt ]; // midi channel array
  445. unsigned voiceCnt; // count of voice records
  446. cmMidiVoice* avail; // avail voice chain
  447. unsigned activeVoiceCnt; // current count of active voices
  448. unsigned voiceStealCnt; // count of times voice stealing was required
  449. cmMidiVoice* voiceArray; // array of voice records
  450. cmMidiSynthPgm pgmArray[ kMidiPgmCnt ]; // array of pgm records
  451. unsigned procSmpCnt; // samples per DSP cycle
  452. unsigned outChCnt; // count of output channels
  453. cmSample_t* outM; // outM[ procSmpCnt, outChCnt ] output buffer
  454. cmSample_t** outChArray; // buffer of pointers to each output channel
  455. cmReal_t srate; // output signal sample rate
  456. } cmMidiSynth;
  457. cmMidiSynth* cmMidiSynthAlloc( cmCtx* ctx, cmMidiSynth* p, const cmMidiSynthPgm* pgmArray, unsigned pgmCnt, unsigned voiceCnt, unsigned procSmpCnt, unsigned outChCnt, cmReal_t srate );
  458. cmRC_t cmMidiSynthFree( cmMidiSynth** pp );
  459. cmRC_t cmMidiSynthInit( cmMidiSynth* p, const cmMidiSynthPgm* pgmArray, unsigned pgmCnt, unsigned voiceCnt, unsigned procSmpCnt, unsigned outChCnt, cmReal_t srate );
  460. cmRC_t cmMidiSynthFinal( cmMidiSynth* p );
  461. cmRC_t cmMidiSynthOnMidi(cmMidiSynth* p, const cmMidiPacket_t* pktArray, unsigned pktCnt );
  462. cmRC_t cmMidiSynthExec( cmMidiSynth* p, cmSample_t** outChArray, unsigned outChCnt );
  463. //------------------------------------------------------------------------------------------------------------
  464. //)
  465. //( { label:cmWtVoice file_desc:"Wavetable oscillator implementation for use with cmMidiSyn." kw:[proc]}
  466. // state id's
  467. enum
  468. {
  469. kOffWtId,
  470. kAtkWtId,
  471. kDcyWtId,
  472. kSusWtId,
  473. kRlsWtId
  474. };
  475. typedef struct
  476. {
  477. cmObj obj;
  478. cmReal_t hz; // current frq in Hz
  479. cmReal_t level; // current gain (0.0 to 1.0)
  480. cmReal_t phase; // osc phase (radians)
  481. unsigned durSmpCnt; // count of samples generated so far
  482. unsigned state; // osc state - see kXXXWtId above
  483. cmSample_t* outV; // signal output vector
  484. unsigned outN; // samples in outV[]
  485. } cmWtVoice;
  486. cmWtVoice* cmWtVoiceAlloc( cmCtx* ctx, cmWtVoice* p, unsigned procSmpCnt, cmReal_t hz );
  487. cmRC_t cmWtVoiceFree( cmWtVoice** pp );
  488. cmRC_t cmWtVoiceInit( cmWtVoice* p, unsigned procSmpCnt, cmReal_t hz );
  489. cmRC_t cmWtVoiceFinal( cmWtVoice* p );
  490. // 'sel' values are cmMidiSynthExec (kXXXMsId) values
  491. // Set outChArray[] to NULL to use internal audio buffer.
  492. int cmWtVoiceExec( cmWtVoice* p, struct cmMidiVoice_str* voicePtr, unsigned sel, cmSample_t* outChArray[], unsigned outChCnt );
  493. //------------------------------------------------------------------------------------------------------------
  494. //)
  495. //( { label:cmWtVoiceBank file_desc:"A bank of cmWtVoice oscillator for use with cmMidiSynth." kw:[proc]}
  496. typedef struct
  497. {
  498. cmObj obj;
  499. cmWtVoice** voiceArray; // osc state array
  500. unsigned voiceCnt;
  501. cmSample_t* buf;
  502. cmSample_t** chArray;
  503. unsigned chCnt;
  504. unsigned procSmpCnt; // count of samples in each chArray[i] sample vector
  505. double srate; // synth sample rate
  506. } cmWtVoiceBank;
  507. cmWtVoiceBank* cmWtVoiceBankAlloc( cmCtx* ctx, cmWtVoiceBank* p, double srate, unsigned procSmpCnt, unsigned voiceCnt, unsigned chCnt );
  508. cmRC_t cmWtVoiceBankFree( cmWtVoiceBank** pp );
  509. cmRC_t cmWtVoiceBankInit( cmWtVoiceBank* p, double srate, unsigned procSmpCnt, unsigned voiceCnt, unsigned chCnt );
  510. cmRC_t cmWtVoiceBankFinal( cmWtVoiceBank* p );
  511. // 'sel' values are cmMidiSynthExec (kXXXMsId) values
  512. // Set outChArray[] to NULL to use internal audio buffer.
  513. // Return 0 if the voice has gone inactive otherwise return 1.
  514. int cmWtVoiceBankExec( cmWtVoiceBank* p, struct cmMidiVoice_str* voicePtr, unsigned sel, cmSample_t* chArray[], unsigned chCnt );
  515. //------------------------------------------------------------------------------------------------------------
  516. //)
  517. //( { label:cmAudioFileBuf file_desc:"Generate a signal by caching all or part of an audio file." kw:[proc]}
  518. typedef struct
  519. {
  520. cmObj obj;
  521. cmSample_t* bufV; // bufV[ bufN ]
  522. unsigned bufN;
  523. cmAudioFileInfo_t info;
  524. unsigned begSmpIdx;
  525. unsigned chIdx;
  526. char* fn;
  527. } cmAudioFileBuf;
  528. // set 'durSmpCnt' to cmInvalidCnt to include all samples to the end of the file
  529. cmAudioFileBuf* cmAudioFileBufAlloc( cmCtx* ctx, cmAudioFileBuf* p, unsigned procSmpCnt, const char* fn, unsigned chIdx, unsigned begSmpIdx, unsigned durSmpCnt );
  530. cmRC_t cmAudioFileBufFree( cmAudioFileBuf** pp );
  531. cmRC_t cmAudioFileBufInit( cmAudioFileBuf* p, unsigned procSmpCnt, const char* fn, unsigned chIdx, unsigned begSmpIdx, unsigned durSmpCnt );
  532. cmRC_t cmAudioFileBufFinal(cmAudioFileBuf* p );
  533. // Returns the count of samples copied into outV or 0 if smpIdx >= p->bufN.
  534. // If less than outN samples are available then the remaining samples are set to 0.
  535. unsigned cmAudioFileBufExec( cmAudioFileBuf* p, unsigned smpIdx, cmSample_t* outV, unsigned outN, bool sumIntoOutFl );
  536. //------------------------------------------------------------------------------------------------------------
  537. //)
  538. //( { label:cmMDelay file_desc:"Multi-tap audio delay with feedback." kw:[proc]}
  539. // Multi-delay. Each of the taps of this delay operates as a independent delay with feedback.
  540. // Delay line specification.
  541. typedef struct
  542. {
  543. cmReal_t delayGain; // delay gain
  544. cmReal_t delayMs; // delay time in milliseconds
  545. cmReal_t delaySmpFrac; // delay time in samples (next fractional delay index = inIdx - delaySmpFrac)
  546. cmSample_t* delayBuf; // delayBuf[delayBufSmpCnt] delay line memory
  547. int delayBufSmpCnt; // delay buffer length in samples
  548. int inIdx; // next delay input index
  549. } cmMDelayHead;
  550. typedef struct
  551. {
  552. cmObj obj;
  553. unsigned delayCnt; // count of taps
  554. cmMDelayHead* delayArray; // tap specs
  555. cmSample_t* outV; // outV[outN] output buffer
  556. unsigned outN; // procSmpCnt
  557. cmReal_t fbCoeff; // feedback coeff.
  558. cmReal_t srate; // system sample rate
  559. } cmMDelay;
  560. cmMDelay* cmMDelayAlloc( cmCtx* ctx, cmMDelay* p, unsigned procSmpCnt, cmReal_t srate, cmReal_t fbCoeff, unsigned delayCnt, const cmReal_t* delayMsArray, const cmReal_t* delayGainArray );
  561. cmRC_t cmMDelayFree( cmMDelay** pp );
  562. cmRC_t cmMDelayInit( cmMDelay* p, unsigned procSmpCnt, cmReal_t srate, cmReal_t fbCoeff, unsigned delayCnt, const cmReal_t* delayMsArray, const cmReal_t* delayGainArray );
  563. cmRC_t cmMDelayFinal( cmMDelay* p );
  564. cmRC_t cmMDelayExec( cmMDelay* p, const cmSample_t* sigV, cmSample_t* outV, unsigned sigN, bool bypassFl );
  565. void cmMDelaySetTapMs( cmMDelay* p, unsigned tapIdx, cmReal_t ms );
  566. void cmMDelaySetTapGain(cmMDelay* p, unsigned tapIdx, cmReal_t gain );
  567. void cmMDelayReport( cmMDelay* p, cmRpt_t* rpt );
  568. //------------------------------------------------------------------------------------------------------------
  569. //)
  570. //( { label:cmAudioSegPlayer file_desc:"Buffer and playback an arbitrary number of audio signals." kw:[proc]}
  571. enum
  572. {
  573. kEnableAspFl = 0x01,
  574. kDelAspFl = 0x02
  575. };
  576. typedef struct cmAudioSeg_str
  577. {
  578. cmAudioFileBuf* bufPtr; // pointer to the audio file buffer this segment is contained in
  579. unsigned id; // id (unique amoung segments)
  580. unsigned smpIdx; // offset into audioBuf[] of first sample
  581. unsigned smpCnt; // total count of samples to play
  582. unsigned outChIdx; // output buffer channel
  583. unsigned outSmpIdx; // outSmpIdx + smpIdx == next sample to play
  584. unsigned flags; // see kXXXAspFl
  585. } cmAudioSeg;
  586. typedef struct
  587. {
  588. cmObj obj;
  589. unsigned segCnt;
  590. cmAudioSeg* segArray;
  591. unsigned procSmpCnt;
  592. cmSample_t** outChArray;
  593. unsigned outChCnt;
  594. cmSample_t* outM;
  595. } cmAudioSegPlayer;
  596. cmAudioSegPlayer* cmAudioSegPlayerAlloc( cmCtx* ctx, cmAudioSegPlayer* p, unsigned procSmpCnt, unsigned outChCnt );
  597. cmRC_t cmAudioSegPlayerFree( cmAudioSegPlayer** pp );
  598. cmRC_t cmAudioSegPlayerInit( cmAudioSegPlayer* p, unsigned procSmpCnt, unsigned outChCnt );
  599. cmRC_t cmAudioSegPlayerFinal( cmAudioSegPlayer* p );
  600. cmRC_t cmAudioSegPlayerInsert( cmAudioSegPlayer* p, unsigned id, cmAudioFileBuf* bufPtr, unsigned smpIdx, unsigned smpCnt, unsigned outChIdx );
  601. cmRC_t cmAudioSegPlayerEdit( cmAudioSegPlayer* p, unsigned id, cmAudioFileBuf* bufPtr, unsigned smpIdx, unsigned smpCnt, unsigned outChIdx );
  602. cmRC_t cmAudioSegPlayerRemove( cmAudioSegPlayer* p, unsigned id, bool delFl );
  603. cmRC_t cmAudioSegPlayerEnable( cmAudioSegPlayer* p, unsigned id, bool enableFl, unsigned outSmpIdx );
  604. cmRC_t cmAudioSegPlayerReset( cmAudioSegPlayer* p );
  605. cmRC_t cmAudioSegPlayerExec( cmAudioSegPlayer* p, cmSample_t** outChPtr, unsigned chCnt, unsigned outSmpCnt );
  606. //------------------------------------------------------------------------------------------------------------
  607. //)
  608. /*
  609. cmReal_t (*cmCluster0DistFunc_t)( void* userPtr, const cmReal_t* v0, const cmReal_t* v1, unsigned binCnt );
  610. typedef struct
  611. {
  612. cmObj obj;
  613. unsigned flags;
  614. unsigned stateCnt;
  615. unsigned binCnt;
  616. cmReal_t* oM; // oM[ binCnt, stateCnt ]
  617. unsigned* tM; // tM[ stateCnt, stateCnt ]
  618. cmReal_t* dV; // dV[ state
  619. cmCluster0DistFunc_t distFunc;
  620. void* distUserPtr;
  621. unsigned cnt;
  622. } cmCluster0;
  623. enum
  624. {
  625. kCalcTransFl = 0x01,
  626. kCalcDurFl = 0x02
  627. };
  628. cmCluster0* cmCluster0Alloc( cmCtx* ctx, cmCluster0* ap, unsigned stateCnt, unsigned binCnt, unsigned flags, cmCluster0DistFunc_t distFunc, void* dstUserPtr );
  629. cmRC_t cmCluster0Free( cmCluster0** pp );
  630. cmRC_t cmCluster0Init( cmCluster0* p, unsigned stateCnt, unsigned binCnt, unsigned flags, cmCluster0DistFunc_t distFunc, void* dstUserPtr );
  631. cmRC_t cmCluster0Final( cmCluster0* p );
  632. cmRC_t cmCluster0Exec( cmCluster0* p, const cmReal_t* v, unsigned vn );
  633. */
  634. //( { label:cmNmf file_desc:"Non-negative matrix factorization implementation." kw:[proc]}
  635. typedef struct
  636. {
  637. cmObj obj;
  638. unsigned n;
  639. unsigned m;
  640. unsigned r;
  641. unsigned maxIterCnt;
  642. unsigned convergeCnt;
  643. cmReal_t* V; // V[n,m]
  644. cmReal_t* W; // W[n,r]
  645. cmReal_t* H; // H[r,m]
  646. cmReal_t* tr;
  647. cmReal_t* x;
  648. cmReal_t* t0nm;
  649. cmReal_t* t1nm;
  650. cmReal_t* Wt;
  651. cmReal_t* Ht;
  652. cmReal_t* trm;
  653. unsigned* crm;
  654. cmReal_t* tnr;
  655. unsigned* c0;
  656. unsigned* c1;
  657. unsigned* c0m;
  658. unsigned* c1m;
  659. unsigned* idxV;
  660. } cmNmf_t;
  661. cmNmf_t* cmNmfAlloc( cmCtx* ctx, cmNmf_t* ap, unsigned n, unsigned m, unsigned r, unsigned maxIterCnt, unsigned convergeCnt );
  662. cmRC_t cmNmfFree( cmNmf_t** pp );
  663. cmRC_t cmNmfInit( cmNmf_t* p, unsigned n, unsigned m, unsigned r, unsigned maxIterCnt, unsigned convergeCnt );
  664. cmRC_t cmNmfFinal(cmNmf_t* p );
  665. //
  666. cmRC_t cmNmfExec( cmNmf_t* p, const cmReal_t* v, unsigned cn );
  667. //------------------------------------------------------------------------------------------------------------
  668. //)
  669. //( { label:cmVectArray file_desc:"Store and recall arrays of arbitrary length numeric vectors." kw:[proc]}
  670. // cmVectArray buffers row vectors of arbitrary length in memory.
  671. // The buffers may then be access using the cmVectArrayGetXXX() functions.
  672. // The entire contents of the file may be written to a file using atVectArrayWrite().
  673. // The file may then be read in back into memory using cmVectArrayAllocFromFile()
  674. // or in octave via readVectArray.m.
  675. // A rectantular matrix in memory may be written to a VectArray file in one operation
  676. // via the function cmVectArrayWriteMatrixXXX().
  677. typedef struct cmVectArrayVect_str
  678. {
  679. unsigned n; // length of this vector in values (not bytes)
  680. union
  681. {
  682. char* v; // raw memory vector pointer
  683. double* dV; // dV[n] vector of doubles
  684. float* fV; // fV[n] vecotr of floats
  685. cmSample_t* sV; // sV[n] vector of cmSample_t
  686. int* iV;
  687. unsigned* uV;
  688. } u;
  689. struct cmVectArrayVect_str* link; // link to next element record
  690. } cmVectArrayVect_t;
  691. enum
  692. {
  693. kDoubleVaFl = 0x01,
  694. kRealVaFl = 0x01,
  695. kFloatVaFl = 0x02,
  696. kSampleVaFl = 0x02,
  697. kIntVaFl = 0x04,
  698. kUIntVaFl = 0x08,
  699. kVaMask = 0x0f
  700. };
  701. typedef struct
  702. {
  703. cmObj obj;
  704. cmVectArrayVect_t* bp; // first list element
  705. cmVectArrayVect_t* ep; // last list element
  706. unsigned vectCnt; // count of elements in linked list
  707. unsigned flags; // data vector type (See: kFloatVaFl, kDoubleVaFl, ... )
  708. unsigned typeByteCnt; // size of a single data vector value (e.g. 4=float 8=double)
  709. unsigned maxEleCnt; // length of the longest data vector
  710. double* tempV;
  711. cmVectArrayVect_t* cur;
  712. } cmVectArray_t;
  713. // Flags must be set to one of the kXXXVAFl flag values.
  714. cmVectArray_t* cmVectArrayAlloc( cmCtx* ctx, unsigned flags );
  715. cmVectArray_t* cmVectArrayAllocFromFile(cmCtx* ctx, const char* fn );
  716. cmRC_t cmVectArrayFree( cmVectArray_t** pp );
  717. // Release all the stored vectors but do not release the object.
  718. cmRC_t cmVectArrayClear( cmVectArray_t* p );
  719. // Return the count of vectors contained in the vector array.
  720. cmRC_t cmVectArrayCount( const cmVectArray_t* p );
  721. // Return the maximum element count among all rows.
  722. unsigned cmVectArrayMaxRowCount( const cmVectArray_t* p );
  723. // Store a new vector by appending it to the end of the internal vector list.
  724. // Note:
  725. // 1. The true type of v[] in the call to cmVectArrayAppendV() must match
  726. // the data type set in p->flags.
  727. // 2. The 'vn' argument to atVectArrayAppendV() is an element count not
  728. // a byte count. The size of each element is determined by the data type
  729. // as set by atVectArrayAlloc().
  730. cmRC_t cmVectArrayAppendV( cmVectArray_t* p, const void* v, unsigned vn );
  731. cmRC_t cmVectArrayAppendS( cmVectArray_t* p, const cmSample_t* v, unsigned vn );
  732. cmRC_t cmVectArrayAppendR( cmVectArray_t* p, const cmReal_t* v, unsigned vn );
  733. cmRC_t cmVectArrayAppendF( cmVectArray_t* p, const float* v, unsigned vn );
  734. cmRC_t cmVectArrayAppendD( cmVectArray_t* p, const double* v, unsigned vn );
  735. cmRC_t cmVectArrayAppendI( cmVectArray_t* p, const int* v, unsigned vn );
  736. cmRC_t cmVectArrayAppendU( cmVectArray_t* p, const unsigned* v, unsigned vn );
  737. // Write a vector array in a format that can be read by readVectArray.m.
  738. cmRC_t cmVectArrayWrite( cmVectArray_t* p, const char* fn );
  739. cmRC_t cmVectArrayWriteDirFn(cmVectArray_t* p, const char* dir, const char* fn );
  740. // Print the vector array to rpt.
  741. cmRC_t cmVectArrayPrint( cmVectArray_t* p, cmRpt_t* rpt );
  742. typedef cmRC_t (*cmVectArrayForEachFuncS_t)( void* arg, unsigned idx, const cmSample_t* xV, unsigned xN );
  743. unsigned cmVectArrayForEachS( cmVectArray_t* p, unsigned idx, unsigned cnt, cmVectArrayForEachFuncS_t func, void* arg );
  744. // Write the vector v[vn] in the VectArray file format.
  745. // Note:
  746. // 1. The true type of v[] in cmVectArrayWriteVectoV() must match the
  747. // data type set in the 'flags' parameter.
  748. // 2. The 'vn' argument to atVectArrayWriteVectorV() is an element count not
  749. // a byte count. The size of each element is determined by the data type
  750. // as set by atVectArrayAlloc().
  751. cmRC_t cmVectArrayWriteVectorV( cmCtx* ctx, const char* fn, const void* v, unsigned vn, unsigned flags );
  752. cmRC_t cmVectArrayWriteVectorS( cmCtx* ctx, const char* fn, const cmSample_t* v, unsigned vn );
  753. cmRC_t cmVectArrayWriteVectorR( cmCtx* ctx, const char* fn, const cmReal_t* v, unsigned vn );
  754. cmRC_t cmVectArrayWriteVectorD( cmCtx* ctx, const char* fn, const double* v, unsigned vn );
  755. cmRC_t cmVectArrayWriteVectorF( cmCtx* ctx, const char* fn, const float* v, unsigned vn );
  756. cmRC_t cmVectArrayWriteVectorI( cmCtx* ctx, const char* fn, const int* v, unsigned vn );
  757. cmRC_t cmVectArrayWriteVectorU( cmCtx* ctx, const char* fn, const unsigned* v, unsigned vn );
  758. // Write the column-major matrix m[rn,cn] to the file 'fn'.
  759. // Notes:
  760. // 1. The true type of m[] in cmVectArrayWriteMatrixV() must match the
  761. // data type set in the 'flags' parameter.
  762. // 2. The 'rn','cn' arguments to atVectWriteMatrixV() is are element counts not
  763. // byte counts. The size of each element is determined by the data type
  764. // as set by atVectArrayAlloc().
  765. cmRC_t cmVectArrayWriteMatrixV( cmCtx* ctx, const char* fn, const void* m, unsigned rn, unsigned cn, unsigned flags );
  766. cmRC_t cmVectArrayWriteMatrixS( cmCtx* ctx, const char* fn, const cmSample_t* m, unsigned rn, unsigned cn );
  767. cmRC_t cmVectArrayWriteMatrixR( cmCtx* ctx, const char* fn, const cmReal_t* m, unsigned rn, unsigned cn );
  768. cmRC_t cmVectArrayWriteMatrixD( cmCtx* ctx, const char* fn, const double* m, unsigned rn, unsigned cn );
  769. cmRC_t cmVectArrayWriteMatrixF( cmCtx* ctx, const char* fn, const float* m, unsigned rn, unsigned cn );
  770. cmRC_t cmVectArrayWriteMatrixI( cmCtx* ctx, const char* fn, const int* m, unsigned rn, unsigned cn );
  771. cmRC_t cmVectArrayWriteMatrixU( cmCtx* ctx, const char* fn, const unsigned* m, unsigned rn, unsigned cn );
  772. // Read a VectArray file and return it as a matrix.
  773. // The returned memory must be released with a subsequent call to cmMemFree().
  774. // Note that the true type of the pointer address 'mRef' in the call to
  775. // cmVectArrayReadMatrixV() must match the data type of the cmVectArray_t
  776. // specified by 'fn'.
  777. cmRC_t cmVectArrayReadMatrixV( cmCtx* ctx, const char* fn, void** mRef, unsigned* rnRef, unsigned* cnRef );
  778. cmRC_t cmVectArrayReadMatrixS( cmCtx* ctx, const char* fn, cmSample_t** mRef, unsigned* rnRef, unsigned* cnRef );
  779. cmRC_t cmVectArrayReadMatrixR( cmCtx* ctx, const char* fn, cmReal_t** mRef, unsigned* rnRef, unsigned* cnRef );
  780. cmRC_t cmVectArrayReadMatrixD( cmCtx* ctx, const char* fn, double** mRef, unsigned* rnRef, unsigned* cnRef );
  781. cmRC_t cmVectArrayReadMatrixF( cmCtx* ctx, const char* fn, float** mRef, unsigned* rnRef, unsigned* cnRef );
  782. cmRC_t cmVectArrayReadMatrixI( cmCtx* ctx, const char* fn, int** mRef, unsigned* rnRef, unsigned* cnRef );
  783. cmRC_t cmVectArrayReadMatrixU( cmCtx* ctx, const char* fn, unsigned** mRef, unsigned* rnRef, unsigned* cnRef );
  784. // Row iteration control functions.
  785. cmRC_t cmVectArrayRewind( cmVectArray_t* p );
  786. cmRC_t cmVectArrayAdvance( cmVectArray_t* p, unsigned n );
  787. bool cmVectArrayIsEOL( const cmVectArray_t* p );
  788. unsigned cmVectArrayEleCount( const cmVectArray_t* p );
  789. // Copy the current row vector to v[].
  790. // Note that the true type of v[] in cmVectArrayGetV() must match the data type of 'p'.
  791. cmRC_t cmVectArrayGetV( cmVectArray_t* p, void* v, unsigned* vnRef );
  792. cmRC_t cmVectArrayGetS( cmVectArray_t* p, cmSample_t* v, unsigned* vnRef );
  793. cmRC_t cmVectArrayGetR( cmVectArray_t* p, cmReal_t* v, unsigned* vnRef );
  794. cmRC_t cmVectArrayGetD( cmVectArray_t* p, double* v, unsigned* vnRef );
  795. cmRC_t cmVectArrayGetF( cmVectArray_t* p, float* v, unsigned* vnRef );
  796. cmRC_t cmVectArrayGetI( cmVectArray_t* p, int* v, unsigned* vnRef );
  797. cmRC_t cmVectArrayGetU( cmVectArray_t* p, unsigned* v, unsigned* vnRef );
  798. // Set *resultFlRef to true if m[rn,cn] is equal to the cmVectArray_t specified by 'fn'.
  799. // Note that the true type of 'm[]' in the call to cmVectArrayMatrixIsEqualV()
  800. // must match the data type set in 'flags'.
  801. cmRC_t cmVectArrayMatrixIsEqualV( cmCtx* ctx, const char* fn, const void* m, unsigned rn, unsigned cn, bool* resultFlRef, unsigned flags );
  802. cmRC_t cmVectArrayMatrixIsEqualS( cmCtx* ctx, const char* fn, const cmSample_t* m, unsigned rn, unsigned cn, bool* resultFlRef );
  803. cmRC_t cmVectArrayMatrixIsEqualR( cmCtx* ctx, const char* fn, const cmReal_t* m, unsigned rn, unsigned cn, bool* resultFlRef );
  804. cmRC_t cmVectArrayMatrixIsEqualD( cmCtx* ctx, const char* fn, const double* m, unsigned rn, unsigned cn, bool* resultFlRef );
  805. cmRC_t cmVectArrayMatrixIsEqualF( cmCtx* ctx, const char* fn, const float* m, unsigned rn, unsigned cn, bool* resultFlRef );
  806. cmRC_t cmVectArrayMatrixIsEqualI( cmCtx* ctx, const char* fn, const int* m, unsigned rn, unsigned cn, bool* resultFlRef );
  807. cmRC_t cmVectArrayMatrixIsEqualU( cmCtx* ctx, const char* fn, const unsigned* m, unsigned rn, unsigned cn, bool* resultFlRef );
  808. // If a vector array is composed of repeating blocks of 'groupCnt' sub-vectors
  809. // where the concatenated ith sub-vectors in each group form a single super-vector then
  810. // this function will return the super-vector. Use cmMemFree(*vRef) to release
  811. // the returned super-vector.
  812. cmRC_t cmVectArrayFormVectR( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, cmReal_t** vRef, unsigned* vnRef );
  813. cmRC_t cmVectArrayFormVectF( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, float** vRef, unsigned* vnRef );
  814. cmRC_t cmVectArrayFormVectColF( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, unsigned colIdx, float** vRef, unsigned* vnRef );
  815. cmRC_t cmVectArrayFormVectColU( cmVectArray_t* p, unsigned groupIdx, unsigned groupCnt, unsigned colIdx, unsigned** vRef, unsigned* vnRef );
  816. cmRC_t cmVectArrayTest( cmCtx* ctx, const char* fn, bool genFl );
  817. //------------------------------------------------------------------------------------------------------------
  818. //)
  819. //( { label:cmWhFilt file_desc:"Spectral whitening filter." kw:[proc]}
  820. // Spectral whitening filter.
  821. // Based on: Klapuri, A., 2006: Multiple fundamental frequency estimation by summing
  822. // harmonic amplitudes.
  823. typedef struct
  824. {
  825. cmObj obj;
  826. unsigned binCnt; //
  827. cmReal_t binHz; //
  828. unsigned bandCnt; //
  829. cmReal_t coeff; //
  830. cmReal_t* whiV; // whiV[bandCnt+2] - fractional bin index of each center frequency
  831. cmReal_t* whM; // whM[binCnt,bandCnt]
  832. cmReal_t* iV; // iV[ binCnt ] - working memory
  833. } cmWhFilt;
  834. cmWhFilt* cmWhFiltAlloc( cmCtx* c, cmWhFilt* p, unsigned binCnt, cmReal_t binHz, cmReal_t coeff, cmReal_t maxHz );
  835. cmRC_t cmWhFiltFree( cmWhFilt** pp );
  836. cmRC_t cmWhFiltInit( cmWhFilt* p, unsigned binCnt, cmReal_t binHz, cmReal_t coeff, cmReal_t maxHz );
  837. cmRC_t cmWhFiltFinal( cmWhFilt* p );
  838. cmRC_t cmWhFiltExec( cmWhFilt* p, const cmReal_t* xV, cmReal_t* yV, unsigned xyN );
  839. //-----------------------------------------------------------------------------------------------------------------------
  840. //)
  841. //( { label:cmFrqTrk file_desc:"Track sinusoids from STFT frame data." kw:[proc]}
  842. typedef enum
  843. {
  844. kNoStateFrqTrkId,
  845. kDlyFrqTrkId,
  846. kAtkFrqTrkId,
  847. kSusFrqTrkId,
  848. kDcyFrqTrkId
  849. } cmFrqTrkAttenStateId_t;
  850. typedef struct
  851. {
  852. double srate; // system sample rate
  853. unsigned chCnt; // tracking channel count
  854. unsigned binCnt; // count of spectrum elements passed in each call to cmFrqTrkExec()
  855. unsigned hopSmpCnt; // phase vocoder hop count in samples
  856. cmReal_t stRange; // maximum allowable semi-tones between a tracker and a peak
  857. cmReal_t wndSecs; // duration of the
  858. cmReal_t minTrkSec; // minimum track length before track is considered stable
  859. cmReal_t maxTrkDeadSec; // maximum length of time a tracker may fail to connect to a peak before being declared disconnected.
  860. cmReal_t pkThreshDb; // minimum amplitide in Decibels of a selected spectral peak.
  861. cmReal_t pkAtkThreshDb; // minimum amplitude in Decibels for the first frame of a new track.
  862. cmReal_t pkMaxHz; // maximum frequency to track
  863. cmReal_t whFiltCoeff;
  864. cmReal_t attenThresh;
  865. cmReal_t attenGain;
  866. cmReal_t attenDlySec;
  867. cmReal_t attenAtkSec;
  868. const char* logFn; // log file name or NULL if no file is to be written
  869. const char* levelFn; // level file name or NULL if no file is to be written
  870. const char* specFn; // spectrum file name or NULL if no file is to be written
  871. const char* attenFn;
  872. } cmFrqTrkArgs_t;
  873. typedef struct
  874. {
  875. bool activeFl;
  876. unsigned id;
  877. unsigned tN; // age of this track in frames
  878. unsigned dN; // count of consecutive times this ch has not connected
  879. cmReal_t hz; // current center frequency
  880. cmReal_t db; // current magnitude
  881. cmReal_t* dbV; // dbV[]
  882. cmReal_t* hzV; // hzV[]
  883. unsigned si;
  884. unsigned sn;
  885. cmReal_t db_mean;
  886. cmReal_t db_std;
  887. cmReal_t hz_mean;
  888. cmReal_t hz_std;
  889. cmReal_t score;
  890. cmFrqTrkAttenStateId_t state;
  891. int attenPhsIdx;
  892. cmReal_t attenGain;
  893. } cmFrqTrkCh_t;
  894. struct cmBinMtxFile_str;
  895. typedef struct cmFrqTrk_str
  896. {
  897. cmObj obj;
  898. cmFrqTrkArgs_t a;
  899. cmFrqTrkCh_t* ch; // ch[ a.chCnt ]
  900. unsigned hN; // count of magnitude buffer frames
  901. unsigned sN; // count of frames in channel statistics buffers
  902. unsigned bN; // count of bins in peak matrices
  903. cmReal_t* dbM; // dbM[ hN, bN ]
  904. unsigned hi; // next row of dbM to fill
  905. unsigned fN; // total count of frames processed.
  906. cmReal_t binHz;
  907. cmReal_t* dbV;
  908. unsigned* pkiV;
  909. unsigned deadN_max; // max. count of hops a tracker may fail to connect before being set to inactive
  910. unsigned minTrkN; // minimum track length in hops
  911. unsigned nextTrkId;
  912. unsigned newTrkCnt;
  913. unsigned curTrkCnt;
  914. unsigned deadTrkCnt;
  915. cmReal_t* aV;
  916. int attenDlyPhsMax;
  917. int attenPhsMax;
  918. cmWhFilt* wf;
  919. cmVectArray_t* logVa;
  920. cmVectArray_t* levelVa;
  921. cmVectArray_t* specVa;
  922. cmVectArray_t* attenVa;
  923. cmChar_t* logFn;
  924. cmChar_t* levelFn;
  925. cmChar_t* specFn;
  926. cmChar_t* attenFn;
  927. } cmFrqTrk;
  928. //
  929. // 1. Calculate the mean spectral magnitude profile over the last hN frames.
  930. // 2. Locate the peaks in the profile.
  931. // 3. Allow each active tracker to select the closest peak to extend its life.
  932. // a) The distance between the trackers current location and a given
  933. // peak is measured based on magnitude and frequency over time.
  934. // b) There is a frequency range limit outside of which a given track-peak
  935. // connection may not go.
  936. // c) There is an amplitude threshold below which a track may not fall.
  937. cmFrqTrk* cmFrqTrkAlloc( cmCtx* c, cmFrqTrk* p, const cmFrqTrkArgs_t* a );
  938. cmRC_t cmFrqTrkFree( cmFrqTrk** pp );
  939. cmRC_t cmFrqTrkInit( cmFrqTrk* p, const cmFrqTrkArgs_t* a );
  940. cmRC_t cmFrqTrkFinal( cmFrqTrk* p );
  941. cmRC_t cmFrqTrkExec( cmFrqTrk* p, const cmReal_t* magV, const cmReal_t* phsV, const cmReal_t* hzV );
  942. void cmFrqTrkPrint( cmFrqTrk* p );
  943. //-----------------------------------------------------------------------------------------------------------------------
  944. //)
  945. //( { label:cmFbCtl file_desc:"Perform acoustic feedback control by attenuating loud sinusoid signals." kw:[proc]}
  946. typedef struct
  947. {
  948. double srate;
  949. unsigned binCnt;
  950. unsigned hopSmpCnt;
  951. unsigned bufMs;
  952. cmReal_t maxHz;
  953. } cmFbCtlArgs_t;
  954. typedef struct
  955. {
  956. cmObj obj;
  957. cmFbCtlArgs_t a;
  958. unsigned binCnt;
  959. unsigned frmCnt;
  960. cmReal_t* bM; // bM[ frmCnt, binCnt ];
  961. unsigned bfi; // current buffer frame (column) index
  962. unsigned bfN; // currrent count of frames in the buffer
  963. cmReal_t* rmsV; // rmsV[ frmCnt ];
  964. cmReal_t* sV; // sV[ binCnt ]
  965. cmReal_t* uV;
  966. cmVectArray_t* sva;
  967. cmVectArray_t* uva;
  968. } cmFbCtl_t;
  969. cmFbCtl_t* cmFbCtlAlloc( cmCtx* c, cmFbCtl_t* p, const cmFbCtlArgs_t* a );
  970. cmRC_t cmFbCtlFree( cmFbCtl_t** pp );
  971. cmRC_t cmFbCtlInit( cmFbCtl_t* p, const cmFbCtlArgs_t* a );
  972. cmRC_t cmFbCtlFinal(cmFbCtl_t* p );
  973. cmRC_t cmFbCtlExec( cmFbCtl_t* p, const cmReal_t* xV );
  974. //------------------------------------------------------------------------------------------------------------
  975. //)
  976. //( { label:cmExpander file_desc:"Expander implementation for audio dynamics processing." kw:[proc]}
  977. typedef struct
  978. {
  979. cmObj obj;
  980. cmReal_t* rmsV; // rmsV[rmsN]
  981. unsigned rmsN; //
  982. unsigned rmsIdx;//
  983. cmReal_t rmsValue; // last RMS value
  984. cmSample_t* envV; // envV[envN]
  985. unsigned envN; // atkSmp + rlsSmp;
  986. unsigned threshN;
  987. unsigned threshIdx;
  988. float threshLvl;
  989. float rlsLvl;
  990. unsigned envIdx;
  991. double gain;
  992. unsigned atkCnt;
  993. } cmExpander;
  994. cmExpander* cmExpanderAlloc( cmCtx* c, cmExpander* p, double srate, unsigned procSmpCnt, double threshDb, double rlsDb, double threshMs, double rmsMs, double atkMs, double rlsMs );
  995. cmRC_t cmExpanderFree( cmExpander** pp );
  996. cmRC_t cmExpanderInit( cmExpander* p, double srate, unsigned procSmpCnt, double threshDb, double rlsDb, double threshMs, double rmsMs, double atkMs, double rlsMs );
  997. cmRC_t cmExpanderFinal( cmExpander* p );
  998. cmRC_t cmExpanderExec( cmExpander* p, cmSample_t* x, cmSample_t* y, unsigned xyN );
  999. cmRC_t cmExpanderExecD( cmExpander* p, double* x, double* y, unsigned xyN );
  1000. //-----------------------------------------------------------------------------------------------------------------------
  1001. //)
  1002. //( { label:cmExpanderBank file_desc:"Bank of audio dynamics expanders based on cmExpander." kw:[proc]}
  1003. typedef struct
  1004. {
  1005. cmObj obj;
  1006. cmExpander** b; // b[bandN]
  1007. unsigned bandN;
  1008. double rmsValue;
  1009. unsigned atkCnt;
  1010. } cmExpanderBank;
  1011. cmExpanderBank* cmExpanderBankAlloc( cmCtx* c, cmExpanderBank* p, unsigned bandN, double srate, unsigned procSmpCnt, double threshDb, double rlsDb, double threshMs, double rmsMs, double atkMs, double rlsMs );
  1012. cmRC_t cmExpanderBankFree( cmExpanderBank** pp );
  1013. cmRC_t cmExpanderBankInit( cmExpanderBank* p, unsigned bandN, double srate, unsigned procSmpCnt, double threshDb, double rlsDb, double threshMs, double rmsMs, double atkMs, double rlsMs );
  1014. cmRC_t cmExpanderBankFinal( cmExpanderBank* p );
  1015. cmRC_t cmExpanderBankExec( cmExpanderBank* p, cmSample_t* x, unsigned bandN );
  1016. cmRC_t cmExpanderBankExecD( cmExpanderBank* p, double* x, unsigned bandN );
  1017. //-----------------------------------------------------------------------------------------------------------------------
  1018. //)
  1019. //( { label:cmSpecDist file_desc:"Spectral distortion algorithm based on non-linear transform." kw:[proc]}
  1020. enum
  1021. {
  1022. kBypassModeSdId, // 0 - no effect
  1023. kBasicModeSdId, // 1 - fixed thresh
  1024. kSpecCentSdId, // 2 - thresh = max magn - (offset * spec_cent)
  1025. kAmpEnvSdId, // 3 - thresh = max magn - offset
  1026. kBumpSdId,
  1027. kModeSdCnt
  1028. };
  1029. typedef struct
  1030. {
  1031. cmObj obj;
  1032. double srate;
  1033. unsigned wndSmpCnt;
  1034. unsigned hopFcmt;
  1035. unsigned hopSmpCnt;
  1036. unsigned procSmpCnt;
  1037. cmPvAnl* pva;
  1038. cmPvSyn* pvs;
  1039. cmFrqTrk* ft;
  1040. cmFbCtl_t* fbc;
  1041. cmExpanderBank* exb;
  1042. unsigned mode;
  1043. double thresh;
  1044. double uprSlope;
  1045. double lwrSlope;
  1046. double offset;
  1047. bool invertFl;
  1048. double spcBwHz; // spectral centroid bandwidth in Hz
  1049. double spcSmArg; // spectral centroid smoothing
  1050. double spcMin;
  1051. double spcMax;
  1052. unsigned spcBinCnt; // count of bins used in the spectral centroid
  1053. cmReal_t* hzV; // hzV[spcBinCnt];
  1054. cmReal_t spc;
  1055. unsigned spcCnt;
  1056. cmReal_t spcSum;
  1057. cmReal_t spcSqSum;
  1058. cmReal_t aeSmMax; // smoothed max bin magn - used by spectral centroid
  1059. cmReal_t aeSmOffs; // smoothed offset
  1060. cmReal_t ae;
  1061. cmReal_t aeMin;
  1062. cmReal_t aeMax;
  1063. cmReal_t aeUnit;
  1064. cmReal_t ogain;
  1065. cmReal_t ogain0;
  1066. unsigned phaseModIndex;
  1067. unsigned fi; // total count of frames processed by cmSpecDistExec()
  1068. unsigned hN;
  1069. unsigned hi;
  1070. cmReal_t* iSpecM; // iSpecMtx[hN binN]
  1071. cmReal_t* iSpecV; // mean of rows of iSpecM
  1072. cmVectArray_t* iSpecVa;
  1073. cmReal_t* oSpecM; // oSpecMtx[hN binN]
  1074. cmReal_t* oSpecV; // mean of rows of oSpecM
  1075. cmVectArray_t* oSpecVa;
  1076. cmVectArray_t* statVa;
  1077. } cmSpecDist_t;
  1078. cmSpecDist_t* cmSpecDistAlloc( cmCtx* ctx,cmSpecDist_t* ap, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId );
  1079. cmRC_t cmSpecDistFree( cmSpecDist_t** pp );
  1080. cmRC_t cmSpecDistInit( cmSpecDist_t* p, unsigned procSmpCnt, double srate, unsigned wndSmpCnt, unsigned hopFcmt, unsigned olaWndTypeId );
  1081. cmRC_t cmSpecDistFinal(cmSpecDist_t* p );
  1082. cmRC_t cmSpecDistExec( cmSpecDist_t* p, const cmSample_t* sp, unsigned sn );
  1083. const cmSample_t* cmSpecDistOut( cmSpecDist_t* p );
  1084. //------------------------------------------------------------------------------------------------------------
  1085. //)
  1086. //( { label:cmBinMtxFile file_desc:"Write a binary matrix which can be read by readBinFile.m." kw:[proc]}
  1087. // Write a binary matrix file in the format acceppted by the octave function readBinFile.m
  1088. typedef struct cmBinMtxFile_str
  1089. {
  1090. cmObj obj;
  1091. cmFileH_t fh;
  1092. unsigned rowCnt;
  1093. unsigned maxRowEleCnt;
  1094. unsigned eleByteCnt;
  1095. } cmBinMtxFile_t;
  1096. cmBinMtxFile_t* cmBinMtxFileAlloc( cmCtx* ctx, cmBinMtxFile_t* ap, const cmChar_t* fn );
  1097. cmRC_t cmBinMtxFileFree( cmBinMtxFile_t** pp );
  1098. cmRC_t cmBinMtxFileInit( cmBinMtxFile_t* p, const cmChar_t* fn );
  1099. cmRC_t cmBinMtxFileFinal( cmBinMtxFile_t* p );
  1100. // Write one row of 'xn' columns to the matrix file.
  1101. cmRC_t cmBinMtxFileExecS( cmBinMtxFile_t* p, const cmSample_t* x, unsigned xn );
  1102. cmRC_t cmBinMtxFileExecR( cmBinMtxFile_t* p, const cmReal_t* x, unsigned xn );
  1103. bool cmBinMtxFileIsValid( cmBinMtxFile_t* p );
  1104. // Write a binary matrix file.
  1105. // The matrix data is provided as sp[rowCnt,colCnt] or rp[rowCnt,colCnt].
  1106. // The matrix is assumed to be in column major order (like all matrices in the cm library)
  1107. // Either 'sp' or 'rp' must be given but not both.
  1108. // 'ctx' is optional and defaults to NULL.
  1109. // If 'ctx' is not provided then 'rpt' must be provided.
  1110. // If 'ctx' is provided then 'rpt' is not used.
  1111. // See cmAudioFileReadWriteTest() in cmProcTest.c for an example usage.
  1112. cmRC_t cmBinMtxFileWrite( const cmChar_t* fn, unsigned rowCnt, unsigned colCnt, const cmSample_t* sp, const cmReal_t* rp, cmCtx* ctx, cmRpt_t* rpt );
  1113. // Return the matrix file geometry.
  1114. // rowCntPtr,colCntPtr and eleByteCntPtr are optional
  1115. cmRC_t cmBinMtxFileSize( cmCtx_t* ctx, const cmChar_t* fn, unsigned* rowCntPtr, unsigned* colCntPtr, unsigned* eleByteCntPtr );
  1116. // Fill buf[rowCnt*colCnt*byteEleCnt] buffer from the binary matrix file 'fn'.
  1117. // rowCnt,colCnt,eleByteCnt must be exactly the same as the actual file.
  1118. // Use cmBinMtxFileSize() to determine the buffer size prior to calling this function.
  1119. // colCntV[colCnt] is optional.
  1120. cmRC_t cmBinMtxFileRead( cmCtx_t* ctx, const cmChar_t* fn, unsigned rowCnt, unsigned colCnt, unsigned eleByteCnt, void* buf, unsigned* colCntV );
  1121. //)
  1122. #ifdef __cplusplus
  1123. }
  1124. #endif
  1125. #endif