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
2223static 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
0 commit comments