aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-01 13:11:19 +0100
committerMax Kellermann <max@duempel.org>2013-12-01 19:13:39 +0100
commit3ed80f31399c80a90bc3d2a845e739fff485d7c5 (patch)
treef25a37007835eec0daf31e9ba028eea213ea8957 /src/pcm
parenta698cc81126c6958d9d67f02a71277cc7f183454 (diff)
downloadmpd-3ed80f31399c80a90bc3d2a845e739fff485d7c5.tar.gz
mpd-3ed80f31399c80a90bc3d2a845e739fff485d7c5.tar.xz
mpd-3ed80f31399c80a90bc3d2a845e739fff485d7c5.zip
pcm/ConfiguredResampler: convert boolean flag to enum
Prepare for adding more resamplers.
Diffstat (limited to 'src/pcm')
-rw-r--r--src/pcm/ConfiguredResampler.cxx44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/pcm/ConfiguredResampler.cxx b/src/pcm/ConfiguredResampler.cxx
index 92f3d0903..f562e4a2b 100644
--- a/src/pcm/ConfiguredResampler.cxx
+++ b/src/pcm/ConfiguredResampler.cxx
@@ -20,44 +20,62 @@
#include "config.h"
#include "ConfiguredResampler.hxx"
#include "FallbackResampler.hxx"
+#include "ConfigGlobal.hxx"
+#include "ConfigOption.hxx"
+#include "ConfigError.hxx"
+#include "util/Error.hxx"
#ifdef HAVE_LIBSAMPLERATE
#include "LibsamplerateResampler.hxx"
-#include "ConfigGlobal.hxx"
-#include "ConfigOption.hxx"
#endif
#include <string.h>
+enum class SelectedResampler {
+ FALLBACK,
+
#ifdef HAVE_LIBSAMPLERATE
-static bool lsr_enabled;
+ LIBSAMPLERATE,
#endif
+};
+
+static SelectedResampler selected_resampler = SelectedResampler::FALLBACK;
bool
pcm_resampler_global_init(Error &error)
{
-#ifdef HAVE_LIBSAMPLERATE
const char *converter =
config_get_string(CONF_SAMPLERATE_CONVERTER, "");
- lsr_enabled = strcmp(converter, "internal") != 0;
- if (lsr_enabled)
- return pcm_resample_lsr_global_init(converter, error);
- else
+ if (strcmp(converter, "internal") == 0)
return true;
-#else
- (void)error;
- return true;
+
+#ifdef HAVE_LIBSAMPLERATE
+ selected_resampler = SelectedResampler::LIBSAMPLERATE;
+ return pcm_resample_lsr_global_init(converter, error);
#endif
+
+ if (*converter == 0)
+ return true;
+
+ error.Format(config_domain,
+ "The samplerate_converter '%s' is not available",
+ converter);
+ return false;
}
PcmResampler *
pcm_resampler_create()
{
+ switch (selected_resampler) {
+ case SelectedResampler::FALLBACK:
+ return new FallbackPcmResampler();
+
#ifdef HAVE_LIBSAMPLERATE
- if (lsr_enabled)
+ case SelectedResampler::LIBSAMPLERATE:
return new LibsampleratePcmResampler();
#endif
+ }
- return new FallbackPcmResampler();
+ gcc_unreachable();
}