Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/audio/mfcc/mfcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,32 @@ static int mfcc_init(struct processing_module *mod)
return -EINVAL;
}

cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
cd = mod_zalloc(mod, sizeof(*cd));
if (!cd)
return -ENOMEM;

/* Handler for configuration data */
md->private = cd;
cd->model_handler = comp_data_blob_handler_new(dev);
cd->model_handler = mod_data_blob_handler_new(mod);
if (!cd->model_handler) {
comp_err(dev, "comp_data_blob_handler_new() failed.");
ret = -ENOMEM;
goto err;
return -ENOMEM;
}

/* Get configuration data */
ret = comp_init_data_blob(cd->model_handler, bs, cfg->init_data);
if (ret < 0) {
comp_err(mod->dev, "comp_init_data_blob() failed.");
goto err_init;
return ret;
}

return 0;

err_init:
comp_data_blob_handler_free(cd->model_handler);

err:
rfree(cd);
return ret;
}

static int mfcc_free(struct processing_module *mod)
{
struct mfcc_comp_data *cd = module_get_private_data(mod);

comp_info(mod->dev, "mfcc_free()");
comp_data_blob_handler_free(cd->model_handler);
mfcc_free_buffers(cd);
rfree(cd);
mfcc_free_buffers(mod);
return 0;
}

