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