From a465858947599c5577f89e71cb8846a02adbafad Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 14 Oct 2026 15:19:53 +0200 Subject: [PATCH 1/4] audio: drc: drop const-discarding casts on source pointers Declare the source read pointers const and drop the casts that discarded const. Use source_cir_buf_wrap for the source-side wrap to preserve the const qualifier, and take const void * in the local set_circular helpers. In the HiFi4 path, switch the sample pointers to ae_int16 and ae_int32 end to end, which also removes the int16_t-to-ae_int16 bridging casts. Signed-off-by: Adrian Warecki --- src/audio/drc/drc_generic.c | 23 +++++----- src/audio/drc/drc_hifi4.c | 87 ++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/audio/drc/drc_generic.c b/src/audio/drc/drc_generic.c index bf903d1cbabf..221936337bd6 100644 --- a/src/audio/drc/drc_generic.c +++ b/src/audio/drc/drc_generic.c @@ -480,20 +480,19 @@ void drc_default_pass(struct processing_module *mod, size_t bytes = (size_t)frames * cd->channels * sample_bytes; const uint8_t *src = source->ptr; uint8_t *dst = sink->ptr; - int n; + size_t n; while (bytes) { - n = MIN((const uint8_t *)source->buf_end - src, - (uint8_t *)sink->buf_end - dst); + n = MIN(cir_buf_bytes_without_wrap(src, source->buf_end), + cir_buf_bytes_without_wrap(dst, sink->buf_end)); n = MIN(n, bytes); if (!n) { - src = cir_buf_wrap(src, source->buf_start, source->buf_end); + src = source_cir_buf_wrap(src, source->buf_start, source->buf_end); dst = cir_buf_wrap(dst, sink->buf_start, sink->buf_end); continue; } memcpy_s(dst, n, src, n); - src = cir_buf_wrap((void *)(src + n), (void *)source->buf_start, - (void *)source->buf_end); + src = source_cir_buf_wrap(src + n, source->buf_start, source->buf_end); dst = cir_buf_wrap(dst + n, sink->buf_start, sink->buf_end); bytes -= n; } @@ -560,8 +559,8 @@ static void drc_s16_default(struct processing_module *mod, { struct drc_comp_data *cd = module_get_private_data(mod); int nch = cd->channels; - const int16_t *x = (int16_t *)source->ptr; - int16_t *y = (int16_t *)sink->ptr; + const int16_t *x = source->ptr; + int16_t *y = sink->ptr; size_t samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ @@ -704,8 +703,8 @@ static void drc_s24_default(struct processing_module *mod, { struct drc_comp_data *cd = module_get_private_data(mod); int nch = cd->channels; - const int32_t *x = (int32_t *)source->ptr; - int32_t *y = (int32_t *)sink->ptr; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; size_t samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ @@ -752,8 +751,8 @@ static void drc_s32_default(struct processing_module *mod, { struct drc_comp_data *cd = module_get_private_data(mod); int nch = cd->channels; - const int32_t *x = (int32_t *)source->ptr; - int32_t *y = (int32_t *)sink->ptr; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; size_t samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ diff --git a/src/audio/drc/drc_hifi4.c b/src/audio/drc/drc_hifi4.c index 707aa2d89d98..20c440132f9f 100644 --- a/src/audio/drc/drc_hifi4.c +++ b/src/audio/drc/drc_hifi4.c @@ -41,13 +41,13 @@ /* This is the knee part of the compression curve. Returns the output level * given the input level x. */ -static inline void set_circular_buf0(void *buf, void *buf_end) +static inline void set_circular_buf0(const void *buf, const void *buf_end) { AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); } -static inline void set_circular_buf1(void *buf, void *buf_end) +static inline void set_circular_buf1(const void *buf, const void *buf_end) { AE_SETCBEGIN1(buf); AE_SETCEND1(buf_end); @@ -534,20 +534,19 @@ void drc_default_pass(struct processing_module *mod, size_t bytes = (size_t)frames * cd->channels * sample_bytes; const uint8_t *src = source->ptr; uint8_t *dst = sink->ptr; - int n; + size_t n; while (bytes) { - n = MIN((const uint8_t *)source->buf_end - src, - (uint8_t *)sink->buf_end - dst); + n = MIN(cir_buf_bytes_without_wrap(src, source->buf_end), + cir_buf_bytes_without_wrap(dst, sink->buf_end)); n = MIN(n, bytes); if (!n) { - src = cir_buf_wrap(src, source->buf_start, source->buf_end); + src = source_cir_buf_wrap(src, source->buf_start, source->buf_end); dst = cir_buf_wrap(dst, sink->buf_start, sink->buf_end); continue; } memcpy_s(dst, n, src, n); - src = cir_buf_wrap((void *)(src + n), (void *)source->buf_start, - (void *)source->buf_end); + src = source_cir_buf_wrap(src + n, source->buf_start, source->buf_end); dst = cir_buf_wrap(dst + n, sink->buf_start, sink->buf_end); bytes -= n; } @@ -562,9 +561,9 @@ static inline void drc_pre_delay_index_inc(int *idx, int increment) static void drc_delay_input_sample_s16(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - int16_t **x, int16_t **y, int samples, int nch) + const ae_int16 **x, ae_int16 **y, int samples, int nch) { - ae_int16 *x1; + const ae_int16 *x1; ae_int16 *y1; ae_int16 *pd; ae_int16 *pd_r; @@ -572,8 +571,8 @@ static void drc_delay_input_sample_s16(struct drc_state *state, int nbuf, npcm, nfrm; int ch; int i; - ae_int16 *x0 = (ae_int16 *)*x; - ae_int16 *y0 = (ae_int16 *)*y; + const ae_int16 *x0 = *x; + ae_int16 *y0 = *y; int remaining_samples = samples; const int sample_inc = nch * sizeof(int16_t); const int delay_inc = sizeof(int16_t); @@ -601,14 +600,14 @@ static void drc_delay_input_sample_s16(struct drc_state *state, } } remaining_samples -= npcm; - x0 = cir_buf_wrap(x0 + npcm, source->buf_start, source->buf_end); + x0 = source_cir_buf_wrap(x0 + npcm, source->buf_start, source->buf_end); y0 = cir_buf_wrap(y0 + npcm, sink->buf_start, sink->buf_end); drc_pre_delay_index_inc(&state->pre_delay_write_index, nfrm); drc_pre_delay_index_inc(&state->pre_delay_read_index, nfrm); } - *x = (int16_t *)x0; - *y = (int16_t *)y0; + *x = x0; + *y = y0; } static void drc_s16_default(struct processing_module *mod, @@ -617,9 +616,9 @@ static void drc_s16_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; - int16_t *x = (int16_t *)source->ptr; - int16_t *y = (int16_t *)sink->ptr; + const unsigned int nch = cd->channels; + const ae_int16 *x = source->ptr; + ae_int16 *y = sink->ptr; int samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ @@ -627,7 +626,7 @@ static void drc_s16_default(struct processing_module *mod, ae_int16 *pd; ae_int16 *pd_r; ae_int16 *pd_w; - ae_int16 *x1; + const ae_int16 *x1; ae_int16 *y1; int i, ch; ae_int16x4 sample; @@ -649,7 +648,7 @@ static void drc_s16_default(struct processing_module *mod, state->processed = 1; } - set_circular_buf0((void *)source->buf_start, (void *)source->buf_end); + set_circular_buf0(source->buf_start, source->buf_end); set_circular_buf1(sink->buf_start, sink->buf_end); while (frames) { @@ -659,8 +658,8 @@ static void drc_s16_default(struct processing_module *mod, for (ch = 0; ch < nch; ++ch) { pd = (ae_int16 *)state->pre_delay_buffers[ch]; - x1 = (ae_int16 *)x + ch; - y1 = (ae_int16 *)y + ch; + x1 = x + ch; + y1 = y + ch; pd_r = pd + state->pre_delay_read_index; pd_w = pd + state->pre_delay_write_index; @@ -680,7 +679,7 @@ static void drc_s16_default(struct processing_module *mod, } drc_pre_delay_index_inc(&state->pre_delay_write_index, fragment); drc_pre_delay_index_inc(&state->pre_delay_read_index, fragment); - x = cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); + x = source_cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); y = cir_buf_wrap(y + fragment * nch, sink->buf_start, sink->buf_end); frames -= fragment; @@ -695,9 +694,9 @@ static void drc_s16_default(struct processing_module *mod, static void drc_delay_input_sample_s32(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - int32_t **x, int32_t **y, int samples, int nch) + const ae_int32 **x, ae_int32 **y, int samples, int nch) { - ae_int32 *x1; + const ae_int32 *x1; ae_int32 *y1; ae_int32 *pd_r; ae_int32 *pd_w; @@ -705,8 +704,8 @@ static void drc_delay_input_sample_s32(struct drc_state *state, int nbuf, npcm, nfrm; int ch; int i; - ae_int32 *x0 = (ae_int32 *)*x; - ae_int32 *y0 = (ae_int32 *)*y; + const ae_int32 *x0 = *x; + ae_int32 *y0 = *y; ae_int32x2 sample; int remaining_samples = samples; @@ -738,14 +737,14 @@ static void drc_delay_input_sample_s32(struct drc_state *state, } } remaining_samples -= npcm; - x0 = cir_buf_wrap(x0 + npcm, source->buf_start, source->buf_end); + x0 = source_cir_buf_wrap(x0 + npcm, source->buf_start, source->buf_end); y0 = cir_buf_wrap(y0 + npcm, sink->buf_start, sink->buf_end); drc_pre_delay_index_inc(&state->pre_delay_write_index, nfrm); drc_pre_delay_index_inc(&state->pre_delay_read_index, nfrm); } - *x = (int32_t *)x0; - *y = (int32_t *)y0; + *x = x0; + *y = y0; } #endif @@ -758,8 +757,8 @@ static void drc_s24_default(struct processing_module *mod, { struct drc_comp_data *cd = module_get_private_data(mod); int nch = cd->channels; - int32_t *x = (int32_t *)source->ptr; - int32_t *y = (int32_t *)sink->ptr; + const ae_int32 *x = source->ptr; + ae_int32 *y = sink->ptr; int samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ @@ -767,7 +766,7 @@ static void drc_s24_default(struct processing_module *mod, ae_int32 *pd; ae_int32 *pd_r; ae_int32 *pd_w; - ae_int32 *x1; + const ae_int32 *x1; ae_int32 *y1; int i, ch; ae_int32x2 sample; @@ -789,7 +788,7 @@ static void drc_s24_default(struct processing_module *mod, state->processed = 1; } - set_circular_buf0((void *)source->buf_start, (void *)source->buf_end); + set_circular_buf0(source->buf_start, source->buf_end); set_circular_buf1(sink->buf_start, sink->buf_end); while (frames) { @@ -799,8 +798,8 @@ static void drc_s24_default(struct processing_module *mod, for (ch = 0; ch < nch; ++ch) { pd = (ae_int32 *)state->pre_delay_buffers[ch]; - x1 = (ae_int32 *)x + ch; - y1 = (ae_int32 *)y + ch; + x1 = x + ch; + y1 = y + ch; pd_r = pd + state->pre_delay_read_index; pd_w = pd + state->pre_delay_write_index; @@ -827,7 +826,7 @@ static void drc_s24_default(struct processing_module *mod, } drc_pre_delay_index_inc(&state->pre_delay_write_index, fragment); drc_pre_delay_index_inc(&state->pre_delay_read_index, fragment); - x = cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); + x = source_cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); y = cir_buf_wrap(y + fragment * nch, sink->buf_start, sink->buf_end); frames -= fragment; @@ -846,15 +845,15 @@ static void drc_s32_default(struct processing_module *mod, { struct drc_comp_data *cd = module_get_private_data(mod); int nch = cd->channels; - int32_t *x = (int32_t *)source->ptr; - int32_t *y = (int32_t *)sink->ptr; + const ae_int32 *x = source->ptr; + ae_int32 *y = sink->ptr; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ int fragment; ae_int32 *pd; ae_int32 *pd_r; ae_int32 *pd_w; - ae_int32 *x1; + const ae_int32 *x1; ae_int32 *y1; int i, ch; ae_int32x2 sample; @@ -876,7 +875,7 @@ static void drc_s32_default(struct processing_module *mod, state->processed = 1; } - set_circular_buf0((void *)source->buf_start, (void *)source->buf_end); + set_circular_buf0(source->buf_start, source->buf_end); set_circular_buf1(sink->buf_start, sink->buf_end); while (frames) { @@ -886,8 +885,8 @@ static void drc_s32_default(struct processing_module *mod, for (ch = 0; ch < nch; ++ch) { pd = (ae_int32 *)state->pre_delay_buffers[ch]; - x1 = (ae_int32 *)x + ch; - y1 = (ae_int32 *)y + ch; + x1 = x + ch; + y1 = y + ch; pd_r = pd + state->pre_delay_read_index; pd_w = pd + state->pre_delay_write_index; @@ -909,7 +908,7 @@ static void drc_s32_default(struct processing_module *mod, } drc_pre_delay_index_inc(&state->pre_delay_write_index, fragment); drc_pre_delay_index_inc(&state->pre_delay_read_index, fragment); - x = cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); + x = source_cir_buf_wrap(x + fragment * nch, source->buf_start, source->buf_end); y = cir_buf_wrap(y + fragment * nch, sink->buf_start, sink->buf_end); frames -= fragment; From a1da69db69840d35e194516e4b74435671cc17df Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 14 Oct 2026 15:36:01 +0200 Subject: [PATCH 2/4] audio: drc: use unsigned int for channel counts Change the channels field, the channel-count parameters and the per-channel loop counters from int and uint16_t to unsigned int. This matches the type returned by source_get_channels and sink_get_channels and removes the signed/unsigned comparisons. Signed-off-by: Adrian Warecki --- src/audio/drc/drc.c | 10 +++++----- src/audio/drc/drc.h | 2 +- src/audio/drc/drc_algorithm.h | 6 +++--- src/audio/drc/drc_generic.c | 33 +++++++++++++++++++-------------- src/audio/drc/drc_hifi3.c | 10 ++++++---- src/audio/drc/drc_hifi4.c | 35 +++++++++++++++++++++-------------- 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index ceb1b1b0bd6e..d49337c9a5ed 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -70,11 +70,11 @@ void drc_reset_state(struct processing_module *mod, struct drc_state *state) int drc_init_pre_delay_buffers(struct processing_module *mod, struct drc_state *state, size_t sample_bytes, - int channels) + unsigned int channels) { size_t bytes_per_channel = sample_bytes * CONFIG_DRC_MAX_PRE_DELAY_FRAMES; size_t bytes_total = bytes_per_channel * channels; - int i; + unsigned int i; /* Allocate pre-delay (lookahead) buffers */ state->pre_delay_buffers[0] = mod_alloc(mod, bytes_total); @@ -122,7 +122,7 @@ int drc_set_pre_delay_time(struct drc_state *state, } /* Called from drc_process(), so cannot be __cold */ -static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t rate) +static int drc_setup(struct processing_module *mod, unsigned int channels, uint32_t rate) { struct drc_comp_data *cd = module_get_private_data(mod); uint32_t sample_bytes = get_sample_bytes(cd->source_format); @@ -132,7 +132,7 @@ static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t drc_reset_state(mod, &cd->state); /* Allocate pre-delay buffers */ - ret = drc_init_pre_delay_buffers(mod, &cd->state, (size_t)sample_bytes, (int)channels); + ret = drc_init_pre_delay_buffers(mod, &cd->state, (size_t)sample_bytes, channels); if (ret < 0) return ret; @@ -388,7 +388,7 @@ static int drc_prepare(struct processing_module *mod, struct drc_comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; struct comp_dev *dev = mod->dev; - int channels; + unsigned int channels; int rate; int ret; diff --git a/src/audio/drc/drc.h b/src/audio/drc/drc.h index 140877b21895..0f58495f7696 100644 --- a/src/audio/drc/drc.h +++ b/src/audio/drc/drc.h @@ -81,7 +81,7 @@ struct drc_comp_data { bool enabled; /**< control processing via blob and switch */ bool enable_switch; /**< enable switch state */ enum sof_ipc_frame source_format; /**< source frame format */ - int channels; /**< number of channels */ + unsigned int channels; /**< number of channels */ drc_func drc_func; /**< processing function */ }; diff --git a/src/audio/drc/drc_algorithm.h b/src/audio/drc/drc_algorithm.h index 8d9d759eb3a8..9d827b77bbc7 100644 --- a/src/audio/drc/drc_algorithm.h +++ b/src/audio/drc/drc_algorithm.h @@ -20,7 +20,7 @@ void drc_reset_state(struct processing_module *mod, struct drc_state *state); int drc_init_pre_delay_buffers(struct processing_module *mod, struct drc_state *state, size_t sample_bytes, - int channels); + unsigned int channels); int drc_set_pre_delay_time(struct drc_state *state, int32_t pre_delay_time, int32_t rate); @@ -29,11 +29,11 @@ int drc_set_pre_delay_time(struct drc_state *state, void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch); + unsigned int nch); void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p); void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch); + unsigned int nch); #endif // __SOF_AUDIO_DRC_DRC_ALGORITHM_H__ diff --git a/src/audio/drc/drc_generic.c b/src/audio/drc/drc_generic.c index 221936337bd6..d418985c20e9 100644 --- a/src/audio/drc/drc_generic.c +++ b/src/audio/drc/drc_generic.c @@ -82,11 +82,12 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { int32_t detector_average = state->detector_average; /* Q2.30 */ int32_t abs_input_array[DRC_DIVISION_FRAMES]; /* Q1.31 */ - int div_start, i, ch; + int div_start, i; + unsigned int ch; int16_t *sample16_p; /* for s16 format case */ int32_t *sample32_p; /* for s24 and s32 format cases */ int32_t sample; @@ -265,7 +266,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { const int div_start = state->pre_delay_read_index; int count = DRC_DIVISION_FRAMES >> 2; @@ -275,7 +276,8 @@ void drc_compress_output(struct drc_state *state, int32_t post_warp_compressor_gain; int32_t total_gain; - int i, j, ch, inc; + int i, j, inc; + unsigned int ch; int16_t *sample16_p; /* for s16 format case */ int32_t *sample32_p; /* for s24 and s32 format cases */ int32_t sample; @@ -464,7 +466,7 @@ void drc_compress_output(struct drc_state *state, static void drc_process_one_division(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { drc_update_detector_average(state, p, nbyte, nch); drc_update_envelope(state, p); @@ -507,14 +509,15 @@ static inline void drc_pre_delay_index_inc(int *idx, int increment) static void drc_delay_input_sample_s16(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const int16_t **x, int16_t **y, size_t samples, int nch) + const int16_t **x, int16_t **y, size_t samples, + unsigned int nch) { const int16_t *x1; int16_t *y1; int16_t *pd; int pd_write_index, pd_read_index; size_t nbuf, npcm, nfrm; - int ch; + unsigned int ch; size_t i; const int16_t *x0 = *x; int16_t *y0 = *y; @@ -558,7 +561,7 @@ static void drc_s16_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; + const unsigned int nch = cd->channels; const int16_t *x = source->ptr; int16_t *y = sink->ptr; size_t samples = frames * nch; @@ -601,14 +604,15 @@ static void drc_s16_default(struct processing_module *mod, static void drc_delay_input_sample_s32(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const int32_t **x, int32_t **y, size_t samples, int nch) + const int32_t **x, int32_t **y, size_t samples, + unsigned int nch) { const int32_t *x1; int32_t *y1; int32_t *pd; int pd_write_index, pd_read_index; size_t nbuf, npcm, nfrm; - int ch; + unsigned int ch; size_t i; const int32_t *x0 = *x; int32_t *y0 = *y; @@ -651,14 +655,15 @@ static void drc_delay_input_sample_s32(struct drc_state *state, static void drc_delay_input_sample_s24(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const int32_t **x, int32_t **y, size_t samples, int nch) + const int32_t **x, int32_t **y, size_t samples, + unsigned int nch) { const int32_t *x1; int32_t *y1; int32_t *pd; int pd_write_index, pd_read_index; size_t nbuf, npcm, nfrm; - int ch; + unsigned int ch; size_t i; const int32_t *x0 = *x; int32_t *y0 = *y; @@ -702,7 +707,7 @@ static void drc_s24_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; + const unsigned int nch = cd->channels; const int32_t *x = source->ptr; int32_t *y = sink->ptr; size_t samples = frames * nch; @@ -750,7 +755,7 @@ static void drc_s32_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; + const unsigned int nch = cd->channels; const int32_t *x = source->ptr; int32_t *y = sink->ptr; size_t samples = frames * nch; diff --git a/src/audio/drc/drc_hifi3.c b/src/audio/drc/drc_hifi3.c index 3a5d23c7d230..e94332167d42 100644 --- a/src/audio/drc/drc_hifi3.c +++ b/src/audio/drc/drc_hifi3.c @@ -90,12 +90,13 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { ae_f32 detector_average = state->detector_average; /* Q2.30 */ int32_t abs_input_array[DRC_DIVISION_FRAMES]; /* Q1.31 */ int32_t *abs_input_array_p; - int div_start, i, ch; + int div_start, i; + unsigned int ch; int16_t *sample16_p; /* for s16 format case */ int32_t *sample32_p; /* for s24 and s32 format cases */ int32_t sample; @@ -293,7 +294,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { const int div_start = state->pre_delay_read_index; const int count = DRC_DIVISION_FRAMES >> 2; @@ -304,7 +305,8 @@ void drc_compress_output(struct drc_state *state, ae_f32 total_gain; ae_f32 tmp; - int i, j, ch, inc; + int i, j, inc; + unsigned int ch; int16_t *sample16_p; /* for s16 format case */ int32_t *sample32_p; /* for s24 and s32 format cases */ int32_t sample; diff --git a/src/audio/drc/drc_hifi4.c b/src/audio/drc/drc_hifi4.c index 20c440132f9f..038ee7bba63b 100644 --- a/src/audio/drc/drc_hifi4.c +++ b/src/audio/drc/drc_hifi4.c @@ -114,12 +114,13 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { ae_f32 detector_average = state->detector_average; /* Q2.30 */ ae_int32 abs_input_array[DRC_DIVISION_FRAMES] __attribute__((aligned(8))); /* Q1.31 */ ae_int32 *abs_input_array_p; - int div_start, i, ch; + int div_start, i; + unsigned int ch; ae_int16 *sample16_p; /* for s16 format case */ ae_int32 *sample32_p; /* for s24 and s32 format cases */ ae_int32x2 sample32; @@ -324,14 +325,15 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { const int count = DRC_DIVISION_FRAMES >> 2; ae_f32 x[4]; /* Q2.30 */ ae_f32 c, base, r, r2, r4; /* Q2.30 */ ae_f32 post_warp_compressor_gain; ae_f32 total_gain; - int i, j, ch; + int i, j; + unsigned int ch; int inc = state->pre_delay_read_index; int16_t *sample16_p; /* for s16 format case */ int32_t *sample32_p; /* for s24 and s32 format cases */ @@ -518,7 +520,7 @@ void drc_compress_output(struct drc_state *state, static void drc_process_one_division(struct drc_state *state, const struct sof_drc_params *p, int nbyte, - int nch) + unsigned int nch) { drc_update_detector_average(state, p, nbyte, nch); drc_update_envelope(state, p); @@ -561,7 +563,8 @@ static inline void drc_pre_delay_index_inc(int *idx, int increment) static void drc_delay_input_sample_s16(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const ae_int16 **x, ae_int16 **y, int samples, int nch) + const ae_int16 **x, ae_int16 **y, int samples, + unsigned int nch) { const ae_int16 *x1; ae_int16 *y1; @@ -569,7 +572,7 @@ static void drc_delay_input_sample_s16(struct drc_state *state, ae_int16 *pd_r; ae_int16 *pd_w; int nbuf, npcm, nfrm; - int ch; + unsigned int ch; int i; const ae_int16 *x0 = *x; ae_int16 *y0 = *y; @@ -628,7 +631,8 @@ static void drc_s16_default(struct processing_module *mod, ae_int16 *pd_w; const ae_int16 *x1; ae_int16 *y1; - int i, ch; + int i; + unsigned int ch; ae_int16x4 sample; const int sample_inc = nch * sizeof(ae_int16); const int delay_inc = sizeof(ae_int16); @@ -694,7 +698,8 @@ static void drc_s16_default(struct processing_module *mod, static void drc_delay_input_sample_s32(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const ae_int32 **x, ae_int32 **y, int samples, int nch) + const ae_int32 **x, ae_int32 **y, int samples, + unsigned int nch) { const ae_int32 *x1; ae_int32 *y1; @@ -702,7 +707,7 @@ static void drc_delay_input_sample_s32(struct drc_state *state, ae_int32 *pd_w; ae_int32 *pd; int nbuf, npcm, nfrm; - int ch; + unsigned int ch; int i; const ae_int32 *x0 = *x; ae_int32 *y0 = *y; @@ -756,7 +761,7 @@ static void drc_s24_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; + const unsigned int nch = cd->channels; const ae_int32 *x = source->ptr; ae_int32 *y = sink->ptr; int samples = frames * nch; @@ -768,7 +773,8 @@ static void drc_s24_default(struct processing_module *mod, ae_int32 *pd_w; const ae_int32 *x1; ae_int32 *y1; - int i, ch; + int i; + unsigned int ch; ae_int32x2 sample; const int sample_inc = nch * sizeof(int32_t); const int delay_inc = sizeof(int32_t); @@ -844,7 +850,7 @@ static void drc_s32_default(struct processing_module *mod, uint32_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - int nch = cd->channels; + const unsigned int nch = cd->channels; const ae_int32 *x = source->ptr; ae_int32 *y = sink->ptr; struct drc_state *state = &cd->state; @@ -855,7 +861,8 @@ static void drc_s32_default(struct processing_module *mod, ae_int32 *pd_w; const ae_int32 *x1; ae_int32 *y1; - int i, ch; + int i; + unsigned int ch; ae_int32x2 sample; const int sample_inc = nch * sizeof(int32_t); const int delay_inc = sizeof(int32_t); From 7cbfdcb8018927c073654e3ad8f007fbf1759dfb Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 14 Oct 2026 16:59:15 +0200 Subject: [PATCH 3/4] audio: drc: use size_t for byte, sample and frame counts Convert the frame, sample and byte counts from int and uint32_t to size_t and propagate the type through the dependent locals and the DSP helper signatures. This aligns with the size_t byte sizes already used by the sink/source API. Signed-off-by: Adrian Warecki --- src/audio/drc/drc.c | 6 ++--- src/audio/drc/drc.h | 4 +-- src/audio/drc/drc_algorithm.h | 4 +-- src/audio/drc/drc_generic.c | 18 ++++++------- src/audio/drc/drc_hifi3.c | 4 +-- src/audio/drc/drc_hifi4.c | 50 +++++++++++++++++------------------ 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index d49337c9a5ed..cfdc4c08f8f7 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -125,14 +125,14 @@ int drc_set_pre_delay_time(struct drc_state *state, static int drc_setup(struct processing_module *mod, unsigned int channels, uint32_t rate) { struct drc_comp_data *cd = module_get_private_data(mod); - uint32_t sample_bytes = get_sample_bytes(cd->source_format); + size_t sample_bytes = get_sample_bytes(cd->source_format); int ret; /* Reset any previous state */ drc_reset_state(mod, &cd->state); /* Allocate pre-delay buffers */ - ret = drc_init_pre_delay_buffers(mod, &cd->state, (size_t)sample_bytes, channels); + ret = drc_init_pre_delay_buffers(mod, &cd->state, sample_bytes, channels); if (ret < 0) return ret; @@ -285,7 +285,7 @@ static int drc_process(struct processing_module *mod, size_t sink_frame_bytes = sink_get_frame_bytes(sink); size_t source_bytes, sink_bytes; size_t source_buf_size, sink_buf_size; - uint32_t frames; + size_t frames; int ret; comp_dbg(dev, "entry"); diff --git a/src/audio/drc/drc.h b/src/audio/drc/drc.h index 0f58495f7696..cde3b9658dbd 100644 --- a/src/audio/drc/drc.h +++ b/src/audio/drc/drc.h @@ -70,7 +70,7 @@ struct drc_state { typedef void (*drc_func)(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames); + size_t frames); /* DRC component private data */ struct drc_comp_data { @@ -95,7 +95,7 @@ extern const size_t drc_proc_fncount; void drc_default_pass(struct processing_module *mod, const struct cir_buf_source *source, - struct cir_buf_sink *sink, uint32_t frames); + struct cir_buf_sink *sink, size_t frames); /** * \brief Returns DRC processing function. */ diff --git a/src/audio/drc/drc_algorithm.h b/src/audio/drc/drc_algorithm.h index 9d827b77bbc7..a3ee831926c7 100644 --- a/src/audio/drc/drc_algorithm.h +++ b/src/audio/drc/drc_algorithm.h @@ -28,12 +28,12 @@ int drc_set_pre_delay_time(struct drc_state *state, /* drc process functions */ void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch); void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p); void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch); #endif // __SOF_AUDIO_DRC_DRC_ALGORITHM_H__ diff --git a/src/audio/drc/drc_generic.c b/src/audio/drc/drc_generic.c index d418985c20e9..7aa32ccb30a6 100644 --- a/src/audio/drc/drc_generic.c +++ b/src/audio/drc/drc_generic.c @@ -81,7 +81,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) /* Update detector_average from the last input division. */ void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { int32_t detector_average = state->detector_average; /* Q2.30 */ @@ -265,7 +265,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p * the next output division. */ void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { const int div_start = state->pre_delay_read_index; @@ -465,7 +465,7 @@ void drc_compress_output(struct drc_state *state, */ static void drc_process_one_division(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { drc_update_detector_average(state, p, nbyte, nch); @@ -475,11 +475,11 @@ static void drc_process_one_division(struct drc_state *state, void drc_default_pass(struct processing_module *mod, const struct cir_buf_source *source, - struct cir_buf_sink *sink, uint32_t frames) + struct cir_buf_sink *sink, size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - const int sample_bytes = get_sample_bytes(cd->source_format); - size_t bytes = (size_t)frames * cd->channels * sample_bytes; + const size_t sample_bytes = get_sample_bytes(cd->source_format); + size_t bytes = frames * cd->channels * sample_bytes; const uint8_t *src = source->ptr; uint8_t *dst = sink->ptr; size_t n; @@ -558,7 +558,7 @@ static void drc_delay_input_sample_s16(struct drc_state *state, static void drc_s16_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; @@ -704,7 +704,7 @@ static void drc_delay_input_sample_s24(struct drc_state *state, static void drc_s24_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; @@ -752,7 +752,7 @@ static void drc_s24_default(struct processing_module *mod, static void drc_s32_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; diff --git a/src/audio/drc/drc_hifi3.c b/src/audio/drc/drc_hifi3.c index e94332167d42..4710b27a3a6b 100644 --- a/src/audio/drc/drc_hifi3.c +++ b/src/audio/drc/drc_hifi3.c @@ -89,7 +89,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) /* Update detector_average from the last input division. */ void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { ae_f32 detector_average = state->detector_average; /* Q2.30 */ @@ -293,7 +293,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p */ void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { const int div_start = state->pre_delay_read_index; diff --git a/src/audio/drc/drc_hifi4.c b/src/audio/drc/drc_hifi4.c index 038ee7bba63b..16763aa30823 100644 --- a/src/audio/drc/drc_hifi4.c +++ b/src/audio/drc/drc_hifi4.c @@ -113,7 +113,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) /* Update detector_average from the last input division. */ void drc_update_detector_average(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { ae_f32 detector_average = state->detector_average; /* Q2.30 */ @@ -324,7 +324,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p */ void drc_compress_output(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { const int count = DRC_DIVISION_FRAMES >> 2; @@ -519,7 +519,7 @@ void drc_compress_output(struct drc_state *state, */ static void drc_process_one_division(struct drc_state *state, const struct sof_drc_params *p, - int nbyte, + size_t nbyte, unsigned int nch) { drc_update_detector_average(state, p, nbyte, nch); @@ -529,11 +529,11 @@ static void drc_process_one_division(struct drc_state *state, void drc_default_pass(struct processing_module *mod, const struct cir_buf_source *source, - struct cir_buf_sink *sink, uint32_t frames) + struct cir_buf_sink *sink, size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); - const int sample_bytes = get_sample_bytes(cd->source_format); - size_t bytes = (size_t)frames * cd->channels * sample_bytes; + const size_t sample_bytes = get_sample_bytes(cd->source_format); + size_t bytes = frames * cd->channels * sample_bytes; const uint8_t *src = source->ptr; uint8_t *dst = sink->ptr; size_t n; @@ -563,7 +563,7 @@ static inline void drc_pre_delay_index_inc(int *idx, int increment) static void drc_delay_input_sample_s16(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const ae_int16 **x, ae_int16 **y, int samples, + const ae_int16 **x, ae_int16 **y, size_t samples, unsigned int nch) { const ae_int16 *x1; @@ -571,12 +571,12 @@ static void drc_delay_input_sample_s16(struct drc_state *state, ae_int16 *pd; ae_int16 *pd_r; ae_int16 *pd_w; - int nbuf, npcm, nfrm; + size_t nbuf, npcm, nfrm; unsigned int ch; - int i; + size_t i; const ae_int16 *x0 = *x; ae_int16 *y0 = *y; - int remaining_samples = samples; + size_t remaining_samples = samples; const int sample_inc = nch * sizeof(int16_t); const int delay_inc = sizeof(int16_t); ae_int16x4 sample; @@ -616,22 +616,22 @@ static void drc_delay_input_sample_s16(struct drc_state *state, static void drc_s16_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; const ae_int16 *x = source->ptr; ae_int16 *y = sink->ptr; - int samples = frames * nch; + size_t samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ - int fragment; + size_t fragment; ae_int16 *pd; ae_int16 *pd_r; ae_int16 *pd_w; const ae_int16 *x1; ae_int16 *y1; - int i; + size_t i; unsigned int ch; ae_int16x4 sample; const int sample_inc = nch * sizeof(ae_int16); @@ -698,7 +698,7 @@ static void drc_s16_default(struct processing_module *mod, static void drc_delay_input_sample_s32(struct drc_state *state, const struct cir_buf_source *source, struct cir_buf_sink *sink, - const ae_int32 **x, ae_int32 **y, int samples, + const ae_int32 **x, ae_int32 **y, size_t samples, unsigned int nch) { const ae_int32 *x1; @@ -706,14 +706,14 @@ static void drc_delay_input_sample_s32(struct drc_state *state, ae_int32 *pd_r; ae_int32 *pd_w; ae_int32 *pd; - int nbuf, npcm, nfrm; + size_t nbuf, npcm, nfrm; unsigned int ch; - int i; + size_t i; const ae_int32 *x0 = *x; ae_int32 *y0 = *y; ae_int32x2 sample; - int remaining_samples = samples; + size_t remaining_samples = samples; const int sample_inc = nch * sizeof(int32_t); const int delay_inc = sizeof(int32_t); @@ -758,22 +758,22 @@ static void drc_delay_input_sample_s32(struct drc_state *state, static void drc_s24_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; const ae_int32 *x = source->ptr; ae_int32 *y = sink->ptr; - int samples = frames * nch; + size_t samples = frames * nch; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ - int fragment; + size_t fragment; ae_int32 *pd; ae_int32 *pd_r; ae_int32 *pd_w; const ae_int32 *x1; ae_int32 *y1; - int i; + size_t i; unsigned int ch; ae_int32x2 sample; const int sample_inc = nch * sizeof(int32_t); @@ -847,7 +847,7 @@ static void drc_s24_default(struct processing_module *mod, static void drc_s32_default(struct processing_module *mod, const struct cir_buf_source *source, struct cir_buf_sink *sink, - uint32_t frames) + size_t frames) { struct drc_comp_data *cd = module_get_private_data(mod); const unsigned int nch = cd->channels; @@ -855,13 +855,13 @@ static void drc_s32_default(struct processing_module *mod, ae_int32 *y = sink->ptr; struct drc_state *state = &cd->state; const struct sof_drc_params *p = &cd->config->params; /* Read-only */ - int fragment; + size_t fragment; ae_int32 *pd; ae_int32 *pd_r; ae_int32 *pd_w; const ae_int32 *x1; ae_int32 *y1; - int i; + size_t i; unsigned int ch; ae_int32x2 sample; const int sample_inc = nch * sizeof(int32_t); From a63a058d78c29b573c5d2c11dacba9c878ef7fca Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 14 Oct 2026 17:19:19 +0200 Subject: [PATCH 4/4] audio: drc: drop comp_buffer from prepare and params Convert prepare and the IPC4 params helper to the sink/source API and drop the struct comp_buffer uses in the module. Signed-off-by: Adrian Warecki --- src/audio/drc/drc.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index cfdc4c08f8f7..b9265ed18238 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -360,10 +360,10 @@ static int drc_process(struct processing_module *mod, } #if CONFIG_IPC_MAJOR_4 -static void drc_params(struct processing_module *mod) +static void drc_params(struct processing_module *mod, struct sof_source *source, + struct sof_sink *sink) { struct sof_ipc_stream_params *params = mod->stream_params; - struct comp_buffer *sinkb, *sourceb; struct comp_dev *dev = mod->dev; comp_dbg(dev, "entry"); @@ -372,12 +372,8 @@ static void drc_params(struct processing_module *mod) component_set_nearest_period_frames(dev, params->rate); /* The caller has verified, that sink and source buffers are connected */ - - sinkb = comp_dev_get_first_data_consumer(dev); - ipc4_update_buffer_format(sinkb, &mod->priv.cfg.base_cfg.audio_fmt); - - sourceb = comp_dev_get_first_data_producer(dev); - ipc4_update_buffer_format(sourceb, &mod->priv.cfg.base_cfg.audio_fmt); + ipc4_update_sink_format(sink, &mod->priv.cfg.base_cfg.audio_fmt); + ipc4_update_source_format(source, &mod->priv.cfg.base_cfg.audio_fmt); } #endif /* CONFIG_IPC_MAJOR_4 */ @@ -386,7 +382,6 @@ static int drc_prepare(struct processing_module *mod, struct sof_sink **sinks, int num_of_sinks) { struct drc_comp_data *cd = module_get_private_data(mod); - struct comp_buffer *sourceb, *sinkb; struct comp_dev *dev = mod->dev; unsigned int channels; int rate; @@ -395,21 +390,20 @@ static int drc_prepare(struct processing_module *mod, comp_info(dev, "entry"); /* DRC component will only ever have 1 source and 1 sink buffer */ - sourceb = comp_dev_get_first_data_producer(dev); - sinkb = comp_dev_get_first_data_consumer(dev); - if (!sourceb || !sinkb) { - comp_err(dev, "no source or sink buffer"); + if (num_of_sources != 1 || num_of_sinks != 1) { + comp_err(dev, "expected 1 source and 1 sink, got %d sources and %d sinks", + num_of_sources, num_of_sinks); return -ENOTCONN; } #if CONFIG_IPC_MAJOR_4 - drc_params(mod); + drc_params(mod, sources[0], sinks[0]); #endif /* get source data format */ - cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream); - channels = audio_stream_get_channels(&sinkb->stream); - rate = audio_stream_get_rate(&sinkb->stream); + cd->source_format = source_get_frm_fmt(sources[0]); + channels = sink_get_channels(sinks[0]); + rate = sink_get_rate(sinks[0]); cd->channels = channels; /* Initialize DRC */