MFCC.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: MFCC.h
  4. * Description: Node for CMSIS-DSP MFCC
  5. *
  6. * $Date: 06 October 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. #ifndef _MFCC_H_
  29. #define _MFCC_H_
  30. #include <vector>
  31. template<typename IN, int inputSize,typename OUT,int outputSize>
  32. class MFCC;
  33. /*
  34. The MFCC configuration data has to be generated with the script DSP/Scripts/GenMFCCDataForCPP.py.
  35. It is using a yaml file to describe the configuration
  36. */
  37. /*
  38. The CMSIS-DSP MFCC F32
  39. */
  40. template<int inputSize,int outputSize>
  41. class MFCC<float32_t,inputSize,float32_t,outputSize>: public GenericNode<float32_t,inputSize,float32_t,outputSize>
  42. {
  43. public:
  44. MFCC(FIFOBase<float32_t> &src,FIFOBase<float32_t> &dst,const arm_mfcc_instance_f32 *config):GenericNode<float32_t,inputSize,float32_t,outputSize>(src,dst){
  45. mfccConfig = config;
  46. #if defined(ARM_MFCC_CFFT_BASED)
  47. memory.resize(2*inputSize);
  48. #else
  49. memory.resize(inputSize + 2);
  50. #endif
  51. };
  52. int run(){
  53. float32_t *a=this->getReadBuffer();
  54. float32_t *b=this->getWriteBuffer();
  55. arm_mfcc_f32(mfccConfig,a,b,memory.data());
  56. return(0);
  57. };
  58. const arm_mfcc_instance_f32 *mfccConfig;
  59. std::vector<float32_t> memory;
  60. };
  61. #if defined(ARM_FLOAT16_SUPPORTED)
  62. /*
  63. The CMSIS-DSP MFCC F16
  64. */
  65. template<int inputSize,int outputSize>
  66. class MFCC<float16_t,inputSize,float16_t,outputSize>: public GenericNode<float16_t,inputSize,float16_t,outputSize>
  67. {
  68. public:
  69. MFCC(FIFOBase<float16_t> &src,FIFOBase<float16_t> &dst,const arm_mfcc_instance_f16 *config):GenericNode<float16_t,inputSize,float16_t,outputSize>(src,dst){
  70. mfccConfig = config;
  71. #if defined(ARM_MFCC_CFFT_BASED)
  72. memory.resize(2*inputSize);
  73. #else
  74. memory.resize(inputSize + 2);
  75. #endif
  76. };
  77. int run(){
  78. float16_t *a=this->getReadBuffer();
  79. float16_t *b=this->getWriteBuffer();
  80. arm_mfcc_f16(mfccConfig,a,b,memory.data());
  81. return(0);
  82. };
  83. const arm_mfcc_instance_f16 *mfccConfig;
  84. std::vector<float16_t> memory;
  85. };
  86. #endif
  87. /*
  88. The CMSIS-DSP MFCC Q31
  89. */
  90. template<int inputSize,int outputSize>
  91. class MFCC<q31_t,inputSize,q31_t,outputSize>: public GenericNode<q31_t,inputSize,q31_t,outputSize>
  92. {
  93. public:
  94. MFCC(FIFOBase<q31_t> &src,FIFOBase<q31_t> &dst,const arm_mfcc_instance_q31 *config):GenericNode<q31_t,inputSize,q31_t,outputSize>(src,dst){
  95. mfccConfig = config;
  96. memory.resize(2*inputSize);
  97. };
  98. int run(){
  99. q31_t *a=this->getReadBuffer();
  100. q31_t *b=this->getWriteBuffer();
  101. arm_mfcc_q31(mfccConfig,a,b,memory.data());
  102. return(0);
  103. };
  104. const arm_mfcc_instance_q31 *mfccConfig;
  105. std::vector<q31_t> memory;
  106. };
  107. /*
  108. The CMSIS-DSP MFCC Q15
  109. */
  110. template<int inputSize,int outputSize>
  111. class MFCC<q15_t,inputSize,q15_t,outputSize>: public GenericNode<q15_t,inputSize,q15_t,outputSize>
  112. {
  113. public:
  114. MFCC(FIFOBase<q15_t> &src,FIFOBase<q15_t> &dst,const arm_mfcc_instance_q15 *config):GenericNode<q15_t,inputSize,q15_t,outputSize>(src,dst){
  115. mfccConfig = config;
  116. memory.resize(2*inputSize);
  117. };
  118. int run(){
  119. q15_t *a=this->getReadBuffer();
  120. q15_t *b=this->getWriteBuffer();
  121. arm_mfcc_q15(mfccConfig,a,b,memory.data());
  122. return(0);
  123. };
  124. const arm_mfcc_instance_q15 *mfccConfig;
  125. std::vector<q31_t> memory;
  126. };
  127. #endif