Skip to content

Commit 466c4aa

Browse files
audio: dcblock: switch to source/sink API
Convert the DC blocking filter from the deprecated audio_stream / process_audio_stream interface to the modern sof_source / sof_sink processing API. The module .process callback now acquires the source and sink circular buffers once via source_get_data() / sink_get_buffer() and passes them to the processing functions as struct cir_buf_source / struct cir_buf_sink views, mirroring the volume component. The generic path uses the shared cir_buf_samples_without_wrap_*() and cir_buf_wrap() helpers, while the HiFi3/HiFi4 variants derive the circular buffer bounds from the same views. Channel count is cached in comp_data during prepare(). Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent bab7157 commit 466c4aa

5 files changed

Lines changed: 361 additions & 223 deletions

File tree

src/audio/dcblock/dcblock.c

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <sof/audio/data_blob.h>
1111
#include <sof/audio/format.h>
1212
#include <sof/audio/pipeline.h>
13+
#include <sof/audio/sink_api.h>
14+
#include <sof/audio/source_api.h>
1315
#include <sof/audio/ipc-config.h>
1416
#include <sof/common.h>
1517
#include <rtos/panic.h>
@@ -140,25 +142,63 @@ static int dcblock_set_config(struct processing_module *mod, uint32_t config_id,
140142

141143
/**
142144
* \brief Copies and processes stream data.
143-
* \param[in,out] dev DC Blocking Filter module.
145+
* \param[in,out] mod DC Blocking Filter module.
144146
* \return Error code.
145147
*/
146148
static int dcblock_process(struct processing_module *mod,
147-
struct input_stream_buffer *input_buffers,
148-
int num_input_buffers,
149-
struct output_stream_buffer *output_buffers,
150-
int num_output_buffers)
149+
struct sof_source **sources, int num_of_sources,
150+
struct sof_sink **sinks, int num_of_sinks)
151151
{
152152
struct comp_data *cd = module_get_private_data(mod);
153-
struct audio_stream *source = input_buffers[0].data;
154-
struct audio_stream *sink = output_buffers[0].data;
155-
uint32_t frames = input_buffers[0].size;
156-
157-
comp_dbg(mod->dev, "entry");
158-
159-
cd->dcblock_func(cd, source, sink, frames);
153+
struct comp_dev *dev = mod->dev;
154+
struct sof_source *source = sources[0];
155+
struct sof_sink *sink = sinks[0];
156+
struct cir_buf_source source_buf;
157+
struct cir_buf_sink sink_buf;
158+
size_t source_frame_bytes = source_get_frame_bytes(source);
159+
size_t sink_frame_bytes = sink_get_frame_bytes(sink);
160+
size_t source_bytes, sink_bytes, bytes;
161+
uint32_t frames = source_get_data_frames_available(source);
162+
uint32_t sink_frames = sink_get_free_frames(sink);
163+
int ret;
164+
165+
comp_dbg(dev, "entry");
166+
167+
frames = MIN(frames, sink_frames);
168+
frames = MIN(frames, dev->frames);
169+
if (!frames)
170+
return 0;
171+
172+
source_bytes = frames * source_frame_bytes;
173+
sink_bytes = frames * sink_frame_bytes;
174+
175+
/* acquire the source and sink circular buffer views once */
176+
ret = source_get_data(source, source_bytes, &source_buf.ptr,
177+
&source_buf.buf_start, &bytes);
178+
if (ret)
179+
return ret;
180+
source_buf.buf_end = (const char *)source_buf.buf_start + bytes;
181+
182+
ret = sink_get_buffer(sink, sink_bytes, &sink_buf.ptr,
183+
&sink_buf.buf_start, &bytes);
184+
if (ret) {
185+
source_release_data(source, 0);
186+
return ret;
187+
}
188+
sink_buf.buf_end = (char *)sink_buf.buf_start + bytes;
189+
190+
ret = cd->dcblock_func(cd, &source_buf, &sink_buf, frames);
191+
if (ret) {
192+
/* Undo the acquire without consuming source data or
193+
* publishing partially-written output.
194+
*/
195+
source_release_data(source, 0);
196+
sink_commit_buffer(sink, 0);
197+
return ret;
198+
}
160199

161-
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
200+
source_release_data(source, source_bytes);
201+
sink_commit_buffer(sink, sink_bytes);
162202
return 0;
163203
}
164204

