From 838652d00717b125394ba47923420c628fe4c1b3 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Thu, 25 Jun 2026 17:46:32 +0200 Subject: [PATCH 1/8] lmdk: rtos: Add panic.h header Add a new header file panic.h that defines an assert() macro for runtime assertions. This macro is used by inline static functions in module api header files. Signed-off-by: Adrian Warecki --- lmdk/include/rtos/panic.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lmdk/include/rtos/panic.h diff --git a/lmdk/include/rtos/panic.h b/lmdk/include/rtos/panic.h new file mode 100644 index 000000000000..baef9541ddb9 --- /dev/null +++ b/lmdk/include/rtos/panic.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2026 Intel Corporation. All rights reserved. + * + * Author: Piotr Hoppe + */ + +#ifndef __LMDK_RTOS_PANIC_H__ +#define __LMDK_RTOS_PANIC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* runtime assertion */ +#define assert(x) do {if (!(x)) while (1);} while (0) + +#ifdef __cplusplus +} +#endif + +#endif /* __LMDK_RTOS_PANIC_H__ */ + From 047d322653d258a529b73f3f1a46fcb245476675 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Thu, 25 Jun 2026 17:50:09 +0200 Subject: [PATCH 2/8] module: audio: circ_buf: Add circular buffer utility functions Add two inline utility functions for calculating the number of samples to the end of a circular buffer: cir_buf_samples_to_wrap_s16() for 16-bit samples and cir_buf_samples_to_wrap_s32() for 32-bit samples. Signed-off-by: Adrian Warecki --- src/include/module/audio/audio_stream.h | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/include/module/audio/audio_stream.h b/src/include/module/audio/audio_stream.h index e032ef322f85..8204eff9726d 100644 --- a/src/include/module/audio/audio_stream.h +++ b/src/include/module/audio/audio_stream.h @@ -11,6 +11,7 @@ #include #include +#include #include "../ipc/stream.h" @@ -74,4 +75,38 @@ struct sof_audio_stream_params { enum sof_audio_buffer_state state; /**< audio stream state */ }; +/** + * @brief Calculates numbers of s16 samples to buffer wrap. + * @param ptr Read or write pointer of circular buffer. + * @param buf_start Start address of circular buffer. + * @param buf_samples Total size of circular buffer in samples. + * @return Number of samples to buffer wrap. + */ +static inline size_t cir_buf_samples_to_wrap_s16(const int16_t *ptr, const int16_t *buf_start, + size_t buf_samples) +{ + const int16_t *const buf_end = buf_start + buf_samples; + + assert(buf_end >= ptr); + + return buf_end - ptr; +} + +/** + * @brief Calculates numbers of s32 samples to buffer wrap. + * @param ptr Read or write pointer of circular buffer. + * @param buf_start Start address of circular buffer. + * @param buf_samples Total size of circular buffer in samples. + * @return Number of samples to buffer wrap. + */ +static inline size_t cir_buf_samples_to_wrap_s32(const int32_t *ptr, const int32_t *buf_start, + size_t buf_samples) +{ + const int32_t *const buf_end = buf_start + buf_samples; + + assert(buf_end >= ptr); + + return buf_end - ptr; +} + #endif /* __MODULE_AUDIO_AUDIO_STREAM_H__ */ From 38e172fe8aba1e6823bb437eb9643b881fd70d05 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Tue, 23 Jun 2026 16:34:19 +0200 Subject: [PATCH 3/8] module: audio: circ_buf: Add circular buffer source and sink structures Introduce two new structures cir_buf_source and cir_buf_sink. The cir_buf_source structure provides a read-only view of source data in a circular buffer, with const pointers. The cir_buf_sink structure provides a writable view of sink data in a circular buffer. Both structures include pointers for buffer start, end, and current position. Signed-off-by: Adrian Warecki --- src/include/module/audio/audio_stream.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/include/module/audio/audio_stream.h b/src/include/module/audio/audio_stream.h index 8204eff9726d..a3fa3cf2395a 100644 --- a/src/include/module/audio/audio_stream.h +++ b/src/include/module/audio/audio_stream.h @@ -75,6 +75,31 @@ struct sof_audio_stream_params { enum sof_audio_buffer_state state; /**< audio stream state */ }; +/** + * @brief Read-only view of source data in a circular buffer. + * + * Describes a contiguous fragment of a circular buffer obtained from the source + * API together with the buffer boundaries needed for wrap handling. All pointers + * are const because the source data must not be modified. + */ +struct cir_buf_source { + const void *buf_start; /**< Start address of the circular buffer. */ + const void *buf_end; /**< End address of the circular buffer. */ + const void *ptr; /**< Current read pointer within the buffer. */ +}; + +/** + * @brief Writable view of sink data in a circular buffer. + * + * Describes a contiguous fragment of a circular buffer obtained from the sink + * API together with the buffer boundaries needed for wrap handling. + */ +struct cir_buf_sink { + void *buf_start; /**< Start address of the circular buffer. */ + void *buf_end; /**< End address of the circular buffer. */ + void *ptr; /**< Current write pointer within the buffer. */ +}; + /** * @brief Calculates numbers of s16 samples to buffer wrap. * @param ptr Read or write pointer of circular buffer. From 18a65f0fee270f6460a8476d6b382aea7597c46e Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 24 Jun 2026 17:54:34 +0200 Subject: [PATCH 4/8] module: audio: sink: source: Add aligned frame calculation utilities Introduce functions to calculate aligned frames for sink and source api. Add sink_get_free_frames_aligned() to compute free aligned frames in a sink. Add source_get_aligned_frames_available() to compute aligned available frames in a source. Add source_sink_avail_frames_aligned to determine the maximum number of aligned frames that can be processed between a source and a sink. Signed-off-by: Adrian Warecki --- src/include/module/audio/sink_api.h | 11 +++++++++++ src/include/module/audio/source_api.h | 11 +++++++++++ src/include/sof/audio/sink_source_utils.h | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/include/module/audio/sink_api.h b/src/include/module/audio/sink_api.h index 920087d6f8b3..14c14af0187b 100644 --- a/src/include/module/audio/sink_api.h +++ b/src/include/module/audio/sink_api.h @@ -145,6 +145,17 @@ static inline size_t sink_get_free_size(struct sof_sink *sink) return sink->ops->get_free_size(sink); } +/** + * Retrieves number of free frames in sink aligned to the alignment constants + * set by sink_set_alignment_constants(). + * @return Number of aligned free frames. + */ +static inline size_t sink_get_free_frames_aligned(struct sof_sink *sink) +{ + return (sink_get_free_size(sink) >> sink->audio_stream_params->align_shift_idx) * + sink->audio_stream_params->align_frame_cnt; +} + static inline enum sof_ipc_frame sink_get_frm_fmt(struct sof_sink *sink) { return sink->audio_stream_params->frame_fmt; diff --git a/src/include/module/audio/source_api.h b/src/include/module/audio/source_api.h index 556dead4a583..06a40d9f5980 100644 --- a/src/include/module/audio/source_api.h +++ b/src/include/module/audio/source_api.h @@ -140,6 +140,17 @@ static inline size_t source_get_data_available(struct sof_source *source) return source->ops->get_data_available(source); } +/** + * Retrieves number of available data frames aligned to the alignment constants + * set by source_set_alignment_constants(). + * @return Number of aligned available frames. + */ +static inline size_t source_get_aligned_frames_available(struct sof_source *source) +{ + return (source_get_data_available(source) >> source->audio_stream_params->align_shift_idx) * + source->audio_stream_params->align_frame_cnt; +} + static inline enum sof_ipc_frame source_get_frm_fmt(struct sof_source *source) { return source->audio_stream_params->frame_fmt; diff --git a/src/include/sof/audio/sink_source_utils.h b/src/include/sof/audio/sink_source_utils.h index 818f29444c22..27bcd2eabe07 100644 --- a/src/include/sof/audio/sink_source_utils.h +++ b/src/include/sof/audio/sink_source_utils.h @@ -9,6 +9,7 @@ #include #include +#include /** * copy bytes from source to sink @@ -38,4 +39,19 @@ int sink_fill_with_silence(struct sof_sink *sink, size_t size); */ int source_drop_data(struct sof_source *source, size_t size); +/** + * Computes maximum number of aligned frames that can be copied from source to sink. + * Uses alignment constants set by source_set_alignment_constants() / + * sink_set_alignment_constants() to ensure the result satisfies both sides. + * + * @param source the data source + * @param sink the data sink + * @return Number of aligned frames available for processing. + */ +static inline size_t source_sink_avail_frames_aligned(struct sof_source *source, + struct sof_sink *sink) +{ + return MIN(source_get_aligned_frames_available(source), sink_get_free_frames_aligned(sink)); +} + #endif /* SINK_SOURCE_UTILS_H */ From 41ec6c1dc5a4bfdd54725bcb6c68737515c02408 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Tue, 16 Jun 2026 18:08:51 +0200 Subject: [PATCH 5/8] module: audio: circ_buf: Move some circ_buf_* handling fuctions Move circular buffer helper functions cir_buf_samples_without_wrap_s32() and cir_buf_wrap() to a public module api header. Introduce a new cir_buf_samples_without_wrap_s16() variant that returns the number of samples without buffer wrap for s16 data. Signed-off-by: Adrian Warecki --- src/include/module/audio/audio_stream.h | 50 +++++++++++++++++++++++++ src/include/sof/audio/audio_stream.h | 35 ----------------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/include/module/audio/audio_stream.h b/src/include/module/audio/audio_stream.h index a3fa3cf2395a..1cbff53c4269 100644 --- a/src/include/module/audio/audio_stream.h +++ b/src/include/module/audio/audio_stream.h @@ -134,4 +134,54 @@ static inline size_t cir_buf_samples_to_wrap_s32(const int32_t *ptr, const int32 return buf_end - ptr; } +/** + * @brief Calculates numbers of s16 samples to buffer wrap when reading stream + * backwards from current sample pointed by ptr towards begin. + * @param ptr Read or write pointer og circular buffer. + * @param buf_end End address of circular buffer. + * @return Number of samples to buffer wrap. + */ +static inline int cir_buf_samples_without_wrap_s16(const void *ptr, const void *buf_end) +{ + int to_end = (const int16_t *)buf_end - (const int16_t *)ptr; + + assert((intptr_t)buf_end >= (intptr_t)ptr); + return to_end; +} + +/** + * @brief Calculates numbers of s32 samples to buffer wrap when reading stream + * backwards from current sample pointed by ptr towards begin. + * @param ptr Read or write pointer og circular buffer. + * @param buf_end End address of circular buffer. + * @return Number of bytes to buffer wrap. For number of samples calculate + * need to add size of sample to returned bytes count. + */ +static inline int cir_buf_samples_without_wrap_s32(const void *ptr, const void *buf_end) +{ + int to_end = (const int32_t *)buf_end - (const int32_t *)ptr; + + assert((intptr_t)buf_end >= (intptr_t)ptr); + return to_end; +} + +/** + * Verifies the pointer and performs rollover when reached the end of + * the circular buffer. + * @param ptr Pointer + * @param buf_addr Start address of the circular buffer. + * @param buf_end End address of the circular buffer. + * @return Pointer, adjusted if necessary. + */ +static inline void *cir_buf_wrap(const void *ptr, const void *buf_addr, const void *buf_end) +{ + if (ptr >= buf_end) + ptr = (const char *)buf_addr + + ((const char *)ptr - (const char *)buf_end); + + assert((intptr_t)ptr <= (intptr_t)buf_end); + + return (void *)ptr; +} + #endif /* __MODULE_AUDIO_AUDIO_STREAM_H__ */ diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index 5c6f15392800..dc5d55103b4b 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -410,25 +410,6 @@ static inline void *audio_stream_wrap(const struct audio_stream *buffer, void *p return ptr; } -/** - * Verifies the pointer and performs rollover when reached the end of - * the circular buffer. - * @param ptr Pointer - * @param buf_addr Start address of the circular buffer. - * @param buf_end End address of the circular buffer. - * @return Pointer, adjusted if necessary. - */ -static inline void *cir_buf_wrap(void *ptr, void *buf_addr, void *buf_end) -{ - if (ptr >= buf_end) - ptr = (char *)buf_addr + - ((char *)ptr - (char *)buf_end); - - assert((intptr_t)ptr <= (intptr_t)buf_end); - - return ptr; -} - /** * Verifies the pointer and performs rollover when reached the end of * the buffer. @@ -927,22 +908,6 @@ static inline int cir_buf_bytes_without_wrap(void *ptr, void *buf_end) return (intptr_t)buf_end - (intptr_t)ptr; } -/** - * @brief Calculates numbers of s32 samples to buffer wrap when reading stream - * backwards from current sample pointed by ptr towards begin. - * @param ptr Read or write pointer og circular buffer. - * @param buf_end End address of circular buffer. - * @return Number of bytes to buffer wrap. For number of samples calculate - * need to add size of sample to returned bytes count. - */ -static inline int cir_buf_samples_without_wrap_s32(void *ptr, void *buf_end) -{ - int to_end = (int32_t *)buf_end - (int32_t *)ptr; - - assert((intptr_t)buf_end >= (intptr_t)ptr); - return to_end; -} - /** * @brief Calculates numbers of frames to buffer wrap and return * minimum of calculated value. From 6633729e6dbbb63feed8f599edee1aebf47cbc27 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 24 Jun 2026 16:30:42 +0200 Subject: [PATCH 6/8] module: audio: circ_buf: Add functions for circular buffer rewind handling Introduce cir_buf_bytes_without_wrap_rewind() to calculate the number of bytes to rewind in a circular buffer from the current pointer to the buffer start. This function ensures proper handling of backward reads. Add cir_buf_rewind_wrap() to verify and adjust pointers when rewinding past the start of a circular buffer. This function wraps the pointer to the buffer's end if necessary, ensuring correct behavior. Signed-off-by: Adrian Warecki --- src/include/module/audio/audio_stream.h | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/include/module/audio/audio_stream.h b/src/include/module/audio/audio_stream.h index 1cbff53c4269..3bb9d7d985aa 100644 --- a/src/include/module/audio/audio_stream.h +++ b/src/include/module/audio/audio_stream.h @@ -184,4 +184,37 @@ static inline void *cir_buf_wrap(const void *ptr, const void *buf_addr, const vo return (void *)ptr; } +/** + * @brief Calculates number of bytes to buffer wrap when reading a circular + * buffer backwards from current pointer towards the buffer start. + * @param ptr Read or write pointer of circular buffer. + * @param buf_start Start address of circular buffer. + * @return Number of bytes between the buffer start and the pointer. + */ +static inline int cir_buf_bytes_without_wrap_rewind(const void *ptr, const void *buf_start) +{ + assert((intptr_t)ptr >= (intptr_t)buf_start); + + return (intptr_t)ptr - (intptr_t)buf_start; +} + +/** + * @brief Verifies the pointer and performs rollover when reading a circular + * buffer backwards past its start address. + * @param ptr Pointer that may have moved below the buffer start. + * @param buf_start Start address of the circular buffer. + * @param buf_end End address of the circular buffer. + * @return Pointer, wrapped to the end of the buffer if necessary. + */ +static inline void *cir_buf_rewind_wrap(const void *ptr, const void *buf_start, + const void *buf_end) +{ + if (ptr < buf_start) + ptr = (const char *)buf_end - ((const char *)buf_start - (const char *)ptr); + + assert((intptr_t)ptr >= (intptr_t)buf_start); + + return (void *)ptr; +} + #endif /* __MODULE_AUDIO_AUDIO_STREAM_H__ */ From f246f1157e230e008ec477d3193b2442bc07276e Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Thu, 25 Jun 2026 17:23:25 +0200 Subject: [PATCH 7/8] module: source: Add level frame alignment helpers Add source_align_frames_round_up() and source_align_frames_round_nearest() helpers based on existing audio_stream_* alignment utilities, adapting them to operate on source api. Signed-off-by: Adrian Warecki --- src/include/module/audio/source_api.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/include/module/audio/source_api.h b/src/include/module/audio/source_api.h index 06a40d9f5980..580e2cd09882 100644 --- a/src/include/module/audio/source_api.h +++ b/src/include/module/audio/source_api.h @@ -339,4 +339,29 @@ static inline enum sof_audio_buffer_state source_get_state(const struct sof_sour return source->audio_stream_params->state; } +static inline uint32_t source_align_frames_round_up(struct sof_source *source, uint32_t frames) +{ + uint16_t align = source->audio_stream_params->align_frame_cnt; + uint32_t aligned_frames; + + if (!align) + return frames; + + aligned_frames = ROUND_DOWN(frames, align); + if (aligned_frames < frames) + aligned_frames += align; + + return aligned_frames; +} + +static inline uint32_t source_align_frames_round_nearest(struct sof_source *source, uint32_t frames) +{ + uint16_t align = source->audio_stream_params->align_frame_cnt; + + if (!align) + return frames; + + return ROUND_DOWN(frames + (align >> 1), align); +} + #endif /* __MODULE_AUDIO_SOURCE_API_H__ */ From 09b476c99332acb51f0857919cb97bd4e051d47a Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 24 Jun 2026 16:19:37 +0200 Subject: [PATCH 8/8] module: volume: Rework module to use only sink/source api Rework the volume 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/volume/volume.c | 159 ++++++++++------ src/audio/volume/volume.h | 10 +- src/audio/volume/volume_generic.c | 158 +++++++--------- .../volume/volume_generic_with_peakvol.c | 169 +++++++----------- src/audio/volume/volume_hifi3.c | 151 ++++++---------- src/audio/volume/volume_hifi3_with_peakvol.c | 144 ++++++--------- src/audio/volume/volume_hifi4.c | 150 ++++++---------- src/audio/volume/volume_hifi4_with_peakvol.c | 148 ++++++--------- src/audio/volume/volume_hifi5.c | 164 ++++++----------- src/audio/volume/volume_hifi5_with_peakvol.c | 162 ++++++----------- test/cmocka/src/audio/volume/volume_process.c | 15 +- 11 files changed, 590 insertions(+), 840 deletions(-) diff --git a/src/audio/volume/volume.c b/src/audio/volume/volume.c index a6cff8a09083..4716bc9451bc 100644 --- a/src/audio/volume/volume.c +++ b/src/audio/volume/volume.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -51,30 +52,31 @@ LOG_MODULE_REGISTER(volume, CONFIG_SOF_LOG_LEVEL); #if CONFIG_FORMAT_S16LE /** * \brief Used to find nearest zero crossing frame for 16 bit format. - * \param[in,out] source Source buffer. + * \param[in,out] source Source circular buffer view. + * \param[in] channels Number of channels in the stream. * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s16(const struct audio_stream *source, +static uint32_t vol_zc_get_s16(struct cir_buf_source *source, const int channels, uint32_t frames, int64_t *prev_sum) { uint32_t curr_frames = frames; int32_t sum; - int16_t *x = audio_stream_get_rptr(source); + const int16_t *x = source->ptr; int bytes; int nmax; int i, j, n; - const int nch = audio_stream_get_channels(source); - int remaining_samples = frames * nch; + int remaining_samples = frames * channels; - x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */ + /* Go to last channel */ + x = cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); while (remaining_samples) { - bytes = audio_stream_rewind_bytes_without_wrap(source, x); + bytes = cir_buf_bytes_without_wrap_rewind(x, source->buf_start); nmax = VOL_BYTES_TO_S16_SAMPLES(bytes) + 1; n = MIN(nmax, remaining_samples); - for (i = 0; i < n; i += nch) { + for (i = 0; i < n; i += channels) { sum = 0; - for (j = 0; j < nch; j++) { + for (j = 0; j < channels; j++) { sum += *x; x--; } @@ -87,7 +89,7 @@ static uint32_t vol_zc_get_s16(const struct audio_stream *source, curr_frames--; } remaining_samples -= n; - x = audio_stream_rewind_wrap(source, x); + x = cir_buf_rewind_wrap(x, source->buf_start, source->buf_end); } /* sign change not detected, process all samples */ @@ -99,30 +101,31 @@ static uint32_t vol_zc_get_s16(const struct audio_stream *source, #if CONFIG_FORMAT_S24LE /** * \brief Used to find nearest zero crossing frame for 24 in 32 bit format. - * \param[in,out] source Source buffer. + * \param[in,out] source Source circular buffer view. + * \param[in] channels Number of channels in the stream. * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s24(const struct audio_stream *source, +static uint32_t vol_zc_get_s24(struct cir_buf_source *source, const int channels, uint32_t frames, int64_t *prev_sum) { int64_t sum; uint32_t curr_frames = frames; - int32_t *x = audio_stream_get_rptr(source); + const int32_t *x = source->ptr; int bytes; int nmax; int i, j, n; - const int nch = audio_stream_get_channels(source); - int remaining_samples = frames * nch; + int remaining_samples = frames * channels; - x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */ + /* Go to last channel */ + x = cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); while (remaining_samples) { - bytes = audio_stream_rewind_bytes_without_wrap(source, x); + bytes = cir_buf_bytes_without_wrap_rewind(x, source->buf_start); nmax = VOL_BYTES_TO_S32_SAMPLES(bytes) + 1; n = MIN(nmax, remaining_samples); - for (i = 0; i < n; i += nch) { + for (i = 0; i < n; i += channels) { sum = 0; - for (j = 0; j < nch; j++) { + for (j = 0; j < channels; j++) { sum += sign_extend_s24(*x); x--; } @@ -135,7 +138,7 @@ static uint32_t vol_zc_get_s24(const struct audio_stream *source, curr_frames--; } remaining_samples -= n; - x = audio_stream_rewind_wrap(source, x); + x = cir_buf_rewind_wrap(x, source->buf_start, source->buf_end); } /* sign change not detected, process all samples */ @@ -147,30 +150,31 @@ static uint32_t vol_zc_get_s24(const struct audio_stream *source, #if CONFIG_FORMAT_S32LE /** * \brief Used to find nearest zero crossing frame for 32 bit format. - * \param[in,out] source Source buffer. + * \param[in,out] source Source circular buffer view. + * \param[in] channels Number of channels in the stream. * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s32(const struct audio_stream *source, +static uint32_t vol_zc_get_s32(struct cir_buf_source *source, const int channels, uint32_t frames, int64_t *prev_sum) { int64_t sum; uint32_t curr_frames = frames; - int32_t *x = audio_stream_get_rptr(source); + const int32_t *x = source->ptr; int bytes; int nmax; int i, j, n; - const int nch = audio_stream_get_channels(source); - int remaining_samples = frames * nch; + int remaining_samples = frames * channels; - x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */ + /* Go to last channel */ + x = cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); while (remaining_samples) { - bytes = audio_stream_rewind_bytes_without_wrap(source, x); + bytes = cir_buf_bytes_without_wrap_rewind(x, source->buf_start); nmax = VOL_BYTES_TO_S32_SAMPLES(bytes) + 1; n = MIN(nmax, remaining_samples); - for (i = 0; i < n; i += nch) { + for (i = 0; i < n; i += channels) { sum = 0; - for (j = 0; j < nch; j++) { + for (j = 0; j < channels; j++) { sum += *x; x--; } @@ -183,7 +187,7 @@ static uint32_t vol_zc_get_s32(const struct audio_stream *source, curr_frames--; } remaining_samples -= n; - x = audio_stream_rewind_wrap(source, x); + x = cir_buf_rewind_wrap(x, source->buf_start, source->buf_end); } /* sign change not detected, process all samples */ @@ -552,17 +556,46 @@ void volume_set_chan_unmute(struct processing_module *mod, int chan) * \return Error code. */ static int volume_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 vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = input_buffers[0].data; - uint32_t avail_frames = input_buffers[0].size; + struct sof_source *source = sources[0]; + struct sof_sink *sink = sinks[0]; + struct cir_buf_source source_buf; + struct cir_buf_sink sink_buf; + const int nch = cd->channels; + size_t source_frame_bytes = source_get_frame_bytes(source); + size_t sink_frame_bytes = sink_get_frame_bytes(sink); + size_t source_bytes, sink_bytes, bytes; + uint32_t avail_frames; uint32_t frames; int64_t prev_sum = 0; + int ret; comp_dbg(mod->dev, "entry"); + avail_frames = source_sink_avail_frames_aligned(source, sink); + if (!avail_frames) + return 0; + + source_bytes = avail_frames * source_frame_bytes; + sink_bytes = avail_frames * sink_frame_bytes; + + /* acquire source and sink buffers once for the whole available period */ + ret = source_get_data(source, source_bytes, &source_buf.ptr, + &source_buf.buf_start, &bytes); + if (ret < 0) + return ret; + source_buf.buf_end = (const char *)source_buf.buf_start + bytes; + + ret = sink_get_buffer(sink, sink_bytes, &sink_buf.ptr, &sink_buf.buf_start, &bytes); + if (ret < 0) { + source_release_data(source, 0); + return ret; + } + sink_buf.buf_end = (char *)sink_buf.buf_start + bytes; + while (avail_frames) { #if CONFIG_COMP_PEAK_VOL volume_update_current_vol_ipc4(cd); @@ -572,19 +605,19 @@ static int volume_process(struct processing_module *mod, frames = avail_frames; } else if (cd->ramp_type == SOF_VOLUME_LINEAR_ZC) { /* with ZC ramping look for next ZC offset */ - frames = cd->zc_get(source, cd->vol_ramp_frames, &prev_sum); + frames = cd->zc_get(&source_buf, nch, cd->vol_ramp_frames, &prev_sum); /* Align frames count to audio stream constraints. If it rounds to zero * round it up to smallest nonzero aligned frames count. */ - frames = audio_stream_align_frames_round_nearest(source, frames); + frames = source_align_frames_round_nearest(source, frames); if (!frames) - frames = audio_stream_align_frames_round_up(source, 1); + frames = source_align_frames_round_up(source, 1); } else { /* During volume ramp align the number of frames used in this * gain step. Align up since with low rates this would typically * become zero. */ - frames = audio_stream_align_frames_round_up(source, cd->vol_ramp_frames); + frames = source_align_frames_round_up(source, cd->vol_ramp_frames); } /* Cancel the gain step for ZC or smaller ramp step if it exceeds @@ -599,10 +632,22 @@ static int volume_process(struct processing_module *mod, } /* copy and scale volume */ - cd->scale_vol(mod, &input_buffers[0], &output_buffers[0], frames, cd->attenuation); + cd->scale_vol(mod, &source_buf, &sink_buf, frames, cd->attenuation); + + /* advance the views by the processed frames */ + source_buf.ptr = cir_buf_wrap((const char *)source_buf.ptr + + frames * source_frame_bytes, + source_buf.buf_start, source_buf.buf_end); + sink_buf.ptr = cir_buf_wrap((char *)sink_buf.ptr + frames * sink_frame_bytes, + sink_buf.buf_start, sink_buf.buf_end); avail_frames -= frames; } + + /* commit the consumed and produced data */ + source_release_data(source, source_bytes); + sink_commit_buffer(sink, sink_bytes); + #if CONFIG_COMP_PEAK_VOL cd->peak_cnt++; if (cd->peak_cnt == cd->peak_report_cnt) { @@ -623,13 +668,13 @@ static int volume_process(struct processing_module *mod, * \param[in,out] dev Volume base component device. */ static vol_zc_func vol_get_zc_function(struct comp_dev *dev, - struct comp_buffer *sinkb) + struct sof_sink *sink) { int i; /* map the zc function to frame format */ for (i = 0; i < ARRAY_SIZE(zc_func_map); i++) { - if (audio_stream_get_valid_fmt(&sinkb->stream) == zc_func_map[i].frame_fmt) + if (sink_get_valid_fmt(sink) == zc_func_map[i].frame_fmt) return zc_func_map[i].func; } @@ -640,7 +685,7 @@ static vol_zc_func vol_get_zc_function(struct comp_dev *dev, * \brief Set volume frames alignment limit. * \param[in,out] source Structure pointer of source. */ -static void volume_set_alignment(struct audio_stream *source) +static void volume_set_alignment(struct sof_source *source) { const int channels = audio_stream_get_channels(source); @@ -662,14 +707,14 @@ static void volume_set_alignment(struct audio_stream *source) * frame align need to be 4, 2, 1, 2, ... */ #if SOF_USE_HIFI(5, VOLUME) - const int n = (audio_stream_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 8 : 4; + const int n = (source_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 8 : 4; #else - const int n = (audio_stream_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 4 : 2; + const int n = (source_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 4 : 2; #endif const uint32_t frame_align_req = (uint32_t)(n / gcd(n, channels)); - audio_stream_set_align(byte_align, frame_align_req, source); + source_set_alignment_constants(source, byte_align, frame_align_req); } /** @@ -688,7 +733,6 @@ static int volume_prepare(struct processing_module *mod, struct vol_data *cd = module_get_private_data(mod); struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct comp_buffer *sourceb, *sinkb; uint32_t sink_period_bytes; int ret; int i; @@ -696,24 +740,21 @@ static int volume_prepare(struct processing_module *mod, comp_dbg(dev, "entry"); /* volume component will only ever have 1 sink and source buffer */ - sinkb = comp_dev_get_first_data_consumer(dev); - sourceb = comp_dev_get_first_data_producer(dev); - if (!sourceb || !sinkb) { + if (num_of_sources < 1 || num_of_sinks < 1 ) { comp_err(dev, "no source or sink buffer"); return -ENOTCONN; } ret = volume_peak_prepare(cd, mod); - volume_set_alignment(&sourceb->stream); + volume_set_alignment(sources[0]); /* get sink period bytes */ - sink_period_bytes = audio_stream_period_bytes(&sinkb->stream, - dev->frames); + sink_period_bytes = dev->frames * sink_get_frame_bytes(sinks[0]); - if (audio_stream_get_size(&sinkb->stream) < sink_period_bytes) { + if (sink_get_free_size(sinks[0]) < sink_period_bytes) { comp_err(dev, "sink buffer size %d is insufficient < %d", - audio_stream_get_size(&sinkb->stream), sink_period_bytes); + sink_get_free_size(sinks[0]), sink_period_bytes); ret = -ENOMEM; goto err; } @@ -727,7 +768,7 @@ static int volume_prepare(struct processing_module *mod, goto err; } - cd->zc_get = vol_get_zc_function(dev, sinkb); + cd->zc_get = vol_get_zc_function(dev, sinks[0]); if (!cd->zc_get) { comp_err(dev, "invalid cd->zc_get"); ret = -EINVAL; @@ -742,14 +783,14 @@ static int volume_prepare(struct processing_module *mod, */ cd->ramp_finished = false; - cd->channels = audio_stream_get_channels(&sinkb->stream); + cd->channels = sink_get_channels(sinks[0]); if (cd->channels > SOF_IPC_MAX_CHANNELS) { ret = -EINVAL; goto err; } cd->sample_rate_inv = (int32_t)(1000LL * INT32_MAX / - audio_stream_get_rate(&sinkb->stream)); + sink_get_rate(sinks[0])); for (i = 0; i < cd->channels; i++) { cd->volume[i] = cd->vol_min; @@ -808,7 +849,7 @@ static int volume_free(struct processing_module *mod) static const struct module_interface volume_interface = { .init = volume_init, .prepare = volume_prepare, - .process_audio_stream = volume_process, + .process = volume_process, .set_configuration = volume_set_config, .get_configuration = volume_get_config, .reset = volume_reset, @@ -819,7 +860,7 @@ static const struct module_interface volume_interface = { static const struct module_interface gain_interface = { .init = volume_init, .prepare = volume_prepare, - .process_audio_stream = volume_process, + .process = volume_process, .set_configuration = volume_set_config, .get_configuration = volume_get_config, .reset = volume_reset, diff --git a/src/audio/volume/volume.h b/src/audio/volume/volume.h index 9d1d08a280fe..478e80673089 100644 --- a/src/audio/volume/volume.h +++ b/src/audio/volume/volume.h @@ -146,14 +146,18 @@ struct sof_ipc_ctrl_value_chan; /** * \brief volume processing function interface + * + * The source and sink circular buffers are acquired and committed once by the + * module's process callback. Each processing function receives ready-to-use + * circular buffer views and only performs the gain scaling. */ -typedef void (*vol_scale_func)(struct processing_module *mod, struct input_stream_buffer *source, - struct output_stream_buffer *sink, uint32_t frames, uint32_t attenuation); +typedef void (*vol_scale_func)(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation); /** * \brief volume interface for function getting nearest zero crossing frame */ -typedef uint32_t (*vol_zc_func)(const struct audio_stream *source, +typedef uint32_t (*vol_zc_func)(struct cir_buf_source *source, const int channels, uint32_t frames, int64_t *prev_sum); /** diff --git a/src/audio/volume/volume_generic.c b/src/audio/volume/volume_generic.c index 0830677c7c94..a721823dd766 100644 --- a/src/audio/volume/volume_generic.c +++ b/src/audio/volume/volume_generic.c @@ -56,29 +56,23 @@ static inline int32_t vol_mult_s24_to_s24(int32_t x, int32_t vol) * Copy and scale volume from 24/32 bit source buffer * to 24/32 bit destination buffer. */ -static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s24_to_s24(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t vol; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s24(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s24(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -89,8 +83,8 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu } } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -106,32 +100,28 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu * to 24/32 bit destination buffer. */ static void vol_passthrough_s24_to_s24(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x; + struct vol_data *cd = module_get_private_data(mod); + const int32_t *x; int32_t *y; int nmax, n; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s24(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s24(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); memcpy_s(y, n * sizeof(int32_t), x, n * sizeof(int32_t)); remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S24LE */ @@ -148,28 +138,23 @@ static void vol_passthrough_s24_to_s24(struct processing_module *mod, * Copy and scale volume from 32 bit source buffer * to 32 bit destination buffer. */ -static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s32_to_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t vol; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s32(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s32(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); /* Note: on Xtensa processing one channel volume at time performed slightly * better than simpler interleaved code version (average 19 us vs. 20 us). @@ -184,8 +169,8 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu } } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -201,31 +186,28 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu * to 32 bit destination buffer. */ static void vol_passthrough_s32_to_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x; + struct vol_data *cd = module_get_private_data(mod); + const int32_t *x; int32_t *y; int nmax, n; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s32(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s32(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); memcpy_s(y, n * sizeof(int32_t), x, n * sizeof(int32_t)); remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -242,28 +224,23 @@ static void vol_passthrough_s32_to_s32(struct processing_module *mod, * Copy and scale volume from 16 bit source buffer * to 16 bit destination buffer. */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int16_t *x, *x0; + const int16_t *x, *x0; int16_t *y, *y0; + int32_t vol; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s16(source, x); + nmax = cir_buf_samples_without_wrap_s16(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s16(sink, y); + nmax = cir_buf_samples_without_wrap_s16(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -275,8 +252,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -292,31 +269,28 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * to 16 bit destination buffer. */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int16_t *x; + struct vol_data *cd = module_get_private_data(mod); + const int16_t *x; int16_t *y; int nmax, n; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s16(source, x); + nmax = cir_buf_samples_without_wrap_s16(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s16(sink, y); + nmax = cir_buf_samples_without_wrap_s16(y, sink->buf_end); n = MIN(n, nmax); memcpy_s(y, n * sizeof(int16_t), x, n * sizeof(int16_t)); remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S16LE */ diff --git a/src/audio/volume/volume_generic_with_peakvol.c b/src/audio/volume/volume_generic_with_peakvol.c index 106e1d3c7bdd..dbca458ed4eb 100644 --- a/src/audio/volume/volume_generic_with_peakvol.c +++ b/src/audio/volume/volume_generic_with_peakvol.c @@ -52,30 +52,24 @@ static inline int32_t vol_mult_s24_to_s24(int32_t x, int32_t vol) * Copy and scale volume from 24/32 bit source buffer * to 24/32 bit destination buffer. */ -static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s24_to_s24(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t vol; + int32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - int32_t tmp; - - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s24(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s24(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -90,8 +84,8 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -107,29 +101,24 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu * to 24/32 bit destination buffer. */ static void vol_passthrough_s24_to_s24(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - int32_t tmp; - - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s24(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s24(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -143,8 +132,8 @@ static void vol_passthrough_s24_to_s24(struct processing_module *mod, cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S24LE */ @@ -161,29 +150,24 @@ static void vol_passthrough_s24_to_s24(struct processing_module *mod, * Copy and scale volume from 32 bit source buffer * to 32 bit destination buffer. */ -static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s32_to_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t vol; + int32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - int32_t tmp; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s32(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s32(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); /* Note: on Xtensa processing one channel volume at time performed slightly * better than simpler interleaved code version (average 19 us vs. 20 us). @@ -202,8 +186,8 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -219,28 +203,24 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu * to 32 bit destination buffer. */ static void vol_passthrough_s32_to_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t *x, *x0; + const int32_t *x, *x0; int32_t *y, *y0; + int32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - int32_t tmp; - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s32(source, x); + nmax = cir_buf_samples_without_wrap_s32(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s32(sink, y); + nmax = cir_buf_samples_without_wrap_s32(y, sink->buf_end); n = MIN(n, nmax); /* Note: on Xtensa processing one channel volume at time performed slightly * better than simpler interleaved code version (average 19 us vs. 20 us). @@ -257,8 +237,8 @@ static void vol_passthrough_s32_to_s32(struct processing_module *mod, cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -275,30 +255,24 @@ static void vol_passthrough_s32_to_s32(struct processing_module *mod, * Copy and scale volume from 16 bit source buffer * to 16 bit destination buffer. */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int32_t vol; - int16_t *x, *x0; + const int16_t *x, *x0; int16_t *y, *y0; + int32_t vol; + uint32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - uint32_t tmp; - - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s16(source, x); + nmax = cir_buf_samples_without_wrap_s16(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s16(sink, y); + nmax = cir_buf_samples_without_wrap_s16(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -314,8 +288,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } @@ -331,29 +305,24 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * to 16 bit destination buffer. */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; - int16_t *x, *x0; + const int16_t *x, *x0; int16_t *y, *y0; + uint32_t tmp; int nmax, n, i, j; - const int nch = audio_stream_get_channels(source); + const int nch = cd->channels; int remaining_samples = frames * nch; - uint32_t tmp; - - x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed); - y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(remaining_samples); + x = source->ptr; + y = sink->ptr; while (remaining_samples) { - nmax = audio_stream_samples_without_wrap_s16(source, x); + nmax = cir_buf_samples_without_wrap_s16(x, source->buf_end); n = MIN(remaining_samples, nmax); - nmax = audio_stream_samples_without_wrap_s16(sink, y); + nmax = cir_buf_samples_without_wrap_s16(y, sink->buf_end); n = MIN(n, nmax); for (j = 0; j < nch; j++) { x0 = x + j; @@ -367,8 +336,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, cd->peak_regs.peak_meter[j] = MAX(tmp, cd->peak_regs.peak_meter[j]); } remaining_samples -= n; - x = audio_stream_wrap(source, x + n); - y = audio_stream_wrap(sink, y + n); + x = cir_buf_wrap(x + n, source->buf_start, source->buf_end); + y = cir_buf_wrap(y + n, sink->buf_start, sink->buf_end); } } #endif diff --git a/src/audio/volume/volume_hifi3.c b/src/audio/volume/volume_hifi3.c index afbb8ff44c02..145be7193db9 100644 --- a/src/audio/volume/volume_hifi3.c +++ b/src/audio/volume/volume_hifi3.c @@ -56,13 +56,11 @@ static void vol_store_gain(struct vol_data *cd, const int channels_count) * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -72,11 +70,9 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; @@ -94,13 +90,10 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -130,8 +123,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -144,30 +137,24 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + const int channels_count = cd->channels; int samples = channels_count * frames; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -179,8 +166,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S24LE */ @@ -194,13 +181,11 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -210,13 +195,11 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; /* to ensure the address is 8-byte aligned and avoid risk of * error loading of volume gain while the cd->vol would be set @@ -232,13 +215,10 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -266,8 +246,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -280,30 +260,24 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -314,8 +288,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -329,13 +303,11 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 volume0; ae_f32x2 volume1; ae_f32x2 out_sample0; @@ -348,11 +320,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; @@ -372,9 +342,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu AE_SETCEND0(buf_end); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); for (i = 0; i < n; i += 4) { @@ -414,10 +384,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } AE_SA64POS_FP(outu, out); samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -430,27 +398,24 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f16x4 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; int samples = channels_count * frames; while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); for (i = 0; i < n; i += 4) { @@ -460,10 +425,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S16LE */ diff --git a/src/audio/volume/volume_hifi3_with_peakvol.c b/src/audio/volume/volume_hifi3_with_peakvol.c index 4f89330baca7..bb38fc9bf7ef 100644 --- a/src/audio/volume/volume_hifi3_with_peakvol.c +++ b/src/audio/volume/volume_hifi3_with_peakvol.c @@ -36,34 +36,28 @@ LOG_MODULE_DECLARE(volume_hifi3, CONFIG_SOF_LOG_LEVEL); * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; int channel, n, i, m; - ae_f32 *in0 = (ae_f32 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32 *out0 = (ae_f32 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + ae_f32 *in0 = (void *)source->ptr; + ae_f32 *out0 = sink->ptr; ae_f32 *in, *out; - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32) * channels_count; int samples = channels_count * frames; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in0); + m = cir_buf_samples_without_wrap_s32(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out0); + m = cir_buf_samples_without_wrap_s32(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -100,8 +94,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } samples -= n; - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); } } @@ -114,32 +108,26 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; int channel, n, i, m; - ae_f32 *in0 = (ae_f32 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32 *out0 = (ae_f32 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + ae_f32 *in0 = (void *)source->ptr; + ae_f32 *out0 = sink->ptr; ae_f32 *in, *out; - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32) * channels_count; int samples = channels_count * frames; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in0); + m = cir_buf_samples_without_wrap_s32(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out0); + m = cir_buf_samples_without_wrap_s32(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -159,8 +147,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } samples -= n; - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); } } #endif /* CONFIG_FORMAT_S24LE */ @@ -174,34 +162,28 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; int i, n, channel, m; - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32) * channels_count; int samples = channels_count * frames; - ae_f32 *in0 = (ae_f32 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32 *out0 = (ae_f32 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + ae_f32 *in0 = (void *)source->ptr; + ae_f32 *out0 = sink->ptr; ae_f32 *in, *out; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in0); + m = cir_buf_samples_without_wrap_s32(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out0); + m = cir_buf_samples_without_wrap_s32(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -236,8 +218,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } samples -= n; - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); } } @@ -250,32 +232,26 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; int i, n, channel, m; - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32) * channels_count; int samples = channels_count * frames; - ae_f32 *in0 = (ae_f32 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32 *out0 = (ae_f32 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + ae_f32 *in0 = (void *)source->ptr; + ae_f32 *out0 = sink->ptr; ae_f32 *in, *out; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in0); + m = cir_buf_samples_without_wrap_s32(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out0); + m = cir_buf_samples_without_wrap_s32(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -295,8 +271,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } samples -= n; - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -310,13 +286,11 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 volume; ae_f32x2 out_sample0; ae_f16x4 in_sample; @@ -324,20 +298,18 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu int i, n, channel, m; ae_f16 *in; ae_f16 *out; - ae_f16 *in0 = (ae_f16 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16 *out0 = (ae_f16 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16 *in0 = (void *)source->ptr; + ae_f16 *out0 = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f16) * channels_count; int samples = channels_count * frames; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in0); + m = cir_buf_samples_without_wrap_s16(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out0); + m = cir_buf_samples_without_wrap_s16(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -377,11 +349,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu peak_vol = AE_SLAA32(peak_vol, PEAK_16S_32C_ADJUST); peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); } } @@ -394,31 +364,27 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f16x4 in_sample; int i, n, channel, m; ae_f16 *in; ae_f16 *out; - ae_f16 *in0 = (ae_f16 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16 *out0 = (ae_f16 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16 *in0 = (void *)source->ptr; + ae_f16 *out0 = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f16) * channels_count; int samples = channels_count * frames; ae_f32x2 peak_vol; uint32_t *peak_meter = cd->peak_regs.peak_meter; while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in0); + m = cir_buf_samples_without_wrap_s16(in0, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out0); + m = cir_buf_samples_without_wrap_s16(out0, sink->buf_end); n = MIN(m, n); for (channel = 0; channel < channels_count; channel++) { peak_vol = AE_ZERO32(); @@ -439,11 +405,9 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, peak_vol = AE_SLAA32(peak_vol, PEAK_16S_32C_ADJUST); peak_meter[channel] = AE_MAX32(peak_vol, peak_meter[channel]); } - out0 = audio_stream_wrap(sink, out0 + n); - in0 = audio_stream_wrap(source, in0 + n); + out0 = cir_buf_wrap(out0 + n, sink->buf_start, sink->buf_end); + in0 = cir_buf_wrap(in0 + n, source->buf_start, source->buf_end); samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); } } #endif /* CONFIG_FORMAT_S16LE */ diff --git a/src/audio/volume/volume_hifi4.c b/src/audio/volume/volume_hifi4.c index 2f879a31ec0e..c5313b319fba 100644 --- a/src/audio/volume/volume_hifi4.c +++ b/src/audio/volume/volume_hifi4.c @@ -56,13 +56,11 @@ static void vol_store_gain(struct vol_data *cd, const int channels_count) * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -72,11 +70,9 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; @@ -94,13 +90,10 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -130,8 +123,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -144,29 +137,23 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - int samples = audio_stream_get_channels(sink) * frames; - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + int samples = cd->channels * frames; while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -178,8 +165,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -194,13 +181,11 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -210,13 +195,11 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; /* to ensure the address is 8-byte aligned and avoid risk of * error loading of volume gain while the cd->vol would be set @@ -232,13 +215,10 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -268,8 +248,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -282,29 +262,24 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -315,8 +290,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -330,13 +305,11 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 volume0; ae_f32x2 volume1; ae_f32x2 out_sample0; @@ -349,11 +322,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; @@ -373,9 +344,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu AE_SETCEND0(buf_end); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); m = n >> 2; @@ -442,10 +413,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -458,29 +427,24 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_f16x4 in_sample; int i, n, m, left; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; int samples = channels_count * frames; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); m = n >> 2; @@ -501,8 +465,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, } samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S16LE */ diff --git a/src/audio/volume/volume_hifi4_with_peakvol.c b/src/audio/volume/volume_hifi4_with_peakvol.c index f3908ee1a8a0..cb5a2476bf5c 100644 --- a/src/audio/volume/volume_hifi4_with_peakvol.c +++ b/src/audio/volume/volume_hifi4_with_peakvol.c @@ -49,13 +49,11 @@ static inline void vol_store_gain(struct vol_data *cd, const int channels_count) * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -63,11 +61,9 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; ae_f32x2 temp; @@ -89,13 +85,10 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(vol); AE_SETCEND0(cd->vol + channels_count * 2); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -128,8 +121,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i], @@ -146,23 +139,19 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; ae_f32x2 temp; @@ -172,13 +161,10 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, AE_SETCBEGIN1(cd->peak_vol); AE_SETCEND1(cd->peak_vol + channels_count * 2); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -194,8 +180,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i], @@ -213,13 +199,11 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; ae_f32x2 out_sample; ae_f32x2 volume; @@ -229,13 +213,11 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; ae_f32x2 temp; ae_f32x2 *peakvol = (ae_f32x2 *)cd->peak_vol; @@ -257,13 +239,10 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -297,8 +276,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i], @@ -314,37 +293,30 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 in_sample; int i, n, m; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; - ae_f32x2 *in = (ae_f32x2 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f32x2 *out = (ae_f32x2 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_f32x2 *in = source->ptr; + ae_f32x2 *out = sink->ptr; ae_f32x2 temp; ae_f32x2 *peakvol = (ae_f32x2 *)cd->peak_vol; /* Set peakvol(which stores the peak volume data twice) as circular buffer */ AE_SETCBEGIN1(cd->peak_vol); AE_SETCEND1(cd->peak_vol + channels_count * 2); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); /* process two continuous sample data once */ @@ -360,8 +332,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, } AE_SA64POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i], @@ -378,13 +350,11 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f32x2 volume0; ae_f32x2 volume1; ae_f32x2 out_sample0; @@ -397,11 +367,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu ae_f32x2 *vol; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; ae_f32x2 temp; @@ -427,9 +395,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu AE_SETCEND0(buf_end); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); m = n >> 2; @@ -509,10 +477,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); @@ -531,22 +497,18 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_f16x4 in_sample; int i, n, m, left; ae_valign inu; ae_valign outu = AE_ZALIGN64(); - ae_f16x4 *in = (ae_f16x4 *)audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_f16x4 *out = (ae_f16x4 *)audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_f16x4 *in = (void *)source->ptr; + ae_f16x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_f32x2); int samples = channels_count * frames; ae_f32x2 temp; @@ -557,9 +519,9 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, AE_SETCEND1(cd->peak_vol + channels_count * 4); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA64_PP(in); m = n >> 2; @@ -594,10 +556,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, } samples -= n; - in = (ae_f16x4 *)audio_stream_wrap(source, in); - out = (ae_f16x4 *)audio_stream_wrap(sink, out); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { diff --git a/src/audio/volume/volume_hifi5.c b/src/audio/volume/volume_hifi5.c index 794330cddd9b..1717f1d50237 100644 --- a/src/audio/volume/volume_hifi5.c +++ b/src/audio/volume/volume_hifi5.c @@ -55,13 +55,11 @@ static void vol_store_gain(struct vol_data *cd, const int channels_count) * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; ae_int32x2 out_sample, out_sample1; ae_int32x2 volume, volume1; @@ -71,13 +69,9 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; @@ -95,13 +89,10 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per iteration */ @@ -138,8 +129,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -152,31 +143,23 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_int32x2 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - int samples = audio_stream_get_channels(sink) * frames; - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; + int samples = cd->channels * frames; while (samples) { - m = audio_stream_samples_without_wrap_s24(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s24(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process 4 continuous samples once */ @@ -188,8 +171,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -204,13 +187,11 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; ae_int32x2 out_sample, out_sample1; ae_int32x2 volume, volume1; @@ -220,15 +201,11 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; /** to ensure the address is 16-byte aligned and avoid risk of * error loading of volume gain while the cd->vol would be set @@ -244,13 +221,10 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per iteration */ @@ -285,8 +259,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -299,31 +273,24 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_int32x2 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; int samples = channels_count * frames; - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; + while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per iteration */ @@ -334,8 +301,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S32LE */ @@ -349,13 +316,11 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 volume, volume1, volume2, volume3; ae_int32x2 out_temp, out_temp1; ae_int16x4 in_sample, in_sample1; @@ -366,13 +331,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int16x8 *in = (ae_int16x8 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int16x8 *out = (ae_int16x8 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_int16x8 *in = (void *)source->ptr; + ae_int16x8 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; @@ -392,9 +353,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu AE_SETCEND0(buf_end); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); for (i = 0; i < n; i += 8) { @@ -440,10 +401,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } AE_SA128POS_FP(outu, out); samples -= n; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } @@ -456,31 +415,24 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; + struct vol_data *cd = module_get_private_data(mod); ae_int16x4 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int16x8 *in = (ae_int16x8 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int16x8 *out = (ae_int16x8 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_int16x8 *in = (void *)source->ptr; + ae_int16x8 *out = sink->ptr; + const int channels_count = cd->channels; int samples = channels_count * frames; - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); for (i = 0; i < n; i += 8) { @@ -490,8 +442,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } } #endif /* CONFIG_FORMAT_S16LE */ diff --git a/src/audio/volume/volume_hifi5_with_peakvol.c b/src/audio/volume/volume_hifi5_with_peakvol.c index 16d2f7cb8bf9..c6b43684115f 100644 --- a/src/audio/volume/volume_hifi5_with_peakvol.c +++ b/src/audio/volume/volume_hifi5_with_peakvol.c @@ -55,13 +55,10 @@ static inline void vol_store_gain(struct vol_data *cd, const int channels_count) * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s24_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; ae_int32x2 out_sample, out_sample1; ae_int32x2 volume, volume1; @@ -69,13 +66,9 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; ae_int32x2 temp, temp1; @@ -97,13 +90,10 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(vol); AE_SETCEND0(cd->vol + channels_count * 4); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per loop */ @@ -145,8 +135,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { @@ -166,24 +156,18 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; ae_int32x2 temp, temp1; @@ -193,13 +177,10 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, AE_SETCBEGIN1(cd->peak_vol); AE_SETCEND1(cd->peak_vol + channels_count * 4); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per loop */ @@ -216,8 +197,8 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); @@ -237,13 +218,10 @@ static void vol_passthrough_s24_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment */ -static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s32_to_s24_s32(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; ae_int32x2 out_sample, out_sample1; ae_int32x2 volume, volume1; @@ -253,15 +231,11 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; ae_int32x2 temp, temp1; ae_int32x4 *peakvol = (ae_int32x4 *)cd->peak_vol; @@ -283,13 +257,10 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea AE_SETCBEGIN0(buf); AE_SETCEND0(buf_end); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); - while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per loop */ @@ -329,8 +300,8 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); @@ -349,39 +320,31 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea * \param[in] attenuation factor for peakmeter adjustment */ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - const int channels_count = audio_stream_get_channels(sink); + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; - ae_int32x4 *in = (ae_int32x4 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int32x4 *out = (ae_int32x4 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); + const ae_int32x4 *in = source->ptr; + ae_int32x4 *out = sink->ptr; ae_int32x2 temp, temp1; ae_int32x4 *peakvol = (ae_int32x4 *)cd->peak_vol; /* Set peakvol(which stores the peak volume data four times) as circular buffer */ AE_SETCBEGIN1(cd->peak_vol); AE_SETCEND1(cd->peak_vol + channels_count * 4); - bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples); - bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples); while (samples) { - m = audio_stream_samples_without_wrap_s32(source, in); + m = cir_buf_samples_without_wrap_s32(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s32(sink, out); + m = cir_buf_samples_without_wrap_s32(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); /* process four continuous samples per iteration */ @@ -398,8 +361,8 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); @@ -419,13 +382,10 @@ static void vol_passthrough_s32_to_s24_s32(struct processing_module *mod, * \param[in] frames Number of frames to process. * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ -static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, - uint32_t attenuation) +static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int32x2 volume, volume1, volume2, volume3; ae_int32x2 out_temp, out_temp1; ae_int16x4 in_sample, in_sample1; @@ -436,13 +396,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu ae_int32x4 *vol; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int16x8 *in = (ae_int16x8 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int16x8 *out = (ae_int16x8 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_int16x8 *in = (void *)source->ptr; + ae_int16x8 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; ae_int32x2 temp, temp1; @@ -468,9 +424,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu AE_SETCEND0(buf_end); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); for (i = 0; i < n; i += 8) { @@ -524,10 +480,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); @@ -546,24 +500,18 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu * \param[in] attenuation factor for peakmeter adjustment (unused for 16bit) */ static void vol_passthrough_s16_to_s16(struct processing_module *mod, - struct input_stream_buffer *bsource, - struct output_stream_buffer *bsink, uint32_t frames, + struct cir_buf_source *source, + struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation) { struct vol_data *cd = module_get_private_data(mod); - struct audio_stream *source = bsource->data; - struct audio_stream *sink = bsink->data; ae_int16x4 in_sample, in_sample1; int i, n, m; ae_valignx2 inu; ae_valignx2 outu = AE_ZALIGN128(); - ae_int16x8 *in = (ae_int16x8 *)audio_stream_wrap(source, - (char *)audio_stream_get_rptr(source) - + bsource->consumed); - ae_int16x8 *out = (ae_int16x8 *)audio_stream_wrap(sink, - (char *)audio_stream_get_wptr(sink) - + bsink->size); - const int channels_count = audio_stream_get_channels(sink); + ae_int16x8 *in = (void *)source->ptr; + ae_int16x8 *out = sink->ptr; + const int channels_count = cd->channels; const int inc = sizeof(ae_int32x4); int samples = channels_count * frames; ae_int32x2 temp, temp1; @@ -574,9 +522,9 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, AE_SETCEND1(cd->peak_vol + channels_count * 4); while (samples) { - m = audio_stream_samples_without_wrap_s16(source, in); + m = cir_buf_samples_without_wrap_s16(in, source->buf_end); n = MIN(m, samples); - m = audio_stream_samples_without_wrap_s16(sink, out); + m = cir_buf_samples_without_wrap_s16(out, sink->buf_end); n = MIN(m, n); inu = AE_LA128_PP(in); for (i = 0; i < n; i += 8) { @@ -598,10 +546,8 @@ static void vol_passthrough_s16_to_s16(struct processing_module *mod, } AE_SA128POS_FP(outu, out); samples -= n; - in = audio_stream_wrap(source, in); - out = audio_stream_wrap(sink, out); - bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n); - bsink->size += VOL_S16_SAMPLES_TO_BYTES(n); + in = cir_buf_wrap(in, source->buf_start, source->buf_end); + out = cir_buf_wrap(out, sink->buf_start, sink->buf_end); } for (i = 0; i < channels_count; i++) { m = MAX(cd->peak_vol[i], cd->peak_vol[i + channels_count]); diff --git a/test/cmocka/src/audio/volume/volume_process.c b/test/cmocka/src/audio/volume/volume_process.c index 389a4e75a503..b6c1fec45e45 100644 --- a/test/cmocka/src/audio/volume/volume_process.c +++ b/test/cmocka/src/audio/volume/volume_process.c @@ -71,6 +71,9 @@ static int setup(void **state) cd->vol = test_malloc(vol_size); + /* number of channels used by the processing functions */ + cd->channels = vol_state->parameters.channels; + /* set processing function and volume */ #if CONFIG_IPC_MAJOR_4 cd->scale_vol = vol_get_processing_function(vol_state->mod->dev, cd); @@ -266,6 +269,8 @@ static void test_audio_vol(void **state) struct processing_module_test_data *vol_state = *state; struct processing_module *mod = vol_state->mod; struct vol_data *cd = module_get_private_data(mod); + struct cir_buf_source source_buf; + struct cir_buf_sink sink_buf; switch (audio_stream_get_frm_fmt(&vol_state->sinks[0]->stream)) { case SOF_IPC_FRAME_S16_LE: @@ -289,7 +294,15 @@ static void test_audio_vol(void **state) vol_state->input_buffers[0]->consumed = 0; vol_state->output_buffers[0]->size = 0; - cd->scale_vol(mod, vol_state->input_buffers[0], vol_state->output_buffers[0], + source_buf.buf_start = audio_stream_get_addr(&vol_state->sources[0]->stream); + source_buf.buf_end = audio_stream_get_end_addr(&vol_state->sources[0]->stream); + source_buf.ptr = audio_stream_get_rptr(&vol_state->sources[0]->stream); + + sink_buf.buf_start = audio_stream_get_addr(&vol_state->sinks[0]->stream); + sink_buf.buf_end = audio_stream_get_end_addr(&vol_state->sinks[0]->stream); + sink_buf.ptr = audio_stream_get_wptr(&vol_state->sinks[0]->stream); + + cd->scale_vol(mod, &source_buf, &sink_buf, mod->dev->frames, cd->attenuation); vol_state->verify(mod, vol_state->sinks[0], vol_state->sources[0]);