Skip to content

Commit

Permalink
up_down_mixer: sink/source refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdobrowolski committed Dec 15, 2023
1 parent 68c6357 commit 8b1081a
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions src/audio/up_down_mixer/up_down_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,44 +401,53 @@ static int up_down_mixer_init(struct processing_module *mod)

static int
up_down_mixer_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers, int num_output_buffers)
struct sof_source **input_buffers, int num_input_buffers,
struct sof_sink **output_buffers, int num_output_buffers)
{
struct up_down_mixer_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
uint32_t source_bytes, sink_bytes;
uint32_t mix_frames;

comp_dbg(dev, "up_down_mixer_process()");

mix_frames = audio_stream_avail_frames(mod->input_buffers[0].data,
mod->output_buffers[0].data);

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

if (source_bytes) {
uint32_t sink_sample_bytes;
size_t frames_to_process, i, ret;
const uint8_t* input0_pos, * input0_start;
uint8_t* output_pos, * output_start;

audio_stream_copy_to_linear(mod->input_buffers[0].data, 0, cd->buf_in, 0,
source_bytes /
audio_stream_sample_bytes(mod->input_buffers[0].data));
comp_dbg(dev, "up_down_mixer_process()");

cd->mix_routine(cd, (uint8_t *)cd->buf_in, source_bytes, (uint8_t *)cd->buf_out);
frames_to_process = sink_get_free_frames(output_buffers[0]);
i = source_get_data_frames_available(input_buffers[0]);
if (i < frames_to_process)
frames_to_process = i;

sink_sample_bytes = audio_stream_sample_bytes(mod->output_buffers[0].data);
audio_stream_copy_from_linear(cd->buf_out, 0, mod->output_buffers[0].data, 0,
sink_bytes / sink_sample_bytes);
mod->output_buffers[0].size = sink_bytes;
mod->input_buffers[0].consumed = source_bytes;
const unsigned int output_channels = sink_get_channels(output_buffers[0]);
const size_t output_frame_bytes = sink_get_frame_bytes(output_buffers[0]);
ret = sink_get_buffer(output_buffers[0], frames_to_process * output_frame_bytes, (void**)&output_pos,
(void**)&output_start, &i);
if (ret)
return -ENOMEM;

const unsigned int input0_channels = source_get_channels(input_buffers[0]);
const size_t input0_frame_bytes = source_get_frame_bytes(input_buffers[0]);
ret = source_get_data(input_buffers[0], frames_to_process * input0_frame_bytes,
(const void**)&input0_pos, (const void**)&input0_start, &i);
if (ret) {
sink_commit_buffer(output_buffers[0], 0);
return -ENOMEM;
}

cd->mix_routine(cd, (const void*)input0_start, input0_channels * frames_to_process * input0_frame_bytes, (void*)output_start);

ret = source_release_data(input_buffers[0], frames_to_process * input0_frame_bytes);
if (ret)
return ret;
ret = sink_commit_buffer(output_buffers[0], frames_to_process * output_frame_bytes);
if (ret)
return ret;
return 0;
}

static const struct module_interface up_down_mixer_interface = {
.init = up_down_mixer_init,
.process_audio_stream = up_down_mixer_process,
.process = up_down_mixer_process,
.free = up_down_mixer_free
};

Expand Down

0 comments on commit 8b1081a

Please sign in to comment.