diff options
author | Max Kellermann <max@duempel.org> | 2013-12-02 09:15:54 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-02 11:21:32 +0100 |
commit | 2b44a2c9bd8f9a171a2e998feb14f3c5a1c29381 (patch) | |
tree | 3e57bc4eafd8d8c377971201049fc5cafde1905b /src/pcm | |
parent | af3b454805b49301b14f2f55f7a99020527bd63a (diff) | |
download | mpd-2b44a2c9bd8f9a171a2e998feb14f3c5a1c29381.tar.gz mpd-2b44a2c9bd8f9a171a2e998feb14f3c5a1c29381.tar.xz mpd-2b44a2c9bd8f9a171a2e998feb14f3c5a1c29381.zip |
pcm/PcmChannels: use struct ConstBuffer
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/ChannelsConverter.cxx | 48 | ||||
-rw-r--r-- | src/pcm/PcmChannels.cxx | 105 | ||||
-rw-r--r-- | src/pcm/PcmChannels.hxx | 33 |
3 files changed, 74 insertions, 112 deletions
diff --git a/src/pcm/ChannelsConverter.cxx b/src/pcm/ChannelsConverter.cxx index 5895fb15d..46197b7e0 100644 --- a/src/pcm/ChannelsConverter.cxx +++ b/src/pcm/ChannelsConverter.cxx @@ -62,11 +62,8 @@ PcmChannelsConverter::Close() } ConstBuffer<void> -PcmChannelsConverter::Convert(ConstBuffer<void> src, Error &error) +PcmChannelsConverter::Convert(ConstBuffer<void> src, gcc_unused Error &error) { - const void *result = nullptr; - size_t result_size = 0; - switch (format) { case SampleFormat::UNDEFINED: case SampleFormat::S8: @@ -75,41 +72,26 @@ PcmChannelsConverter::Convert(ConstBuffer<void> src, Error &error) gcc_unreachable(); case SampleFormat::S16: - result = pcm_convert_channels_16(buffer, dest_channels, - src_channels, - (const int16_t *)src.data, - src.size, &result_size); - break; + return pcm_convert_channels_16(buffer, dest_channels, + src_channels, + ConstBuffer<int16_t>::FromVoid(src)).ToVoid(); case SampleFormat::S24_P32: - result = pcm_convert_channels_24(buffer, dest_channels, - src_channels, - (const int32_t *)src.data, - src.size, &result_size); - break; + return pcm_convert_channels_24(buffer, dest_channels, + src_channels, + ConstBuffer<int32_t>::FromVoid(src)).ToVoid(); case SampleFormat::S32: - result = pcm_convert_channels_32(buffer, dest_channels, - src_channels, - (const int32_t *)src.data, - src.size, &result_size); - break; + return pcm_convert_channels_32(buffer, dest_channels, + src_channels, + ConstBuffer<int32_t>::FromVoid(src)).ToVoid(); case SampleFormat::FLOAT: - result = pcm_convert_channels_float(buffer, dest_channels, - src_channels, - (const float *)src.data, - src.size, &result_size); - break; - } - - if (result == nullptr) { - error.Format(pcm_convert_domain, - "Conversion from %u to %u channels " - "is not implemented", - src_channels, dest_channels); - return nullptr; + return pcm_convert_channels_float(buffer, dest_channels, + src_channels, + ConstBuffer<float>::FromVoid(src)).ToVoid(); } - return { result, result_size }; + assert(false); + gcc_unreachable(); } diff --git a/src/pcm/PcmChannels.cxx b/src/pcm/PcmChannels.cxx index eb69985c1..74f9416f9 100644 --- a/src/pcm/PcmChannels.cxx +++ b/src/pcm/PcmChannels.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "PcmChannels.hxx" #include "PcmBuffer.hxx" -#include "PcmUtils.hxx" +#include "util/ConstBuffer.hxx" #include <assert.h> @@ -73,31 +73,28 @@ pcm_convert_channels_16_n_to_2(int16_t *gcc_restrict dest, } } -const int16_t * +ConstBuffer<int16_t> pcm_convert_channels_16(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int16_t *src, - size_t src_size, size_t *dest_size_r) + unsigned src_channels, + ConstBuffer<int16_t> src) { - assert(src_size % (sizeof(*src) * src_channels) == 0); + assert(src.size % src_channels == 0); - size_t dest_size = src_size / src_channels * dest_channels; - *dest_size_r = dest_size; - - int16_t *dest = (int16_t *)buffer.Get(dest_size); - const int16_t *src_end = pcm_end_pointer(src, src_size); + const size_t dest_size = src.size / src_channels * dest_channels; + int16_t *dest = buffer.GetT<int16_t>(dest_size); if (src_channels == 1 && dest_channels == 2) - MonoToStereo(dest, src, src_end); + MonoToStereo(dest, src.begin(), src.end()); else if (src_channels == 2 && dest_channels == 1) - pcm_convert_channels_16_2_to_1(dest, src, src_end); + pcm_convert_channels_16_2_to_1(dest, src.begin(), src.end()); else if (dest_channels == 2) - pcm_convert_channels_16_n_to_2(dest, src_channels, src, - src_end); + pcm_convert_channels_16_n_to_2(dest, src_channels, + src.begin(), src.end()); else return nullptr; - return dest; + return { dest, dest_size }; } static void @@ -136,32 +133,28 @@ pcm_convert_channels_24_n_to_2(int32_t *gcc_restrict dest, } } -const int32_t * +ConstBuffer<int32_t> pcm_convert_channels_24(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int32_t *src, - size_t src_size, size_t *dest_size_r) + unsigned src_channels, + ConstBuffer<int32_t> src) { - assert(src_size % (sizeof(*src) * src_channels) == 0); - - size_t dest_size = src_size / src_channels * dest_channels; - *dest_size_r = dest_size; + assert(src.size % src_channels == 0); - int32_t *dest = (int32_t *)buffer.Get(dest_size); - const int32_t *src_end = (const int32_t *) - pcm_end_pointer(src, src_size); + size_t dest_size = src.size / src_channels * dest_channels; + int32_t *dest = buffer.GetT<int32_t>(dest_size); if (src_channels == 1 && dest_channels == 2) - MonoToStereo(dest, src, src_end); + MonoToStereo(dest, src.begin(), src.end()); else if (src_channels == 2 && dest_channels == 1) - pcm_convert_channels_24_2_to_1(dest, src, src_end); + pcm_convert_channels_24_2_to_1(dest, src.begin(), src.end()); else if (dest_channels == 2) - pcm_convert_channels_24_n_to_2(dest, src_channels, src, - src_end); + pcm_convert_channels_24_n_to_2(dest, src_channels, + src.begin(), src.end()); else return nullptr; - return dest; + return { dest, dest_size }; } static void @@ -199,32 +192,28 @@ pcm_convert_channels_32_n_to_2(int32_t *dest, } } -const int32_t * +ConstBuffer<int32_t> pcm_convert_channels_32(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int32_t *src, - size_t src_size, size_t *dest_size_r) + unsigned src_channels, + ConstBuffer<int32_t> src) { - assert(src_size % (sizeof(*src) * src_channels) == 0); + assert(src.size % src_channels == 0); - size_t dest_size = src_size / src_channels * dest_channels; - *dest_size_r = dest_size; - - int32_t *dest = (int32_t *)buffer.Get(dest_size); - const int32_t *src_end = (const int32_t *) - pcm_end_pointer(src, src_size); + size_t dest_size = src.size / src_channels * dest_channels; + int32_t *dest = buffer.GetT<int32_t>(dest_size); if (src_channels == 1 && dest_channels == 2) - MonoToStereo(dest, src, src_end); + MonoToStereo(dest, src.begin(), src.end()); else if (src_channels == 2 && dest_channels == 1) - pcm_convert_channels_32_2_to_1(dest, src, src_end); + pcm_convert_channels_32_2_to_1(dest, src.begin(), src.end()); else if (dest_channels == 2) - pcm_convert_channels_32_n_to_2(dest, src_channels, src, - src_end); + pcm_convert_channels_32_n_to_2(dest, src_channels, + src.begin(), src.end()); else return nullptr; - return dest; + return { dest, dest_size }; } static void @@ -262,29 +251,27 @@ pcm_convert_channels_float_n_to_2(float *dest, } } -const float * +ConstBuffer<float> pcm_convert_channels_float(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const float *src, - size_t src_size, size_t *dest_size_r) + unsigned src_channels, + ConstBuffer<float> src) { - assert(src_size % (sizeof(*src) * src_channels) == 0); - - size_t dest_size = src_size / src_channels * dest_channels; - *dest_size_r = dest_size; + assert(src.size % src_channels == 0); - float *dest = (float *)buffer.Get(dest_size); - const float *src_end = (const float *)pcm_end_pointer(src, src_size); + size_t dest_size = src.size / src_channels * dest_channels; + float *dest = buffer.GetT<float>(dest_size); if (src_channels == 1 && dest_channels == 2) - MonoToStereo(dest, src, src_end); + MonoToStereo(dest, src.begin(), src.end()); else if (src_channels == 2 && dest_channels == 1) - pcm_convert_channels_float_2_to_1(dest, src, src_end); + pcm_convert_channels_float_2_to_1(dest, + src.begin(), src.end()); else if (dest_channels == 2) - pcm_convert_channels_float_n_to_2(dest, src_channels, src, - src_end); + pcm_convert_channels_float_n_to_2(dest, src_channels, + src.begin(), src.end()); else return nullptr; - return dest; + return { dest, dest_size }; } diff --git a/src/pcm/PcmChannels.hxx b/src/pcm/PcmChannels.hxx index c67822825..ca4e06a8c 100644 --- a/src/pcm/PcmChannels.hxx +++ b/src/pcm/PcmChannels.hxx @@ -24,6 +24,7 @@ #include <stddef.h> class PcmBuffer; +template<typename T> struct ConstBuffer; /** * Changes the number of channels in 16 bit PCM data. @@ -32,15 +33,13 @@ class PcmBuffer; * @param dest_channels the number of channels requested * @param src_channels the number of channels in the source buffer * @param src the source PCM buffer - * @param src_size the number of bytes in #src - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer */ -const int16_t * +ConstBuffer<int16_t> pcm_convert_channels_16(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int16_t *src, - size_t src_size, size_t *dest_size_r); + unsigned src_channels, + ConstBuffer<int16_t> src); /** * Changes the number of channels in 24 bit PCM data (aligned at 32 @@ -50,15 +49,13 @@ pcm_convert_channels_16(PcmBuffer &buffer, * @param dest_channels the number of channels requested * @param src_channels the number of channels in the source buffer * @param src the source PCM buffer - * @param src_size the number of bytes in #src - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer */ -const int32_t * +ConstBuffer<int32_t> pcm_convert_channels_24(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int32_t *src, - size_t src_size, size_t *dest_size_r); + unsigned src_channels, + ConstBuffer<int32_t> src); /** * Changes the number of channels in 32 bit PCM data. @@ -67,15 +64,13 @@ pcm_convert_channels_24(PcmBuffer &buffer, * @param dest_channels the number of channels requested * @param src_channels the number of channels in the source buffer * @param src the source PCM buffer - * @param src_size the number of bytes in #src - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer */ -const int32_t * +ConstBuffer<int32_t> pcm_convert_channels_32(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const int32_t *src, - size_t src_size, size_t *dest_size_r); + unsigned src_channels, + ConstBuffer<int32_t> src); /** * Changes the number of channels in 32 bit float PCM data. @@ -84,14 +79,12 @@ pcm_convert_channels_32(PcmBuffer &buffer, * @param dest_channels the number of channels requested * @param src_channels the number of channels in the source buffer * @param src the source PCM buffer - * @param src_size the number of bytes in #src - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer */ -const float * +ConstBuffer<float> pcm_convert_channels_float(PcmBuffer &buffer, unsigned dest_channels, - unsigned src_channels, const float *src, - size_t src_size, size_t *dest_size_r); + unsigned src_channels, + ConstBuffer<float> src); #endif |