Skip to content

Commit

Permalink
Ported to new MFCC
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-fariselli committed Jun 8, 2021
1 parent f844407 commit 3d6fb66
Show file tree
Hide file tree
Showing 47 changed files with 42,007 additions and 210 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
BUILD*
*.dat
nntool_script
*_emul
samples/speech_dataset
*__pycache__*
Expand Down
8 changes: 0 additions & 8 deletions MFCC_params_LARGE.h → MFCC_params.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#define SAMPLERATE 16000
#define PREEMP_FACTOR 0.0
#define FRAME_SIZE 640
#define FRAME_STEP 320
#define N_FRAME 49
#define N_FFT 1024
#define USE_RADIX_4 0
#define DATA_TYPE 0
#define USE_POWER 1
#define OUT_FFT 0
#define MFCC_BANK_CNT 40
#define FMIN 20.0
#define FMAX 4000.0
#define MFCC_COEFF_CNT 494
#define N_DCT 40
#define OUTPUT_MELSPECTROGRAM 0
#define LIFTER_COEFF 0
#define USE_DB 0
18 changes: 0 additions & 18 deletions MFCC_params_MEDIUM.h

This file was deleted.

18 changes: 0 additions & 18 deletions MFCC_params_SMALL.h

This file was deleted.

24 changes: 7 additions & 17 deletions MFCCmodel.c
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
#include "AutoTilerLib.h"
#include "AutoTilerLibTypes.h"
#include "MfccGenerator.h"
#ifdef SMALL
#include "MFCC_params_SMALL.h"
#endif
#ifdef MEDIUM
#include "MFCC_params_MEDIUM.h"
#endif
#ifdef LARGE
#include "MFCC_params_LARGE.h"
#endif

#include "DSP_Generators.h"
#include "MFCC_params.h"

void MFCCConfiguration(unsigned int L1Memory)
{
SetInlineMode(ALWAYS_INLINE);
SetSymbolDynamics();
SetSymbolDynamics();

SetUsedFilesNames(0, 1, "MfccBasicKernels.h");
SetUsedFilesNames(0, 3, "MfccBasicKernels.h", "CmplxFunctions.h", "PreProcessing.h");
SetGeneratedFilesNames("MFCCKernels.c", "MFCCKernels.h");

SetL1MemorySize(L1Memory);
}

int main(int argc, char **argv)
{
if (TilerParseOptions(argc, argv)) GenTilingError("Failed to initialize or incorrect output arguments directory.\n");
if (TilerParseOptions(argc, argv)) GenTilingError("Failed to initialize or incorrect output arguments directory.\n");

// Set Auto Tiler configuration, given shared L1 memory is 51200
MFCCConfiguration(51200);
MFCCConfiguration(64*1024);
// Load FIR basic kernels
LoadMFCCLibrary();
MFCC_Generator("MFCC", 0, N_FRAME, FRAME_SIZE, FRAME_STEP, N_FFT, MFCC_COEFF_CNT, N_DCT, PREEMP_FACTOR, LIFTER_COEFF, USE_RADIX_4, USE_POWER, DATA_TYPE, MFCC_BANK_CNT, 0, 0);
//MFCC_Generator("MFCC_single", 0, 1, FRAME_SIZE, FRAME_STEP, N_FFT, MFCC_COEFF_CNT, N_DCT, PREEMP_FACTOR, LIFTER_COEFF, USE_RADIX_4, USE_POWER, DATA_TYPE, MFCC_BANK_CNT, 0, 0);
MFCC_Generator("MFCC", 0, 49, FRAME_SIZE, FRAME_STEP, N_FFT, MFCC_BANK_CNT, MFCC_COEFF_CNT, N_DCT, 0, 0, 0, USE_POWER, DATA_TYPE, 1, 0);
GenerateTilingCode();
}
45 changes: 16 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ QUANT_BITS=8
BUILD_DIR=BUILD

