-
Notifications
You must be signed in to change notification settings - Fork 349
Audio: Volume: Fix the ramping and ZC mode align #10704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,6 +612,38 @@ audio_stream_avail_frames_aligned(const struct audio_stream *source, | |
| return MIN(src_frames, sink_frames); | ||
| } | ||
|
|
||
| /** | ||
| * Rounds down a frame count to meet the alignment constraint of the stream. | ||
| * @param stream Audio stream with alignment requirements set. | ||
| * @param frames Frame count to round down. | ||
| * @return Largest aligned frame count less than or equal to frames. | ||
| */ | ||
| static inline uint32_t audio_stream_align_frames_round_down(const struct audio_stream *stream, | ||
| uint32_t frames) | ||
| { | ||
| uint16_t align = stream->runtime_stream_params.align_frame_cnt; | ||
|
|
||
| return (frames / align) * align; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The align can be any positive integer number. ROUND_DOWN is some operation with modulo and ALIGN_DOWN is for power of 2. I prefer this simple equation. |
||
| } | ||
|
|
||
| /** | ||
| * Rounds up a frame count to meet the alignment constraint of the stream. | ||
| * @param stream Audio stream with alignment requirements set. | ||
| * @param frames Frame count to round up. | ||
| * @return Smallest aligned frame count greater than or equal to frames. | ||
| */ | ||
| static inline uint32_t audio_stream_align_frames_round_up(const struct audio_stream *stream, | ||
| uint32_t frames) | ||
| { | ||
| uint16_t align = stream->runtime_stream_params.align_frame_cnt; | ||
| uint32_t aligned_frames = (frames / align) * align; | ||
|
|
||
| if (aligned_frames < frames) | ||
| aligned_frames += align; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer this simple equation to know exactly what it does.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I reject your reject. |
||
|
|
||
| return aligned_frames; | ||
| } | ||
|
|
||
| /** | ||
| * Updates the buffer state after writing to the buffer. | ||
| * @param buffer Buffer to update. | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A round to nearest (up or down) would be best for ZC but need to check if zero frames need more handling.