Expand Down
77 changes: 28 additions & 49 deletions src/audio/mfcc/mfcc_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int mfcc_get_window(struct mfcc_state *state, enum sof_mfcc_fft_window_ty
* coef[i] = 1.0 + 0.5 * lifter * sin(pi * i / lifter), i = 0 to num_ceps-1
*/

static int mfcc_get_cepstral_lifter(struct mfcc_cepstral_lifter *cl)
static int mfcc_get_cepstral_lifter(struct processing_module *mod, struct mfcc_cepstral_lifter *cl)
{
int32_t inv_cepstral_lifter;
int32_t val;
Expand All @@ -75,7 +75,7 @@ static int mfcc_get_cepstral_lifter(struct mfcc_cepstral_lifter *cl)
if (cl->num_ceps > DCT_MATRIX_SIZE_MAX)
return -EINVAL;

cl->matrix = mat_matrix_alloc_16b(1, cl->num_ceps, 9); /* Use Q7.9 */
cl->matrix = mod_mat_matrix_alloc_16b(mod, 1, cl->num_ceps, 9); /* Use Q7.9 */
if (!cl->matrix)
return -ENOMEM;

Expand Down Expand Up @@ -171,12 +171,10 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
comp_info(dev, "mfcc_setup(), buffer_size = %d, prev_size = %d",
state->buffer_size, state->prev_data_size);

state->buffers = rzalloc(SOF_MEM_FLAG_USER,
state->sample_buffers_size);
state->buffers = mod_zalloc(mod, state->sample_buffers_size);
if (!state->buffers) {
comp_err(dev, "Failed buffer allocate");
ret = -ENOMEM;
goto exit;
return -ENOMEM;
}

mfcc_init_buffer(&state->buf, state->buffers, state->buffer_size);
Expand All @@ -189,29 +187,26 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
#else
fft->fft_buffer_size = fft->fft_padded_size * sizeof(struct icomplex32);
#endif
fft->fft_buf = rzalloc(SOF_MEM_FLAG_USER, fft->fft_buffer_size);
fft->fft_buf = mod_zalloc(mod, fft->fft_buffer_size);
if (!fft->fft_buf) {
comp_err(dev, "Failed FFT buffer allocate");
ret = -ENOMEM;
goto free_buffers;
return -ENOMEM;
}

fft->fft_out = rzalloc(SOF_MEM_FLAG_USER, fft->fft_buffer_size);
fft->fft_out = mod_zalloc(mod, fft->fft_buffer_size);
if (!fft->fft_out) {
comp_err(dev, "Failed FFT output allocate");
ret = -ENOMEM;
goto free_fft_buf;
return -ENOMEM;
}

fft->fft_fill_start_idx = 0; /* From config pad_type */

/* Setup FFT */
fft->fft_plan = fft_plan_new(fft->fft_buf, fft->fft_out, fft->fft_padded_size,
MFCC_FFT_BITS);
fft->fft_plan = mod_fft_plan_new(mod, fft->fft_buf, fft->fft_out, fft->fft_padded_size,
MFCC_FFT_BITS);
if (!fft->fft_plan) {
comp_err(dev, "Failed FFT init");
ret = -EINVAL;
goto free_fft_out;
return -EINVAL;
}

comp_info(dev, "mfcc_setup(), window = %d, num_mel_bins = %d, num_ceps = %d, norm = %d",
Expand All @@ -223,7 +218,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
ret = mfcc_get_window(state, config->window);
if (ret < 0) {
comp_err(dev, "Failed Window function");
goto free_fft_out;
return ret;
}

/* Setup Mel auditory filterbank. FFT input and output buffers are used
Expand All @@ -242,29 +237,29 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
fb->scratch_data2 = (int16_t *)fft->fft_out;
fb->scratch_length1 = fft->fft_buffer_size / sizeof(int16_t);
fb->scratch_length2 = fft->fft_buffer_size / sizeof(int16_t);
ret = psy_get_mel_filterbank(fb);
ret = mod_psy_get_mel_filterbank(mod, fb);
if (ret < 0) {
comp_err(dev, "Failed Mel filterbank");
goto free_fft_out;
return ret;
}

/* Setup DCT */
dct->num_in = config->num_mel_bins;
dct->num_out = config->num_ceps;
dct->type = (enum dct_type)config->dct;
dct->ortho = true;
ret = dct_initialize_16(dct);
ret = mod_dct_initialize_16(mod, dct);
if (ret < 0) {
comp_err(dev, "Failed DCT init");
goto free_melfb_data;
return ret;
}

state->lifter.num_ceps = config->num_ceps;
state->lifter.cepstral_lifter = config->cepstral_lifter; /* Q7.9 max 64.0*/
ret = mfcc_get_cepstral_lifter(&state->lifter);
ret = mfcc_get_cepstral_lifter(mod, &state->lifter);
if (ret < 0) {
comp_err(dev, "Failed cepstral lifter");
goto free_dct_matrix;
return ret;
}

/* Scratch overlay during runtime
Expand Down Expand Up @@ -297,33 +292,17 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i

comp_dbg(dev, "mfcc_setup(), done");
return 0;

free_dct_matrix:
rfree(state->dct.matrix);

free_melfb_data:
rfree(fb->data);

free_fft_out:
rfree(fft->fft_out);

free_fft_buf:
rfree(fft->fft_buf);

free_buffers:
rfree(state->buffers);

exit:
return ret;
}

void mfcc_free_buffers(struct mfcc_comp_data *cd)
void mfcc_free_buffers(struct processing_module *mod)
{
fft_plan_free(cd->state.fft.fft_plan);
rfree(cd->state.fft.fft_buf);
rfree(cd->state.fft.fft_out);
rfree(cd->state.buffers);
rfree(cd->state.melfb.data);
rfree(cd->state.dct.matrix);
rfree(cd->state.lifter.matrix);
struct mfcc_comp_data *cd = module_get_private_data(mod);

mod_fft_plan_free(mod, cd->state.fft.fft_plan);
mod_free(mod, cd->state.fft.fft_buf);
mod_free(mod, cd->state.fft.fft_out);
mod_free(mod, cd->state.buffers);
mod_free(mod, cd->state.melfb.data);
mod_free(mod, cd->state.dct.matrix);
mod_free(mod, cd->state.lifter.matrix);
}
21 changes: 21 additions & 0 deletions src/audio/module_adapter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
menu "Processing modules"
visible if COMP_MODULE_ADAPTER

config MODULE_MEMORY_API_CONTAINER_CHUNK_SIZE
int "Number of memory containers to allocate at once"
default 16
help
The per module resource containers are allocated in
chunks. The unused containers are kept in free
list. When the free list is empty the amount of
containers to allocate at once is selected by this
config option.

config MODULE_MEMORY_API_DEBUG
bool "Turn on memory API thread safety checks"
default y if DEBUG
help
The Module Memory API structures are not protected
by locks. This is because the initialization,
allocation, and freeing of resources should always
be done in the same thread. This option adds an
assert to make sure no other thread makes such
operations.

config CADENCE_CODEC
bool "Cadence codec"
default n
Expand Down
Loading
Loading