Skip to content

Commit ce1d88e

Browse files
audio: drc: switch to source/sink processing API
Convert the DRC module from the legacy audio_stream processing API to the modern sof_source/sof_sink API.
1 parent 5b67ca0 commit ce1d88e

4 files changed

Lines changed: 186 additions & 125 deletions

File tree

src/audio/drc/drc.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sof/audio/format.h>
1212
#include <sof/audio/ipc-config.h>
1313
#include <sof/audio/pipeline.h>
14+
#include <sof/audio/sink_source_utils.h>
1415
#include <sof/ipc/msg.h>
1516
#include <sof/lib/memory.h>
1617
#include <sof/lib/uuid.h>
@@ -269,25 +270,30 @@ __cold static int drc_get_config(struct processing_module *mod,
269270
}
270271

271272
static int drc_process(struct processing_module *mod,
272-
struct input_stream_buffer *input_buffers,
273-
int num_input_buffers,
274-
struct output_stream_buffer *output_buffers,
275-
int num_output_buffers)
273+
struct sof_source **sources,
274+
int num_of_sources,
275+
struct sof_sink **sinks,
276+
int num_of_sinks)
276277
{
277278
struct drc_comp_data *cd = module_get_private_data(mod);
278279
struct comp_dev *dev = mod->dev;
279-
struct audio_stream *source = input_buffers[0].data;
280-
struct audio_stream *sink = output_buffers[0].data;
281-
int frames = input_buffers[0].size;
280+
struct sof_source *source = sources[0];
281+
struct sof_sink *sink = sinks[0];
282+
struct cir_buf_source source_buf;
283+
struct cir_buf_sink sink_buf;
284+
size_t source_frame_bytes = source_get_frame_bytes(source);
285+
size_t sink_frame_bytes = sink_get_frame_bytes(sink);
286+
size_t source_bytes, sink_bytes, bytes;
287+
uint32_t frames;
282288
int ret;
283289

284290
comp_dbg(dev, "entry");
285291

286292
/* Check for changed configuration */
287293
if (comp_is_new_data_blob_available(cd->model_handler)) {
288294
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
289-
ret = drc_setup(mod, audio_stream_get_channels(source),
290-
audio_stream_get_rate(source));
295+
ret = drc_setup(mod, source_get_channels(source),
296+
source_get_rate(source));
291297
if (ret < 0) {
292298
comp_err(dev, "drc_copy(), failed DRC setup");
293299
return ret;
@@ -309,10 +315,32 @@ static int drc_process(struct processing_module *mod,
309315
/* Control pass-though in processing function with switch control */
310316
cd->enabled = cd->config && cd->config->params.enabled && cd->enable_switch;
311317

312-
cd->drc_func(mod, source, sink, frames);
318+
frames = source_sink_avail_frames_aligned(source, sink);
319+
if (!frames)
320+
return 0;
321+
322+
source_bytes = frames * source_frame_bytes;
323+
sink_bytes = frames * sink_frame_bytes;
324+
325+
/* acquire source and sink circular buffers for the whole period */
326+
ret = source_get_data(source, source_bytes, &source_buf.ptr,
327+
&source_buf.buf_start, &bytes);
328+
if (ret < 0)
329+
return ret;
330+
source_buf.buf_end = (const char *)source_buf.buf_start + bytes;
331+
332+
ret = sink_get_buffer(sink, sink_bytes, &sink_buf.ptr, &sink_buf.buf_start, &bytes);
333+
if (ret < 0) {
334+
source_release_data(source, 0);
335+
return ret;
336+
}
337+
sink_buf.buf_end = (char *)sink_buf.buf_start + bytes;
338+
339+
cd->drc_func(mod, &source_buf, &sink_buf, frames);
313340

314-
/* calc new free and available */
315-
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
341+
/* commit the consumed and produced data */
342+
source_release_data(source, source_bytes);
343+
sink_commit_buffer(sink, sink_bytes);
316344
return 0;
317345
}
318346

@@ -367,6 +395,7 @@ static int drc_prepare(struct processing_module *mod,
367395
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
368396
channels = audio_stream_get_channels(&sinkb->stream);
369397
rate = audio_stream_get_rate(&sinkb->stream);
398+
cd->channels = channels;
370399

371400
/* Initialize DRC */
372401
comp_info(dev, "source_format=%d", cd->source_format);
@@ -414,7 +443,7 @@ static int drc_reset(struct processing_module *mod)
414443
static const struct module_interface drc_interface = {
415444
.init = drc_init,
416445
.prepare = drc_prepare,
417-
.process_audio_stream = drc_process,
446+
.process = drc_process,
418447
.set_configuration = drc_set_config,
419448
.get_configuration = drc_get_config,
420449
.reset = drc_reset,

src/audio/drc/drc.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "drc_user.h"
1616

1717
struct audio_stream;
18+
struct cir_buf_source;
19+
struct cir_buf_sink;
1820
struct comp_dev;
1921

2022
/* Define CONFIG_DRC_MAX_PRE_DELAY_FRAMES for the build purposes without Kconfig,
@@ -66,8 +68,8 @@ struct drc_state {
6668
};
6769

6870
typedef void (*drc_func)(struct processing_module *mod,
69-
const struct audio_stream *source,
70-
struct audio_stream *sink,
71+
const struct cir_buf_source *source,
72+
struct cir_buf_sink *sink,
7173
uint32_t frames);
7274

7375
/* DRC component private data */
@@ -79,6 +81,7 @@ struct drc_comp_data {
7981
bool enabled; /**< control processing via blob and switch */
8082
bool enable_switch; /**< enable switch state */
8183
enum sof_ipc_frame source_format; /**< source frame format */
84+
int channels; /**< number of channels */
8285
drc_func drc_func; /**< processing function */
8386
};
8487

@@ -91,8 +94,8 @@ extern const struct drc_proc_fnmap drc_proc_fnmap[];
9194
extern const size_t drc_proc_fncount;
9295

9396
void drc_default_pass(struct processing_module *mod,
94-
const struct audio_stream *source,
95-
struct audio_stream *sink, uint32_t frames);
97+
const struct cir_buf_source *source,
98+
struct cir_buf_sink *sink, uint32_t frames);
9699
/**
97100
* \brief Returns DRC processing function.
98101
*/

0 commit comments

Comments
 (0)