diff options
Diffstat (limited to '')
45 files changed, 229 insertions, 143 deletions
diff --git a/src/pcm/ChannelsConverter.cxx b/src/pcm/ChannelsConverter.cxx index 714613788..261af77ca 100644 --- a/src/pcm/ChannelsConverter.cxx +++ b/src/pcm/ChannelsConverter.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/ChannelsConverter.hxx b/src/pcm/ChannelsConverter.hxx index 1374f9f5d..aba230a86 100644 --- a/src/pcm/ChannelsConverter.hxx +++ b/src/pcm/ChannelsConverter.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/ConfiguredResampler.cxx b/src/pcm/ConfiguredResampler.cxx index f6aec3f95..30cb801c7 100644 --- a/src/pcm/ConfiguredResampler.cxx +++ b/src/pcm/ConfiguredResampler.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -23,13 +23,15 @@ #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" #include "config/ConfigError.hxx" +#include "config/Block.hxx" +#include "config/Param.hxx" #include "util/Error.hxx" -#ifdef HAVE_LIBSAMPLERATE +#ifdef ENABLE_LIBSAMPLERATE #include "LibsamplerateResampler.hxx" #endif -#ifdef HAVE_SOXR +#ifdef ENABLE_SOXR #include "SoxrResampler.hxx" #endif @@ -38,45 +40,130 @@ enum class SelectedResampler { FALLBACK, -#ifdef HAVE_LIBSAMPLERATE +#ifdef ENABLE_LIBSAMPLERATE LIBSAMPLERATE, #endif -#ifdef HAVE_SOXR +#ifdef ENABLE_SOXR SOXR, #endif }; static SelectedResampler selected_resampler = SelectedResampler::FALLBACK; -bool -pcm_resampler_global_init(Error &error) +static const ConfigBlock * +MakeResamplerDefaultConfig(ConfigBlock &block) { - const char *converter = - config_get_string(CONF_SAMPLERATE_CONVERTER, ""); + assert(block.IsEmpty()); + +#ifdef ENABLE_LIBSAMPLERATE + block.AddBlockParam("plugin", "libsamplerate"); +#elif defined(ENABLE_SOXR) + block.AddBlockParam("plugin", "soxr"); +#else + block.AddBlockParam("plugin", "internal"); +#endif + return █ +} - if (strcmp(converter, "internal") == 0) - return true; +/** + * Convert the old "samplerate_converter" setting to a new-style + * "resampler" block. + */ +static const ConfigBlock * +MigrateResamplerConfig(const config_param ¶m, ConfigBlock &block) +{ + assert(block.IsEmpty()); -#ifdef HAVE_SOXR - if (memcmp(converter, "soxr", 4) == 0) { - selected_resampler = SelectedResampler::SOXR; - return pcm_resample_soxr_global_init(converter, error); + block.line = param.line; + + const char *converter = param.value.c_str(); + if (*converter == 0 || strcmp(converter, "internal") == 0) { + block.AddBlockParam("plugin", "internal"); + return █ + } + +#ifdef ENABLE_SOXR + if (strcmp(converter, "soxr") == 0) { + block.AddBlockParam("plugin", "soxr"); + return █ } -#endif -#ifdef HAVE_LIBSAMPLERATE - selected_resampler = SelectedResampler::LIBSAMPLERATE; - return pcm_resample_lsr_global_init(converter, error); + if (memcmp(converter, "soxr ", 5) == 0) { + block.AddBlockParam("plugin", "soxr"); + block.AddBlockParam("quality", converter + 5); + return █ + } #endif - if (*converter == 0) - return true; + block.AddBlockParam("plugin", "libsamplerate"); + block.AddBlockParam("type", converter); + return █ +} + +static const ConfigBlock * +MigrateResamplerConfig(const config_param *param, ConfigBlock &buffer) +{ + assert(buffer.IsEmpty()); - error.Format(config_domain, - "The samplerate_converter '%s' is not available", - converter); - return false; + return param == nullptr + ? MakeResamplerDefaultConfig(buffer) + : MigrateResamplerConfig(*param, buffer); +} + +static const ConfigBlock * +GetResamplerConfig(ConfigBlock &buffer, Error &error) +{ + const auto *old_param = + config_get_param(ConfigOption::SAMPLERATE_CONVERTER); + const auto *block = config_get_block(ConfigBlockOption::RESAMPLER); + if (block == nullptr) + return MigrateResamplerConfig(old_param, buffer); + + if (old_param != nullptr) { + error.Format(config_domain, + "Cannot use both 'resampler' (line %d) and 'samplerate_converter' (line %d)", + block->line, old_param->line); + return nullptr; + } + + return block; +} + +bool +pcm_resampler_global_init(Error &error) +{ + ConfigBlock buffer; + const auto *block = GetResamplerConfig(buffer, error); + if (block == nullptr) + return false; + + const char *plugin_name = block->GetBlockValue("plugin"); + if (plugin_name == nullptr) { + error.Format(config_domain, + "'plugin' missing in line %d", block->line); + return false; + } + + if (strcmp(plugin_name, "internal") == 0) { + selected_resampler = SelectedResampler::FALLBACK; + return true; +#ifdef ENABLE_SOXR + } else if (strcmp(plugin_name, "soxr") == 0) { + selected_resampler = SelectedResampler::SOXR; + return pcm_resample_soxr_global_init(*block, error); +#endif +#ifdef ENABLE_LIBSAMPLERATE + } else if (strcmp(plugin_name, "libsamplerate") == 0) { + selected_resampler = SelectedResampler::LIBSAMPLERATE; + return pcm_resample_lsr_global_init(*block, error); +#endif + } else { + error.Format(config_domain, + "No such resampler plugin: %s", + plugin_name); + return false; + } } PcmResampler * @@ -86,12 +173,12 @@ pcm_resampler_create() case SelectedResampler::FALLBACK: return new FallbackPcmResampler(); -#ifdef HAVE_LIBSAMPLERATE +#ifdef ENABLE_LIBSAMPLERATE case SelectedResampler::LIBSAMPLERATE: return new LibsampleratePcmResampler(); #endif -#ifdef HAVE_SOXR +#ifdef ENABLE_SOXR case SelectedResampler::SOXR: return new SoxrPcmResampler(); #endif diff --git a/src/pcm/ConfiguredResampler.hxx b/src/pcm/ConfiguredResampler.hxx index 2b14b381e..090f2ae0a 100644 --- a/src/pcm/ConfiguredResampler.hxx +++ b/src/pcm/ConfiguredResampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/Domain.cxx b/src/pcm/Domain.cxx index ecd5c22a4..8673e5a10 100644 --- a/src/pcm/Domain.cxx +++ b/src/pcm/Domain.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/Domain.hxx b/src/pcm/Domain.hxx index 781d5c71b..47d5ef8b9 100644 --- a/src/pcm/Domain.hxx +++ b/src/pcm/Domain.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/FallbackResampler.cxx b/src/pcm/FallbackResampler.cxx index bd3f20d86..74fbc29bd 100644 --- a/src/pcm/FallbackResampler.cxx +++ b/src/pcm/FallbackResampler.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/FallbackResampler.hxx b/src/pcm/FallbackResampler.hxx index 38273f53f..d96b89d4f 100644 --- a/src/pcm/FallbackResampler.hxx +++ b/src/pcm/FallbackResampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/FloatConvert.hxx b/src/pcm/FloatConvert.hxx index 93e867159..47fe8d65a 100644 --- a/src/pcm/FloatConvert.hxx +++ b/src/pcm/FloatConvert.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/FormatConverter.cxx b/src/pcm/FormatConverter.cxx index 8874e1b3c..28e585e70 100644 --- a/src/pcm/FormatConverter.cxx +++ b/src/pcm/FormatConverter.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/FormatConverter.hxx b/src/pcm/FormatConverter.hxx index 3d8b6fb75..a67fcd7d6 100644 --- a/src/pcm/FormatConverter.hxx +++ b/src/pcm/FormatConverter.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/GlueResampler.cxx b/src/pcm/GlueResampler.cxx index 0f5fe0271..3b1b61c3b 100644 --- a/src/pcm/GlueResampler.cxx +++ b/src/pcm/GlueResampler.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/GlueResampler.hxx b/src/pcm/GlueResampler.hxx index aff07823e..7471d39b7 100644 --- a/src/pcm/GlueResampler.hxx +++ b/src/pcm/GlueResampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/LibsamplerateResampler.cxx b/src/pcm/LibsamplerateResampler.cxx index 8b22f1e32..cc6f3d43f 100644 --- a/src/pcm/LibsamplerateResampler.cxx +++ b/src/pcm/LibsamplerateResampler.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "config.h" #include "LibsamplerateResampler.hxx" +#include "config/Block.hxx" #include "util/ASCII.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" @@ -63,8 +64,9 @@ lsr_parse_converter(const char *s) } bool -pcm_resample_lsr_global_init(const char *converter, Error &error) +pcm_resample_lsr_global_init(const ConfigBlock &block, Error &error) { + const char *converter = block.GetBlockValue("type", "2"); if (!lsr_parse_converter(converter)) { error.Format(libsamplerate_domain, "unknown samplerate converter '%s'", converter); diff --git a/src/pcm/LibsamplerateResampler.hxx b/src/pcm/LibsamplerateResampler.hxx index 4f4e645e6..f19dc19eb 100644 --- a/src/pcm/LibsamplerateResampler.hxx +++ b/src/pcm/LibsamplerateResampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -27,6 +27,8 @@ #include <samplerate.h> +struct ConfigBlock; + /** * A resampler using libsamplerate. */ @@ -51,6 +53,6 @@ private: }; bool -pcm_resample_lsr_global_init(const char *converter, Error &error); +pcm_resample_lsr_global_init(const ConfigBlock &block, Error &error); #endif diff --git a/src/pcm/Neon.hxx b/src/pcm/Neon.hxx index 7109778ab..a2a92eea6 100644 --- a/src/pcm/Neon.hxx +++ b/src/pcm/Neon.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmBuffer.cxx b/src/pcm/PcmBuffer.cxx index 7bba2de47..e767872bd 100644 --- a/src/pcm/PcmBuffer.cxx +++ b/src/pcm/PcmBuffer.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmBuffer.hxx b/src/pcm/PcmBuffer.hxx index f56a85985..eafdc649e 100644 --- a/src/pcm/PcmBuffer.hxx +++ b/src/pcm/PcmBuffer.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmChannels.cxx b/src/pcm/PcmChannels.cxx index 276f31045..5cf730e6c 100644 --- a/src/pcm/PcmChannels.cxx +++ b/src/pcm/PcmChannels.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmChannels.hxx b/src/pcm/PcmChannels.hxx index 6ad093c3b..eb6aa4828 100644 --- a/src/pcm/PcmChannels.hxx +++ b/src/pcm/PcmChannels.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 438566759..ccc45c246 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx index 26ab02923..1f5e41bc6 100644 --- a/src/pcm/PcmConvert.hxx +++ b/src/pcm/PcmConvert.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -74,11 +74,8 @@ public: /** * Converts PCM data between two audio formats. * - * @param src_format the source audio format * @param src the source PCM buffer - * @param dest_format the requested destination audio format - * @param error_r location to store the error occurring, or nullptr to - * ignore errors + * @param error location to store the error occurring * @return the destination buffer, or nullptr on error */ ConstBuffer<void> Convert(ConstBuffer<void> src, Error &error); diff --git a/src/pcm/PcmDither.cxx b/src/pcm/PcmDither.cxx index 7b2a9e900..25252458b 100644 --- a/src/pcm/PcmDither.cxx +++ b/src/pcm/PcmDither.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmDither.hxx b/src/pcm/PcmDither.hxx index 54b0f7315..491f22601 100644 --- a/src/pcm/PcmDither.hxx +++ b/src/pcm/PcmDither.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -36,9 +36,9 @@ public: * Shift the given sample by #SBITS-#DBITS to the right, and * apply dithering. * - * @param ST the input sample type - * @param SBITS the input bit width - * @param DBITS the output bit width + * @tparam ST the input sample type + * @tparam SBITS the input bit width + * @tparam DBITS the output bit width * @param sample the input sample value */ template<typename ST, unsigned SBITS, unsigned DBITS> diff --git a/src/pcm/PcmDop.cxx b/src/pcm/PcmDop.cxx index b2096d9e4..e60c6d14d 100644 --- a/src/pcm/PcmDop.cxx +++ b/src/pcm/PcmDop.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmDop.hxx b/src/pcm/PcmDop.hxx index 03161c456..82c045911 100644 --- a/src/pcm/PcmDop.hxx +++ b/src/pcm/PcmDop.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmDsd.cxx b/src/pcm/PcmDsd.cxx index 53d26d480..f27c63f33 100644 --- a/src/pcm/PcmDsd.cxx +++ b/src/pcm/PcmDsd.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmDsd.hxx b/src/pcm/PcmDsd.hxx index e3e3a3cb1..89654ebe6 100644 --- a/src/pcm/PcmDsd.hxx +++ b/src/pcm/PcmDsd.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmExport.cxx b/src/pcm/PcmExport.cxx index ef099ba71..af2eb7d9f 100644 --- a/src/pcm/PcmExport.cxx +++ b/src/pcm/PcmExport.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmExport.hxx b/src/pcm/PcmExport.hxx index b99a35835..7265ca07d 100644 --- a/src/pcm/PcmExport.hxx +++ b/src/pcm/PcmExport.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -86,7 +86,7 @@ struct PcmExport { uint8_t reverse_endian; /** - * Open the #pcm_export_state object. + * Open the object. * * There is no "close" method. This function may be called multiple * times to reuse the object. diff --git a/src/pcm/PcmFormat.cxx b/src/pcm/PcmFormat.cxx index 4cabc05a0..a70a38982 100644 --- a/src/pcm/PcmFormat.cxx +++ b/src/pcm/PcmFormat.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmFormat.hxx b/src/pcm/PcmFormat.hxx index da182e771..9d15011a7 100644 --- a/src/pcm/PcmFormat.hxx +++ b/src/pcm/PcmFormat.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -33,9 +33,8 @@ class PcmDither; * Converts PCM samples to 16 bit. If the source format is 24 bit, * then dithering is applied. * - * @param buffer a PcmBuffer object - * @param dither a pcm_dither object for 24-to-16 conversion - * @param bits the number of in the source buffer + * @param buffer a #PcmBuffer object + * @param dither a #PcmDither object for 24-to-16 conversion * @param src the source PCM buffer * @return the destination buffer */ @@ -47,8 +46,7 @@ pcm_convert_to_16(PcmBuffer &buffer, PcmDither &dither, /** * Converts PCM samples to 24 bit (32 bit alignment). * - * @param buffer a PcmBuffer object - * @param bits the number of in the source buffer + * @param buffer a #PcmBuffer object * @param src the source PCM buffer * @return the destination buffer */ @@ -60,8 +58,7 @@ pcm_convert_to_24(PcmBuffer &buffer, /** * Converts PCM samples to 32 bit. * - * @param buffer a PcmBuffer object - * @param bits the number of in the source buffer + * @param buffer a #PcmBuffer object * @param src the source PCM buffer * @return the destination buffer */ @@ -73,11 +70,8 @@ pcm_convert_to_32(PcmBuffer &buffer, /** * Converts PCM samples to 32 bit floating point. * - * @param buffer a PcmBuffer object - * @param bits the number of in the source buffer + * @param buffer a #PcmBuffer object * @param src the source PCM buffer - * @param src_size the size of #src in bytes - * @param dest_size_r returns the number of bytes of the destination buffer * @return the destination buffer */ gcc_pure diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx index d21b5f04b..b67a4ec24 100644 --- a/src/pcm/PcmMix.cxx +++ b/src/pcm/PcmMix.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmMix.hxx b/src/pcm/PcmMix.hxx index 4e22a33f1..a906dc402 100644 --- a/src/pcm/PcmMix.hxx +++ b/src/pcm/PcmMix.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmPack.cxx b/src/pcm/PcmPack.cxx index 7a3379ad0..ef4406b82 100644 --- a/src/pcm/PcmPack.cxx +++ b/src/pcm/PcmPack.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmPack.hxx b/src/pcm/PcmPack.hxx index 271a3cd25..e05601986 100644 --- a/src/pcm/PcmPack.hxx +++ b/src/pcm/PcmPack.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -35,7 +35,6 @@ * * @param dest the destination buffer (array of triples) * @param src the source buffer - * @param num_samples the number of samples to convert */ void pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end); @@ -46,7 +45,6 @@ pcm_pack_24(uint8_t *dest, const int32_t *src, const int32_t *src_end); * * @param dest the destination buffer * @param src the source buffer (array of triples) - * @param num_samples the number of samples to convert */ void pcm_unpack_24(int32_t *dest, const uint8_t *src, const uint8_t *src_end); diff --git a/src/pcm/PcmPrng.hxx b/src/pcm/PcmPrng.hxx index 5233caba6..38b48de7f 100644 --- a/src/pcm/PcmPrng.hxx +++ b/src/pcm/PcmPrng.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/PcmUtils.hxx b/src/pcm/PcmUtils.hxx index 23870a729..9ea9cf3b3 100644 --- a/src/pcm/PcmUtils.hxx +++ b/src/pcm/PcmUtils.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/Resampler.hxx b/src/pcm/Resampler.hxx index 9b6ccbbc7..75f91b6ab 100644 --- a/src/pcm/Resampler.hxx +++ b/src/pcm/Resampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -58,10 +58,7 @@ public: * Resamples a block of PCM data. * * @param src the input buffer - * @param src_size the size of #src_buffer in bytes - * @param dest_size_r the size of the returned buffer - * @param error location to store the error occurring, or nullptr - * to ignore errors. + * @param error location to store the error occurring * @return the destination buffer on success (will be * invalidated by filter_close() or filter_filter()), nullptr on * error diff --git a/src/pcm/ShiftConvert.hxx b/src/pcm/ShiftConvert.hxx index 92f96b7ba..e678abc56 100644 --- a/src/pcm/ShiftConvert.hxx +++ b/src/pcm/ShiftConvert.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/SoxrResampler.cxx b/src/pcm/SoxrResampler.cxx index b9d6fc099..f335e92e6 100644 --- a/src/pcm/SoxrResampler.cxx +++ b/src/pcm/SoxrResampler.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -20,6 +20,7 @@ #include "config.h" #include "SoxrResampler.hxx" #include "AudioFormat.hxx" +#include "config/Block.hxx" #include "util/ASCII.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" @@ -32,68 +33,76 @@ static constexpr Domain soxr_domain("soxr"); -static unsigned long soxr_quality_recipe = SOXR_HQ; +static constexpr unsigned long SOXR_DEFAULT_RECIPE = SOXR_HQ; +/** + * Special value for "invalid argument". + */ +static constexpr unsigned long SOXR_INVALID_RECIPE = -1; + +static soxr_quality_spec_t soxr_quality; +static soxr_runtime_spec_t soxr_runtime; + +static constexpr struct { + unsigned long recipe; + const char *name; +} soxr_quality_table[] = { + { SOXR_VHQ, "very high" }, + { SOXR_HQ, "high" }, + { SOXR_MQ, "medium" }, + { SOXR_LQ, "low" }, + { SOXR_QQ, "quick" }, + { SOXR_INVALID_RECIPE, nullptr } +}; + +gcc_const static const char * soxr_quality_name(unsigned long recipe) { - switch (recipe) { - case SOXR_VHQ: - return "Very High Quality"; - case SOXR_HQ: - return "High Quality"; - case SOXR_MQ: - return "Medium Quality"; - case SOXR_LQ: - return "Low Quality"; - case SOXR_QQ: - return "Quick"; - } + for (const auto *i = soxr_quality_table;; ++i) { + assert(i->name != nullptr); - gcc_unreachable(); + if (i->recipe == recipe) + return i->name; + } } -static bool -soxr_parse_converter(const char *converter) +gcc_pure +static unsigned long +soxr_parse_quality(const char *quality) { - assert(converter != nullptr); - - assert(memcmp(converter, "soxr", 4) == 0); - if (converter[4] == '\0') - return true; - if (converter[4] != ' ') - return false; + if (quality == nullptr) + return SOXR_DEFAULT_RECIPE; - // converter example is "soxr very high", we want the "very high" part - const char *quality = converter + 5; - if (strcmp(quality, "very high") == 0) - soxr_quality_recipe = SOXR_VHQ; - else if (strcmp(quality, "high") == 0) - soxr_quality_recipe = SOXR_HQ; - else if (strcmp(quality, "medium") == 0) - soxr_quality_recipe = SOXR_MQ; - else if (strcmp(quality, "low") == 0) - soxr_quality_recipe = SOXR_LQ; - else if (strcmp(quality, "quick") == 0) - soxr_quality_recipe = SOXR_QQ; - else - return false; + for (const auto *i = soxr_quality_table; i->name != nullptr; ++i) + if (strcmp(i->name, quality) == 0) + return i->recipe; - return true; + return SOXR_INVALID_RECIPE; } bool -pcm_resample_soxr_global_init(const char *converter, Error &error) +pcm_resample_soxr_global_init(const ConfigBlock &block, Error &error) { - if (!soxr_parse_converter(converter)) { + const char *quality_string = block.GetBlockValue("quality"); + unsigned long recipe = soxr_parse_quality(quality_string); + if (recipe == SOXR_INVALID_RECIPE) { + assert(quality_string != nullptr); + error.Format(soxr_domain, - "unknown samplerate converter '%s'", converter); + "unknown quality setting '%s' in line %d", + quality_string, block.line); return false; } + soxr_quality = soxr_quality_spec(recipe, 0); + FormatDebug(soxr_domain, "soxr converter '%s'", - soxr_quality_name(soxr_quality_recipe)); + soxr_quality_name(recipe)); + + const unsigned n_threads = block.GetBlockValue("threads", 1); + soxr_runtime = soxr_runtime_spec(n_threads); return true; } @@ -106,10 +115,9 @@ SoxrPcmResampler::Open(AudioFormat &af, unsigned new_sample_rate, assert(audio_valid_sample_rate(new_sample_rate)); soxr_error_t e; - soxr_quality_spec_t quality = soxr_quality_spec(soxr_quality_recipe, 0); soxr = soxr_create(af.sample_rate, new_sample_rate, af.channels, &e, - nullptr, &quality, nullptr); + nullptr, &soxr_quality, &soxr_runtime); if (soxr == nullptr) { error.Format(soxr_domain, "soxr initialization has failed: %s", e); diff --git a/src/pcm/SoxrResampler.hxx b/src/pcm/SoxrResampler.hxx index e4cba4a64..6c31ca45a 100644 --- a/src/pcm/SoxrResampler.hxx +++ b/src/pcm/SoxrResampler.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -25,6 +25,7 @@ #include "Compiler.h" struct AudioFormat; +struct ConfigBlock; /** * A resampler using soxr. @@ -46,6 +47,6 @@ public: }; bool -pcm_resample_soxr_global_init(const char *converter, Error &error); +pcm_resample_soxr_global_init(const ConfigBlock &block, Error &error); #endif diff --git a/src/pcm/Traits.hxx b/src/pcm/Traits.hxx index 97259ac73..3d124ea2f 100644 --- a/src/pcm/Traits.hxx +++ b/src/pcm/Traits.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx index b12d8fd41..86dd8bd71 100644 --- a/src/pcm/Volume.cxx +++ b/src/pcm/Volume.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/pcm/Volume.hxx b/src/pcm/Volume.hxx index a156fc72e..5d51343b3 100644 --- a/src/pcm/Volume.hxx +++ b/src/pcm/Volume.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify |