aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm/GlueResampler.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-11 22:31:46 +0100
committerMax Kellermann <max@duempel.org>2013-11-30 16:22:57 +0100
commit5ba90cd8ea87cf97d64409b7b4c59033c2450c77 (patch)
treeeec1565c805de7bc142de82e5100cc3c1f86aa8d /src/pcm/GlueResampler.cxx
parente9127523db55a267f67532fd61e913f2879324fc (diff)
downloadmpd-5ba90cd8ea87cf97d64409b7b4c59033c2450c77.tar.gz
mpd-5ba90cd8ea87cf97d64409b7b4c59033c2450c77.tar.xz
mpd-5ba90cd8ea87cf97d64409b7b4c59033c2450c77.zip
pcm/PcmResampler: convert to abstract interface
The PcmResampler interface is implemented by the two classes FallbackPcmResampler and LibsampleratePcmResampler. This prepares for adding more resampler libraries.
Diffstat (limited to 'src/pcm/GlueResampler.cxx')
-rw-r--r--src/pcm/GlueResampler.cxx99
1 files changed, 45 insertions, 54 deletions
diff --git a/src/pcm/GlueResampler.cxx b/src/pcm/GlueResampler.cxx
index 8aee98f38..ef80e08a5 100644
--- a/src/pcm/GlueResampler.cxx
+++ b/src/pcm/GlueResampler.cxx
@@ -19,76 +19,67 @@
#include "config.h"
#include "GlueResampler.hxx"
-#include "PcmConvert.hxx"
-#include "PcmFormat.hxx"
-#include "util/ConstBuffer.hxx"
-#include "util/Error.hxx"
+#include "ConfiguredResampler.hxx"
+#include "Resampler.hxx"
+
+#include <assert.h>
+
+GluePcmResampler::GluePcmResampler()
+ :resampler(pcm_resampler_create()) {}
+
+GluePcmResampler::~GluePcmResampler()
+{
+ delete resampler;
+}
bool
-GluePcmResampler::Open(AudioFormat _src_format, unsigned _new_sample_rate,
- gcc_unused Error &error)
+GluePcmResampler::Open(AudioFormat src_format, unsigned new_sample_rate,
+ Error &error)
{
- src_format = _src_format;
- new_sample_rate = _new_sample_rate;
+ assert(src_format.IsValid());
+ assert(audio_valid_sample_rate(new_sample_rate));
+
+ AudioFormat requested_format = src_format;
+ AudioFormat dest_format = resampler->Open(requested_format,
+ new_sample_rate,
+ error);
+ if (!dest_format.IsValid())
+ return false;
+
+ assert(requested_format.channels == src_format.channels);
+ assert(dest_format.channels == src_format.channels);
+ assert(dest_format.sample_rate == new_sample_rate);
+ if (requested_format.format != src_format.format &&
+ !format_converter.Open(src_format.format, requested_format.format,
+ error))
+ return false;
+
+ src_sample_format = src_format.format;
+ requested_sample_format = requested_format.format;
+ output_sample_format = dest_format.format;
return true;
}
void
GluePcmResampler::Close()
{
- resampler.Reset();
+ if (requested_sample_format != src_sample_format)
+ format_converter.Close();
+
+ resampler->Close();
}
ConstBuffer<void>
GluePcmResampler::Resample(ConstBuffer<void> src, Error &error)
{
- const void *result;
- size_t size;
-
- switch (src_format.format) {
- case SampleFormat::S16:
- result = resampler.Resample16(src_format.channels,
- src_format.sample_rate,
- (const int16_t *)src.data,
- src.size,
- new_sample_rate, &size,
- error);
- break;
-
- case SampleFormat::S24_P32:
- result = resampler.Resample24(src_format.channels,
- src_format.sample_rate,
- (const int32_t *)src.data,
- src.size,
- new_sample_rate, &size,
- error);
- break;
-
- case SampleFormat::S32:
- result = resampler.Resample24(src_format.channels,
- src_format.sample_rate,
- (const int32_t *)src.data,
- src.size,
- new_sample_rate, &size,
- error);
- break;
-
- case SampleFormat::FLOAT:
- result = resampler.ResampleFloat(src_format.channels,
- src_format.sample_rate,
- (const float *)src.data,
- src.size,
- new_sample_rate, &size,
- error);
- break;
+ assert(!src.IsNull());
- default:
- error.Format(pcm_convert_domain,
- "Resampling %s is not implemented",
- sample_format_to_string(src_format.format));
- return nullptr;
+ if (requested_sample_format != src_sample_format) {
+ src = format_converter.Convert(src, error);
+ if (src.IsNull())
+ return nullptr;
}
- return { result, size };
+ return resampler->Resample(src, error);
}