arm_mfcc_init_f16.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mfcc_init_f16.c
  4. * Description: MFCC initialization function for the f16 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 MFCCF16 MFCC F16
  30. */
  31. /**
  32. @ingroup MFCC
  33. */
  34. /**
  35. @addtogroup MFCCF16
  36. @{
  37. */
  38. #include "dsp/transform_functions_f16.h"
  39. #if defined(ARM_FLOAT16_SUPPORTED)
  40. /**
  41. @brief Generic initialization of the MFCC F16 instance structure
  42. @param[out] S points to the mfcc instance structure
  43. @param[in] fftLen fft length
  44. @param[in] nbMelFilters number of Mel filters
  45. @param[in] nbDctOutputs number of Dct outputs
  46. @param[in] dctCoefs points to an array of DCT coefficients
  47. @param[in] filterPos points of the array of filter positions
  48. @param[in] filterLengths points to the array of filter lengths
  49. @param[in] filterCoefs points to the array of filter coefficients
  50. @param[in] windowCoefs points to the array of window coefficients
  51. @return error status
  52. @par Description
  53. The matrix of Mel filter coefficients is sparse.
  54. Most of the coefficients are zero.
  55. To avoid multiplying the spectrogram by those zeros, the
  56. filter is applied only to a given position in the spectrogram
  57. and on a given number of FFT bins (the filter length).
  58. It is the reason for the arrays filterPos and filterLengths.
  59. window coefficients can describe (for instance) a Hamming window.
  60. The array has the same size as the FFT length.
  61. The folder Scripts is containing a Python script that can be used
  62. to generate the filter, dct and window arrays.
  63. @par
  64. This function should be used only if you don't know the FFT sizes that
  65. you'll need at build time. The use of this function will prevent the
  66. linker from removing the FFT tables that are not needed and the library
  67. code size will be bigger than needed.
  68. @par
  69. If you use CMSIS-DSP as a static library, and if you know the MFCC sizes
  70. that you need at build time, then it is better to use the initialization
  71. functions defined for each MFCC size.
  72. */
  73. arm_status arm_mfcc_init_f16(
  74. arm_mfcc_instance_f16 * S,
  75. uint32_t fftLen,
  76. uint32_t nbMelFilters,
  77. uint32_t nbDctOutputs,
  78. const float16_t *dctCoefs,
  79. const uint32_t *filterPos,
  80. const uint32_t *filterLengths,
  81. const float16_t *filterCoefs,
  82. const float16_t *windowCoefs
  83. )
  84. {
  85. arm_status status;
  86. S->fftLen=fftLen;
  87. S->nbMelFilters=nbMelFilters;
  88. S->nbDctOutputs=nbDctOutputs;
  89. S->dctCoefs=dctCoefs;
  90. S->filterPos=filterPos;
  91. S->filterLengths=filterLengths;
  92. S->filterCoefs=filterCoefs;
  93. S->windowCoefs=windowCoefs;
  94. #if defined(ARM_MFCC_CFFT_BASED)
  95. status=arm_cfft_init_f16(&(S->cfft),fftLen);
  96. #else
  97. status=arm_rfft_fast_init_f16(&(S->rfft),fftLen);
  98. #endif
  99. return(status);
  100. }
  101. #if defined(ARM_MFCC_CFFT_BASED)
  102. #define MFCC_INIT_F16(LEN) \
  103. arm_status arm_mfcc_init_##LEN##_f16( \
  104. arm_mfcc_instance_f16 * S, \
  105. uint32_t nbMelFilters, \
  106. uint32_t nbDctOutputs, \
  107. const float16_t *dctCoefs, \
  108. const uint32_t *filterPos, \
  109. const uint32_t *filterLengths, \
  110. const float16_t *filterCoefs, \
  111. const float16_t *windowCoefs \
  112. ) \
  113. { \
  114. arm_status status; \
  115. \
  116. S->fftLen=LEN; \
  117. S->nbMelFilters=nbMelFilters; \
  118. S->nbDctOutputs=nbDctOutputs; \
  119. S->dctCoefs=dctCoefs; \
  120. S->filterPos=filterPos; \
  121. S->filterLengths=filterLengths; \
  122. S->filterCoefs=filterCoefs; \
  123. S->windowCoefs=windowCoefs; \
  124. \
  125. status=arm_cfft_init_##LEN##_f16(&(S->cfft));\
  126. \
  127. return(status); \
  128. }
  129. #else
  130. #define MFCC_INIT_F16(LEN) \
  131. arm_status arm_mfcc_init_##LEN##_f16( \
  132. arm_mfcc_instance_f16 * S, \
  133. uint32_t nbMelFilters, \
  134. uint32_t nbDctOutputs, \
  135. const float16_t *dctCoefs, \
  136. const uint32_t *filterPos, \
  137. const uint32_t *filterLengths, \
  138. const float16_t *filterCoefs, \
  139. const float16_t *windowCoefs \
  140. ) \
  141. { \
  142. arm_status status; \
  143. \
  144. S->fftLen=LEN; \
  145. S->nbMelFilters=nbMelFilters; \
  146. S->nbDctOutputs=nbDctOutputs; \
  147. S->dctCoefs=dctCoefs; \
  148. S->filterPos=filterPos; \
  149. S->filterLengths=filterLengths; \
  150. S->filterCoefs=filterCoefs; \
  151. S->windowCoefs=windowCoefs; \
  152. \
  153. status=arm_rfft_fast_init_##LEN##_f16(&(S->rfft));\
  154. \
  155. return(status); \
  156. }
  157. #endif
  158. /**
  159. @brief Initialization of the MFCC F16 instance structure for 32 samples MFCC
  160. @param[out] S points to the mfcc instance structure
  161. @param[in] nbMelFilters number of Mel filters
  162. @param[in] nbDctOutputs number of Dct outputs
  163. @param[in] dctCoefs points to an array of DCT coefficients
  164. @param[in] filterPos points of the array of filter positions
  165. @param[in] filterLengths points to the array of filter lengths
  166. @param[in] filterCoefs points to the array of filter coefficients
  167. @param[in] windowCoefs points to the array of window coefficients
  168. @return error status
  169. @par Description
  170. The matrix of Mel filter coefficients is sparse.
  171. Most of the coefficients are zero.
  172. To avoid multiplying the spectrogram by those zeros, the
  173. filter is applied only to a given position in the spectrogram
  174. and on a given number of FFT bins (the filter length).
  175. It is the reason for the arrays filterPos and filterLengths.
  176. window coefficients can describe (for instance) a Hamming window.
  177. The array has the same size as the FFT length.
  178. The folder Scripts is containing a Python script that can be used
  179. to generate the filter, dct and window arrays.
  180. */
  181. MFCC_INIT_F16(32)
  182. /**
  183. @brief Initialization of the MFCC F16 instance structure for 64 samples MFCC
  184. @param[out] S points to the mfcc instance structure
  185. @param[in] nbMelFilters number of Mel filters
  186. @param[in] nbDctOutputs number of Dct outputs
  187. @param[in] dctCoefs points to an array of DCT coefficients
  188. @param[in] filterPos points of the array of filter positions
  189. @param[in] filterLengths points to the array of filter lengths
  190. @param[in] filterCoefs points to the array of filter coefficients
  191. @param[in] windowCoefs points to the array of window coefficients
  192. @return error status
  193. @par Description
  194. The matrix of Mel filter coefficients is sparse.
  195. Most of the coefficients are zero.
  196. To avoid multiplying the spectrogram by those zeros, the
  197. filter is applied only to a given position in the spectrogram
  198. and on a given number of FFT bins (the filter length).
  199. It is the reason for the arrays filterPos and filterLengths.
  200. window coefficients can describe (for instance) a Hamming window.
  201. The array has the same size as the FFT length.
  202. The folder Scripts is containing a Python script that can be used
  203. to generate the filter, dct and window arrays.
  204. */
  205. MFCC_INIT_F16(64)
  206. /**
  207. @brief Initialization of the MFCC F16 instance structure for 128 samples MFCC
  208. @param[out] S points to the mfcc instance structure
  209. @param[in] nbMelFilters number of Mel filters
  210. @param[in] nbDctOutputs number of Dct outputs
  211. @param[in] dctCoefs points to an array of DCT coefficients
  212. @param[in] filterPos points of the array of filter positions
  213. @param[in] filterLengths points to the array of filter lengths
  214. @param[in] filterCoefs points to the array of filter coefficients
  215. @param[in] windowCoefs points to the array of window coefficients
  216. @return error status
  217. @par Description
  218. The matrix of Mel filter coefficients is sparse.
  219. Most of the coefficients are zero.
  220. To avoid multiplying the spectrogram by those zeros, the
  221. filter is applied only to a given position in the spectrogram
  222. and on a given number of FFT bins (the filter length).
  223. It is the reason for the arrays filterPos and filterLengths.
  224. window coefficients can describe (for instance) a Hamming window.
  225. The array has the same size as the FFT length.
  226. The folder Scripts is containing a Python script that can be used
  227. to generate the filter, dct and window arrays.
  228. */
  229. MFCC_INIT_F16(128)
  230. /**
  231. @brief Initialization of the MFCC F16 instance structure for 256 samples MFCC
  232. @param[out] S points to the mfcc instance structure
  233. @param[in] nbMelFilters number of Mel filters
  234. @param[in] nbDctOutputs number of Dct outputs
  235. @param[in] dctCoefs points to an array of DCT coefficients
  236. @param[in] filterPos points of the array of filter positions
  237. @param[in] filterLengths points to the array of filter lengths
  238. @param[in] filterCoefs points to the array of filter coefficients
  239. @param[in] windowCoefs points to the array of window coefficients
  240. @return error status
  241. @par Description
  242. The matrix of Mel filter coefficients is sparse.
  243. Most of the coefficients are zero.
  244. To avoid multiplying the spectrogram by those zeros, the
  245. filter is applied only to a given position in the spectrogram
  246. and on a given number of FFT bins (the filter length).
  247. It is the reason for the arrays filterPos and filterLengths.
  248. window coefficients can describe (for instance) a Hamming window.
  249. The array has the same size as the FFT length.
  250. The folder Scripts is containing a Python script that can be used
  251. to generate the filter, dct and window arrays.
  252. */
  253. MFCC_INIT_F16(256)
  254. /**
  255. @brief Initialization of the MFCC F16 instance structure for 512 samples MFCC
  256. @param[out] S points to the mfcc instance structure
  257. @param[in] nbMelFilters number of Mel filters
  258. @param[in] nbDctOutputs number of Dct outputs
  259. @param[in] dctCoefs points to an array of DCT coefficients
  260. @param[in] filterPos points of the array of filter positions
  261. @param[in] filterLengths points to the array of filter lengths
  262. @param[in] filterCoefs points to the array of filter coefficients
  263. @param[in] windowCoefs points to the array of window coefficients
  264. @return error status
  265. @par Description
  266. The matrix of Mel filter coefficients is sparse.
  267. Most of the coefficients are zero.
  268. To avoid multiplying the spectrogram by those zeros, the
  269. filter is applied only to a given position in the spectrogram
  270. and on a given number of FFT bins (the filter length).
  271. It is the reason for the arrays filterPos and filterLengths.
  272. window coefficients can describe (for instance) a Hamming window.
  273. The array has the same size as the FFT length.
  274. The folder Scripts is containing a Python script that can be used
  275. to generate the filter, dct and window arrays.
  276. */
  277. MFCC_INIT_F16(512)
  278. /**
  279. @brief Initialization of the MFCC F16 instance structure for 1024 samples MFCC
  280. @param[out] S points to the mfcc instance structure
  281. @param[in] nbMelFilters number of Mel filters
  282. @param[in] nbDctOutputs number of Dct outputs
  283. @param[in] dctCoefs points to an array of DCT coefficients
  284. @param[in] filterPos points of the array of filter positions
  285. @param[in] filterLengths points to the array of filter lengths
  286. @param[in] filterCoefs points to the array of filter coefficients
  287. @param[in] windowCoefs points to the array of window coefficients
  288. @return error status
  289. @par Description
  290. The matrix of Mel filter coefficients is sparse.
  291. Most of the coefficients are zero.
  292. To avoid multiplying the spectrogram by those zeros, the
  293. filter is applied only to a given position in the spectrogram
  294. and on a given number of FFT bins (the filter length).
  295. It is the reason for the arrays filterPos and filterLengths.
  296. window coefficients can describe (for instance) a Hamming window.
  297. The array has the same size as the FFT length.
  298. The folder Scripts is containing a Python script that can be used
  299. to generate the filter, dct and window arrays.
  300. */
  301. MFCC_INIT_F16(1024)
  302. /**
  303. @brief Initialization of the MFCC F16 instance structure for 2048 samples MFCC
  304. @param[out] S points to the mfcc instance structure
  305. @param[in] nbMelFilters number of Mel filters
  306. @param[in] nbDctOutputs number of Dct outputs
  307. @param[in] dctCoefs points to an array of DCT coefficients
  308. @param[in] filterPos points of the array of filter positions
  309. @param[in] filterLengths points to the array of filter lengths
  310. @param[in] filterCoefs points to the array of filter coefficients
  311. @param[in] windowCoefs points to the array of window coefficients
  312. @return error status
  313. @par Description
  314. The matrix of Mel filter coefficients is sparse.
  315. Most of the coefficients are zero.
  316. To avoid multiplying the spectrogram by those zeros, the
  317. filter is applied only to a given position in the spectrogram
  318. and on a given number of FFT bins (the filter length).
  319. It is the reason for the arrays filterPos and filterLengths.
  320. window coefficients can describe (for instance) a Hamming window.
  321. The array has the same size as the FFT length.
  322. The folder Scripts is containing a Python script that can be used
  323. to generate the filter, dct and window arrays.
  324. */
  325. MFCC_INIT_F16(2048)
  326. /**
  327. @brief Initialization of the MFCC F16 instance structure for 4096 samples MFCC
  328. @param[out] S points to the mfcc instance structure
  329. @param[in] nbMelFilters number of Mel filters
  330. @param[in] nbDctOutputs number of Dct outputs
  331. @param[in] dctCoefs points to an array of DCT coefficients
  332. @param[in] filterPos points of the array of filter positions
  333. @param[in] filterLengths points to the array of filter lengths
  334. @param[in] filterCoefs points to the array of filter coefficients
  335. @param[in] windowCoefs points to the array of window coefficients
  336. @return error status
  337. @par Description
  338. The matrix of Mel filter coefficients is sparse.
  339. Most of the coefficients are zero.
  340. To avoid multiplying the spectrogram by those zeros, the
  341. filter is applied only to a given position in the spectrogram
  342. and on a given number of FFT bins (the filter length).
  343. It is the reason for the arrays filterPos and filterLengths.
  344. window coefficients can describe (for instance) a Hamming window.
  345. The array has the same size as the FFT length.
  346. The folder Scripts is containing a Python script that can be used
  347. to generate the filter, dct and window arrays.
  348. */
  349. MFCC_INIT_F16(4096)
  350. #endif /* defined(ARM_FLOAT16_SUPPORTED) */
  351. /**
  352. @} end of MFCCF16 group
  353. */