From 97f23a2a6668a54235dc4cfc45fa023aec1ecff8 Mon Sep 17 00:00:00 2001 From: Ievgen Ganakov Date: Wed, 7 Jun 2023 16:00:11 +0200 Subject: [PATCH] copier: fix attenuation stream frames calculation When calculating number of frames to be attenuated in HOST copier source stream frame bytes should be used instead of sink frame bytes. E.g. in case of 24/24 bit to 24/32 bit PCM conversion using sink container size will reduce frames number by 1/4 which will lead to multiple glitches. Also attenuation has to be applied in HOST copier in playback scenario only, thus remove from do_conversion_copy() Signed-off-by: Ievgen Ganakov --- src/audio/copier/copier.c | 7 ------- src/audio/copier/copier_host.c | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 1cd887de0c90..3e685f5edfd8 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -439,7 +439,6 @@ static int do_conversion_copy(struct comp_dev *dev, struct comp_copy_limits *processed_data) { int i; - int ret; /* buffer params might be not yet configured by component on another pipeline */ if (!src->hw_params_configured || !sink->hw_params_configured) @@ -455,12 +454,6 @@ static int do_conversion_copy(struct comp_dev *dev, cd->converter[i](&src->stream, 0, &sink->stream, 0, processed_data->frames * audio_stream_get_channels(&sink->stream)); - if (cd->attenuation) { - ret = apply_attenuation(dev, cd, sink, processed_data->frames); - if (ret < 0) - return ret; - } - buffer_stream_writeback(sink, processed_data->sink_bytes); comp_update_buffer_produce(sink, processed_data->sink_bytes); diff --git a/src/audio/copier/copier_host.c b/src/audio/copier/copier_host.c index 772e1bf4d551..4b448045126d 100644 --- a/src/audio/copier/copier_host.c +++ b/src/audio/copier/copier_host.c @@ -126,7 +126,7 @@ void copier_host_free(struct copier_data *cd) void copier_host_dma_cb(struct comp_dev *dev, size_t bytes) { struct copier_data *cd = comp_get_drvdata(dev); - struct comp_buffer __sparse_cache *sink; + struct comp_buffer __sparse_cache *sink, *source; int ret, frames; comp_dbg(dev, "copier_host_dma_cb() %p", dev); @@ -138,21 +138,22 @@ void copier_host_dma_cb(struct comp_dev *dev, size_t bytes) if (cd->hd->copy_type == COMP_COPY_ONE_SHOT) host_common_one_shot(cd->hd, bytes); - /* apply attenuation since copier copy missed this with host device remove */ - if (cd->attenuation) { - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - sink = buffer_acquire(cd->hd->local_buffer); - else - sink = buffer_acquire(cd->hd->dma_buffer); - - frames = bytes / get_sample_bytes(audio_stream_get_frm_fmt(&sink->stream)); - frames = frames / audio_stream_get_channels(&sink->stream); + /* Apply attenuation since copier copy missed this with host device + * remove. Attenuation has to be applied in HOST Copier only with + * playback scenario. + */ + if (cd->attenuation && dev->direction == SOF_IPC_STREAM_PLAYBACK) { + source = buffer_acquire(cd->hd->dma_buffer); + sink = buffer_acquire(cd->hd->local_buffer); + frames = bytes / audio_stream_frame_bytes(&source->stream); ret = apply_attenuation(dev, cd, sink, frames); if (ret < 0) comp_dbg(dev, "copier_host_dma_cb() apply attenuation failed! %d", ret); buffer_stream_writeback(sink, bytes); + + buffer_release(source); buffer_release(sink); } }