arm_mfcc_f16.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mfcc_f16.c
  4. * Description: MFCC 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. #include "dsp/transform_functions_f16.h"
  29. #include "dsp/statistics_functions_f16.h"
  30. #include "dsp/basic_math_functions_f16.h"
  31. #include "dsp/complex_math_functions_f16.h"
  32. #include "dsp/fast_math_functions_f16.h"
  33. #include "dsp/matrix_functions_f16.h"
  34. #if defined(ARM_FLOAT16_SUPPORTED)
  35. /**
  36. @ingroup groupTransforms
  37. */
  38. /**
  39. @defgroup MFCC MFCC
  40. MFCC Transform
  41. There are separate functions for floating-point, Q15, and Q31 data types.
  42. */
  43. /**
  44. @addtogroup MFCC
  45. @{
  46. */
  47. /**
  48. @brief MFCC F16
  49. @param[in] S points to the mfcc instance structure
  50. @param[in] pSrc points to the input samples
  51. @param[out] pDst points to the output MFCC values
  52. @param[inout] pTmp points to a temporary buffer of complex
  53. @return none
  54. @par Description
  55. The number of input samples if the FFT length used
  56. when initializing the instance data structure.
  57. The temporary buffer has a 2*fft length size when MFCC
  58. is implemented with CFFT.
  59. It has length FFT Length + 2 when implemented with RFFT
  60. (default implementation).
  61. The source buffer is modified by this function.
  62. */
  63. void arm_mfcc_f16(
  64. const arm_mfcc_instance_f16 * S,
  65. float16_t *pSrc,
  66. float16_t *pDst,
  67. float16_t *pTmp
  68. )
  69. {
  70. float16_t maxValue;
  71. uint32_t index;
  72. uint32_t i;
  73. float16_t result;
  74. const float16_t *coefs=S->filterCoefs;
  75. arm_matrix_instance_f16 pDctMat;
  76. /* Normalize */
  77. arm_absmax_f16(pSrc,S->fftLen,&maxValue,&index);
  78. arm_scale_f16(pSrc,1.0f16/(_Float16)maxValue,pSrc,S->fftLen);
  79. /* Multiply by window */
  80. arm_mult_f16(pSrc,S->windowCoefs,pSrc,S->fftLen);
  81. /* Compute spectrum magnitude
  82. */
  83. #if defined(ARM_MFCC_CFFT_BASED)
  84. /* some HW accelerator for CMSIS-DSP used in some boards
  85. are only providing acceleration for CFFT.
  86. With ARM_MFCC_CFFT_BASED enabled, CFFT is used and the MFCC
  87. will be accelerated on those boards.
  88. The default is to use RFFT
  89. */
  90. /* Convert from real to complex */
  91. for(i=0; i < S->fftLen ; i++)
  92. {
  93. pTmp[2*i] = pSrc[i];
  94. pTmp[2*i+1] = 0.0f16;
  95. }
  96. arm_cfft_f16(&(S->cfft),pTmp,0,1);
  97. #else
  98. /* Default RFFT based implementation */
  99. arm_rfft_fast_f16(&(S->rfft),pSrc,pTmp,0);
  100. /* Unpack real values */
  101. pTmp[S->fftLen]=pTmp[1];
  102. pTmp[S->fftLen+1]=0.0f16;
  103. pTmp[1]=0.0f;
  104. #endif
  105. arm_cmplx_mag_f16(pTmp,pSrc,S->fftLen);
  106. /* Apply MEL filters */
  107. for(i=0; i<S->nbMelFilters; i++)
  108. {
  109. arm_dot_prod_f16(pSrc+S->filterPos[i],
  110. coefs,
  111. S->filterLengths[i],
  112. &result);
  113. coefs += S->filterLengths[i];
  114. pTmp[i] = result;
  115. }
  116. /* Compute the log */
  117. arm_offset_f16(pTmp,1.0e-4f16,pTmp,S->nbMelFilters);
  118. arm_vlog_f16(pTmp,pTmp,S->nbMelFilters);
  119. /* Multiply with the DCT matrix */
  120. pDctMat.numRows=S->nbDctOutputs;
  121. pDctMat.numCols=S->nbMelFilters;
  122. pDctMat.pData=(float16_t*)S->dctCoefs;
  123. arm_mat_vec_mult_f16(&pDctMat, pTmp, pDst);
  124. }
  125. #endif /* defined(ARM_FLOAT16_SUPPORTED) */
  126. /**
  127. @} end of MFCC group
  128. */