GenMFCCDataForCPP.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ###########################################
  2. # Project: CMSIS DSP Library
  3. # Title: GenMFCCDataForCPP.py
  4. # Description: Generation of MFCC arrays for the MFCC function
  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. # This script is generating arrays required by the MFCC implementation:
  31. # DCT coefficients and Mel filters
  32. # Those arrays must be used with the arm_mfcc_init functions
  33. # The configuration is done through a yaml file describing the values for the
  34. # MFCC and the type
  35. #
  36. import argparse
  37. import yaml
  38. import mfccdata
  39. import os.path
  40. parser = argparse.ArgumentParser(description='Generate MFCC Data for CPP')
  41. parser.add_argument('-n', nargs='?',type = str, default="mfccdata", help="mfcc file name")
  42. parser.add_argument('-d', nargs='?',type = str, default="Testing/Source/Tests", help="mfcc c file directory")
  43. parser.add_argument('-i', nargs='?',type = str, default="Testing/Include/Tests", help="mfcc h file directory")
  44. parser.add_argument('others', help="yaml configuration file", nargs=argparse.REMAINDER)
  45. args = parser.parse_args()
  46. if args.n and args.d and args.others:
  47. cpath=os.path.join(args.d,args.n + ".c")
  48. hpath=os.path.join(args.i,args.n + ".h")
  49. with open(args.others[0],"r") as f:
  50. configs=yaml.safe_load(f)
  51. mfccdata.checkF16(configs)
  52. mfccdata.prepareDctconfig(configs["dct"])
  53. mfccdata.prepareMelconfig(configs["melfilter"])
  54. mfccdata.prepareWindowConfig(configs["window"])
  55. with open(hpath,"w") as h:
  56. mfccdata.genMfccHeader(h,configs,args.n)
  57. with open(cpath,"w") as c:
  58. mfccdata.genMfccInit(c,configs,args.n)