diff options
author | Max Kellermann <max@duempel.org> | 2014-08-12 21:40:06 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-12 22:19:53 +0200 |
commit | 0e756e43774ef95ea9685e57f0c51331a9a7d1dc (patch) | |
tree | 8f935d93255755193ce3ae2473cbdf693a8c385a /src/pcm | |
parent | ee7282ce0ddb85e4e0d8174a8db6d3853b2b41a5 (diff) | |
download | mpd-0e756e43774ef95ea9685e57f0c51331a9a7d1dc.tar.gz mpd-0e756e43774ef95ea9685e57f0c51331a9a7d1dc.tar.xz mpd-0e756e43774ef95ea9685e57f0c51331a9a7d1dc.zip |
PcmExport: use class ConstBuffer
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/PcmExport.cxx | 53 | ||||
-rw-r--r-- | src/pcm/PcmExport.hxx | 6 |
2 files changed, 23 insertions, 36 deletions
diff --git a/src/pcm/PcmExport.cxx b/src/pcm/PcmExport.cxx index fc3ef57ca..e04a7fdd9 100644 --- a/src/pcm/PcmExport.cxx +++ b/src/pcm/PcmExport.cxx @@ -22,6 +22,7 @@ #include "PcmDsdUsb.hxx" #include "PcmPack.hxx" #include "util/ByteReverse.hxx" +#include "util/ConstBuffer.hxx" void PcmExport::Open(SampleFormat sample_format, unsigned _channels, @@ -71,59 +72,47 @@ PcmExport::GetFrameSize(const AudioFormat &audio_format) const return audio_format.GetFrameSize(); } -const void * -PcmExport::Export(const void *data, size_t size, size_t &dest_size_r) +ConstBuffer<void> +PcmExport::Export(ConstBuffer<void> data) { if (dsd_usb) - data = pcm_dsd_to_usb(dsd_buffer, channels, - (const uint8_t *)data, size, &size); + data.data = pcm_dsd_to_usb(dsd_buffer, channels, + (const uint8_t *)data.data, + data.size, &data.size); if (pack24) { - assert(size % 4 == 0); - - const size_t num_samples = size / 4; + const auto src = ConstBuffer<int32_t>::FromVoid(data); + const size_t num_samples = src.size; const size_t dest_size = num_samples * 3; - - const uint8_t *src8 = (const uint8_t *)data; - const uint8_t *src_end8 = src8 + size; uint8_t *dest = (uint8_t *)pack_buffer.Get(dest_size); assert(dest != nullptr); - pcm_pack_24(dest, (const int32_t *)src8, - (const int32_t *)src_end8); + pcm_pack_24(dest, src.begin(), src.end()); - data = dest; - size = dest_size; + data.data = dest; + data.size = dest_size; } else if (shift8) { - assert(size % 4 == 0); - - const uint8_t *src8 = (const uint8_t *)data; - const uint8_t *src_end8 = src8 + size; - const uint32_t *src = (const uint32_t *)src8; - const uint32_t *const src_end = (const uint32_t *)src_end8; + const auto src = ConstBuffer<int32_t>::FromVoid(data); - uint32_t *dest = (uint32_t *)pack_buffer.Get(size); - data = dest; + uint32_t *dest = (uint32_t *)pack_buffer.Get(data.size); + data.data = dest; - while (src < src_end) - *dest++ = *src++ << 8; + for (auto i : src) + *dest++ = i << 8; } - if (reverse_endian > 0) { assert(reverse_endian >= 2); - uint8_t *dest = (uint8_t *)reverse_buffer.Get(size); - assert(dest != nullptr); + const auto src = ConstBuffer<uint8_t>::FromVoid(data); - const uint8_t *src = (const uint8_t *)data; - const uint8_t *src_end = src + size; - reverse_bytes(dest, src, src_end, reverse_endian); + uint8_t *dest = (uint8_t *)reverse_buffer.Get(data.size); + assert(dest != nullptr); + data.data = dest; - data = dest; + reverse_bytes(dest, src.begin(), src.end(), reverse_endian); } - dest_size_r = size; return data; } diff --git a/src/pcm/PcmExport.hxx b/src/pcm/PcmExport.hxx index 61ac14c6f..75050e5c2 100644 --- a/src/pcm/PcmExport.hxx +++ b/src/pcm/PcmExport.hxx @@ -25,6 +25,7 @@ #include "AudioFormat.hxx" struct AudioFormat; +template<typename T> struct ConstBuffer; /** * An object that handles export of PCM samples to some instance @@ -108,12 +109,9 @@ struct PcmExport { * * @param state an initialized and open pcm_export_state object * @param src the source PCM buffer - * @param src_size the size of #src in bytes - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer (may be a pointer to the source buffer) */ - const void *Export(const void *src, size_t src_size, - size_t &dest_size_r); + ConstBuffer<void> Export(ConstBuffer<void> src); /** * Converts the number of consumed bytes from the pcm_export() |