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