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 <karolx.trzcinski@linux.intel.com>
This commit is contained in:
Karol Trzcinski 2020-07-24 15:29:59 +02:00 committed by Marcin Maka
parent af136e0325
commit f34d9ba928
1 changed files with 11 additions and 16 deletions

View File

@ -546,21 +546,22 @@ audio_stream_frames_without_wrap(const struct audio_stream *source,
/** /**
* Copies data from source buffer to sink buffer. * Copies data from source buffer to sink buffer.
* @param source Source buffer. * @param source Source buffer.
* @param ioffset_bytes Offset (in bytes) in source buffer to start reading * @param ioffset Offset (in samples) in source buffer to start reading from.
* from.
* @param sink Sink buffer. * @param sink Sink buffer.
* @param ooffset_bytes Offset (in bytes) in sink buffer to start writing to. * @param ooffset Offset (in samples) in sink buffer to start writing to.
* @param bytes Number of bytes to copy. * @param samples Number of samples to copy.
*/ */
static inline void audio_stream_copy(const struct audio_stream *source, static inline void audio_stream_copy(const struct audio_stream *source,
uint32_t ioffset_bytes, uint32_t ioffset,
struct audio_stream *sink, 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, void *src = audio_stream_wrap(source,
(char *)source->r_ptr + ioffset_bytes); (char *)source->r_ptr + ioffset * ssize);
void *snk = audio_stream_wrap(sink, 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_src;
uint32_t bytes_snk; uint32_t bytes_snk;
uint32_t bytes_copied; uint32_t bytes_copied;
@ -598,10 +599,7 @@ static inline void audio_stream_copy_s16(const struct audio_stream *source,
struct audio_stream *sink, struct audio_stream *sink,
uint32_t ooffset, uint32_t samples) uint32_t ooffset, uint32_t samples)
{ {
const int ssize = sizeof(int16_t); audio_stream_copy(source, ioffset, sink, ooffset, samples);
audio_stream_copy(source, ioffset * ssize, sink, ooffset * ssize,
samples * ssize);
} }
#endif /* CONFIG_FORMAT_S16LE */ #endif /* CONFIG_FORMAT_S16LE */
@ -621,10 +619,7 @@ static inline void audio_stream_copy_s32(const struct audio_stream *source,
struct audio_stream *sink, struct audio_stream *sink,
uint32_t ooffset, uint32_t samples) uint32_t ooffset, uint32_t samples)
{ {
const int ssize = sizeof(int32_t); audio_stream_copy(source, ioffset, sink, ooffset, samples);
audio_stream_copy(source, ioffset * ssize, sink, ooffset * ssize,
samples * ssize);
} }
#endif /* CONFIG_FORMAT_S24LE || CONFIG_FORMAT_S32LE || CONFIG_FORMAT_FLOAT */ #endif /* CONFIG_FORMAT_S24LE || CONFIG_FORMAT_S32LE || CONFIG_FORMAT_FLOAT */