filter/ReplayGain: add ReplayGainConfig copy
Remove dependency on ReplayGain global variables.
This commit is contained in:
parent
3b867462a3
commit
3000b9dcde
@ -1979,7 +1979,6 @@ test_run_filter_LDADD = \
|
||||
libsystem.a \
|
||||
libutil.a
|
||||
test_run_filter_SOURCES = test/run_filter.cxx \
|
||||
test/FakeReplayGainGlobal.cxx \
|
||||
src/Log.cxx src/LogBackend.cxx \
|
||||
src/filter/FilterPlugin.cxx src/filter/FilterRegistry.cxx
|
||||
|
||||
@ -2074,7 +2073,6 @@ test_run_output_LDADD = $(MPD_LIBS) \
|
||||
libthread.a \
|
||||
libutil.a
|
||||
test_run_output_SOURCES = test/run_output.cxx \
|
||||
test/FakeReplayGainGlobal.cxx \
|
||||
test/ScopeIOThread.hxx \
|
||||
src/Log.cxx src/LogBackend.cxx \
|
||||
src/IOThread.cxx \
|
||||
|
@ -477,10 +477,11 @@ try {
|
||||
|
||||
command_init();
|
||||
initAudioConfig();
|
||||
replay_gain_global_init();
|
||||
instance->partition->outputs.Configure(instance->event_loop,
|
||||
replay_gain_config,
|
||||
instance->partition->pc);
|
||||
client_manager_init();
|
||||
replay_gain_global_init();
|
||||
input_stream_global_init();
|
||||
playlist_list_global_init();
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "ReplayGainInfo.hxx"
|
||||
#include "ReplayGainGlobal.hxx"
|
||||
#include "ReplayGainConfig.hxx"
|
||||
#include "mixer/MixerControl.hxx"
|
||||
#include "pcm/Volume.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
@ -36,6 +36,8 @@
|
||||
static constexpr Domain replay_gain_domain("replay_gain");
|
||||
|
||||
class ReplayGainFilter final : public Filter {
|
||||
const ReplayGainConfig config;
|
||||
|
||||
/**
|
||||
* If set, then this hardware mixer is used for applying
|
||||
* replay gain, instead of the software volume library.
|
||||
@ -67,9 +69,11 @@ class ReplayGainFilter final : public Filter {
|
||||
PcmVolume pv;
|
||||
|
||||
public:
|
||||
ReplayGainFilter(const AudioFormat &audio_format,
|
||||
ReplayGainFilter(const ReplayGainConfig &_config,
|
||||
const AudioFormat &audio_format,
|
||||
Mixer *_mixer, unsigned _base)
|
||||
:Filter(audio_format),
|
||||
config(_config),
|
||||
mixer(_mixer), base(_base) {
|
||||
info.Clear();
|
||||
|
||||
@ -108,6 +112,8 @@ public:
|
||||
};
|
||||
|
||||
class PreparedReplayGainFilter final : public PreparedFilter {
|
||||
const ReplayGainConfig config;
|
||||
|
||||
/**
|
||||
* If set, then this hardware mixer is used for applying
|
||||
* replay gain, instead of the software volume library.
|
||||
@ -121,6 +127,9 @@ class PreparedReplayGainFilter final : public PreparedFilter {
|
||||
unsigned base;
|
||||
|
||||
public:
|
||||
explicit PreparedReplayGainFilter(const ReplayGainConfig _config)
|
||||
:config(_config) {}
|
||||
|
||||
void SetMixer(Mixer *_mixer, unsigned _base) {
|
||||
assert(_mixer == nullptr || (_base > 0 && _base <= 100));
|
||||
|
||||
@ -138,7 +147,7 @@ ReplayGainFilter::Update()
|
||||
unsigned volume = PCM_VOLUME_1;
|
||||
if (mode != ReplayGainMode::OFF) {
|
||||
const auto &tuple = info.Get(mode);
|
||||
float scale = tuple.CalculateScale(replay_gain_config);
|
||||
float scale = tuple.CalculateScale(config);
|
||||
FormatDebug(replay_gain_domain,
|
||||
"scale=%f\n", (double)scale);
|
||||
|
||||
@ -162,15 +171,15 @@ ReplayGainFilter::Update()
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
NewReplayGainFilter()
|
||||
NewReplayGainFilter(const ReplayGainConfig &config)
|
||||
{
|
||||
return new PreparedReplayGainFilter();
|
||||
return new PreparedReplayGainFilter(config);
|
||||
}
|
||||
|
||||
Filter *
|
||||
PreparedReplayGainFilter::Open(AudioFormat &af)
|
||||
{
|
||||
return new ReplayGainFilter(af, mixer, base);
|
||||
return new ReplayGainFilter(config, af, mixer, base);
|
||||
}
|
||||
|
||||
ConstBuffer<void>
|
||||
|
@ -25,10 +25,11 @@
|
||||
class Filter;
|
||||
class PreparedFilter;
|
||||
class Mixer;
|
||||
struct ReplayGainConfig;
|
||||
struct ReplayGainInfo;
|
||||
|
||||
PreparedFilter *
|
||||
NewReplayGainFilter();
|
||||
NewReplayGainFilter(const ReplayGainConfig &config);
|
||||
|
||||
/**
|
||||
* Enables or disables the hardware mixer for applying replay gain.
|
||||
|
@ -205,7 +205,9 @@ AudioOutput::Configure(const ConfigBlock &block)
|
||||
}
|
||||
|
||||
static void
|
||||
audio_output_setup(EventLoop &event_loop, AudioOutput &ao,
|
||||
audio_output_setup(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
AudioOutput &ao,
|
||||
MixerListener &mixer_listener,
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
@ -216,12 +218,14 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao,
|
||||
block.GetBlockValue("replay_gain_handler", "software");
|
||||
|
||||
if (strcmp(replay_gain_handler, "none") != 0) {
|
||||
ao.prepared_replay_gain_filter = NewReplayGainFilter();
|
||||
ao.prepared_replay_gain_filter =
|
||||
NewReplayGainFilter(replay_gain_config);
|
||||
assert(ao.prepared_replay_gain_filter != nullptr);
|
||||
|
||||
ao.replay_gain_serial = 0;
|
||||
|
||||
ao.prepared_other_replay_gain_filter = NewReplayGainFilter();
|
||||
ao.prepared_other_replay_gain_filter =
|
||||
NewReplayGainFilter(replay_gain_config);
|
||||
assert(ao.prepared_other_replay_gain_filter != nullptr);
|
||||
|
||||
ao.other_replay_gain_serial = 0;
|
||||
@ -267,7 +271,9 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao,
|
||||
}
|
||||
|
||||
AudioOutput *
|
||||
audio_output_new(EventLoop &event_loop, const ConfigBlock &block,
|
||||
audio_output_new(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
const ConfigBlock &block,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc)
|
||||
{
|
||||
@ -298,7 +304,8 @@ audio_output_new(EventLoop &event_loop, const ConfigBlock &block,
|
||||
assert(ao != nullptr);
|
||||
|
||||
try {
|
||||
audio_output_setup(event_loop, *ao, mixer_listener, block);
|
||||
audio_output_setup(event_loop, replay_gain_config,
|
||||
*ao, mixer_listener, block);
|
||||
} catch (...) {
|
||||
ao_plugin_finish(ao);
|
||||
throw;
|
||||
|
@ -40,6 +40,7 @@ struct MusicChunk;
|
||||
struct ConfigBlock;
|
||||
struct PlayerControl;
|
||||
struct AudioOutputPlugin;
|
||||
struct ReplayGainConfig;
|
||||
|
||||
struct AudioOutput {
|
||||
enum class Command {
|
||||
@ -464,7 +465,9 @@ extern struct notify audio_output_client_notify;
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
AudioOutput *
|
||||
audio_output_new(EventLoop &event_loop, const ConfigBlock &block,
|
||||
audio_output_new(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
const ConfigBlock &block,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc);
|
||||
|
||||
|
@ -50,10 +50,12 @@ MultipleOutputs::~MultipleOutputs()
|
||||
}
|
||||
|
||||
static AudioOutput *
|
||||
LoadOutput(EventLoop &event_loop, MixerListener &mixer_listener,
|
||||
LoadOutput(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc, const ConfigBlock &block)
|
||||
try {
|
||||
return audio_output_new(event_loop, block,
|
||||
return audio_output_new(event_loop, replay_gain_config, block,
|
||||
mixer_listener,
|
||||
pc);
|
||||
} catch (const std::runtime_error &e) {
|
||||
@ -65,11 +67,14 @@ try {
|
||||
}
|
||||
|
||||
void
|
||||
MultipleOutputs::Configure(EventLoop &event_loop, PlayerControl &pc)
|
||||
MultipleOutputs::Configure(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
PlayerControl &pc)
|
||||
{
|
||||
for (const auto *param = config_get_block(ConfigBlockOption::AUDIO_OUTPUT);
|
||||
param != nullptr; param = param->next) {
|
||||
auto output = LoadOutput(event_loop, mixer_listener,
|
||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||
mixer_listener,
|
||||
pc, *param);
|
||||
if (FindByName(output->name) != nullptr)
|
||||
throw FormatRuntimeError("output devices with identical "
|
||||
@ -81,7 +86,8 @@ MultipleOutputs::Configure(EventLoop &event_loop, PlayerControl &pc)
|
||||
if (outputs.empty()) {
|
||||
/* auto-detect device */
|
||||
const ConfigBlock empty;
|
||||
auto output = LoadOutput(event_loop, mixer_listener,
|
||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||
mixer_listener,
|
||||
pc, empty);
|
||||
outputs.push_back(output);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class MixerListener;
|
||||
struct MusicChunk;
|
||||
struct PlayerControl;
|
||||
struct AudioOutput;
|
||||
struct ReplayGainConfig;
|
||||
|
||||
class MultipleOutputs {
|
||||
MixerListener &mixer_listener;
|
||||
@ -75,7 +76,9 @@ public:
|
||||
MultipleOutputs(MixerListener &_mixer_listener);
|
||||
~MultipleOutputs();
|
||||
|
||||
void Configure(EventLoop &event_loop, PlayerControl &pc);
|
||||
void Configure(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
PlayerControl &pc);
|
||||
|
||||
/**
|
||||
* Returns the total number of audio output devices, including
|
||||
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2016 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 "config.h"
|
||||
#include "ReplayGainGlobal.hxx"
|
||||
#include "ReplayGainConfig.hxx"
|
||||
|
||||
ReplayGainConfig replay_gain_config;
|
@ -29,6 +29,7 @@
|
||||
#include "ScopeIOThread.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "AudioParser.hxx"
|
||||
#include "ReplayGainConfig.hxx"
|
||||
#include "pcm/PcmConvert.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "player/Control.hxx"
|
||||
@ -71,7 +72,7 @@ load_audio_output(EventLoop &event_loop, const char *name)
|
||||
*(MultipleOutputs *)nullptr,
|
||||
32, 4);
|
||||
|
||||
return audio_output_new(event_loop, *param,
|
||||
return audio_output_new(event_loop, ReplayGainConfig(), *param,
|
||||
*(MixerListener *)nullptr,
|
||||
dummy_player_control);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user