Skip to content

Commit

Permalink
copier: fix attenuation stream frames calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
iganakov authored and kv2019i committed Jun 13, 2023
1 parent d3f8bdc commit 8fb011d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
7 changes: 0 additions & 7 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
21 changes: 11 additions & 10 deletions src/audio/copier/copier_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 8fb011d

Please sign in to comment.