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