Skip to content

Audio: Volume: Fix the ramping and ZC mode align#10704

Draft
singalsu wants to merge 2 commits intothesofproject:mainfrom
singalsu:volume_ramp_align_fix
Draft

Audio: Volume: Fix the ramping and ZC mode align#10704
singalsu wants to merge 2 commits intothesofproject:mainfrom
singalsu:volume_ramp_align_fix

Conversation

@singalsu
Copy link
Copy Markdown
Collaborator

No description provided.

This patch adds to audio_stream.h inline functions:

- audio_stream_align_frames_round_down()
- audio_stream_align_frames_round_up()

They are useful when an algorithm needs to process a number of
frames that is smaller then data size than offered by module
API. E.g. when volume component ramps the volume, the block with
same gain is smaller than a normal processing period.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch fixes an issue where processing smaller parts of
the period can break the data align constraints. The frames
count value from zc_get() function or from cd->vol_ramp_frames
is rounded up to next align compatible frames count.

The failure with align constraints appeared as glitches in
audio with some 44.1 kHz family sample rates.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
{
uint16_t align = stream->runtime_stream_params.align_frame_cnt;

return (frames / align) * align;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can alignment be not a power of 2? We have multiple locations in SOF where we enforce that assumption and then use bit-wise operations apply such power-of-2 alignment. Either way you can use ROUND_DOWN() for the generic case or ALIGN_DOWN() for the power-of-2 case

uint32_t aligned_frames = (frames / align) * align;

if (aligned_frames < frames)
aligned_frames += align;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROUND_UP() or ALIGN_UP()

Comment thread src/audio/volume/volume.c
frames = cd->zc_get(input_buffers[0].data, cd->vol_ramp_frames, &prev_sum);
frames = cd->zc_get(source, cd->vol_ramp_frames, &prev_sum);
/* Align frames count to audio stream constraints */
frames = audio_stream_align_frames_round_up(source, frames);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is rounding up correct? Wouldn't that grab incomplete frames? Same below. And if you round down then you presumably wouldn't need to add lines 589-590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants