pcm/Dop: stash odd frames away for the next call

First part of the "real" fix for
https://github.com/MusicPlayerDaemon/MPD/issues/469
This commit is contained in:
Max Kellermann
2019-06-17 12:37:28 +02:00
parent c9f1354e4d
commit 32380d1db0
3 changed files with 46 additions and 15 deletions

View File

@@ -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));
}

View File

@@ -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;