Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/include/sof/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,52 @@ 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 ROUND_DOWN(frames, align);
}

/**
* 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 = ROUND_DOWN(frames, align);

if (aligned_frames < frames)
aligned_frames += align;
Comment thread
singalsu marked this conversation as resolved.

return aligned_frames;
}

/**
* Rounds to nearest 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 to nearest.
* @return Aligned frame count.
*/
static inline uint32_t audio_stream_align_frames_round_nearest(const struct audio_stream *stream,
uint32_t frames)
{
uint16_t align = stream->runtime_stream_params.align_frame_cnt;

return ROUND_DOWN(frames + (align >> 1), 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.

we need proper ROUND_UP() and ROUND_CLOSEST() but not in this PR

}

/**
* Updates the buffer state after writing to the buffer.
* @param buffer Buffer to update.
Expand Down