From 15259c17dcc1b0059bc267462a1ef85f7cc59f90 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Tue, 13 Oct 2026 12:27:13 +0200 Subject: [PATCH 1/3] math: iir_df1: return size_t from iir_delay_size_df1 Change iir_delay_size_df1() to return size_t and report 0 on an invalid configuration instead of a negative value. Document that a 0 return signals an error, and add the missing return-value checks where callers did not handle that failure. Signed-off-by: Adrian Warecki --- src/audio/eq_iir/eq_iir_generic.c | 5 ++--- src/audio/sound_dose/sound_dose.c | 4 ++++ src/audio/tdfb/tdfb_direction.c | 4 ++++ src/include/sof/math/iir_df1.h | 4 ++-- src/math/iir_df1.c | 6 +++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/audio/eq_iir/eq_iir_generic.c b/src/audio/eq_iir/eq_iir_generic.c index b9f723b0c778..aa8cd968d65c 100644 --- a/src/audio/eq_iir/eq_iir_generic.c +++ b/src/audio/eq_iir/eq_iir_generic.c @@ -356,7 +356,7 @@ static int eq_iir_init_coef(struct processing_module *mod, int nch) int size_sum = 0; int resp = 0; int i; - int s; + size_t s; int ret; comp_info(mod->dev, "%u responses, %u channels, stream %d channels", @@ -404,8 +404,7 @@ static int eq_iir_init_coef(struct processing_module *mod, int nch) if (s > 0) { size_sum += s; } else { - comp_err(mod->dev, "sections count %d exceeds max", - eq->num_sections); + comp_err(mod->dev, "sections count %u exceeds max", eq->num_sections); return -EINVAL; } diff --git a/src/audio/sound_dose/sound_dose.c b/src/audio/sound_dose/sound_dose.c index 6455c870d9f7..692c94d39b99 100644 --- a/src/audio/sound_dose/sound_dose.c +++ b/src/audio/sound_dose/sound_dose.c @@ -92,6 +92,10 @@ int sound_dose_filters_init(struct processing_module *mod) /* Apply the first responses in the blobs */ iir_coef = (struct sof_eq_iir_header *)&iir_config->data[iir_config->channels_in_config]; iir_size = iir_delay_size_df1(iir_coef); + if (!iir_size) { + comp_err(dev, "Invalid iir coef"); + return -EINVAL; + } alloc_size = cd->channels * iir_size; cd->delay_lines = rzalloc(SOF_MEM_FLAG_USER, alloc_size); if (!cd->delay_lines) { diff --git a/src/audio/tdfb/tdfb_direction.c b/src/audio/tdfb/tdfb_direction.c index b81bb2e77477..d7c35048fcf2 100644 --- a/src/audio/tdfb/tdfb_direction.c +++ b/src/audio/tdfb/tdfb_direction.c @@ -200,6 +200,10 @@ int tdfb_direction_init(struct processing_module *mod, int32_t fs, int ch_count) /* Allocate delay lines for IIR filters and initialize them */ size = ch_count * iir_delay_size_df1(filt); + if (!size) { + comp_err(mod->dev, "Invalid iir configuration"); + return -EINVAL; + } delay = mod_zalloc(mod, size); if (!delay) return -ENOMEM; diff --git a/src/include/sof/math/iir_df1.h b/src/include/sof/math/iir_df1.h index 12a71535bcf8..9334b917c264 100644 --- a/src/include/sof/math/iir_df1.h +++ b/src/include/sof/math/iir_df1.h @@ -44,9 +44,9 @@ int iir_init_coef_df1(struct iir_state_df1 *iir, /** * @brief Calculate required delay line buffer size in bytes for a DF1 configuration. * @param config Pointer to IIR equalizer configuration header. - * @return Required delay buffer size in bytes. + * @return Required delay buffer size in bytes or 0 in case of error. */ -int iir_delay_size_df1(struct sof_eq_iir_header *config); +size_t iir_delay_size_df1(struct sof_eq_iir_header *config); /** * @brief Assign and initialize delay line state memory for DF1 filter. diff --git a/src/math/iir_df1.c b/src/math/iir_df1.c index 5e4d13b8cc70..a8763bc8de7a 100644 --- a/src/math/iir_df1.c +++ b/src/math/iir_df1.c @@ -14,16 +14,16 @@ #include -int iir_delay_size_df1(struct sof_eq_iir_header *config) +size_t iir_delay_size_df1(struct sof_eq_iir_header *config) { uint32_t n = config->num_sections; /* One section uses four unit delays */ if (!n || n > SOF_EQ_IIR_BIQUADS_MAX) - return -EINVAL; + return 0; if (!config->num_sections_in_series || config->num_sections_in_series > n) - return -EINVAL; + return 0; return 4 * n * sizeof(int32_t); } From cadf92ebed59cb1dce5d2e53251f206683ed91d9 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Fri, 9 Oct 2026 20:09:39 +0200 Subject: [PATCH 2/3] module: tdfb: rework module to use sink/source api Rework the tdfb module to only use the sink/source api to prepare sof for the full transition to pipeline 2.0. Signed-off-by: Adrian Warecki --- src/audio/tdfb/tdfb.c | 214 +++++++++++++++++--------------- src/audio/tdfb/tdfb_comp.h | 29 +++-- src/audio/tdfb/tdfb_direction.c | 3 +- src/audio/tdfb/tdfb_generic.c | 99 ++++++--------- src/audio/tdfb/tdfb_hifi3.c | 105 ++++++---------- src/audio/tdfb/tdfb_hifiep.c | 94 ++++++-------- src/audio/tdfb/tdfb_ipc3.c | 3 +- src/audio/tdfb/tdfb_ipc4.c | 12 +- 8 files changed, 256 insertions(+), 303 deletions(-) diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index 2cec0b052bd6..c2cc899f1344 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -77,36 +79,33 @@ static inline int set_func(struct processing_module *mod, enum sof_ipc_frame fmt * Pass-through processing functions */ -static void tdfb_pass_same_format(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +static void tdfb_pass_same_format(struct tdfb_comp_data *cd, struct cir_buf_source *source, + unsigned int in_nch, struct cir_buf_sink *sink, + unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - - audio_stream_copy(source, 0, sink, 0, frames * audio_stream_get_channels(source)); + cir_buf_copy(source->ptr, source->buf_start, source->buf_end, + sink->ptr, sink->buf_start, sink->buf_end, + frames * in_nch * cd->sample_bytes); } #if CONFIG_FORMAT_S16LE -static void tdfb_pass_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +static void tdfb_pass_s16(struct tdfb_comp_data *cd, struct cir_buf_source *source, + unsigned int in_nch, struct cir_buf_sink *sink, + unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int16_t *x = audio_stream_get_rptr(source); - int16_t *y = audio_stream_get_wptr(sink); + const int16_t *x = source->ptr; + int16_t *y = sink->ptr; int16_t s0, s1; - int fmax; - int is, om; - int f, i, j, k; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); + int i, is, om; + size_t f, fmax, j; + unsigned int k; const int num_filters = cd->config->num_filters; - int remaining_frames = frames; + size_t remaining_frames = frames; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int16_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int16_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { for (i = 0; i < num_filters; i++) { @@ -126,33 +125,30 @@ static void tdfb_pass_s16(struct tdfb_comp_data *cd, struct input_stream_buffer y += 2 * out_nch; } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S24LE -static void tdfb_pass_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +static void tdfb_pass_s24(struct tdfb_comp_data *cd, struct cir_buf_source *source, + unsigned int in_nch, struct cir_buf_sink *sink, + unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; int32_t s0, s1; - int fmax; - int is, om; - int f, i, j, k; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); + int i, is, om; + size_t f, fmax, j; + unsigned int k; const int num_filters = cd->config->num_filters; - int remaining_frames = frames; + size_t remaining_frames = frames; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { for (i = 0; i < num_filters; i++) { @@ -172,33 +168,30 @@ static void tdfb_pass_s24(struct tdfb_comp_data *cd, struct input_stream_buffer y += 2 * out_nch; } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S32LE -static void tdfb_pass_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +static void tdfb_pass_s32(struct tdfb_comp_data *cd, struct cir_buf_source *source, + unsigned int in_nch, struct cir_buf_sink *sink, + unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; int32_t s0, s1; - int fmax; - int is, om; - int f, i, j, k; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); + int i, is, om; + size_t f, fmax, j; + unsigned int k; const int num_filters = cd->config->num_filters; - int remaining_frames = frames; + size_t remaining_frames = frames; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { for (i = 0; i < num_filters; i++) { @@ -218,8 +211,8 @@ static void tdfb_pass_s32(struct tdfb_comp_data *cd, struct input_stream_buffer y += 2 * out_nch; } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif @@ -564,12 +557,14 @@ static void tdfb_init_delay(struct tdfb_comp_data *cd) } } -static int tdfb_setup(struct processing_module *mod, int source_nch, int sink_nch, - enum sof_ipc_frame fmt) +static int tdfb_setup(struct processing_module *mod, unsigned int source_nch, + unsigned int sink_nch, enum sof_ipc_frame fmt) { struct tdfb_comp_data *cd = module_get_private_data(mod); int delay_size; + cd->sample_bytes = get_sample_bytes(fmt); + /* If beam on, restore processing function. If off, use for same source and * sink format the efficient 1:1 copy, otherwise faster pass-through processing * functions those copy selected source channels to selected sink channels. @@ -721,14 +716,20 @@ static int tdfb_set_config(struct processing_module *mod, uint32_t param_id, */ static int tdfb_process(struct processing_module *mod, - struct input_stream_buffer *input_buffers, int num_input_buffers, - struct output_stream_buffer *output_buffers, int num_output_buffers) + struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; struct tdfb_comp_data *cd = module_get_private_data(mod); - struct audio_stream *source = input_buffers[0].data; - struct audio_stream *sink = output_buffers[0].data; - int frame_count = input_buffers[0].size; + struct sof_source *source = sources[0]; + struct sof_sink *sink = sinks[0]; + const unsigned int in_nch = source_get_channels(source); + const unsigned int out_nch = sink_get_channels(sink); + const size_t src_frame_bytes = source_get_frame_bytes(source); + const size_t snk_frame_bytes = sink_get_frame_bytes(sink); + struct cir_buf_source source_buf; + struct cir_buf_sink sink_buf; + size_t frame_count, bytes; int ret; comp_dbg(dev, "entry"); @@ -741,9 +742,7 @@ static int tdfb_process(struct processing_module *mod, cd->config = comp_get_data_blob(cd->model_handler, &cd->config_size, NULL); if (!cd->config) return -EINVAL; - ret = tdfb_setup(mod, audio_stream_get_channels(source), - audio_stream_get_channels(sink), - audio_stream_get_frm_fmt(source)); + ret = tdfb_setup(mod, in_nch, out_nch, source_get_frm_fmt(source)); if (ret < 0) { comp_err(dev, "failed FIR setup"); return ret; @@ -753,9 +752,7 @@ static int tdfb_process(struct processing_module *mod, /* Handle enum controls */ if (cd->update) { cd->update = false; - ret = tdfb_setup(mod, audio_stream_get_channels(source), - audio_stream_get_channels(sink), - audio_stream_get_frm_fmt(source)); + ret = tdfb_setup(mod, in_nch, out_nch, source_get_frm_fmt(source)); if (ret < 0) { comp_err(dev, "failed FIR setup"); return ret; @@ -767,33 +764,52 @@ static int tdfb_process(struct processing_module *mod, * optimized filter function loads the successive input samples from * internal delay line with a 64 bit load operation. */ - frame_count = MIN(frame_count, cd->max_frames) & ~0x1; - if (frame_count) { - cd->tdfb_func(cd, input_buffers, output_buffers, frame_count); - module_update_buffer_position(input_buffers, output_buffers, frame_count); - - /* Update sound direction estimate */ - tdfb_direction_estimate(cd, frame_count, audio_stream_get_channels(source)); - comp_dbg(dev, "tdfb_dint %u %d %d %d", cd->direction.trigger, cd->direction.level, - (int32_t)(cd->direction.level_ambient >> 32), cd->direction.az_slow); - - if (cd->direction_updates && cd->direction_change) { - tdfb_send_ipc_notification(mod); - cd->direction_change = false; - comp_dbg(dev, "tdfb_dupd %d %d", - cd->az_value_estimate, cd->direction.az_slow); - } + frame_count = MIN(source_get_data_frames_available(source), + sink_get_free_frames(sink)); + frame_count = MIN(frame_count, cd->max_frames) & ~(size_t)1; + if (!frame_count) + return 0; + + ret = source_get_data(source, frame_count * src_frame_bytes, + &source_buf.ptr, &source_buf.buf_start, &bytes); + if (ret) + return ret; + source_buf.buf_end = (const char *)source_buf.buf_start + bytes; + + ret = sink_get_buffer(sink, frame_count * snk_frame_bytes, + &sink_buf.ptr, &sink_buf.buf_start, &bytes); + if (ret) { + source_release_data(source, 0); + return ret; + } + sink_buf.buf_end = (char *)sink_buf.buf_start + bytes; + + cd->tdfb_func(cd, &source_buf, in_nch, &sink_buf, out_nch, frame_count); + + source_release_data(source, frame_count * src_frame_bytes); + sink_commit_buffer(sink, frame_count * snk_frame_bytes); + + /* Update sound direction estimate */ + tdfb_direction_estimate(cd, frame_count, in_nch); + comp_dbg(dev, "tdfb_dint %u %d %d %d", cd->direction.trigger, cd->direction.level, + (int32_t)(cd->direction.level_ambient >> 32), cd->direction.az_slow); + + if (cd->direction_updates && cd->direction_change) { + tdfb_send_ipc_notification(mod); + cd->direction_change = false; + comp_dbg(dev, "tdfb_dupd %d %d", + cd->az_value_estimate, cd->direction.az_slow); } return 0; } -static void tdfb_set_alignment(struct audio_stream *source) +static void tdfb_set_alignment(struct sof_source *source) { const uint32_t byte_align = SOF_FRAME_BYTE_ALIGN; const uint32_t frame_align_req = 2; /* Process multiples of 2 frames */ - audio_stream_set_align(byte_align, frame_align_req, source); + source_set_alignment_constants(source, byte_align, frame_align_req); } static int tdfb_prepare(struct processing_module *mod, @@ -801,36 +817,38 @@ static int tdfb_prepare(struct processing_module *mod, struct sof_sink **sinks, int num_of_sinks) { struct tdfb_comp_data *cd = module_get_private_data(mod); - struct comp_buffer *sourceb, *sinkb; + struct sof_source *source; + struct sof_sink *sink; struct comp_dev *dev = mod->dev; enum sof_ipc_frame frame_fmt; - int source_channels; - int sink_channels; + unsigned int source_channels; + unsigned int sink_channels; int rate; int ret; comp_info(dev, "entry"); /* Find source and sink buffers */ - sourceb = comp_dev_get_first_data_producer(dev); - sinkb = comp_dev_get_first_data_consumer(dev); - if (!sourceb || !sinkb) { + if (!num_of_sources || !num_of_sinks) { comp_err(dev, "no source or sink buffer"); return -ENOTCONN; } - ret = tdfb_params(mod); + source = sources[0]; + sink = sinks[0]; + + ret = tdfb_params(mod, source, sink); if (ret) { comp_err(dev, "Failed tdfb_params()"); return ret; } - tdfb_set_alignment(&sourceb->stream); + tdfb_set_alignment(source); - frame_fmt = audio_stream_get_frm_fmt(&sourceb->stream); - source_channels = audio_stream_get_channels(&sourceb->stream); - sink_channels = audio_stream_get_channels(&sinkb->stream); - rate = audio_stream_get_rate(&sourceb->stream); + frame_fmt = source_get_frm_fmt(source); + source_channels = source_get_channels(source); + sink_channels = sink_get_channels(sink); + rate = source_get_rate(source); /* Cache stream channel counts for the blob validator before any * validate_config() call runs. @@ -922,7 +940,7 @@ static const struct module_interface tdfb_interface = { .free = tdfb_free, .set_configuration = tdfb_set_config, .get_configuration = tdfb_get_config, - .process_audio_stream = tdfb_process, + .process = tdfb_process, .prepare = tdfb_prepare, .reset = tdfb_reset, }; diff --git a/src/audio/tdfb/tdfb_comp.h b/src/audio/tdfb/tdfb_comp.h index f59ff48bacaf..26eebc51bb0a 100644 --- a/src/audio/tdfb/tdfb_comp.h +++ b/src/audio/tdfb/tdfb_comp.h @@ -85,44 +85,46 @@ struct tdfb_comp_data { int32_t *fir_delay; /**< pointer to allocated RAM */ int16_t *input_channel_select; /**< For each FIR define in ch */ int16_t *output_channel_mix; /**< For each FIR define out ch */ - int16_t *output_stream_mix; /**< for each FIR define stream */ + int16_t *output_stream_mix; /**< for each FIR define stream */ int16_t az_value; /**< beam steer azimuth as in control enum */ int16_t az_value_estimate; /**< beam steer azimuth as in control enum */ int16_t source_channels; /**< source channel count cached for validator */ int16_t sink_channels; /**< sink channel count cached for validator */ + size_t sample_bytes; /**< sample container size in bytes */ size_t config_size; /**< size of the configuration blob */ - size_t fir_delay_size; /**< allocated size */ + size_t fir_delay_size; /**< allocated size */ unsigned int max_frames; /**< max frames to process */ bool direction_updates:1; /**< set true if direction angle control is updated */ bool direction_change:1; /**< set if direction value has significant change */ bool beam_on:1; /**< set true if beam is off */ bool update:1; /**< set true if control enum has been received */ void (*tdfb_func)(struct tdfb_comp_data *cd, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, - int frames); + struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, + size_t frames); }; #if CONFIG_FORMAT_S16LE void tdfb_fir_s16(struct tdfb_comp_data *cd, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames); + struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames); #endif #if CONFIG_FORMAT_S24LE void tdfb_fir_s24(struct tdfb_comp_data *cd, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames); + struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames); #endif #if CONFIG_FORMAT_S32LE void tdfb_fir_s32(struct tdfb_comp_data *cd, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames); + struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames); #endif int tdfb_direction_init(struct processing_module *mod, int32_t fs, int channels); -void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, int channels, int *channel, int32_t x); +void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, unsigned int channels, + unsigned int *channel, int32_t x); void tdfb_direction_estimate(struct tdfb_comp_data *cd, int frames, int channels); void tdfb_direction_free(struct processing_module *mod); @@ -147,7 +149,8 @@ int tdfb_set_ipc_config(struct processing_module *mod, uint32_t param_id, enum module_cfg_fragment_position pos, uint32_t data_offset_size, const uint8_t *fragment, size_t fragment_size, uint8_t *response, size_t response_size); -int tdfb_params(struct processing_module *mod); +int tdfb_params(struct processing_module *mod, struct sof_source *source, + struct sof_sink *sink); #ifdef UNIT_TEST void sys_comp_module_tdfb_interface_init(void); diff --git a/src/audio/tdfb/tdfb_direction.c b/src/audio/tdfb/tdfb_direction.c index d7c35048fcf2..b821037784f0 100644 --- a/src/audio/tdfb/tdfb_direction.c +++ b/src/audio/tdfb/tdfb_direction.c @@ -82,7 +82,8 @@ static const uint32_t iir_emphasis_16k[20] = { * and reset to zero after channel_count -1. * \param[in] x Input PCM sample */ -void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, int ch_count, int *ch, int32_t x) +void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, unsigned int ch_count, + unsigned int *ch, int32_t x) { int32_t y; diff --git a/src/audio/tdfb/tdfb_generic.c b/src/audio/tdfb/tdfb_generic.c index ba4e44c8073f..ac30f264c47a 100644 --- a/src/audio/tdfb/tdfb_generic.c +++ b/src/audio/tdfb/tdfb_generic.c @@ -15,16 +15,13 @@ #include -static inline void tdfb_core(struct tdfb_comp_data *cd, int in_nch, int out_nch) +static inline void tdfb_core(struct tdfb_comp_data *cd, unsigned int in_nch, unsigned int out_nch) { struct fir_state_32x16 *filter; int32_t y0; int32_t y1; - int is2; - int is; - int om; - int i; - int k; + int i, is, is2, om; + unsigned int k; const int num_filters = cd->config->num_filters; /* Clear output mix*/ @@ -56,26 +53,20 @@ static inline void tdfb_core(struct tdfb_comp_data *cd, int in_nch, int out_nch) #if CONFIG_FORMAT_S16LE -void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s16(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int16_t *x = audio_stream_get_rptr(source); - int16_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int16_t *x = source->ptr; + int16_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int16_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int16_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Read two frames from all input channels */ @@ -97,33 +88,27 @@ void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S24LE -void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s24(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Read two frames from all input channels */ @@ -145,33 +130,27 @@ void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S32LE -void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s32(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Read two frames from all input channels */ @@ -195,8 +174,8 @@ void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif diff --git a/src/audio/tdfb/tdfb_hifi3.c b/src/audio/tdfb/tdfb_hifi3.c index f5484d337395..68d900ce5af9 100644 --- a/src/audio/tdfb/tdfb_hifi3.c +++ b/src/audio/tdfb/tdfb_hifi3.c @@ -16,36 +16,27 @@ #include #if CONFIG_FORMAT_S16LE -void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s16(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; struct sof_tdfb_config *cfg = cd->config; struct fir_state_32x16 *f; ae_int16x4 d; ae_int32 y0; ae_int32 y1; - ae_int16 *x = audio_stream_get_rptr(source); - ae_int16 *y = audio_stream_get_wptr(sink); - int shift; - int is2; - int is; - int om; - int i; - int j; - int k; - int in_nch = audio_stream_get_channels(source); - int out_nch = audio_stream_get_channels(sink); - int emp_ch = 0; - int n, nmax; - int remaining_frames = frames; + const ae_int16 *x = source->ptr; + ae_int16 *y = sink->ptr; + int is, is2, om, shift; + unsigned int i, k; + size_t j, n, nmax; + unsigned int emp_ch = 0; + size_t remaining_frames = frames; const int inc = sizeof(ae_int16); while (remaining_frames) { - nmax = audio_stream_frames_without_wrap(source, x); + nmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(ae_int16), in_nch); n = MIN(remaining_frames, nmax); - nmax = audio_stream_frames_without_wrap(sink, y); + nmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(ae_int16), out_nch); n = MIN(n, nmax); for (j = 0; j < n; j += 2) { @@ -99,43 +90,34 @@ void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= n; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S24LE -void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s24(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; struct sof_tdfb_config *cfg = cd->config; struct fir_state_32x16 *f; ae_int32x2 d; ae_int32 y0; ae_int32 y1; - ae_int32 *x = audio_stream_get_rptr(source); - ae_int32 *y = audio_stream_get_wptr(sink); - int shift; - int is2; - int is; - int om; - int i; - int j; - int k; - int in_nch = audio_stream_get_channels(source); - int out_nch = audio_stream_get_channels(sink); - int emp_ch = 0; - int n, nmax; - int remaining_frames = frames; + const ae_int32 *x = source->ptr; + ae_int32 *y = sink->ptr; + int is, is2, om, shift; + unsigned int i, k; + size_t j, n, nmax; + unsigned int emp_ch = 0; + size_t remaining_frames = frames; const int inc = sizeof(ae_int32); while (remaining_frames) { - nmax = audio_stream_frames_without_wrap(source, x); + nmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(ae_int32), in_nch); n = MIN(remaining_frames, nmax); - nmax = audio_stream_frames_without_wrap(sink, y); + nmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(ae_int32), out_nch); n = MIN(n, nmax); for (j = 0; j < n; j += 2) { @@ -189,43 +171,34 @@ void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= n; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S32LE -void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s32(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; struct sof_tdfb_config *cfg = cd->config; struct fir_state_32x16 *f; ae_int32x2 d; ae_int32 y0; ae_int32 y1; - ae_int32 *x = audio_stream_get_rptr(source); - ae_int32 *y = audio_stream_get_wptr(sink); - int shift; - int is2; - int is; - int om; - int i; - int j; - int k; - int in_nch = audio_stream_get_channels(source); - int out_nch = audio_stream_get_channels(sink); - int emp_ch = 0; - int n, nmax; - int remaining_frames = frames; + const ae_int32 *x = source->ptr; + ae_int32 *y = sink->ptr; + int is, is2, om, shift; + unsigned int i, k; + size_t j, n, nmax; + unsigned int emp_ch = 0; + size_t remaining_frames = frames; const int inc = sizeof(ae_int32); while (remaining_frames) { - nmax = audio_stream_frames_without_wrap(source, x); + nmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(ae_int32), in_nch); n = MIN(remaining_frames, nmax); - nmax = audio_stream_frames_without_wrap(sink, y); + nmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(ae_int32), out_nch); n = MIN(n, nmax); for (j = 0; j < n; j += 2) { @@ -277,8 +250,8 @@ void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= n; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif diff --git a/src/audio/tdfb/tdfb_hifiep.c b/src/audio/tdfb/tdfb_hifiep.c index d6fea124b542..996ba6546a4f 100644 --- a/src/audio/tdfb/tdfb_hifiep.c +++ b/src/audio/tdfb/tdfb_hifiep.c @@ -15,7 +15,7 @@ #include -static inline void tdfb_core(struct tdfb_comp_data *cd, int in_nch, int out_nch) +static inline void tdfb_core(struct tdfb_comp_data *cd, unsigned int in_nch, unsigned int out_nch) { struct fir_state_32x16 *f; int32_t y0; @@ -26,7 +26,7 @@ static inline void tdfb_core(struct tdfb_comp_data *cd, int in_nch, int out_nch) int is; int om; int i; - int k; + unsigned int k; const int num_filters = cd->config->num_filters; /* Clear output mix*/ @@ -55,26 +55,20 @@ static inline void tdfb_core(struct tdfb_comp_data *cd, int in_nch, int out_nch) } #if CONFIG_FORMAT_S16LE -void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s16(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int16_t *x = audio_stream_get_rptr(source); - int16_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int16_t *x = source->ptr; + int16_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int16_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int16_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Read two frames from all input channels */ @@ -96,33 +90,27 @@ void tdfb_fir_s16(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S24LE -void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s24(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Read two frames from all input channels */ @@ -144,33 +132,27 @@ void tdfb_fir_s24(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif #if CONFIG_FORMAT_S32LE -void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, int frames) +void tdfb_fir_s32(struct tdfb_comp_data *cd, struct cir_buf_source *source, unsigned int in_nch, + struct cir_buf_sink *sink, unsigned int out_nch, size_t frames) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x = audio_stream_get_rptr(source); - int32_t *y = audio_stream_get_wptr(sink); - int fmax; - int i; - int j; - int f; - const int in_nch = audio_stream_get_channels(source); - const int out_nch = audio_stream_get_channels(sink); - int remaining_frames = frames; - int emp_ch = 0; + const int32_t *x = source->ptr; + int32_t *y = sink->ptr; + unsigned int i; + size_t f, fmax, j; + size_t remaining_frames = frames; + unsigned int emp_ch = 0; while (remaining_frames) { - fmax = audio_stream_frames_without_wrap(source, x); + fmax = circ_buf_frames_without_wrap(x, source->buf_end, sizeof(int32_t), in_nch); f = MIN(remaining_frames, fmax); - fmax = audio_stream_frames_without_wrap(sink, y); + fmax = circ_buf_frames_without_wrap(y, sink->buf_end, sizeof(int32_t), out_nch); f = MIN(f, fmax); for (j = 0; j < f; j += 2) { /* Clear output mix*/ @@ -197,8 +179,8 @@ void tdfb_fir_s32(struct tdfb_comp_data *cd, struct input_stream_buffer *bsource } } remaining_frames -= f; - x = audio_stream_wrap(source, x); - y = audio_stream_wrap(sink, y); + x = source_cir_buf_wrap(x, source->buf_start, source->buf_end); + y = cir_buf_wrap(y, sink->buf_start, sink->buf_end); } } #endif diff --git a/src/audio/tdfb/tdfb_ipc3.c b/src/audio/tdfb/tdfb_ipc3.c index f7b655065674..1550c0e7474d 100644 --- a/src/audio/tdfb/tdfb_ipc3.c +++ b/src/audio/tdfb/tdfb_ipc3.c @@ -226,7 +226,8 @@ int tdfb_set_ipc_config(struct processing_module *mod, uint32_t param_id, return ret; } -int tdfb_params(struct processing_module *mod) +int tdfb_params(struct processing_module *mod, struct sof_source *source, + struct sof_sink *sink) { return 0; } diff --git a/src/audio/tdfb/tdfb_ipc4.c b/src/audio/tdfb/tdfb_ipc4.c index a7b4e34977c7..b84ce1cbbada 100644 --- a/src/audio/tdfb/tdfb_ipc4.c +++ b/src/audio/tdfb/tdfb_ipc4.c @@ -181,10 +181,10 @@ int tdfb_set_ipc_config(struct processing_module *mod, uint32_t param_id, } } -int tdfb_params(struct processing_module *mod) +int tdfb_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; if (mod->priv.cfg.nb_input_pins != SOF_TDFB_NUM_INPUT_PINS) { @@ -200,12 +200,8 @@ int tdfb_params(struct processing_module *mod) ipc4_base_module_cfg_to_stream_params(&mod->priv.cfg.base_cfg, params); component_set_nearest_period_frames(dev, params->rate); - /* The caller has verified source and sink buffer validity */ - sourceb = comp_dev_get_first_data_producer(dev); - ipc4_update_buffer_format(sourceb, &mod->priv.cfg.input_pins[0].audio_fmt); - - sinkb = comp_dev_get_first_data_consumer(dev); - ipc4_update_buffer_format(sinkb, &mod->priv.cfg.output_pins[0].audio_fmt); + ipc4_update_source_format(source, &mod->priv.cfg.input_pins[0].audio_fmt); + ipc4_update_sink_format(sink, &mod->priv.cfg.output_pins[0].audio_fmt); return 0; } From 461a293b4db13fe8bc8952090640a7235eb67683 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Mon, 12 Oct 2026 22:53:23 +0200 Subject: [PATCH 3/3] audio: tdfb: use unsigned channel and size_t for frame counts and size Use unsigned int for channel counts and size_t for frame, sample counts and buffer size. Change the IIR delay-size helper to return size_t. Signed-off-by: Adrian Warecki --- src/audio/tdfb/tdfb_comp.h | 4 ++-- src/audio/tdfb/tdfb_direction.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/audio/tdfb/tdfb_comp.h b/src/audio/tdfb/tdfb_comp.h index 26eebc51bb0a..2b7c168ed456 100644 --- a/src/audio/tdfb/tdfb_comp.h +++ b/src/audio/tdfb/tdfb_comp.h @@ -122,10 +122,10 @@ void tdfb_fir_s32(struct tdfb_comp_data *cd, struct cir_buf_sink *sink, unsigned int out_nch, size_t frames); #endif -int tdfb_direction_init(struct processing_module *mod, int32_t fs, int channels); +int tdfb_direction_init(struct processing_module *mod, int32_t fs, unsigned int channels); void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, unsigned int channels, unsigned int *channel, int32_t x); -void tdfb_direction_estimate(struct tdfb_comp_data *cd, int frames, int channels); +void tdfb_direction_estimate(struct tdfb_comp_data *cd, size_t frames, unsigned int channels); void tdfb_direction_free(struct processing_module *mod); static inline void tdfb_cinc_s16(int16_t **ptr, int16_t *end, size_t size) diff --git a/src/audio/tdfb/tdfb_direction.c b/src/audio/tdfb/tdfb_direction.c index b821037784f0..11dc25a0433d 100644 --- a/src/audio/tdfb/tdfb_direction.c +++ b/src/audio/tdfb/tdfb_direction.c @@ -176,16 +176,15 @@ static bool line_array_mode_check(struct tdfb_comp_data *cd) return true; } -int tdfb_direction_init(struct processing_module *mod, int32_t fs, int ch_count) +int tdfb_direction_init(struct processing_module *mod, int32_t fs, unsigned int ch_count) { struct tdfb_comp_data *cd = module_get_private_data(mod); struct sof_eq_iir_header *filt; int32_t *delay; int32_t d_max; int32_t t_max; - size_t size; - int n; - int i; + size_t size, n; + unsigned int i; /* Select emphasis response per sample rate */ switch (fs) { @@ -275,7 +274,8 @@ void tdfb_direction_free(struct processing_module *mod) } /* Measure level of one channel */ -static void level_update(struct tdfb_comp_data *cd, int frames, int ch_count, int channel) +static void level_update(struct tdfb_comp_data *cd, size_t frames, unsigned int ch_count, + unsigned int channel) { int64_t tmp = 0; int64_t ambient; @@ -284,7 +284,7 @@ static void level_update(struct tdfb_comp_data *cd, int frames, int ch_count, in int16_t *p = cd->direction.rp + channel; int shift; int thr; - int n; + size_t n; /* Calculate mean square level */ for (n = 0; n < frames; n++) { @@ -327,7 +327,7 @@ static int find_max_value_index(int32_t *v, int length) return idx; } -static void time_differences(struct tdfb_comp_data *cd, int frames, int ch_count) +static void time_differences(struct tdfb_comp_data *cd, size_t frames, unsigned int ch_count) { int64_t r; int16_t *x; @@ -336,14 +336,14 @@ static void time_differences(struct tdfb_comp_data *cd, int frames, int ch_count int max_lag = cd->direction.max_lag; int c; int k; - int i; + size_t i; int32_t maxval = 0; /* Calculate xcorr for channel 0 vs. 1 .. (ch_count-1). Scan -maxlag .. +maxlag*/ for (c = 1; c < ch_count; c++) { for (k = -max_lag; k <= max_lag; k++) { y = cd->direction.rp; /* First channel */ - x = y + k * ch_count + c; /* other channel C */ + x = y + k * (int)ch_count + c; /* other channel C */ tdfb_cinc_s16(&x, cd->direction.d_end, cd->direction.d_size); tdfb_cdec_s16(&x, cd->direction.d, cd->direction.d_size); r = 0; @@ -510,7 +510,7 @@ static void iterate_source_angle(struct tdfb_comp_data *cd) cd->direction.az_slow = unwrap_radians(az_slow); } -static void updates_when_no_trigger(struct tdfb_comp_data *cd, int frames, int ch_count) +static void updates_when_no_trigger(struct tdfb_comp_data *cd, size_t frames, unsigned int ch_count) { cd->direction.rp += frames * ch_count; tdfb_cinc_s16(&cd->direction.rp, cd->direction.d_end, cd->direction.d_size); @@ -538,7 +538,7 @@ static int convert_angle_to_enum(struct tdfb_comp_data *cd) } /* Placeholder function for sound direction estimate */ -void tdfb_direction_estimate(struct tdfb_comp_data *cd, int frames, int ch_count) +void tdfb_direction_estimate(struct tdfb_comp_data *cd, size_t frames, unsigned int ch_count) { int32_t time_since; int new_az_value;