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
32 changes: 19 additions & 13 deletions src/audio/mixer/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ static int mixer_process(struct processing_module *mod,
struct mixer_data *md = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
const struct audio_stream __sparse_cache *sources_stream[PLATFORM_MAX_STREAMS];
int32_t i = 0;
int32_t i = 0, j = 0;
uint32_t frames = INT32_MAX;
/* Redundant, but helps the compiler */
uint32_t source_bytes = 0;
uint32_t sink_bytes;
int active_input_buffers = 0;

comp_dbg(dev, "mixer_process() %d", num_input_buffers);

Expand All @@ -105,10 +106,11 @@ static int mixer_process(struct processing_module *mod,
if (avail_frames == 0)
continue;

active_input_buffers++;
frames = MIN(frames, avail_frames);
}

if (!num_input_buffers || (frames == 0 && md->sources_inactive)) {
if (!active_input_buffers) {
/*
* Generate silence when sources are inactive. When
* sources change to active, additionally keep
Expand All @@ -119,33 +121,37 @@ static int mixer_process(struct processing_module *mod,
if (!audio_stream_set_zero(mod->output_buffers[0].data, sink_bytes))
mod->output_buffers[0].size = sink_bytes;

md->sources_inactive = true;

Comment thread
paulstelian97 marked this conversation as resolved.
Outdated
return 0;
}

/* Every source has the same format, so calculate bytes based on the first one */
source_bytes = frames * audio_stream_frame_bytes(mod->input_buffers[0].data);

if (md->sources_inactive) {
md->sources_inactive = false;
comp_dbg(dev, "mixer_copy exit sources_inactive state");
}

sink_bytes = frames * audio_stream_frame_bytes(mod->output_buffers[0].data);

comp_dbg(dev, "mixer_process(), source_bytes = 0x%x, sink_bytes = 0x%x",
source_bytes, sink_bytes);

/* mix streams */
for (i = 0; i < num_input_buffers; i++)
sources_stream[i] = mod->input_buffers[i].data;
for (i = 0; i < num_input_buffers; i++) {
uint32_t avail_frames;

avail_frames = audio_stream_avail_frames_aligned(mod->input_buffers[i].data,
mod->output_buffers[0].data);

/* if one source is inactive, skip it */
if (avail_frames == 0)
continue;

sources_stream[j++] = mod->input_buffers[i].data;
}

md->mix_func(dev, mod->output_buffers[0].data, sources_stream, num_input_buffers, frames);
if (j)
md->mix_func(dev, mod->output_buffers[0].data, sources_stream, j, frames);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps I should use active_input_buffers here and below?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need j anyway to have the exact active buffers, so you can continue using j here and below

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, wouldn't j==active_input_buffers ? If j can be differnent, then I think it deserves a longer more descriptive name as it's used across this long function (i.e. not just a loop index variable anymore).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

They can differ if there's a race changing which buffers are active between the first check and this loop. I can write an assert stating that they don't differ I suppose.

mod->output_buffers[0].size = sink_bytes;

/* update source buffer consumed bytes */
for (i = 0; i < num_input_buffers; i++)
for (i = 0; i < j; i++)
mod->input_buffers[i].consumed = source_bytes;

return 0;
Expand Down
42 changes: 21 additions & 21 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,16 @@ int module_adapter_prepare(struct comp_dev *dev)

comp_dbg(dev, "module_adapter_prepare() start");

/*
* check if the component is already active. This could happen in the case of mixer when
* one of the sources is already active
*/
if (dev->state == COMP_STATE_ACTIVE)
return 0;
/* Prepare module */
ret = module_prepare(mod);
if (ret) {
if (ret == PPL_STATUS_PATH_STOP)
return ret;

/* Are we already prepared? */
ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
if (ret < 0)
return ret;
comp_err(dev, "module_adapter_prepare() error %x: module prepare failed",
ret);

if (ret == COMP_STATUS_STATE_ALREADY_SET) {
comp_warn(dev, "module_adapter_prepare(): module has already been prepared");
return PPL_STATUS_PATH_STOP;
return -EIO;
Comment thread
paulstelian97 marked this conversation as resolved.
}

/* Get period_bytes first on prepare(). At this point it is guaranteed that the stream
Expand All @@ -195,16 +190,21 @@ int module_adapter_prepare(struct comp_dev *dev)

buffer_release(sink_c);

/* Prepare module */
ret = module_prepare(mod);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

are we sure, that no module is currently relying on mod->period_bytes being assigned before .prepare()?

if (ret) {
if (ret == PPL_STATUS_PATH_STOP)
return ret;
/*
* check if the component is already active. This could happen in the case of mixer when
* one of the sources is already active
*/
if (dev->state == COMP_STATE_ACTIVE)
return PPL_STATUS_PATH_STOP;

comp_err(dev, "module_adapter_prepare() error %x: module prepare failed",
ret);
/* Are we already prepared? */
ret = comp_set_state(dev, COMP_TRIGGER_PREPARE);
if (ret < 0)
return ret;

return -EIO;
if (ret == COMP_STATUS_STATE_ALREADY_SET) {
comp_warn(dev, "module_adapter_prepare(): module has already been prepared");
return PPL_STATUS_PATH_STOP;
}

mod->deep_buff_bytes = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/include/sof/audio/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ void sys_comp_module_mixer_interface_init(void);

/* mixer component private data */
struct mixer_data {
bool sources_inactive;

void (*mix_func)(struct comp_dev *dev, struct audio_stream __sparse_cache *sink,
const struct audio_stream __sparse_cache **sources, uint32_t count,
uint32_t frames);
Expand Down