@@ -172,27 +212,35 @@ static int dcblock_prepare(struct processing_module *mod,
172212
struct sof_sink **sinks, int num_of_sinks)
173213
{
174214
struct comp_data *cd = module_get_private_data(mod);
175-
struct comp_buffer *sourceb, *sinkb;
176215
struct comp_dev *dev = mod->dev;
177216
size_t data_size;
178217

179218
comp_info(dev, "entry");
180219

181220
/* DC Filter component will only ever have one source and sink buffer */
182-
sourceb = comp_dev_get_first_data_producer(dev);
183-
sinkb = comp_dev_get_first_data_consumer(dev);
184-
if (!sourceb || !sinkb) {
185-
comp_err(dev, "no source or sink buffer");
186-
return -ENOTCONN;
221+
if (num_of_sources != 1 || num_of_sinks != 1) {
222+
comp_err(dev, "Invalid number of sources/sinks");
223+
return -EINVAL;
187224
}
188225

189226
dcblock_params(mod);
190227

191228
/* get source data format */
192-
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
229+
cd->source_format = source_get_frm_fmt(sources[0]);
230+
231+
/* get sink data format */
232+
cd->sink_format = sink_get_frm_fmt(sinks[0]);
233+
234+
/* The processing uses a single channel count as the frame stride for
235+
* both source and sink, so they must match to avoid corrupt output.
236+
*/
237+
if (source_get_channels(sources[0]) != sink_get_channels(sinks[0])) {
238+
comp_err(dev, "mismatch source/sink stream channels");
239+
return -EINVAL;
240+
}
193241

194-
/* get sink data format and period bytes */
195-
cd->sink_format = audio_stream_get_frm_fmt(&sinkb->stream);
242+
/* get channel count for processing */
243+
cd->channels = source_get_channels(sources[0]);
196244

197245
dcblock_init_state(cd);
198246
cd->dcblock_func = dcblock_find_func(cd->source_format);
@@ -238,7 +286,7 @@ static int dcblock_reset(struct processing_module *mod)
238286
static const struct module_interface dcblock_interface = {
239287
.init = dcblock_init,
240288
.prepare = dcblock_prepare,
241-
.process_audio_stream = dcblock_process,
289+
.process = dcblock_process,
242290
.set_configuration = dcblock_set_config,
243291
.get_configuration = dcblock_get_config,
244292
.reset = dcblock_reset,

src/audio/dcblock/dcblock.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
#include <sof/platform.h>
1313
#include <ipc/stream.h>
1414
#include <sof/compiler_info.h>
15+
#include <sof/audio/sink_api.h>
16+
#include <sof/audio/source_api.h>
1517
#include <module/module/base.h>
1618
#include <module/module/interface.h>
1719

1820
struct audio_stream;
1921
struct comp_dev;
22+
struct sof_source;
23+
struct sof_sink;
24+
struct cir_buf_source;
25+
struct cir_buf_sink;
2026

2127
struct dcblock_state {
2228
int32_t x_prev; /**< state variable referring to x[n-1] */
@@ -30,10 +36,10 @@ struct dcblock_state {
3036

3137
struct comp_data;
3238

33-
typedef void (*dcblock_func)(struct comp_data *cd,
34-
const struct audio_stream *source,
35-
const struct audio_stream *sink,
36-
uint32_t frames);
39+
typedef int (*dcblock_func)(struct comp_data *cd,
40+
struct cir_buf_source *source,
41+
struct cir_buf_sink *sink,
42+
uint32_t frames);
3743

3844
/* DC Blocking Filter component private data */
3945
struct comp_data {
@@ -48,6 +54,7 @@ struct comp_data {
4854

4955
enum sof_ipc_frame source_format;
5056
enum sof_ipc_frame sink_format;
57+
int channels; /**< number of channels */
5158
dcblock_func dcblock_func; /**< processing function */
5259
};
5360

0 commit comments

Comments
 (0)