aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm/PcmConvert.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-30 13:19:07 +0100
committerMax Kellermann <max@duempel.org>2013-11-30 13:22:25 +0100
commit92004f2e7e6ec8479805313b0bdac7258d53c74e (patch)
treee8d522cd55c015e145816f6df6db8316ea6cad6a /src/pcm/PcmConvert.cxx
parent0eefc7a43ce13876cdfb434e2a890a16befcb847 (diff)
downloadmpd-92004f2e7e6ec8479805313b0bdac7258d53c74e.tar.gz
mpd-92004f2e7e6ec8479805313b0bdac7258d53c74e.tar.xz
mpd-92004f2e7e6ec8479805313b0bdac7258d53c74e.zip
pcm/PcmConvert: move code to new class PcmChannelsConverter
Diffstat (limited to 'src/pcm/PcmConvert.cxx')
-rw-r--r--src/pcm/PcmConvert.cxx85
1 files changed, 22 insertions, 63 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx
index eb9c0e052..bc289460d 100644
--- a/src/pcm/PcmConvert.cxx
+++ b/src/pcm/PcmConvert.cxx
@@ -19,7 +19,6 @@
#include "config.h"
#include "PcmConvert.hxx"
-#include "PcmChannels.hxx"
#include "AudioFormat.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
@@ -72,12 +71,22 @@ PcmConvert::Open(AudioFormat _src_format, AudioFormat _dest_format,
return false;
format.format = dest_format.format;
+ if (format.channels != dest_format.channels &&
+ !channels_converter.Open(format.format, format.channels,
+ dest_format.channels, error)) {
+ format_converter.Close();
+ return false;
+ }
+
return true;
}
void
PcmConvert::Close()
{
+ if (src_format.channels != dest_format.channels)
+ channels_converter.Close();
+
if (src_format.format != dest_format.format)
format_converter.Close();
@@ -96,25 +105,11 @@ PcmConvert::Convert16(ConstBuffer<int16_t> src, AudioFormat format,
{
assert(format.format == SampleFormat::S16);
assert(dest_format.format == SampleFormat::S16);
+ assert(format.channels == dest_format.channels);
auto buf = src.data;
size_t len = src.size * sizeof(*src.data);
- if (format.channels != dest_format.channels) {
- buf = pcm_convert_channels_16(channels_buffer,
- dest_format.channels,
- format.channels,
- buf, len, &len);
- if (buf == nullptr) {
- error.Format(pcm_convert_domain,
- "Conversion from %u to %u channels "
- "is not implemented",
- format.channels,
- dest_format.channels);
- return nullptr;
- }
- }
-
if (format.sample_rate != dest_format.sample_rate) {
buf = resampler.Resample16(dest_format.channels,
format.sample_rate, buf, len,
@@ -133,25 +128,11 @@ PcmConvert::Convert24(ConstBuffer<int32_t> src, AudioFormat format,
{
assert(format.format == SampleFormat::S24_P32);
assert(dest_format.format == SampleFormat::S24_P32);
+ assert(format.channels == dest_format.channels);
auto buf = src.data;
size_t len = src.size * sizeof(*src.data);
- if (format.channels != dest_format.channels) {
- buf = pcm_convert_channels_24(channels_buffer,
- dest_format.channels,
- format.channels,
- buf, len, &len);
- if (buf == nullptr) {
- error.Format(pcm_convert_domain,
- "Conversion from %u to %u channels "
- "is not implemented",
- format.channels,
- dest_format.channels);
- return nullptr;
- }
- }
-
if (format.sample_rate != dest_format.sample_rate) {
buf = resampler.Resample24(dest_format.channels,
format.sample_rate, buf, len,
@@ -170,25 +151,11 @@ PcmConvert::Convert32(ConstBuffer<int32_t> src, AudioFormat format,
{
assert(format.format == SampleFormat::S32);
assert(dest_format.format == SampleFormat::S32);
+ assert(format.channels == dest_format.channels);
auto buf = src.data;
size_t len = src.size * sizeof(*src.data);
- if (format.channels != dest_format.channels) {
- buf = pcm_convert_channels_32(channels_buffer,
- dest_format.channels,
- format.channels,
- buf, len, &len);
- if (buf == nullptr) {
- error.Format(pcm_convert_domain,
- "Conversion from %u to %u channels "
- "is not implemented",
- format.channels,
- dest_format.channels);
- return nullptr;
- }
- }
-
if (format.sample_rate != dest_format.sample_rate) {
buf = resampler.Resample32(dest_format.channels,
format.sample_rate, buf, len,
@@ -207,27 +174,11 @@ PcmConvert::ConvertFloat(ConstBuffer<float> src, AudioFormat format,
{
assert(format.format == SampleFormat::FLOAT);
assert(dest_format.format == SampleFormat::FLOAT);
+ assert(format.channels == dest_format.channels);
auto buffer = src.data;
size_t size = src.size * sizeof(*src.data);
- /* convert channels */
-
- if (format.channels != dest_format.channels) {
- buffer = pcm_convert_channels_float(channels_buffer,
- dest_format.channels,
- format.channels,
- buffer, size, &size);
- if (buffer == nullptr) {
- error.Format(pcm_convert_domain,
- "Conversion from %u to %u channels "
- "is not implemented",
- format.channels,
- dest_format.channels);
- return nullptr;
- }
- }
-
/* resample with float, because this is the best format for
libsamplerate */
@@ -274,6 +225,14 @@ PcmConvert::Convert(const void *src, size_t src_size,
format.format = dest_format.format;
}
+ if (format.channels != dest_format.channels) {
+ buffer = channels_converter.Convert(buffer, error);
+ if (buffer.IsNull())
+ return nullptr;
+
+ format.channels = dest_format.channels;
+ }
+
switch (dest_format.format) {
case SampleFormat::S16:
buffer = Convert16(ConstBuffer<int16_t>::FromVoid(buffer),