audio_stream: Add function returning number of samples without memory wrap

Such a function will be needed to calculate chunk size during processing
data from circular buffers by functions working on linear memory
regions.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
This commit is contained in:
Karol Trzcinski 2020-04-28 08:17:31 +02:00 committed by Liam Girdwood
parent 86c5075429
commit a03bf08f54
1 changed files with 17 additions and 2 deletions

View File

@ -511,6 +511,21 @@ static inline void audio_stream_writeback(struct audio_stream *buffer,
dcache_writeback_region(buffer->addr, tail_size);
}
/**
* @brief Calculates numbers of bytes to buffer wrap and return
* minimum of calculated value and given bytes number.
* @param source Stream to get information from.
* @param ptr Read or write pointer from source
* @return Number of data samples to buffer wrap or given samples number.
*/
static inline int
audio_stream_bytes_without_wrap(const struct audio_stream *source,
const void *ptr)
{
int to_end = (intptr_t)source->end_addr - (intptr_t)ptr;
return to_end;
}
/**
* Copies data from source buffer to sink buffer.
* @param source Source buffer.
@ -535,8 +550,8 @@ static inline void audio_stream_copy(const struct audio_stream *source,
int ret;
while (bytes) {
bytes_src = (char *)source->end_addr - (char *)src;
bytes_snk = (char *)sink->end_addr - (char *)snk;
bytes_src = audio_stream_bytes_without_wrap(source, src);
bytes_snk = audio_stream_bytes_without_wrap(sink, snk);
bytes_copied = MIN(bytes, MIN(bytes_src, bytes_snk));
ret = memcpy_s(snk, bytes_snk, src, bytes_copied);