arm_mfcc_init_q15.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mfcc_init_q15.c
  4. * Description: MFCC initialization function for the q15 version
  5. *
  6. * $Date: 07 September 2021
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. /**
  29. * @defgroup MFCCQ15 MFCC Q15
  30. */
  31. /**
  32. @ingroup MFCC
  33. */
  34. /**
  35. @addtogroup MFCCQ15
  36. @{
  37. */
  38. #include "dsp/transform_functions.h"
  39. /**
  40. @brief Generic initialization of the MFCC Q15 instance structure
  41. @param[out] S points to the mfcc instance structure
  42. @param[in] fftLen fft length
  43. @param[in] nbMelFilters number of Mel filters
  44. @param[in] nbDctOutputs number of Dct outputs
  45. @param[in] dctCoefs points to an array of DCT coefficients
  46. @param[in] filterPos points of the array of filter positions
  47. @param[in] filterLengths points to the array of filter lengths
  48. @param[in] filterCoefs points to the array of filter coefficients
  49. @param[in] windowCoefs points to the array of window coefficients
  50. @return error status
  51. @par Description
  52. The matrix of Mel filter coefficients is sparse.
  53. Most of the coefficients are zero.
  54. To avoid multiplying the spectrogram by those zeros, the
  55. filter is applied only to a given position in the spectrogram
  56. and on a given number of FFT bins (the filter length).
  57. It is the reason for the arrays filterPos and filterLengths.
  58. window coefficients can describe (for instance) a Hamming window.
  59. The array has the same size as the FFT length.
  60. The folder Scripts is containing a Python script which can be used
  61. to generate the filter, dct and window arrays.
  62. @par
  63. This function should be used only if you don't know the FFT sizes that
  64. you'll need at build time. The use of this function will prevent the
  65. linker from removing the FFT tables that are not needed and the library
  66. code size will be bigger than needed.
  67. @par
  68. If you use CMSIS-DSP as a static library, and if you know the MFCC sizes
  69. that you need at build time, then it is better to use the initialization
  70. functions defined for each MFCC size.
  71. */
  72. arm_status arm_mfcc_init_q15(
  73. arm_mfcc_instance_q15 * S,
  74. uint32_t fftLen,
  75. uint32_t nbMelFilters,
  76. uint32_t nbDctOutputs,
  77. const q15_t *dctCoefs,
  78. const uint32_t *filterPos,
  79. const uint32_t *filterLengths,
  80. const q15_t *filterCoefs,
  81. const q15_t *windowCoefs
  82. )
  83. {
  84. arm_status status;
  85. S->fftLen=fftLen;
  86. S->nbMelFilters=nbMelFilters;
  87. S->nbDctOutputs=nbDctOutputs;
  88. S->dctCoefs=dctCoefs;
  89. S->filterPos=filterPos;
  90. S->filterLengths=filterLengths;
  91. S->filterCoefs=filterCoefs;
  92. S->windowCoefs=windowCoefs;
  93. #if defined(ARM_MFCC_CFFT_BASED)
  94. status=arm_cfft_init_q15(&(S->cfft),fftLen);
  95. #else
  96. status=arm_rfft_init_q15(&(S->rfft),fftLen,0,1);
  97. #endif
  98. return(status);
  99. }
  100. #if defined(ARM_MFCC_CFFT_BASED)
  101. #define MFCC_INIT_Q15(LEN) \
  102. arm_status arm_mfcc_init_##LEN##_q15( \
  103. arm_mfcc_instance_q15 * S, \
  104. uint32_t nbMelFilters, \
  105. uint32_t nbDctOutputs, \
  106. const q15_t *dctCoefs, \
  107. const uint32_t *filterPos, \
  108. const uint32_t *filterLengths, \
  109. const q15_t *filterCoefs, \
  110. const q15_t *windowCoefs \
  111. ) \
  112. { \
  113. arm_status status; \
  114. \
  115. S->fftLen=LEN; \
  116. S->nbMelFilters=nbMelFilters; \
  117. S->nbDctOutputs=nbDctOutputs; \
  118. S->dctCoefs=dctCoefs; \
  119. S->filterPos=filterPos; \
  120. S->filterLengths=filterLengths; \
  121. S->filterCoefs=filterCoefs; \
  122. S->windowCoefs=windowCoefs; \
  123. \
  124. status=arm_cfft_init_##LEN##_q15(&(S->cfft));\
  125. \
  126. return(status); \
  127. }
  128. #else
  129. #define MFCC_INIT_Q15(LEN) \
  130. arm_status arm_mfcc_init_##LEN##_q15( \
  131. arm_mfcc_instance_q15 * S, \
  132. uint32_t nbMelFilters, \
  133. uint32_t nbDctOutputs, \
  134. const q15_t *dctCoefs, \
  135. const uint32_t *filterPos, \
  136. const uint32_t *filterLengths, \
  137. const q15_t *filterCoefs, \
  138. const q15_t *windowCoefs \
  139. ) \
  140. { \
  141. arm_status status; \
  142. \
  143. S->fftLen=LEN; \
  144. S->nbMelFilters=nbMelFilters; \
  145. S->nbDctOutputs=nbDctOutputs; \
  146. S->dctCoefs=dctCoefs; \
  147. S->filterPos=filterPos; \
  148. S->filterLengths=filterLengths; \
  149. S->filterCoefs=filterCoefs; \
  150. S->windowCoefs=windowCoefs; \
  151. \
  152. status=arm_rfft_init_##LEN##_q15(&(S->rfft),0,1);\
  153. \
  154. return(status); \
  155. }
  156. #endif
  157. /**
  158. @brief Initialization of the MFCC Q15 instance structure for 32 samples MFCC
  159. @param[out] S points to the mfcc instance structure
  160. @param[in] nbMelFilters number of Mel filters
  161. @param[in] nbDctOutputs number of Dct outputs
  162. @param[in] dctCoefs points to an array of DCT coefficients
  163. @param[in] filterPos points of the array of filter positions
  164. @param[in] filterLengths points to the array of filter lengths
  165. @param[in] filterCoefs points to the array of filter coefficients
  166. @param[in] windowCoefs points to the array of window coefficients
  167. @return error status
  168. @par Description
  169. The matrix of Mel filter coefficients is sparse.
  170. Most of the coefficients are zero.
  171. To avoid multiplying the spectrogram by those zeros, the
  172. filter is applied only to a given position in the spectrogram
  173. and on a given number of FFT bins (the filter length).
  174. It is the reason for the arrays filterPos and filterLengths.
  175. window coefficients can describe (for instance) a Hamming window.
  176. The array has the same size as the FFT length.
  177. The folder Scripts is containing a Python script which can be used
  178. to generate the filter, dct and window arrays.
  179. */
  180. MFCC_INIT_Q15(32)
  181. /**
  182. @brief Initialization of the MFCC Q15 instance structure for 64 samples MFCC
  183. @param[out] S points to the mfcc instance structure
  184. @param[in] nbMelFilters number of Mel filters
  185. @param[in] nbDctOutputs number of Dct outputs
  186. @param[in] dctCoefs points to an array of DCT coefficients
  187. @param[in] filterPos points of the array of filter positions
  188. @param[in] filterLengths points to the array of filter lengths
  189. @param[in] filterCoefs points to the array of filter coefficients
  190. @param[in] windowCoefs points to the array of window coefficients
  191. @return error status
  192. @par Description
  193. The matrix of Mel filter coefficients is sparse.
  194. Most of the coefficients are zero.
  195. To avoid multiplying the spectrogram by those zeros, the
  196. filter is applied only to a given position in the spectrogram
  197. and on a given number of FFT bins (the filter length).
  198. It is the reason for the arrays filterPos and filterLengths.
  199. window coefficients can describe (for instance) a Hamming window.
  200. The array has the same size as the FFT length.
  201. The folder Scripts is containing a Python script which can be used
  202. to generate the filter, dct and window arrays.
  203. */
  204. MFCC_INIT_Q15(64)
  205. /**
  206. @brief Initialization of the MFCC Q15 instance structure for 128 samples MFCC
  207. @param[out] S points to the mfcc instance structure
  208. @param[in] nbMelFilters number of Mel filters
  209. @param[in] nbDctOutputs number of Dct outputs
  210. @param[in] dctCoefs points to an array of DCT coefficients
  211. @param[in] filterPos points of the array of filter positions
  212. @param[in] filterLengths points to the array of filter lengths
  213. @param[in] filterCoefs points to the array of filter coefficients
  214. @param[in] windowCoefs points to the array of window coefficients
  215. @return error status
  216. @par Description
  217. The matrix of Mel filter coefficients is sparse.
  218. Most of the coefficients are zero.
  219. To avoid multiplying the spectrogram by those zeros, the
  220. filter is applied only to a given position in the spectrogram
  221. and on a given number of FFT bins (the filter length).
  222. It is the reason for the arrays filterPos and filterLengths.
  223. window coefficients can describe (for instance) a Hamming window.
  224. The array has the same size as the FFT length.
  225. The folder Scripts is containing a Python script which can be used
  226. to generate the filter, dct and window arrays.
  227. */
  228. MFCC_INIT_Q15(128)
  229. /**
  230. @brief Initialization of the MFCC Q15 instance structure for 256 samples MFCC
  231. @param[out] S points to the mfcc instance structure
  232. @param[in] nbMelFilters number of Mel filters
  233. @param[in] nbDctOutputs number of Dct outputs
  234. @param[in] dctCoefs points to an array of DCT coefficients
  235. @param[in] filterPos points of the array of filter positions
  236. @param[in] filterLengths points to the array of filter lengths
  237. @param[in] filterCoefs points to the array of filter coefficients
  238. @param[in] windowCoefs points to the array of window coefficients
  239. @return error status
  240. @par Description
  241. The matrix of Mel filter coefficients is sparse.
  242. Most of the coefficients are zero.
  243. To avoid multiplying the spectrogram by those zeros, the
  244. filter is applied only to a given position in the spectrogram
  245. and on a given number of FFT bins (the filter length).
  246. It is the reason for the arrays filterPos and filterLengths.
  247. window coefficients can describe (for instance) a Hamming window.
  248. The array has the same size as the FFT length.
  249. The folder Scripts is containing a Python script which can be used
  250. to generate the filter, dct and window arrays.
  251. */
  252. MFCC_INIT_Q15(256)
  253. /**
  254. @brief Initialization of the MFCC Q15 instance structure for 512 samples MFCC
  255. @param[out] S points to the mfcc instance structure
  256. @param[in] nbMelFilters number of Mel filters
  257. @param[in] nbDctOutputs number of Dct outputs
  258. @param[in] dctCoefs points to an array of DCT coefficients
  259. @param[in] filterPos points of the array of filter positions
  260. @param[in] filterLengths points to the array of filter lengths
  261. @param[in] filterCoefs points to the array of filter coefficients
  262. @param[in] windowCoefs points to the array of window coefficients
  263. @return error status
  264. @par Description
  265. The matrix of Mel filter coefficients is sparse.
  266. Most of the coefficients are zero.
  267. To avoid multiplying the spectrogram by those zeros, the
  268. filter is applied only to a given position in the spectrogram
  269. and on a given number of FFT bins (the filter length).
  270. It is the reason for the arrays filterPos and filterLengths.
  271. window coefficients can describe (for instance) a Hamming window.
  272. The array has the same size as the FFT length.
  273. The folder Scripts is containing a Python script which can be used
  274. to generate the filter, dct and window arrays.
  275. */
  276. MFCC_INIT_Q15(512)
  277. /**
  278. @brief Initialization of the MFCC Q15 instance structure for 1024 samples MFCC
  279. @param[out] S points to the mfcc instance structure
  280. @param[in] nbMelFilters number of Mel filters
  281. @param[in] nbDctOutputs number of Dct outputs
  282. @param[in] dctCoefs points to an array of DCT coefficients
  283. @param[in] filterPos points of the array of filter positions
  284. @param[in] filterLengths points to the array of filter lengths
  285. @param[in] filterCoefs points to the array of filter coefficients
  286. @param[in] windowCoefs points to the array of window coefficients
  287. @return error status
  288. @par Description
  289. The matrix of Mel filter coefficients is sparse.
  290. Most of the coefficients are zero.
  291. To avoid multiplying the spectrogram by those zeros, the
  292. filter is applied only to a given position in the spectrogram
  293. and on a given number of FFT bins (the filter length).
  294. It is the reason for the arrays filterPos and filterLengths.
  295. window coefficients can describe (for instance) a Hamming window.
  296. The array has the same size as the FFT length.
  297. The folder Scripts is containing a Python script which can be used
  298. to generate the filter, dct and window arrays.
  299. */
  300. MFCC_INIT_Q15(1024)
  301. /**
  302. @brief Initialization of the MFCC Q15 instance structure for 2048 samples MFCC
  303. @param[out] S points to the mfcc instance structure
  304. @param[in] nbMelFilters number of Mel filters
  305. @param[in] nbDctOutputs number of Dct outputs
  306. @param[in] dctCoefs points to an array of DCT coefficients
  307. @param[in] filterPos points of the array of filter positions
  308. @param[in] filterLengths points to the array of filter lengths
  309. @param[in] filterCoefs points to the array of filter coefficients
  310. @param[in] windowCoefs points to the array of window coefficients
  311. @return error status
  312. @par Description
  313. The matrix of Mel filter coefficients is sparse.
  314. Most of the coefficients are zero.
  315. To avoid multiplying the spectrogram by those zeros, the
  316. filter is applied only to a given position in the spectrogram
  317. and on a given number of FFT bins (the filter length).
  318. It is the reason for the arrays filterPos and filterLengths.
  319. window coefficients can describe (for instance) a Hamming window.
  320. The array has the same size as the FFT length.
  321. The folder Scripts is containing a Python script which can be used
  322. to generate the filter, dct and window arrays.
  323. */
  324. MFCC_INIT_Q15(2048)
  325. /**
  326. @brief Initialization of the MFCC Q15 instance structure for 4096 samples MFCC
  327. @param[out] S points to the mfcc instance structure
  328. @param[in] nbMelFilters number of Mel filters
  329. @param[in] nbDctOutputs number of Dct outputs
  330. @param[in] dctCoefs points to an array of DCT coefficients
  331. @param[in] filterPos points of the array of filter positions
  332. @param[in] filterLengths points to the array of filter lengths
  333. @param[in] filterCoefs points to the array of filter coefficients
  334. @param[in] windowCoefs points to the array of window coefficients
  335. @return error status
  336. @par Description
  337. The matrix of Mel filter coefficients is sparse.
  338. Most of the coefficients are zero.
  339. To avoid multiplying the spectrogram by those zeros, the
  340. filter is applied only to a given position in the spectrogram
  341. and on a given number of FFT bins (the filter length).
  342. It is the reason for the arrays filterPos and filterLengths.
  343. window coefficients can describe (for instance) a Hamming window.
  344. The array has the same size as the FFT length.
  345. The folder Scripts is containing a Python script which can be used
  346. to generate the filter, dct and window arrays.
  347. */
  348. MFCC_INIT_Q15(4096)
  349. /**
  350. @} end of MFCCQ15 group
  351. */