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
53 changes: 22 additions & 31 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <sof/common.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
#include <rtos/alloc.h>
#include <rtos/init.h>
#include <sof/lib/uuid.h>
#include <sof/math/iir_df1.h>
Expand Down Expand Up @@ -47,12 +46,13 @@ DECLARE_TR_CTX(crossover_tr, SOF_UUID(crossover_uuid), LOG_LEVEL_INFO);
* \brief Reset the state (coefficients and delay) of the crossover filter
* across all channels
*/
static void crossover_reset_state(struct comp_data *cd)
static void crossover_reset_state(struct processing_module *mod,
struct comp_data *cd)
{
int i;

for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
crossover_reset_state_ch(&cd->state[i]);
crossover_reset_state_ch(mod, &cd->state[i]);
}

/**
Expand Down Expand Up @@ -156,7 +156,8 @@ static int crossover_assign_sinks(struct processing_module *mod,
* high/low pass filter.
* \param[out] lr4 initialized struct
*/
static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
static int crossover_init_coef_lr4(struct processing_module *mod,
struct sof_eq_iir_biquad *coef,
struct iir_state_df1 *lr4)
{
int ret;
Expand All @@ -169,8 +170,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
* in series due to identity. To maintain the structure of
* iir_state_df1, it requires two copies of coefficients in a row.
*/
lr4->coef = rzalloc(SOF_MEM_FLAG_USER,
sizeof(struct sof_eq_iir_biquad) * 2);
lr4->coef = mod_zalloc(mod, sizeof(struct sof_eq_iir_biquad) * 2);
if (!lr4->coef)
return -ENOMEM;

Expand All @@ -189,8 +189,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
* delay[0..1] -> state for first biquad
* delay[2..3] -> state for second biquad
*/
lr4->delay = rzalloc(SOF_MEM_FLAG_USER,
sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
lr4->delay = mod_zalloc(mod, sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
if (!lr4->delay)
return -ENOMEM;

Expand All @@ -203,7 +202,8 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
/**
* \brief Initializes the crossover coefficients for one channel
*/
int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef,
int crossover_init_coef_ch(struct processing_module *mod,
struct sof_eq_iir_biquad *coef,
struct crossover_state *ch_state,
int32_t num_sinks)
{
Expand All @@ -214,12 +214,12 @@ int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef,

for (i = 0; i < num_lr4s; i++) {
/* Get the low pass coefficients */
err = crossover_init_coef_lr4(&coef[j],
err = crossover_init_coef_lr4(mod, &coef[j],
&ch_state->lowpass[i]);
if (err < 0)
return -EINVAL;
/* Get the high pass coefficients */
err = crossover_init_coef_lr4(&coef[j + 1],
err = crossover_init_coef_lr4(mod, &coef[j + 1],
&ch_state->highpass[i]);
if (err < 0)
return -EINVAL;
Expand Down Expand Up @@ -259,13 +259,13 @@ static int crossover_init_coef(struct processing_module *mod, int nch)
/* Collect the coef array and assign it to every channel */
crossover = config->coef;
for (ch = 0; ch < nch; ch++) {
err = crossover_init_coef_ch(crossover, &cd->state[ch],
err = crossover_init_coef_ch(mod, crossover, &cd->state[ch],
config->num_sinks);
/* Free all previously allocated blocks in case of an error */
if (err < 0) {
comp_err(mod->dev, "crossover_init_coef(), could not assign coefficients to ch %d",
ch);
crossover_reset_state(cd);
crossover_reset_state(mod, cd);
return err;
}
}
Expand All @@ -282,7 +282,7 @@ static int crossover_setup(struct processing_module *mod, int nch)
int ret = 0;

/* Reset any previous state */
crossover_reset_state(cd);
crossover_reset_state(mod, cd);

/* Assign LR4 coefficients from config */
ret = crossover_init_coef(mod, nch);
Expand Down Expand Up @@ -312,40 +312,34 @@ static int crossover_init(struct processing_module *mod)
return -ENOMEM;
}

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

md->private = cd;

/* Handler for configuration data */
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 cd_fail;
return -ENOMEM;
}

/* Get configuration data and reset Crossover state */
ret = comp_init_data_blob(cd->model_handler, bs, ipc_crossover->data);
if (ret < 0) {
comp_err(dev, "comp_init_data_blob() failed.");
goto cd_fail;
return ret;
}

ret = crossover_output_pin_init(mod);
if (ret < 0) {
comp_err(dev, "crossover_init_output_pins() failed.");
goto cd_fail;
return ret;
}

crossover_reset_state(cd);
crossover_reset_state(mod, cd);
return 0;

cd_fail:
comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
return ret;
}

/**
Expand All @@ -357,11 +351,8 @@ static int crossover_free(struct processing_module *mod)

comp_info(mod->dev, "crossover_free()");

comp_data_blob_handler_free(cd->model_handler);

crossover_reset_state(cd);
crossover_reset_state(mod, cd);

rfree(cd);
return 0;
}

Expand Down Expand Up @@ -616,7 +607,7 @@ static int crossover_reset(struct processing_module *mod)

comp_info(mod->dev, "crossover_reset()");

crossover_reset_state(cd);
crossover_reset_state(mod, cd);

cd->crossover_process = NULL;
cd->crossover_split = NULL;
Expand Down
43 changes: 17 additions & 26 deletions src/audio/drc/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <module/module/llext.h>
#include <rtos/alloc.h>
#include <rtos/init.h>
#include <rtos/panic.h>
#include <rtos/string.h>
Expand All @@ -43,11 +42,11 @@ extern const struct sof_uuid drc_uuid;
extern struct tr_ctx drc_tr;

/* Called from drc_setup() from drc_process(), so cannot be __cold */
void drc_reset_state(struct drc_state *state)
void drc_reset_state(struct processing_module *mod, struct drc_state *state)
{
int i;

rfree(state->pre_delay_buffers[0]);
mod_free(mod, state->pre_delay_buffers[0]);
for (i = 0; i < PLATFORM_MAX_CHANNELS; ++i) {
state->pre_delay_buffers[i] = NULL;
}
Expand All @@ -67,7 +66,8 @@ void drc_reset_state(struct drc_state *state)
state->max_attack_compression_diff_db = INT32_MIN;
}

int drc_init_pre_delay_buffers(struct drc_state *state,
int drc_init_pre_delay_buffers(struct processing_module *mod,
struct drc_state *state,
size_t sample_bytes,
int channels)
{
Expand All @@ -76,7 +76,7 @@ int drc_init_pre_delay_buffers(struct drc_state *state,
int i;

/* Allocate pre-delay (lookahead) buffers */
state->pre_delay_buffers[0] = rballoc(SOF_MEM_FLAG_USER, bytes_total);
state->pre_delay_buffers[0] = mod_alloc(mod, bytes_total);
if (!state->pre_delay_buffers[0])
return -ENOMEM;

Expand Down Expand Up @@ -121,16 +121,17 @@ int drc_set_pre_delay_time(struct drc_state *state,
}

/* Called from drc_process(), so cannot be __cold */
static int drc_setup(struct drc_comp_data *cd, uint16_t channels, uint32_t rate)
static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t rate)
{
struct drc_comp_data *cd = module_get_private_data(mod);
uint32_t sample_bytes = get_sample_bytes(cd->source_format);
int ret;

/* Reset any previous state */
drc_reset_state(&cd->state);
drc_reset_state(mod, &cd->state);

/* Allocate pre-delay buffers */
ret = drc_init_pre_delay_buffers(&cd->state, (size_t)sample_bytes, (int)channels);
ret = drc_init_pre_delay_buffers(mod, &cd->state, (size_t)sample_bytes, (int)channels);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -164,28 +165,27 @@ __cold static int drc_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;

md->private = cd;

/* Handler for configuration data */
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 cd_fail;
return -ENOMEM;
}

/* Get configuration data and reset DRC state */
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
if (ret < 0) {
comp_err(dev, "comp_init_data_blob() failed.");
goto cd_fail;
return ret;
}

drc_reset_state(&cd->state);
drc_reset_state(mod, &cd->state);

/* Initialize DRC to enabled. If defined by topology, a control may set
* enabled to false before prepare() or during streaming with the switch
Expand All @@ -194,21 +194,12 @@ __cold static int drc_init(struct processing_module *mod)
cd->enabled = true;
cd->enable_switch = true;
return 0;

cd_fail:
comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
return ret;
}

__cold static int drc_free(struct processing_module *mod)
{
struct drc_comp_data *cd = module_get_private_data(mod);

assert_can_be_cold();

comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
return 0;
}

Expand Down Expand Up @@ -284,7 +275,7 @@ static int drc_process(struct processing_module *mod,
/* Check for changed configuration */
if (comp_is_new_data_blob_available(cd->model_handler)) {
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
ret = drc_setup(cd, audio_stream_get_channels(source),
ret = drc_setup(mod, audio_stream_get_channels(source),
audio_stream_get_rate(source));
if (ret < 0) {
comp_err(dev, "drc_copy(), failed DRC setup");
Expand Down Expand Up @@ -370,7 +361,7 @@ static int drc_prepare(struct processing_module *mod,
comp_info(dev, "drc_prepare(), source_format=%d", cd->source_format);
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
if (cd->config) {
ret = drc_setup(cd, channels, rate);
ret = drc_setup(mod, channels, rate);
if (ret < 0) {
comp_err(dev, "drc_prepare() error: drc_setup failed.");
return ret;
Expand Down Expand Up @@ -403,7 +394,7 @@ static int drc_reset(struct processing_module *mod)
{
struct drc_comp_data *cd = module_get_private_data(mod);

drc_reset_state(&cd->state);
drc_reset_state(mod, &cd->state);

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions src/audio/drc/drc_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include "drc.h"

/* drc reset function */
void drc_reset_state(struct drc_state *state);
void drc_reset_state(struct processing_module *mod, struct drc_state *state);

/* drc init functions */
int drc_init_pre_delay_buffers(struct drc_state *state,
int drc_init_pre_delay_buffers(struct processing_module *mod,
struct drc_state *state,
size_t sample_bytes,
int channels);
int drc_set_pre_delay_time(struct drc_state *state,
Expand Down
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