Skip to content

Commit

Permalink
Audio: Copier: optimize the usage of read frag
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Andrula Song authored and lgirdwood committed Jul 4, 2022
1 parent 7c5bf65 commit 4b4b752
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/audio/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand Down

0 comments on commit 4b4b752

Please sign in to comment.