Skip to content

Commit 4ab8d5c

Browse files
piotrhoppeintelkv2019i
authored andcommitted
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. Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent a122407 commit 4ab8d5c

4 files changed

Lines changed: 211 additions & 125 deletions

File tree

src/audio/drc/drc.c

Lines changed: 57 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,31 @@ __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;
287+
size_t source_buf_size, sink_buf_size;
288+
uint32_t frames;
282289
int ret;
283290

284291
comp_dbg(dev, "entry");
285292

286293
/* Check for changed configuration */
287294
if (comp_is_new_data_blob_available(cd->model_handler)) {
288295
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));
296+
ret = drc_setup(mod, source_get_channels(source),
297+
source_get_rate(source));
291298
if (ret < 0) {
292299
comp_err(dev, "drc_copy(), failed DRC setup");
293300
return ret;
@@ -309,10 +316,46 @@ static int drc_process(struct processing_module *mod,
309316
/* Control pass-though in processing function with switch control */
310317
cd->enabled = cd->config && cd->config->params.enabled && cd->enable_switch;
311318

312-
cd->drc_func(mod, source, sink, frames);
319+
frames = source_sink_avail_frames_aligned(source, sink);
320+
if (!frames)
321+
return 0;
322+
323+
source_bytes = frames * source_frame_bytes;
324+
sink_bytes = frames * sink_frame_bytes;
325+
326+
/* acquire source and sink circular buffers for the whole period */
327+
ret = source_get_data(source, source_bytes, &source_buf.ptr,
328+
&source_buf.buf_start, &source_buf_size);
329+
if (ret < 0)
330+
return ret;
331+
if (source_buf_size < source_bytes) {
332+
comp_err(dev, "source buffer size %zu is insufficient for %zu bytes",
333+
source_buf_size, source_bytes);
334+
source_release_data(source, 0);
335+
return -EINVAL;
336+
}
337+
source_buf.buf_end = (const char *)source_buf.buf_start + source_buf_size;
338+
339+
ret = sink_get_buffer(sink, sink_bytes, &sink_buf.ptr, &sink_buf.buf_start,
340+
&sink_buf_size);
341+
if (ret < 0) {
342+
source_release_data(source, 0);
343+
return ret;
344+
}
345+
if (sink_buf_size < sink_bytes) {
346+
comp_err(dev, "sink buffer size %zu is insufficient for %zu bytes",
347+
sink_buf_size, sink_bytes);
348+
source_release_data(source, 0);
349+
sink_commit_buffer(sink, 0);
350+
return -EINVAL;
351+
}
352+
sink_buf.buf_end = (char *)sink_buf.buf_start + sink_buf_size;
353+
354+
cd->drc_func(mod, &source_buf, &sink_buf, frames);
313355

314-
/* calc new free and available */
315-
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
356+
/* commit the consumed and produced data */
357+
source_release_data(source, source_bytes);
358+
sink_commit_buffer(sink, sink_bytes);
316359
return 0;
317360
}
318361

@@ -367,6 +410,7 @@ static int drc_prepare(struct processing_module *mod,
367410
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
368411
channels = audio_stream_get_channels(&sinkb->stream);
369412
rate = audio_stream_get_rate(&sinkb->stream);
413+
cd->channels = channels;
370414

371415
/* Initialize DRC */
372416
comp_info(dev, "source_format=%d", cd->source_format);
@@ -414,7 +458,7 @@ static int drc_reset(struct processing_module *mod)
414458
static const struct module_interface drc_interface = {
415459
.init = drc_init,
416460
.prepare = drc_prepare,
417-
.process_audio_stream = drc_process,
461+
.process = drc_process,
418462
.set_configuration = drc_set_config,
419463
.get_configuration = drc_get_config,
420464
.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)