#MODEL_NE16 ?= 0
NNTOOL_SCRIPT_PARAMETRIC=model/nntool_script_params
MODEL_SUFFIX = _$(QUANT_BITS)BIT
NNTOOL_SCRIPT=model/nntool_script
MODEL_SUFFIX = _SQ$(QUANT_BITS)
ifeq ($(MODEL_NE16), 1)
NNTOOL_SCRIPT_PARAMETRIC=model/nntool_script_ne16_params
NNTOOL_SCRIPT=model/nntool_script_ne16
MODEL_SUFFIX = _NE16
endif
ifeq ($(DUMP_TENSORS), 1)
NNTOOL_SET_GRAPH_DUMP = set graph_dump_tensor 7
endif
NNTOOL_EXTRA_FLAGS = -q
MODEL_BUILD = BUILD_MODEL_$(QUANT_BITS)BIT
MODEL_BUILD = BUILD_MODEL$(MODEL_SUFFIX)

CLUSTER_STACK_SIZE=4096
CLUSTER_SLAVE_STACK_SIZE=1024
Expand All @@ -83,26 +80,24 @@ endif
FREQ_FC?=250
VOLTAGE?=1.2

include common/model_decl.mk
ifeq ($(USE_POWER), 1)
# override the tflite model name to the one which expects power MFCC -> more efficient
TRAINED_TFLITE_MODEL=model/$(MODEL_PREFIX)_power.tflite
TRAINED_MODEL=model/$(MODEL_PREFIX)_power.tflite
else
TRAINED_MODEL=model/$(MODEL_PREFIX).tflite
endif
include common/model_decl.mk
include mfcc_model.mk


ifeq ($(WITH_MFCC), 1)
APP_SRCS += main_with_mfcc.c $(MODEL_GEN_C) $(MODEL_COMMON_SRCS) $(CNN_LIB)
APP_SRCS += $(GAP_LIB_PATH)/wav_io/wavIO.c $(MFCC_KER_SRCS) $(MFCCBUILD_DIR)/MFCCKernels.c
APP_SRCS += $(GAP_LIB_PATH)/wav_io/wavIO.c $(MFCCBUILD_DIR)/MFCCKernels.c $(TILER_DSP_KERNEL_PATH)/LUT_Tables/TwiddlesDef.c $(TILER_DSP_KERNEL_PATH)/LUT_Tables/RFFTTwiddlesDef.c $(TILER_DSP_KERNEL_PATH)/LUT_Tables/SwapTablesDef.c
APP_SRCS += $(TILER_DSP_KERNEL_PATH)/MfccBasicKernels.c $(TILER_DSP_KERNEL_PATH)/FFT_Library.c $(TILER_DSP_KERNEL_PATH)/CmplxFunctions.c $(TILER_DSP_KERNEL_PATH)/PreProcessing.c
APP_CFLAGS += -I$(MFCC_GENERATOR) -I$(MFCCBUILD_DIR)
else
APP_SRCS += main.c $(MODEL_GEN_C) $(MODEL_COMMON_SRCS) $(CNN_LIB)
endif
ifeq ($(USE_POWER), 0)
APP_CFLAGS += -DUSE_ABS
endif
ifeq ($(USE_HIGH_PREC), 1)
APP_CFLAGS += -DHIGH_PREC_FFT
endif
ifeq ($(PMSIS_OS), freertos)
APP_CFLAGS += -DFREERTOS
endif
Expand All @@ -111,7 +106,7 @@ APP_CFLAGS += -O3 -s -mno-memcpy -fno-tree-loop-distribute-patterns
APP_CFLAGS += -I. -I$(MODEL_COMMON_INC) -I$(TILER_EMU_INC) -I$(TILER_INC) -I$(MODEL_BUILD) $(CNN_LIB_INCLUDE)
APP_CFLAGS += -DAT_MODEL_PREFIX=$(MODEL_PREFIX) $(MODEL_SIZE_CFLAGS)
APP_CFLAGS += -DSTACK_SIZE=$(CLUSTER_STACK_SIZE) -DSLAVE_STACK_SIZE=$(CLUSTER_SLAVE_STACK_SIZE) -DFREQ_FC=$(FREQ_FC) -DFREQ_CL=$(FREQ_CL) -DVOLTAGE=$(VOLTAGE)
APP_CFLAGS += -DAT_IMAGE=$(IMAGE) -DAT_WAV=$(WAV_PATH) #-DWRITE_WAV #-DPRINT_AT_INPUT #-DPRINT_WAV
APP_CFLAGS += -DAT_IMAGE=$(IMAGE) -DAT_WAV=$(WAV_PATH)

