Skip to content
Merged
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
47 changes: 23 additions & 24 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 = module_get_private_data(mod);
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);
return err;
}
}
Expand All @@ -278,11 +278,10 @@ static int crossover_init_coef(struct processing_module *mod, int nch)
*/
static int crossover_setup(struct processing_module *mod, int nch)
{
struct comp_data *cd = module_get_private_data(mod);
int ret = 0;

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

/* Assign LR4 coefficients from config */
ret = crossover_init_coef(mod, nch);
Expand Down Expand Up @@ -312,14 +311,14 @@ 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;
Expand All @@ -339,12 +338,12 @@ static int crossover_init(struct processing_module *mod)
goto cd_fail;
}

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

cd_fail:
comp_data_blob_handler_free(cd->model_handler);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - `.init()? might need to clean up manually

Copy link
Contributor Author

@jsarha jsarha Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh , are you referring to comp_init_data_blob()? No there is no need. comp_data_blob_handler_free() is called automatically when mod_data_blob_handler_new() is used, and there is no separate call to clean up comp_init_data_blob().

edit:
With #10320 this should be Ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - `.init()? might need to clean up manually

@jsarha oh... Well, yes, that fixes it... I was initially a bit uncomfortable with that because of the "if a function fails, it should release all the resources it has managed to allocate before failing." But that's one of the modes how this module-managed allocations work: if a later stage calls mod_alloc() which succeeds, but then another call fails, the function won't call mod_free() explicitly and will rely on the automatic clean up. So maybe we can do it here too...

rfree(cd);
mod_data_blob_handler_free(mod, cd->model_handler);
mod_free(mod, cd);
return ret;
}

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

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

comp_data_blob_handler_free(cd->model_handler);
mod_data_blob_handler_free(mod, cd->model_handler);

crossover_reset_state(cd);
crossover_reset_state(mod);

rfree(cd);
mod_free(mod, cd);
return 0;
}

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

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

crossover_reset_state(cd);
crossover_reset_state(mod);

cd->crossover_process = NULL;
cd->crossover_split = NULL;
Expand Down
39 changes: 20 additions & 19 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_balloc(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,16 +165,16 @@ __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.");
comp_err(dev, "mod_data_blob_handler_new() failed.");
ret = -ENOMEM;
goto cd_fail;
}
Expand All @@ -185,7 +186,7 @@ __cold static int drc_init(struct processing_module *mod)
goto cd_fail;
}

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 @@ -196,8 +197,8 @@ __cold static int drc_init(struct processing_module *mod)
return 0;

cd_fail:
comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
mod_data_blob_handler_free(mod, cd->model_handler);
mod_free(mod, cd);
return ret;
}

Expand All @@ -207,8 +208,8 @@ __cold static int drc_free(struct processing_module *mod)

assert_can_be_cold();

comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
mod_data_blob_handler_free(mod, cd->model_handler);
mod_free(mod, cd);
return 0;
}

Expand Down Expand Up @@ -284,7 +285,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 +371,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 +404,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
Loading
Loading