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 <xiaoyuan.song@intel.com>
This commit is contained in:
Andrula Song 2022-06-29 14:30:39 +08:00 committed by Liam Girdwood
parent 7c5bf651f8
commit 4b4b752a14
1 changed files with 13 additions and 6 deletions

View File

@ -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, static inline int apply_attenuation(struct comp_dev *dev, struct copier_data *cd,
struct comp_buffer __sparse_cache *sink, int frame) struct comp_buffer __sparse_cache *sink, int frame)
{ {
uint32_t buff_frag = 0;
uint32_t *dst;
int i; 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 */ /* only support attenuation in format of 32bit */
switch (sink->stream.frame_fmt) { switch (sink->stream.frame_fmt) {
@ -784,10 +786,15 @@ static inline int apply_attenuation(struct comp_dev *dev, struct copier_data *cd
return -EINVAL; return -EINVAL;
case SOF_IPC_FRAME_S24_4LE: case SOF_IPC_FRAME_S24_4LE:
case SOF_IPC_FRAME_S32_LE: case SOF_IPC_FRAME_S32_LE:
for (i = 0; i < frame * sink->stream.channels; i++) { while (remaining_samples) {
dst = audio_stream_read_frag_s32(&sink->stream, buff_frag); nmax = audio_stream_samples_without_wrap_s32(&sink->stream, dst);
*dst >>= cd->attenuation; n = MIN(remaining_samples, nmax);
buff_frag++; for (i = 0; i < n; i++) {
*dst >>= cd->attenuation;
dst++;
}
remaining_samples -= n;
dst = audio_stream_wrap(&sink->stream, dst);
} }
return 0; return 0;
default: default: