summaryrefslogtreecommitdiff
path: root/src/pcm
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-06-18 11:19:27 +0200
committerMax Kellermann <max@musicpd.org>2019-06-18 11:19:27 +0200
commitbf26adf55546771e92fcfd2cc192c70c7eb5f1cd (patch)
treed59dbbc94ad0423ab587c67ed29bceeb7edae862 /src/pcm
parent0cc94fe30c213999e9cdd9b1e769e83369b78666 (diff)
pcm/Dsd{16,32}: stash odd frames away for the next call
Similar to commit 32380d1db046dc596e9f8198d22050b2beab8a41, these are the final parts for really fixing https://github.com/MusicPlayerDaemon/MPD/issues/469
Diffstat (limited to 'src/pcm')
-rw-r--r--src/pcm/Dsd16.cxx18
-rw-r--r--src/pcm/Dsd16.hxx4
-rw-r--r--src/pcm/Dsd32.cxx19
-rw-r--r--src/pcm/Dsd32.hxx4
4 files changed, 24 insertions, 21 deletions
diff --git a/src/pcm/Dsd16.cxx b/src/pcm/Dsd16.cxx
index 2052abce0..56a2bd65e 100644
--- a/src/pcm/Dsd16.cxx
+++ b/src/pcm/Dsd16.cxx
@@ -20,6 +20,8 @@
#include "Dsd16.hxx"
#include "util/ConstBuffer.hxx"
+#include <functional>
+
/**
* Construct a 16 bit integer from two bytes.
*/
@@ -54,18 +56,14 @@ void
Dsd16Converter::Open(unsigned _channels) noexcept
{
channels = _channels;
+
+ rest_buffer.Open(channels);
}
ConstBuffer<uint16_t>
-Dsd16Converter::Convert(ConstBuffer<uint8_t> _src) noexcept
+Dsd16Converter::Convert(ConstBuffer<uint8_t> src) noexcept
{
- const size_t in_frames = _src.size / channels;
- const size_t out_frames = in_frames / 2;
- const size_t out_samples = out_frames * channels;
-
- const uint8_t *src = _src.data;
- const auto dest = buffer.GetT<uint16_t>(out_samples);
- Dsd8To16(dest, src, out_frames, channels);
-
- return {dest, out_samples};
+ using namespace std::placeholders;
+ return rest_buffer.Process<uint16_t>(buffer, src, channels,
+ std::bind(Dsd8To16, _1, _2, _3, channels));
}
diff --git a/src/pcm/Dsd16.hxx b/src/pcm/Dsd16.hxx
index 227e8d479..18b31b83a 100644
--- a/src/pcm/Dsd16.hxx
+++ b/src/pcm/Dsd16.hxx
@@ -21,6 +21,7 @@
#define MPD_PCM_DSD_16_HXX
#include "Buffer.hxx"
+#include "RestBuffer.hxx"
#include <stdint.h>
@@ -34,10 +35,13 @@ class Dsd16Converter {
PcmBuffer buffer;
+ PcmRestBuffer<uint8_t, 2> rest_buffer;
+
public:
void Open(unsigned _channels) noexcept;
void Reset() noexcept {
+ rest_buffer.Reset();
}
ConstBuffer<uint16_t> Convert(ConstBuffer<uint8_t> src) noexcept;
diff --git a/src/pcm/Dsd32.cxx b/src/pcm/Dsd32.cxx
index e9c09f633..cefb5932f 100644
--- a/src/pcm/Dsd32.cxx
+++ b/src/pcm/Dsd32.cxx
@@ -18,9 +18,10 @@
*/
#include "Dsd32.hxx"
-#include "Buffer.hxx"
#include "util/ConstBuffer.hxx"
+#include <functional>
+
/**
* Construct a 32 bit integer from four bytes.
*/
@@ -57,18 +58,14 @@ void
Dsd32Converter::Open(unsigned _channels) noexcept
{
channels = _channels;
+
+ rest_buffer.Open(channels);
}
ConstBuffer<uint32_t>
-Dsd32Converter::Convert(ConstBuffer<uint8_t> _src) noexcept
+Dsd32Converter::Convert(ConstBuffer<uint8_t> src) noexcept
{
- const size_t in_frames = _src.size / channels;
- const size_t out_frames = in_frames / 4;
- const size_t out_samples = out_frames * channels;
-
- const uint8_t *src = _src.data;
- const auto dest = buffer.GetT<uint32_t>(out_samples);
- Dsd8To32(dest, src, out_frames, channels);
-
- return {dest, out_samples};
+ using namespace std::placeholders;
+ return rest_buffer.Process<uint32_t>(buffer, src, channels,
+ std::bind(Dsd8To32, _1, _2, _3, channels));
}
diff --git a/src/pcm/Dsd32.hxx b/src/pcm/Dsd32.hxx
index 0b2d3570d..f6036c527 100644
--- a/src/pcm/Dsd32.hxx
+++ b/src/pcm/Dsd32.hxx
@@ -21,6 +21,7 @@
#define MPD_PCM_DSD_32_HXX
#include "Buffer.hxx"
+#include "RestBuffer.hxx"
#include <stdint.h>
@@ -34,10 +35,13 @@ class Dsd32Converter {
PcmBuffer buffer;
+ PcmRestBuffer<uint8_t, 4> rest_buffer;
+
public:
void Open(unsigned _channels) noexcept;
void Reset() noexcept {
+ rest_buffer.Reset();
}
ConstBuffer<uint32_t> Convert(ConstBuffer<uint8_t> src) noexcept;