Skip to content

Commit 3d855bd

Browse files
committed
module: multiband_drc: rework module to use sink/source api
Rework the multiband drc module to only use the sink/source api to prepare sof for the full transition to pipeline 2.0. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 4241c75 commit 3d855bd

4 files changed

Lines changed: 144 additions & 73 deletions

File tree

src/audio/multiband_drc/multiband_drc.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
// Author: Pin-chih Lin <johnylin@google.com>
66

77
#include <sof/audio/module_adapter/module/generic.h>
8-
#include <sof/audio/buffer.h>
98
#include <sof/audio/format.h>
109
#include <sof/audio/ipc-config.h>
11-
#include <sof/audio/pipeline.h>
1210
#include <sof/ipc/msg.h>
1311
#include <sof/lib/memory.h>
1412
#include <sof/lib/uuid.h>
@@ -301,38 +299,36 @@ __cold static int multiband_drc_get_config(struct processing_module *mod,
301299
}
302300

303301
static int multiband_drc_process(struct processing_module *mod,
304-
struct input_stream_buffer *input_buffers, int num_input_buffers,
305-
struct output_stream_buffer *output_buffers,
306-
int num_output_buffers)
302+
struct sof_source **sources, int num_of_sources,
303+
struct sof_sink **sinks, int num_of_sinks)
307304
{
308305
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
309306
struct comp_dev *dev = mod->dev;
310-
struct audio_stream *source = input_buffers[0].data;
311-
struct audio_stream *sink = output_buffers[0].data;
312-
int frames = input_buffers[0].size;
307+
int frames = source_get_data_frames_available(sources[0]);
313308
int ret;
314309

315310
comp_dbg(dev, "entry");
316311

317312
/* Check for changed configuration */
318313
if (comp_is_new_data_blob_available(cd->model_handler)) {
319314
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
320-
ret = multiband_drc_setup(mod, (int16_t)audio_stream_get_channels(sink),
321-
audio_stream_get_rate(sink));
315+
ret = multiband_drc_setup(mod, (int16_t)sink_get_channels(sinks[0]),
316+
sink_get_rate(sinks[0]));
322317
if (ret < 0) {
323318
comp_err(dev, "failed DRC setup");
324319
return ret;
325320
}
326321
}
327322

328323
if (cd->process_enabled)
329-
cd->multiband_drc_func(mod, source, sink, frames);
324+
ret = cd->multiband_drc_func(mod, sources[0], sinks[0], frames);
330325
else
331-
multiband_drc_default_pass(mod, source, sink, frames);
326+
ret = multiband_drc_default_pass(mod, sources[0], sinks[0], frames);
332327

333-
/* calc new free and available */
334-
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
335-
return 0;
328+
if (ret < 0)
329+
comp_err(dev, "processing failed: %d", ret);
330+
331+
return ret;
336332
}
337333

