Audio: MFCC: Remove the debug file operations from C code

Remove the debug file operations from C code, and will add
a similar matlab script in the future.

Signed-off-by: Andrula Song <andrula.song@intel.com>
This commit is contained in:
Andrula Song 2023-08-18 10:52:40 +08:00 committed by Liam Girdwood
parent 17ccaf51e5
commit bd35cebc0e
3 changed files with 2 additions and 178 deletions

View File

@ -30,59 +30,7 @@
#endif
#define MFCC_NORMALIZE_MAX_SHIFT 10
/* Open files for data debug output in testbench */
#define DEBUG_WITH_TESTBENCH
#if defined(CONFIG_LIBRARY) && defined(DEBUG_WITH_TESTBENCH)
#include <stdio.h>
#define DEBUGFILES
#undef DEBUGFILES_READ_FFT /* Override FFT out with file input */
#undef DEBUGFILES_READ_MEL /* Override Mel filterbank with file input */
#endif
#ifdef MFCC_DEBUGFILES
#ifdef DEBUGFILES_READ_FFT
FILE *fh_fft_out_read;
#endif
#ifdef DEBUGFILES_READ_MEL
FILE *fh_mel_read;
#endif
FILE *fh_fft_in;
FILE *fh_fft_out;
FILE *fh_pow;
FILE *fh_mel;
FILE *fh_ceps;
void mfcc_generic_debug_open(void)
{
#ifdef DEBUGFILES_READ_FFT
fh_fft_out_read = fopen("ref_fft_out.txt", "r");
#endif
#ifdef DEBUGFILES_READ_MEL
fh_mel_read = fopen("ref_fft_mel.txt", "r");
#endif
fh_fft_in = fopen("fft_in.txt", "w");
fh_fft_out = fopen("fft_out.txt", "w");
fh_pow = fopen("fft_pow.txt", "w");
fh_mel = fopen("fft_mel.txt", "w");
fh_ceps = fopen("ceps.txt", "w");
}
void mfcc_generic_debug_close(void)
{
#ifdef DEBUGFILES_READ_FFT
fclose(fh_fft_out_read);
#endif
#ifdef DEBUGFILES_READ_MEL
fclose(fh_mel_read);
#endif
fclose(fh_fft_in);
fclose(fh_fft_out);
fclose(fh_pow);
fclose(fh_mel);
fclose(fh_ceps);
}
#endif
LOG_MODULE_REGISTER(mfcc_generic, CONFIG_SOF_LOG_LEVEL);
/*
* MFCC algorithm code
*/
@ -262,9 +210,6 @@ static int mfcc_stft_process(const struct comp_dev *dev, struct mfcc_state *stat
int i;
int m;
int cc_count = 0;
#ifdef DEBUGFILES
int j;
#endif
/* Phase 1, wait until whole fft_size is filled with valid data. This way
* first output cepstral coefficients originate from streamed data and not
@ -311,11 +256,6 @@ static int mfcc_stft_process(const struct comp_dev *dev, struct mfcc_state *stat
/* TODO: use_energy & !raw_energy */
#ifdef DEBUGFILES
for (j = 0; j < fft->fft_padded_size; j++)
fprintf(fh_fft_in, "%d %d\n", fft->fft_buf[j].real, fft->fft_buf[j].imag);
#endif
/* The FFT out buffer needs to be cleared to avoid to corrupt
* the output. TODO: check moving it to FFT lib.
*/
@ -328,24 +268,6 @@ static int mfcc_stft_process(const struct comp_dev *dev, struct mfcc_state *stat
fft_execute_32(fft->fft_plan, false);
#endif
#ifdef DEBUGFILES_READ_FFT
double re, im;
int ret;
for (j = 0; j < fft->half_fft_size; j++) {
ret = fscanf(fh_fft_out_read, "%lf %lf", &re, &im);
if (ret != 2)
break;
fft->fft_out[j].real = sat_int16((int32_t)(32768.0 * re));
fft->fft_out[j].imag = sat_int16((int32_t)(32768.0 * im));
}
#endif
#ifdef DEBUGFILES
for (j = 0; j < fft->half_fft_size; j++)
fprintf(fh_fft_out, "%d %d\n", fft->fft_out[j].real, fft->fft_out[j].imag);
#endif
/* Convert powerspectrum to Mel band logarithmic spectrum */
mat_init_16b(state->mel_spectra, 1, state->dct.num_in, 7); /* Q8.7 */
@ -361,18 +283,6 @@ static int mfcc_stft_process(const struct comp_dev *dev, struct mfcc_state *stat
psy_apply_mel_filterbank_32(&state->melfb, fft->fft_out, state->power_spectra,
state->mel_spectra->data, mel_scale_shift);
#endif
#ifdef DEBUGFILES_READ_MEL
double val;
int tmp;
for (j = 0; j < state->dct.num_in; j++) {
tmp = fscanf(fh_mel_read, "%lf", &val);
if (tmp != 1)
break;
state->mel_spectra->data[j] = sat_int16((int32_t)(128.0 * val));
}
#endif
/* Multiply Mel spectra with DCT matrix to get cepstral coefficients */
mat_init_16b(state->cepstral_coef, 1, state->dct.num_out, 7); /* Q8.7 */
@ -386,17 +296,6 @@ static int mfcc_stft_process(const struct comp_dev *dev, struct mfcc_state *stat
cc_count += state->dct.num_out;
/* Output to sink buffer */
#ifdef DEBUGFILES
for (j = 0; j < fft->half_fft_size; j++)
fprintf(fh_pow, "%d\n", state->power_spectra[j]);
for (j = 0; j < state->dct.num_in; j++)
fprintf(fh_mel, " %d\n", state->mel_spectra->data[j]);
for (j = 0; j < state->dct.num_out; j++)
fprintf(fh_ceps, " %d\n", state->cepstral_coef->data[j]);
#endif
}
/* TODO: This version handles only one FFT run per copy(). How to pass multiple

View File

@ -16,42 +16,12 @@
#include <stddef.h>
#include <stdint.h>
#define DEBUG_WITH_TESTBENCH
#if defined(CONFIG_LIBRARY) && defined(DEBUG_WITH_TESTBENCH)
#define DEBUGFILES
#endif
#ifdef DEBUGFILES
#include <stdio.h>
FILE *fh_window;
FILE *fh_triangles;
FILE *fh_dct;
FILE *fh_lifter;
#endif
/* Definitions for cepstral lifter */
#define PI_Q23 Q_CONVERT_FLOAT(3.1415926536, 23)
#define TWO_PI_Q23 Q_CONVERT_FLOAT(6.2831853072, 23)
#define ONE_Q9 Q_CONVERT_FLOAT(1, 9)
#ifdef MFCC_DEBUGFILES
static void mfcc_init_debug_open(void)
{
fh_window = fopen("fft_win.txt", "w");
fh_triangles = fopen("mel_triangles.txt", "w");
fh_dct = fopen("dct_matrix.txt", "w");
fh_lifter = fopen("lifter.txt", "w");
}
static void mfcc_init_debug_close(void)
{
fclose(fh_window);
fclose(fh_triangles);
fclose(fh_dct);
fclose(fh_lifter);
}
#endif
LOG_MODULE_REGISTER(mfcc_setup, CONFIG_SOF_LOG_LEVEL);
static void mfcc_init_buffer(struct mfcc_buffer *buf, int16_t *base, int size)
{
@ -138,11 +108,6 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
struct dct_plan_16 *dct = &state->dct;
int ret;
#ifdef MFCC_DEBUGFILES
mfcc_init_debug_open();
mfcc_generic_debug_open();
#endif
comp_dbg(dev, "mfcc_setup()");
/* Check size */
@ -326,31 +291,6 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
state->cepstral_coef = (struct mat_matrix_16b *)
&state->mel_spectra->data[state->dct.num_in];
#ifdef DEBUGFILES
int i, j;
for (i = 0; i < fft->fft_size; i++)
fprintf(fh_window, "%d\n", state->window[i]);
fprintf(fh_triangles, "%d\n", fb->mel_bins);
fprintf(fh_triangles, "%d\n", fb->half_fft_bins);
fprintf(fh_triangles, "%d\n", fb->scale_log2);
for (i = 0; i < fb->data_length; i++)
fprintf(fh_triangles, "%d\n", fb->data[i]);
for (i = 0; i < dct->num_in; i++) {
for (j = 0; j < dct->num_out; j++)
fprintf(fh_dct, " %d", mat_get_scalar_16b(dct->matrix, i, j));
fprintf(fh_dct, "\n");
}
for (j = 0; j < dct->num_out; j++)
fprintf(fh_lifter, "%d\n", mat_get_scalar_16b(state->lifter.matrix, 0, j));
mfcc_init_debug_close();
#endif
/* Set initial state for STFT */
state->waiting_fill = true;
state->prev_samples_valid = false;
@ -386,8 +326,4 @@ void mfcc_free_buffers(struct mfcc_comp_data *cd)
rfree(cd->state.melfb.data);
rfree(cd->state.dct.matrix);
rfree(cd->state.lifter.matrix);
#ifdef MFCC_DEBUGFILES
mfcc_generic_debug_close();
#endif
}

View File

@ -15,12 +15,6 @@
#include <stddef.h>
#include <stdint.h>
#define MFCC_DEBUG_WITH_TESTBENCH
#if defined(CONFIG_LIBRARY) && defined(MFCC_DEBUG_WITH_TESTBENCH)
#define MFCC_DEBUGFILES
#endif
#define MFCC_MAGIC 0x6d666363 /* ASCII for "mfcc" */
/* Set to 16 for lower RAM and MCPS with slightly lower quality. Set to 32 for best
@ -142,11 +136,6 @@ void mfcc_free_buffers(struct mfcc_comp_data *cd);
void mfcc_s16_default(struct processing_module *mod, struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink, int frames);
#ifdef MFCC_DEBUGFILES
void mfcc_generic_debug_open(void);
void mfcc_generic_debug_close(void);
#endif
#ifdef UNIT_TEST
void sys_comp_mfcc_init(void);
#endif