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