2013-11-11 22:31:46 +01:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2013-11-11 22:31:46 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "ConfiguredResampler.hxx"
|
|
|
|
#include "FallbackResampler.hxx"
|
2014-01-24 00:20:01 +01:00
|
|
|
#include "config/ConfigGlobal.hxx"
|
|
|
|
#include "config/ConfigOption.hxx"
|
|
|
|
#include "config/ConfigError.hxx"
|
2013-12-01 13:11:19 +01:00
|
|
|
#include "util/Error.hxx"
|
2013-11-11 22:31:46 +01:00
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_LIBSAMPLERATE
|
2013-11-11 22:31:46 +01:00
|
|
|
#include "LibsamplerateResampler.hxx"
|
|
|
|
#endif
|
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_SOXR
|
2013-11-10 19:17:16 +01:00
|
|
|
#include "SoxrResampler.hxx"
|
|
|
|
#endif
|
|
|
|
|
2013-11-11 22:31:46 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-12-01 13:11:19 +01:00
|
|
|
enum class SelectedResampler {
|
|
|
|
FALLBACK,
|
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_LIBSAMPLERATE
|
2013-12-01 13:11:19 +01:00
|
|
|
LIBSAMPLERATE,
|
2013-11-11 22:31:46 +01:00
|
|
|
#endif
|
2013-11-10 19:17:16 +01:00
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_SOXR
|
2013-11-10 19:17:16 +01:00
|
|
|
SOXR,
|
|
|
|
#endif
|
2013-12-01 13:11:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static SelectedResampler selected_resampler = SelectedResampler::FALLBACK;
|
2013-11-11 22:31:46 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
pcm_resampler_global_init(Error &error)
|
|
|
|
{
|
|
|
|
const char *converter =
|
|
|
|
config_get_string(CONF_SAMPLERATE_CONVERTER, "");
|
|
|
|
|
2013-12-01 13:11:19 +01:00
|
|
|
if (strcmp(converter, "internal") == 0)
|
2013-11-11 22:31:46 +01:00
|
|
|
return true;
|
2013-12-01 13:11:19 +01:00
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_SOXR
|
2014-01-21 19:34:06 +01:00
|
|
|
if (memcmp(converter, "soxr", 4) == 0) {
|
2013-11-10 19:17:16 +01:00
|
|
|
selected_resampler = SelectedResampler::SOXR;
|
2014-01-21 19:34:06 +01:00
|
|
|
return pcm_resample_soxr_global_init(converter, error);
|
2013-11-10 19:17:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_LIBSAMPLERATE
|
2013-12-01 13:11:19 +01:00
|
|
|
selected_resampler = SelectedResampler::LIBSAMPLERATE;
|
|
|
|
return pcm_resample_lsr_global_init(converter, error);
|
2013-11-11 22:31:46 +01:00
|
|
|
#endif
|
2013-12-01 13:11:19 +01:00
|
|
|
|
|
|
|
if (*converter == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error.Format(config_domain,
|
|
|
|
"The samplerate_converter '%s' is not available",
|
|
|
|
converter);
|
|
|
|
return false;
|
2013-11-11 22:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PcmResampler *
|
|
|
|
pcm_resampler_create()
|
|
|
|
{
|
2013-12-01 13:11:19 +01:00
|
|
|
switch (selected_resampler) {
|
|
|
|
case SelectedResampler::FALLBACK:
|
|
|
|
return new FallbackPcmResampler();
|
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_LIBSAMPLERATE
|
2013-12-01 13:11:19 +01:00
|
|
|
case SelectedResampler::LIBSAMPLERATE:
|
2013-11-11 22:31:46 +01:00
|
|
|
return new LibsampleratePcmResampler();
|
|
|
|
#endif
|
2013-11-10 19:17:16 +01:00
|
|
|
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_SOXR
|
2013-11-10 19:17:16 +01:00
|
|
|
case SelectedResampler::SOXR:
|
|
|
|
return new SoxrPcmResampler();
|
|
|
|
#endif
|
2013-12-01 13:11:19 +01:00
|
|
|
}
|
2013-11-11 22:31:46 +01:00
|
|
|
|
2013-12-01 13:11:19 +01:00
|
|
|
gcc_unreachable();
|
2013-11-11 22:31:46 +01:00
|
|
|
}
|