ifeq ($(USE_MIC_SENSORBOARD), 1)
APP_CFLAGS += -DFROM_SENSOR -DSILENT
Expand All @@ -127,26 +122,18 @@ generate_samples:
python3 utils/generate_samples_images.py --dct_coefficient_count $(DCT_COUNT) --window_size_ms $(FRAME_SIZE_ms) --window_stride_ms $(FRAME_STEP_ms)

test_accuracy:
python3 utils/test_accuracy_emul.py --tflite_model $(TRAINED_TFLITE_MODEL) --dct_coefficient_count $(DCT_COUNT) --window_size_ms $(FRAME_SIZE_ms) --window_stride_ms $(FRAME_STEP_ms) --test_with_wav $(WITH_MFCC) --use_power_spectrogram $(USE_POWER) --use_high_prec $(USE_HIGH_PREC)
python3 utils/test_accuracy_emul.py --tflite_model $(TRAINED_MODEL) --dct_coefficient_count $(DCT_COUNT) --window_size_ms $(FRAME_SIZE_ms) --window_stride_ms $(FRAME_STEP_ms) --test_with_wav $(WITH_MFCC) --use_power_spectrogram $(USE_POWER)

test_accuracy_tflite:
python3 utils/test_accuracy_tflite.py --tflite_model $(TRAINED_TFLITE_MODEL) --dct_coefficient_count $(DCT_COUNT) --window_size_ms $(FRAME_SIZE_ms) --window_stride_ms $(FRAME_STEP_ms) --use_power_spectrogram $(USE_POWER)
python3 utils/test_accuracy_tflite.py --tflite_model $(TRAINED_MODEL) --dct_coefficient_count $(DCT_COUNT) --window_size_ms $(FRAME_SIZE_ms) --window_stride_ms $(FRAME_STEP_ms) --use_power_spectrogram $(USE_POWER)

# all depends on the model
all:: model mfcc_model

clean:: clean_model clean_mfcc_model
all:: $(MFCCBUILD_DIR)/MFCCKernels.c model

clean_at_model:
$(RM) $(MODEL_GEN_EXE)
clean:: clean_model clean_mfcc_code

at_model_disp:: $(MODEL_BUILD) $(MODEL_GEN_EXE)
$(MODEL_GEN_EXE) -o $(MODEL_BUILD) -c $(MODEL_BUILD) $(MODEL_GEN_EXTRA_FLAGS) --debug=Disp

at_model:: $(MODEL_BUILD) $(MODEL_GEN_EXE)
$(MODEL_GEN_EXE) -o $(MODEL_BUILD) -c $(MODEL_BUILD) $(MODEL_GEN_EXTRA_FLAGS)

include common/model_rules.mk
include mfcc_model.mk

include $(GAP_SDK_HOME)/tools/rules/pmsis_rules.mk
12 changes: 12 additions & 0 deletions MfccConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"n_fft": 1024,
"frame_size": 640,
"frame_step": 320,
"sample_rate": 16000,
"mfcc_bank_cnt": 40,
"n_dct": 40,
"fmin": 20.0,
"fmax": 4000.0,
"dtype": "fix16",
"use_tf_mfcc": true
}
12 changes: 12 additions & 0 deletions MfccConfig_HighPrec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"n_fft": 1024,
"frame_size": 640,
"frame_step": 320,
"sample_rate": 16000,
"mfcc_bank_cnt": 40,
"n_dct": 40,
"fmin": 20.0,
"fmax": 4000.0,
"dtype": "fix32_scal",
"use_tf_mfcc": true
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3d6fb66

Please sign in to comment.