2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "SoftwareMixerPlugin.hxx"
22
#include "MixerInternal.hxx"
23
#include "FilterPlugin.hxx"
24
#include "FilterRegistry.hxx"
25
#include "FilterInternal.hxx"
26
#include "filter/VolumeFilterPlugin.hxx"
27
#include "pcm/PcmVolume.hxx"
28
#include "ConfigData.hxx"
29
#include "util/Error.hxx"
38
return filter_new(&volume_filter_plugin, config_param(), error);
41
struct SoftwareMixer final : public Mixer {
45
* If this is true, then this object "owns" the #Filter
46
* instance (see above). It will be set to false by
47
* software_mixer_get_filter(); after that, the caller will be
48
* responsible for the #Filter.
55
:Mixer(software_mixer_plugin),
56
filter(CreateVolumeFilter()),
60
assert(filter != nullptr);
70
software_mixer_init(gcc_unused void *ao,
71
gcc_unused const config_param ¶m,
72
gcc_unused Error &error)
74
return new SoftwareMixer();
78
software_mixer_finish(Mixer *data)
80
SoftwareMixer *sm = (SoftwareMixer *)data;
86
software_mixer_get_volume(Mixer *mixer, gcc_unused Error &error)
88
SoftwareMixer *sm = (SoftwareMixer *)mixer;
94
software_mixer_set_volume(Mixer *mixer, unsigned volume,
95
gcc_unused Error &error)
97
SoftwareMixer *sm = (SoftwareMixer *)mixer;
99
assert(volume <= 100);
104
volume = PCM_VOLUME_1;
106
volume = pcm_float_to_volume((exp(volume / 25.0) - 1) /
107
(54.5981500331F - 1));
109
volume_filter_set(sm->filter, volume);
113
const struct mixer_plugin software_mixer_plugin = {
115
software_mixer_finish,
118
software_mixer_get_volume,
119
software_mixer_set_volume,
124
software_mixer_get_filter(Mixer *mixer)
126
SoftwareMixer *sm = (SoftwareMixer *)mixer;
127
assert(sm->IsPlugin(software_mixer_plugin));
128
assert(sm->owns_filter);
130
sm->owns_filter = false;