ReplayGain{Config,Global}: move to config/

This commit is contained in:
Max Kellermann
2021-12-03 23:04:39 +01:00
parent 95a155b10d
commit dda521a150
8 changed files with 26 additions and 62 deletions

View File

@@ -25,13 +25,13 @@
#include "util/RuntimeError.hxx"
#include "Log.hxx"
#include "MusicChunk.hxx"
#include "ReplayGainGlobal.hxx"
static constexpr
size_t MIN_BUFFER_SIZE = std::max(CHUNK_SIZE * 32,
64 * KILOBYTE);
PlayerConfig::PlayerConfig(const ConfigData &config)
:replay_gain(config)
{
size_t buffer_size = PlayerConfig::DEFAULT_BUFFER_SIZE;
if (auto *param = config.GetParam(ConfigOption::AUDIO_BUFFER_SIZE)) {
@@ -62,6 +62,4 @@ PlayerConfig::PlayerConfig(const ConfigData &config)
return ParseAudioFormat(s, true);
});
replay_gain = LoadReplayGainConfig(config);
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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 "ReplayGainConfig.hxx"
#include "Data.hxx"
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <stdexcept>
static float
ParsePreamp(const char *s)
{
assert(s != nullptr);
char *endptr;
float f = std::strtof(s, &endptr);
if (endptr == s || *endptr != '\0')
throw std::invalid_argument("Not a numeric value");
if (f < -15.0f || f > 15.0f)
throw std::invalid_argument("Number must be between -15 and 15");
return std::pow(10.0f, f / 20.0f);
}
ReplayGainConfig::ReplayGainConfig(const ConfigData &config)
:preamp(config.With(ConfigOption::REPLAYGAIN_PREAMP, [](const char *s){
return s != nullptr
? ParsePreamp(s)
: 1.0f;
})),
missing_preamp(config.With(ConfigOption::REPLAYGAIN_MISSING_PREAMP, [](const char *s){
return s != nullptr
? ParsePreamp(s)
: 1.0f;
})),
limit(config.GetBool(ConfigOption::REPLAYGAIN_LIMIT,
ReplayGainConfig::DEFAULT_LIMIT))
{
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#pragma once
struct ConfigData;
struct ReplayGainConfig {
static constexpr bool DEFAULT_LIMIT = true;
float preamp = 1.0;
float missing_preamp = 1.0;
bool limit = DEFAULT_LIMIT;
ReplayGainConfig() = default;
explicit ReplayGainConfig(const ConfigData &config);
};