summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-06-17 12:37:28 +0200
committerMax Kellermann <max@musicpd.org>2019-06-17 22:18:44 +0200
commit32380d1db046dc596e9f8198d22050b2beab8a41 (patch)
tree17652edc0b8532bd7d575a2a4bf29ecc70549a27
parentc9f1354e4d642b3001aac438a33b98ccb777dd32 (diff)
pcm/Dop: stash odd frames away for the next call
First part of the "real" fix for https://github.com/MusicPlayerDaemon/MPD/issues/469
-rw-r--r--src/pcm/Dop.cxx22
-rw-r--r--src/pcm/Dop.hxx4
-rw-r--r--test/test_pcm_export.cxx35
3 files changed, 46 insertions, 15 deletions
diff --git a/src/pcm/Dop.cxx b/src/pcm/Dop.cxx
index 0ad6271d6..e1103cf4b 100644
--- a/src/pcm/Dop.cxx
+++ b/src/pcm/Dop.cxx
@@ -21,6 +21,8 @@
#include "ChannelDefs.hxx"
#include "util/ConstBuffer.hxx"
+#include <functional>
+
#include <assert.h>
static constexpr uint32_t
@@ -83,24 +85,14 @@ DsdToDopConverter::Open(unsigned _channels) noexcept
assert(audio_valid_channel_count(_channels));
channels = _channels;
+
+ rest_buffer.Open(channels);
}
ConstBuffer<uint32_t>
DsdToDopConverter::Convert(ConstBuffer<uint8_t> src) noexcept
{
- assert(audio_valid_channel_count(channels));
- assert(src.size % channels == 0);
-
- const size_t num_src_samples = src.size;
- const size_t num_src_frames = num_src_samples / channels;
-
- /* this rounds down and discards up to 3 odd frames; not
- elegant, but good enough for now */
- const size_t num_dop_quads = num_src_frames / 4;
- const size_t num_frames = num_dop_quads * 2;
- const size_t num_samples = num_frames * channels;
-
- uint32_t *const dest = (uint32_t *)buffer.GetT<uint32_t>(num_samples);
- DsdToDop(dest, src.data, num_dop_quads, channels);
- return { dest, num_samples };
+ using namespace std::placeholders;
+ return rest_buffer.Process<uint32_t>(buffer, src, 2 * channels,
+ std::bind(DsdToDop, _1, _2, _3, channels));
}
diff --git a/src/pcm/Dop.hxx b/src/pcm/Dop.hxx
index c1806b8c9..c6b6d2947 100644
--- a/src/pcm/Dop.hxx
+++ b/src/pcm/Dop.hxx
@@ -21,6 +21,7 @@
#define MPD_PCM_DOP_HXX
#include "Buffer.hxx"
+#include "RestBuffer.hxx"
#include <stdint.h>
@@ -36,10 +37,13 @@ class DsdToDopConverter {
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;
diff --git a/test/test_pcm_export.cxx b/test/test_pcm_export.cxx
index 63c8ad07a..9411bc580 100644
--- a/test/test_pcm_export.cxx
+++ b/test/test_pcm_export.cxx
@@ -210,6 +210,41 @@ TEST(PcmTest, ExportDop)
auto dest = e.Export({src, sizeof(src)});
EXPECT_EQ(sizeof(expected), dest.size);
EXPECT_TRUE(memcmp(dest.data, expected, dest.size) == 0);
+
+ /* not enough data: 2/8 */
+ static constexpr uint8_t src2[] = { 0x12, 0x34 };
+ static constexpr uint32_t expected2[] = {};
+ dest = e.Export({src2, sizeof(src2)});
+ ASSERT_EQ(sizeof(expected2), dest.size);
+ ASSERT_TRUE(memcmp(dest.data, expected2, dest.size) == 0);
+
+ /* not enough data: 6/8 */
+ static constexpr uint8_t src3[] = { 0x56, 0x78, 0x9a, 0xbc };
+ static constexpr uint32_t expected3[] = {};
+ dest = e.Export({src3, sizeof(src3)});
+ ASSERT_EQ(sizeof(expected3), dest.size);
+ ASSERT_TRUE(memcmp(dest.data, expected3, dest.size) == 0);
+
+ /* just enough data: 8/8 */
+ static constexpr uint8_t src4[] = { 0xde, 0xf0 };
+ static constexpr uint32_t expected4[] = { 0xff051256, 0xff053478, 0xfffa9ade, 0xfffabcf0 };
+ dest = e.Export({src4, sizeof(src4)});
+ ASSERT_EQ(sizeof(expected4), dest.size);
+ ASSERT_TRUE(memcmp(dest.data, expected4, dest.size) == 0);
+
+ /* not enough data: 6/8 */
+ static constexpr uint8_t src5[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+ static constexpr uint32_t expected5[] = {};
+ dest = e.Export({src5, sizeof(src5)});
+ ASSERT_EQ(sizeof(expected5), dest.size);
+ ASSERT_TRUE(memcmp(dest.data, expected5, dest.size) == 0);
+
+ /* two quads returned, not enough data for more: 2/8 */
+ static constexpr uint8_t src6[] = { 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x10, 0x20 };
+ static constexpr uint32_t expected6[] = { 0xff051133, 0xff052244, 0xfffa5577, 0xfffa6688, 0xff0599bb, 0xff05aacc, 0xfffaddff, 0xfffaee00 };
+ dest = e.Export({src6, sizeof(src6)});
+ ASSERT_EQ(sizeof(expected6), dest.size);
+ ASSERT_TRUE(memcmp(dest.data, expected6, dest.size) == 0);
}
#endif