From f34d9ba92898f0c9aa8cc9a55aaef8eb75f7194c Mon Sep 17 00:00:00 2001 From: Karol Trzcinski Date: Fri, 24 Jul 2020 15:29:59 +0200 Subject: [PATCH] audio_stream: Calculate sample size inside audio_stream_copy function Sample size is related with frame format, which is saved inside audio_stream, so this value can be easily calculated inside audio_stream_copy function. This approach allows to delete functions like audio_stream_copy_s16/s32 and functions related to them, then code will be shorter and cleaner. Moreover in future, during compressed stream implementation, there won't be need to add new copy function implementation for compressed streams, it will be sufficient to return 1 in audio_stream_sample_bytes() for non-pcm formats, then sample calculation will be equal to number of bytes and generic function like copy shoudn't have any trouble to handle such a data type. Signed-off-by: Karol Trzcinski --- src/include/sof/audio/audio_stream.h | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index 68c09e9a8..1c3fb81c0 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -546,21 +546,22 @@ audio_stream_frames_without_wrap(const struct audio_stream *source, /** * Copies data from source buffer to sink buffer. * @param source Source buffer. - * @param ioffset_bytes Offset (in bytes) in source buffer to start reading - * from. + * @param ioffset Offset (in samples) in source buffer to start reading from. * @param sink Sink buffer. - * @param ooffset_bytes Offset (in bytes) in sink buffer to start writing to. - * @param bytes Number of bytes to copy. + * @param ooffset Offset (in samples) in sink buffer to start writing to. + * @param samples Number of samples to copy. */ static inline void audio_stream_copy(const struct audio_stream *source, - uint32_t ioffset_bytes, + uint32_t ioffset, struct audio_stream *sink, - uint32_t ooffset_bytes, uint32_t bytes) + uint32_t ooffset, uint32_t samples) { + int ssize = audio_stream_sample_bytes(source); /* src fmt == sink fmt */ void *src = audio_stream_wrap(source, - (char *)source->r_ptr + ioffset_bytes); + (char *)source->r_ptr + ioffset * ssize); void *snk = audio_stream_wrap(sink, - (char *)sink->w_ptr + ooffset_bytes); + (char *)sink->w_ptr + ooffset * ssize); + uint32_t bytes = samples * ssize; uint32_t bytes_src; uint32_t bytes_snk; uint32_t bytes_copied; @@ -598,10 +599,7 @@ static inline void audio_stream_copy_s16(const struct audio_stream *source, struct audio_stream *sink, uint32_t ooffset, uint32_t samples) { - const int ssize = sizeof(int16_t); - - audio_stream_copy(source, ioffset * ssize, sink, ooffset * ssize, - samples * ssize); + audio_stream_copy(source, ioffset, sink, ooffset, samples); } #endif /* CONFIG_FORMAT_S16LE */ @@ -621,10 +619,7 @@ static inline void audio_stream_copy_s32(const struct audio_stream *source, struct audio_stream *sink, uint32_t ooffset, uint32_t samples) { - const int ssize = sizeof(int32_t); - - audio_stream_copy(source, ioffset * ssize, sink, ooffset * ssize, - samples * ssize); + audio_stream_copy(source, ioffset, sink, ooffset, samples); } #endif /* CONFIG_FORMAT_S24LE || CONFIG_FORMAT_S32LE || CONFIG_FORMAT_FLOAT */