aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm/PcmExport.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/pcm/PcmExport.cxx77
1 files changed, 34 insertions, 43 deletions
diff --git a/src/pcm/PcmExport.cxx b/src/pcm/PcmExport.cxx
index f6ce1e661..ef099ba71 100644
--- a/src/pcm/PcmExport.cxx
+++ b/src/pcm/PcmExport.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,21 +19,24 @@
#include "config.h"
#include "PcmExport.hxx"
-#include "PcmDsdUsb.hxx"
+#include "PcmDop.hxx"
#include "PcmPack.hxx"
#include "util/ByteReverse.hxx"
+#include "util/ConstBuffer.hxx"
+
+#include <iterator>
void
PcmExport::Open(SampleFormat sample_format, unsigned _channels,
- bool _dsd_usb, bool _shift8, bool _pack, bool _reverse_endian)
+ bool _dop, bool _shift8, bool _pack, bool _reverse_endian)
{
assert(audio_valid_sample_format(sample_format));
- assert(!_dsd_usb || audio_valid_channel_count(_channels));
+ assert(!_dop || audio_valid_channel_count(_channels));
channels = _channels;
- dsd_usb = _dsd_usb && sample_format == SampleFormat::DSD;
- if (dsd_usb)
- /* after the conversion to DSD-over-USB, the DSD
+ dop = _dop && sample_format == SampleFormat::DSD;
+ if (dop)
+ /* after the conversion to DoP, the DSD
samples are stuffed inside fake 24 bit samples */
sample_format = SampleFormat::S24_P32;
@@ -61,7 +64,7 @@ PcmExport::GetFrameSize(const AudioFormat &audio_format) const
/* packed 24 bit samples (3 bytes per sample) */
return audio_format.channels * 3;
- if (dsd_usb)
+ if (dop)
/* the DSD-over-USB draft says that DSD 1-bit samples
are enclosed within 24 bit samples, and MPD's
representation of 24 bit is padded to 32 bit (4
@@ -71,59 +74,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);
+ if (dop)
+ data = pcm_dsd_to_dop(dop_buffer, channels,
+ ConstBuffer<uint8_t>::FromVoid(data))
+ .ToVoid();
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;
}
@@ -134,8 +125,8 @@ PcmExport::CalcSourceSize(size_t size) const
/* 32 bit to 24 bit conversion (4 to 3 bytes) */
size = (size / 3) * 4;
- if (dsd_usb)
- /* DSD over USB doubles the transport size */
+ if (dop)
+ /* DoP doubles the transport size */
size /= 2;
return size;