Audio: Volume: Fix the ramping and ZC mode align#10704
Draft
singalsu wants to merge 2 commits intothesofproject:mainfrom
Draft
Audio: Volume: Fix the ramping and ZC mode align#10704singalsu wants to merge 2 commits intothesofproject:mainfrom
singalsu wants to merge 2 commits intothesofproject:mainfrom
Conversation
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>
lyakh
requested changes
Apr 16, 2026
| { | ||
| uint16_t align = stream->runtime_stream_params.align_frame_cnt; | ||
|
|
||
| return (frames / align) * align; |
Collaborator
There was a problem hiding this comment.
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; |
| 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); |
Collaborator
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.