diff --git a/src/audio/volume/volume.c b/src/audio/volume/volume.c index 65d4d1e674e6..f57dab472c94 100644 --- a/src/audio/volume/volume.c +++ b/src/audio/volume/volume.c @@ -57,16 +57,15 @@ LOG_MODULE_REGISTER(volume, CONFIG_SOF_LOG_LEVEL); * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s16(struct cir_buf_source *source, const int channels, - uint32_t frames, int64_t *prev_sum) +static size_t vol_zc_get_s16(struct cir_buf_source *source, const unsigned int channels, + size_t frames, int64_t *prev_sum) { - uint32_t curr_frames = frames; + size_t curr_frames = frames; int32_t sum; const int16_t *x = source->ptr; - int bytes; - int nmax; - int i, j, n; - int remaining_samples = frames * channels; + size_t bytes, nmax, i, n; + unsigned int j; + size_t remaining_samples = frames * channels; /* Go to last channel */ x = source_cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); @@ -106,16 +105,15 @@ static uint32_t vol_zc_get_s16(struct cir_buf_source *source, const int channels * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s24(struct cir_buf_source *source, const int channels, - uint32_t frames, int64_t *prev_sum) +static size_t vol_zc_get_s24(struct cir_buf_source *source, const unsigned int channels, + size_t frames, int64_t *prev_sum) { int64_t sum; - uint32_t curr_frames = frames; + size_t curr_frames = frames; const int32_t *x = source->ptr; - int bytes; - int nmax; - int i, j, n; - int remaining_samples = frames * channels; + size_t bytes, nmax, i, n; + unsigned int j; + size_t remaining_samples = frames * channels; /* Go to last channel */ x = source_cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); @@ -155,16 +153,15 @@ static uint32_t vol_zc_get_s24(struct cir_buf_source *source, const int channels * \param[in] frames Number of frames. * \param[in,out] prev_sum Previous sum of channel samples. */ -static uint32_t vol_zc_get_s32(struct cir_buf_source *source, const int channels, - uint32_t frames, int64_t *prev_sum) +static size_t vol_zc_get_s32(struct cir_buf_source *source, const unsigned int channels, + size_t frames, int64_t *prev_sum) { int64_t sum; - uint32_t curr_frames = frames; + size_t curr_frames = frames; const int32_t *x = source->ptr; - int bytes; - int nmax; - int i, j, n; - int remaining_samples = frames * channels; + size_t bytes, nmax, i, n; + unsigned int j; + size_t remaining_samples = frames * channels; /* Go to last channel */ x = source_cir_buf_wrap(x + remaining_samples - 1, source->buf_start, source->buf_end); @@ -564,12 +561,11 @@ static int volume_process(struct processing_module *mod, struct sof_sink *sink = sinks[0]; struct cir_buf_source source_buf; struct cir_buf_sink sink_buf; - const int nch = cd->channels; + const unsigned 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; + size_t avail_frames, frames; int64_t prev_sum = 0; int ret; diff --git a/src/audio/volume/volume.h b/src/audio/volume/volume.h index 478e80673089..7d25e1fc4c97 100644 --- a/src/audio/volume/volume.h +++ b/src/audio/volume/volume.h @@ -157,8 +157,8 @@ typedef void (*vol_scale_func)(struct processing_module *mod, struct cir_buf_sou /** * \brief volume interface for function getting nearest zero crossing frame */ -typedef uint32_t (*vol_zc_func)(struct cir_buf_source *source, const int channels, - uint32_t frames, int64_t *prev_sum); +typedef size_t (*vol_zc_func)(struct cir_buf_source *source, const unsigned int channels, + size_t frames, int64_t *prev_sum); /** * \brief Function for volume ramp shape function diff --git a/src/include/module/audio/audio_stream.h b/src/include/module/audio/audio_stream.h index ffd8832b68c7..9675471528c3 100644 --- a/src/include/module/audio/audio_stream.h +++ b/src/include/module/audio/audio_stream.h @@ -167,7 +167,7 @@ static inline int cir_buf_samples_without_wrap_s16(const void *ptr, const void * { int to_end = (const int16_t *)buf_end - (const int16_t *)ptr; - assert((intptr_t)buf_end >= (intptr_t)ptr); + assert((uintptr_t)buf_end >= (uintptr_t)ptr); return to_end; } @@ -183,14 +183,26 @@ static inline int cir_buf_samples_without_wrap_s32(const void *ptr, const void * { int to_end = (const int32_t *)buf_end - (const int32_t *)ptr; - assert((intptr_t)buf_end >= (intptr_t)ptr); + assert((uintptr_t)buf_end >= (uintptr_t)ptr); return to_end; } /** - * Verifies the pointer and performs rollover when reached the end of - * the circular buffer. - * @param ptr Pointer + * @brief Calculates number of bytes to buffer wrap when reading a circular + * buffer forward from current pointer towards the buffer end. + * @param ptr Read or write pointer of circular buffer. + * @param buf_end End address of circular buffer. + * @return Number of bytes between the pointer and the buffer end. + */ +static inline size_t cir_buf_bytes_without_wrap(const void *ptr, const void *buf_end) +{ + assert((uintptr_t)buf_end >= (uintptr_t)ptr); + return (uintptr_t)buf_end - (uintptr_t)ptr; +} + +/** + * Verifies the pointer and performs rollover when reaching the end of the circular buffer. + * @param ptr Read pointer that may have moved past the buffer end. * @param buf_addr Start address of the circular buffer. * @param buf_end End address of the circular buffer. * @return Pointer, adjusted if necessary. @@ -201,19 +213,18 @@ static inline void *cir_buf_wrap(const void *ptr, const void *buf_addr, const vo ptr = (const char *)buf_addr + ((const char *)ptr - (const char *)buf_end); - assert((intptr_t)ptr <= (intptr_t)buf_end); + assert((uintptr_t)ptr <= (uintptr_t)buf_end); return (void *)ptr; } /** - * Verifies a read pointer and performs rollover when reached the end of the circular buffer. - * @param ptr Pointer + * Verifies a read pointer and performs rollover when reaching the end of the circular buffer. + * @param ptr Read pointer that may have moved past the buffer end. * @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 const void *source_cir_buf_wrap(const void *ptr, const void *buf_addr, const void *buf_end) { @@ -221,7 +232,7 @@ static inline const void *source_cir_buf_wrap(const void *ptr, const void *buf_a ptr = (const char *)buf_addr + ((const char *)ptr - (const char *)buf_end); - assert((intptr_t)ptr <= (intptr_t)buf_end); + assert((uintptr_t)ptr <= (uintptr_t)buf_end); return ptr; } @@ -233,11 +244,11 @@ static inline const void *source_cir_buf_wrap(const void *ptr, const void *buf_a * @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) +static inline size_t cir_buf_bytes_without_wrap_rewind(const void *ptr, const void *buf_start) { - assert((intptr_t)ptr >= (intptr_t)buf_start); + assert((uintptr_t)ptr >= (uintptr_t)buf_start); - return (intptr_t)ptr - (intptr_t)buf_start; + return (uintptr_t)ptr - (uintptr_t)buf_start; } /** @@ -254,7 +265,7 @@ static inline const void *source_cir_buf_rewind_wrap(const void *ptr, const void if (ptr < buf_start) ptr = (const char *)buf_end - ((const char *)buf_start - (const char *)ptr); - assert((intptr_t)ptr >= (intptr_t)buf_start); + assert((uintptr_t)ptr >= (uintptr_t)buf_start); return ptr; } diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index c614284b9358..e515110d3d21 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -405,7 +405,7 @@ static inline void *audio_stream_wrap(const struct audio_stream *buffer, void *p ptr = (char *)buffer->addr + ((char *)ptr - (char *)buffer->end_addr); - assert((intptr_t)ptr <= (intptr_t)buffer->end_addr); + assert((uintptr_t)ptr <= (uintptr_t)buffer->end_addr); return ptr; } @@ -422,7 +422,7 @@ static inline void *audio_stream_rewind_wrap(const struct audio_stream *buffer, if (ptr < buffer->addr) ptr = (char *)buffer->end_addr - ((char *)buffer->addr - (char *)ptr); - assert((intptr_t)ptr >= (intptr_t)buffer->addr); + assert((uintptr_t)ptr >= (uintptr_t)buffer->addr); return ptr; } @@ -804,7 +804,7 @@ static inline void audio_stream_writeback(struct audio_stream *buffer, uint32_t static inline int audio_stream_bytes_without_wrap(const struct audio_stream *source, const void *ptr) { - assert((intptr_t)source->end_addr >= (intptr_t)ptr); + assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); return (intptr_t)source->end_addr - (intptr_t)ptr; } @@ -819,7 +819,7 @@ audio_stream_bytes_without_wrap(const struct audio_stream *source, const void *p static inline int audio_stream_rewind_bytes_without_wrap(const struct audio_stream *source, const void *ptr) { - assert((intptr_t)ptr >= (intptr_t)source->addr); + assert((uintptr_t)ptr >= (uintptr_t)source->addr); int to_begin = (intptr_t)ptr - (intptr_t)source->addr; return to_begin; } @@ -837,8 +837,8 @@ static inline uint32_t void *wptr = audio_stream_get_wptr(source); int to_begin = audio_stream_rewind_bytes_without_wrap(source, wptr); - assert((intptr_t)wptr >= (intptr_t)source->addr); - assert((intptr_t)source->end_addr > (intptr_t)wptr); + assert((uintptr_t)wptr >= (uintptr_t)source->addr); + assert((uintptr_t)source->end_addr > (uintptr_t)wptr); if (to_begin > bytes) return (uint32_t *)((intptr_t)wptr - bytes); @@ -858,7 +858,7 @@ audio_stream_samples_without_wrap_s16(const struct audio_stream *source, const v { int to_end = (int16_t *)source->end_addr - (int16_t *)ptr; - assert((intptr_t)source->end_addr >= (intptr_t)ptr); + assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } @@ -874,7 +874,7 @@ audio_stream_samples_without_wrap_s24(const struct audio_stream *source, const v { int to_end = (int32_t *)source->end_addr - (int32_t *)ptr; - assert((intptr_t)source->end_addr >= (intptr_t)ptr); + assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } @@ -890,24 +890,10 @@ audio_stream_samples_without_wrap_s32(const struct audio_stream *source, const v { int to_end = (int32_t *)source->end_addr - (int32_t *)ptr; - assert((intptr_t)source->end_addr >= (intptr_t)ptr); + assert((uintptr_t)source->end_addr >= (uintptr_t)ptr); return to_end; } -/** - * @brief Calculates numbers of bytes 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_bytes_without_wrap(const void *ptr, const void *buf_end) -{ - assert((intptr_t)buf_end >= (intptr_t)ptr); - return (intptr_t)buf_end - (intptr_t)ptr; -} - /** * @brief Calculates numbers of frames to buffer wrap and return * minimum of calculated value.