338334
static int multiband_drc_prepare(struct processing_module *mod,
@@ -341,7 +337,6 @@ static int multiband_drc_prepare(struct processing_module *mod,
341337
{
342338
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
343339
struct comp_dev *dev = mod->dev;
344-
struct comp_buffer *sourceb;
345340
size_t data_size;
346341
int channels;
347342
int rate;
@@ -353,17 +348,10 @@ static int multiband_drc_prepare(struct processing_module *mod,
353348
if (ret < 0)
354349
return ret;
355350

356-
/* DRC component will only ever have 1 source and 1 sink buffer */
357-
sourceb = comp_dev_get_first_data_producer(dev);
358-
if (!sourceb) {
359-
comp_err(dev, "no source buffer");
360-
return -ENOTCONN;
361-
}
362-
363351
/* get source data format */
364-
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
365-
channels = audio_stream_get_channels(&sourceb->stream);
366-
rate = audio_stream_get_rate(&sourceb->stream);
352+
cd->source_format = source_get_frm_fmt(sources[0]);
353+
channels = (int16_t)source_get_channels(sources[0]);
354+
rate = source_get_rate(sources[0]);
367355

368356
/* Initialize DRC */
369357
comp_dbg(dev, "source_format=%d, sink_format=%d",
@@ -404,7 +392,7 @@ static int multiband_drc_reset(struct processing_module *mod)
404392
static const struct module_interface multiband_drc_interface = {
405393
.init = multiband_drc_init,
406394
.prepare = multiband_drc_prepare,
407-
.process_audio_stream = multiband_drc_process,
395+
.process = multiband_drc_process,
408396
.set_configuration = multiband_drc_set_config,
409397
.get_configuration = multiband_drc_get_config,
410398
.reset = multiband_drc_reset,

src/audio/multiband_drc/multiband_drc.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ struct multiband_drc_state {
2828
struct iir_state_df1 deemphasis[PLATFORM_MAX_CHANNELS];
2929
};
3030

31-
typedef void (*multiband_drc_func)(const struct processing_module *mod,
32-
const struct audio_stream *source,
33-
struct audio_stream *sink,
34-
uint32_t frames);
31+
typedef int (*multiband_drc_func)(const struct processing_module *mod,
32+
struct sof_source *source,
33+
struct sof_sink *sink,
34+
uint32_t frames);
3535

3636
/* Multiband DRC component private data */
3737
struct multiband_drc_comp_data {
@@ -54,10 +54,10 @@ extern const struct multiband_drc_proc_fnmap multiband_drc_proc_fnmap[];
5454
extern const struct multiband_drc_proc_fnmap multiband_drc_proc_fnmap_pass[];
5555
extern const size_t multiband_drc_proc_fncount;
5656

57-
void multiband_drc_default_pass(const struct processing_module *mod,
58-
const struct audio_stream *source,
59-
struct audio_stream *sink,
60-
uint32_t frames);
57+
int multiband_drc_default_pass(const struct processing_module *mod,
58+
struct sof_source *source,
59+
struct sof_sink *sink,
60+
uint32_t frames);
6161

6262
/**
6363
* \brief Returns Multiband DRC processing function.

src/audio/multiband_drc/multiband_drc_generic.c

Lines changed: 93 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
#include <stdint.h>
88
#include <sof/audio/format.h>
9+
#include <sof/audio/sink_source_utils.h>
910
#include <sof/math/iir_df1.h>
1011

1112
#include "multiband_drc.h"
1213
#include "../drc/drc_algorithm.h"
1314

14-
void multiband_drc_default_pass(const struct processing_module *mod,
15-
const struct audio_stream *source,
16-
struct audio_stream *sink,
17-
uint32_t frames)
15+
int multiband_drc_default_pass(const struct processing_module *mod,
16+
struct sof_source *source,
17+
struct sof_sink *sink,
18+
uint32_t frames)
1819
{
19-
audio_stream_copy(source, 0, sink, 0, audio_stream_get_channels(source) * frames);
20+
return source_to_sink_copy(source, sink, true, frames * source_get_frame_bytes(source));
2021
}
2122

2223
static void multiband_drc_process_emp_crossover(struct multiband_drc_state *state,
@@ -203,10 +204,10 @@ static void multiband_drc_process_deemp(struct multiband_drc_state *state,
203204
* :buf_drc_src[nch*nband] :buf_sink[nch]
204205
*/
205206
#if CONFIG_FORMAT_S16LE
206-
static void multiband_drc_s16_default(const struct processing_module *mod,
207-
const struct audio_stream *source,
208-
struct audio_stream *sink,
209-
uint32_t frames)
207+
static int multiband_drc_s16_default(const struct processing_module *mod,
208+
struct sof_source *source,
209+
struct sof_sink *sink,
210+
uint32_t frames)
210211
{
211212
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
212213
struct multiband_drc_state *state = &cd->state;
@@ -216,22 +217,35 @@ static void multiband_drc_s16_default(const struct processing_module *mod,
216217
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
217218
int32_t *band_buf_drc_src;
218219
int32_t *band_buf_drc_sink;
219-
int16_t *x = audio_stream_get_rptr(source);
220-
int16_t *y = audio_stream_get_wptr(sink);
220+
const int16_t *x, *buf_x_start;
221+
int16_t *y, *buf_y_start;
222+
int buf_x_samples, buf_y_samples;
223+
size_t n_bytes = frames * source_get_frame_bytes(source);
221224
int band;
222225
int nbuf;
223226
int npcm;
227+
int ret;
224228
int ch;
225229
int i;
226-
int nch = audio_stream_get_channels(source);
230+
int nch = source_get_channels(source);
227231
int nband = cd->config->num_bands;
228232
int enable_emp_deemp = cd->config->enable_emp_deemp;
229233
int samples = frames * nch;
230234

235+
ret = source_get_data_s16(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
236+
if (ret)
237+
return ret;
238+
239+
ret = sink_get_buffer_s16(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
240+
if (ret) {
241+
source_release_data(source, 0);
242+
return ret;
243+
}
244+
231245
while (samples) {
232-
nbuf = audio_stream_samples_without_wrap_s16(source, x);
246+
nbuf = cir_buf_samples_to_wrap_s16(x, buf_x_start, buf_x_samples);
233247
npcm = MIN(samples, nbuf);
234-
nbuf = audio_stream_samples_without_wrap_s16(sink, y);
248+
nbuf = cir_buf_samples_to_wrap_s16(y, buf_y_start, buf_y_samples);
235249
npcm = MIN(npcm, nbuf);
236250
for (i = 0; i < npcm; i += nch) {
237251
for (ch = 0; ch < nch; ch++) {
@@ -263,17 +277,22 @@ static void multiband_drc_s16_default(const struct processing_module *mod,
263277
}
264278
}
265279
samples -= npcm;
266-
x = audio_stream_wrap(source, x);
267-
y = audio_stream_wrap(sink, y);
280+
if (x >= buf_x_start + buf_x_samples)
281+
x = buf_x_start;
282+
if (y >= buf_y_start + buf_y_samples)
283+
y = buf_y_start;
268284
}
285+
source_release_data(source, n_bytes);
286+
sink_commit_buffer(sink, n_bytes);
287+
return 0;
269288
}
270289
#endif /* CONFIG_FORMAT_S16LE */
271290

272291
#if CONFIG_FORMAT_S24LE
273-
static void multiband_drc_s24_default(const struct processing_module *mod,
274-
const struct audio_stream *source,
275-
struct audio_stream *sink,
276-
uint32_t frames)
292+
static int multiband_drc_s24_default(const struct processing_module *mod,
293+
struct sof_source *source,
294+
struct sof_sink *sink,
295+
uint32_t frames)
277296
{
278297
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
279298
struct multiband_drc_state *state = &cd->state;
@@ -283,22 +302,35 @@ static void multiband_drc_s24_default(const struct processing_module *mod,
283302
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
284303
int32_t *band_buf_drc_src;
285304
int32_t *band_buf_drc_sink;
286-
int32_t *x = audio_stream_get_rptr(source);
287-
int32_t *y = audio_stream_get_wptr(sink);
305+
const int32_t *x, *buf_x_start;
306+
int32_t *y, *buf_y_start;
307+
int buf_x_samples, buf_y_samples;
308+
size_t n_bytes = frames * source_get_frame_bytes(source);
288309
int band;
289310
int nbuf;
290311
int npcm;
312+
int ret;
291313
int ch;
292314
int i;
293-
int nch = audio_stream_get_channels(source);
315+
int nch = source_get_channels(source);
294316
int nband = cd->config->num_bands;
295317
int enable_emp_deemp = cd->config->enable_emp_deemp;
296318
int samples = frames * nch;
297319

320+
ret = source_get_data_s32(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
321+
if (ret)
322+
return ret;
323+
324+
ret = sink_get_buffer_s32(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
325+
if (ret) {
326+
source_release_data(source, 0);
327+
return ret;
328+
}
329+
298330
while (samples) {
299-
nbuf = audio_stream_samples_without_wrap_s24(source, x);
331+
nbuf = cir_buf_samples_to_wrap_s32(x, buf_x_start, buf_x_samples);
300332
npcm = MIN(samples, nbuf);
301-
nbuf = audio_stream_samples_without_wrap_s24(sink, y);
333+
nbuf = cir_buf_samples_to_wrap_s32(y, buf_y_start, buf_y_samples);
302334
npcm = MIN(npcm, nbuf);
303335
for (i = 0; i < npcm; i += nch) {
304336
for (ch = 0; ch < nch; ch++) {
@@ -330,17 +362,22 @@ static void multiband_drc_s24_default(const struct processing_module *mod,
330362
}
331363
}
332364
samples -= npcm;
333-
x = audio_stream_wrap(source, x);
334-
y = audio_stream_wrap(sink, y);
365+
if (x >= buf_x_start + buf_x_samples)
366+
x = buf_x_start;
367+
if (y >= buf_y_start + buf_y_samples)
368+
y = buf_y_start;
335369
}
370+
source_release_data(source, n_bytes);
371+
sink_commit_buffer(sink, n_bytes);
372+
return 0;
336373
}
337374
#endif /* CONFIG_FORMAT_S24LE */
338375

339376
#if CONFIG_FORMAT_S32LE
340-
static void multiband_drc_s32_default(const struct processing_module *mod,
341-
const struct audio_stream *source,
342-
struct audio_stream *sink,
343-
uint32_t frames)
377+
static int multiband_drc_s32_default(const struct processing_module *mod,
378+
struct sof_source *source,
379+
struct sof_sink *sink,
380+
uint32_t frames)
344381
{
345382
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
346383
struct multiband_drc_state *state = &cd->state;
@@ -350,22 +387,35 @@ static void multiband_drc_s32_default(const struct processing_module *mod,
350387
int32_t buf_drc_sink[PLATFORM_MAX_CHANNELS * SOF_MULTIBAND_DRC_MAX_BANDS];
351388
int32_t *band_buf_drc_src;
352389
int32_t *band_buf_drc_sink;
353-
int32_t *x = audio_stream_get_rptr(source);
354-
int32_t *y = audio_stream_get_wptr(sink);
390+
const int32_t *x, *buf_x_start;
391+
int32_t *y, *buf_y_start;
392+
int buf_x_samples, buf_y_samples;
393+
size_t n_bytes = frames * source_get_frame_bytes(source);
355394
int band;
356395
int nbuf;
357396
int npcm;
397+
int ret;
358398
int ch;
359399
int i;
360-
int nch = audio_stream_get_channels(source);
400+
int nch = source_get_channels(source);
361401
int nband = cd->config->num_bands;
362402
int enable_emp_deemp = cd->config->enable_emp_deemp;
363403
int samples = frames * nch;
364404

405+
ret = source_get_data_s32(source, n_bytes, &x, &buf_x_start, &buf_x_samples);
406+
if (ret)
407+
return ret;
408+
409+
ret = sink_get_buffer_s32(sink, n_bytes, &y, &buf_y_start, &buf_y_samples);
410+
if (ret) {
411+
source_release_data(source, 0);
412+
return ret;
413+
}
414+
365415
while (samples) {
366-
nbuf = audio_stream_samples_without_wrap_s32(source, x);
416+
nbuf = cir_buf_samples_to_wrap_s32(x, buf_x_start, buf_x_samples);
367417
npcm = MIN(samples, nbuf);
368-
nbuf = audio_stream_samples_without_wrap_s32(sink, y);
418+
nbuf = cir_buf_samples_to_wrap_s32(y, buf_y_start, buf_y_samples);
369419
npcm = MIN(npcm, nbuf);
370420
for (i = 0; i < npcm; i += nch) {
371421
for (ch = 0; ch < nch; ch++) {
@@ -397,9 +447,14 @@ static void multiband_drc_s32_default(const struct processing_module *mod,
397447
}
398448
}
399449
samples -= npcm;
400-
x = audio_stream_wrap(source, x);
401-
y = audio_stream_wrap(sink, y);
450+
if (x >= buf_x_start + buf_x_samples)
451+
x = buf_x_start;
452+
if (y >= buf_y_start + buf_y_samples)
453+
y = buf_y_start;
402454
}
455+
source_release_data(source, n_bytes);
456+
sink_commit_buffer(sink, n_bytes);
457+
return 0;
403458
}
404459
#endif /* CONFIG_FORMAT_S32LE */
405460

src/include/module/audio/audio_stream.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,32 @@ struct sof_audio_stream_params {
7474
enum sof_audio_buffer_state state; /**< audio stream state */
7575
};
7676

77+
/**
78+
* @brief Calculates numbers of s16 samples to buffer wrap.
79+
* @param ptr Read or write pointer of circular buffer.
80+
* @param buf_start Start address of circular buffer.
81+
* @return Number of samples to buffer wrap.
82+
*/
83+
static inline int cir_buf_samples_to_wrap_s16(const int16_t *ptr, const int16_t *buf_start,
84+
int buf_samples)
85+
{
86+
const int16_t *const buf_end = buf_start + buf_samples;
87+
88+
return buf_end - ptr;
89+
}
90+
91+
/**
92+
* @brief Calculates numbers of s32 samples to buffer wrap.
93+
* @param ptr Read or write pointer of circular buffer.
94+
* @param buf_start Start address of circular buffer.
95+
* @return Number of samples to buffer wrap.
96+
*/
97+
static inline int cir_buf_samples_to_wrap_s32(const int32_t *ptr, const int32_t *buf_start,
98+
int buf_samples)
99+
{
100+
const int32_t *const buf_end = buf_start + buf_samples;
101+
102+
return buf_end - ptr;
103+
}
104+
77105
#endif /* __MODULE_AUDIO_AUDIO_STREAM_H__ */

0 commit comments

Comments
 (0)