From 4b4b752a149bd7b25c846d4117f58e5ce64bc275 Mon Sep 17 00:00:00 2001 From: Andrula Song Date: Wed, 29 Jun 2022 14:30:39 +0800 Subject: [PATCH] Audio: Copier: optimize the usage of read frag Optimize the read frags of copier module in function apply_attenuation. By using the optimized function audio_stream_samples_without_wrap_s32, we can reduce the address judgment and save about 60% MCPS. Signed-off-by: Andrula Song --- src/audio/copier.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/audio/copier.c b/src/audio/copier.c index 9c2f84f06..8a913db6e 100644 --- a/src/audio/copier.c +++ b/src/audio/copier.c @@ -773,9 +773,11 @@ static int copier_comp_trigger(struct comp_dev *dev, int cmd) static inline int apply_attenuation(struct comp_dev *dev, struct copier_data *cd, struct comp_buffer __sparse_cache *sink, int frame) { - uint32_t buff_frag = 0; - uint32_t *dst; int i; + int n; + int nmax; + int remaining_samples = frame * sink->stream.channels; + uint32_t *dst = sink->stream.r_ptr; /* only support attenuation in format of 32bit */ switch (sink->stream.frame_fmt) { @@ -784,10 +786,15 @@ static inline int apply_attenuation(struct comp_dev *dev, struct copier_data *cd return -EINVAL; case SOF_IPC_FRAME_S24_4LE: case SOF_IPC_FRAME_S32_LE: - for (i = 0; i < frame * sink->stream.channels; i++) { - dst = audio_stream_read_frag_s32(&sink->stream, buff_frag); - *dst >>= cd->attenuation; - buff_frag++; + while (remaining_samples) { + nmax = audio_stream_samples_without_wrap_s32(&sink->stream, dst); + n = MIN(remaining_samples, nmax); + for (i = 0; i < n; i++) { + *dst >>= cd->attenuation; + dst++; + } + remaining_samples -= n; + dst = audio_stream_wrap(&sink->stream, dst); } return 0; default: