aboutsummaryrefslogtreecommitdiffstats
path: root/src/mixer/plugins/SoftwareMixerPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-06 20:44:33 +0100
committerMax Kellermann <max@duempel.org>2014-02-06 20:52:33 +0100
commitb6df4680df08db7827af56d5adf2a04264f2dcb9 (patch)
tree310e0e9305cdf1e5ef6da56c2f60af15c3774cb6 /src/mixer/plugins/SoftwareMixerPlugin.cxx
parente04090b477a6ec3c18b43250cf2ea37985057455 (diff)
downloadmpd-b6df4680df08db7827af56d5adf2a04264f2dcb9.tar.gz
mpd-b6df4680df08db7827af56d5adf2a04264f2dcb9.tar.xz
mpd-b6df4680df08db7827af56d5adf2a04264f2dcb9.zip
MixerPlugin: convert function pointers to Mixer virtual methods
Diffstat (limited to '')
-rw-r--r--src/mixer/plugins/SoftwareMixerPlugin.cxx80
1 files changed, 39 insertions, 41 deletions
diff --git a/src/mixer/plugins/SoftwareMixerPlugin.cxx b/src/mixer/plugins/SoftwareMixerPlugin.cxx
index ec7aa197b..7dba2ee5e 100644
--- a/src/mixer/plugins/SoftwareMixerPlugin.cxx
+++ b/src/mixer/plugins/SoftwareMixerPlugin.cxx
@@ -38,7 +38,7 @@ CreateVolumeFilter()
IgnoreError());
}
-struct SoftwareMixer final : public Mixer {
+class SoftwareMixer final : public Mixer {
Filter *filter;
/**
@@ -51,6 +51,7 @@ struct SoftwareMixer final : public Mixer {
unsigned volume;
+public:
SoftwareMixer()
:Mixer(software_mixer_plugin),
filter(CreateVolumeFilter()),
@@ -60,10 +61,26 @@ struct SoftwareMixer final : public Mixer {
assert(filter != nullptr);
}
- ~SoftwareMixer() {
+ virtual ~SoftwareMixer() {
if (owns_filter)
delete filter;
}
+
+ Filter *GetFilter();
+
+ /* virtual methods from class Mixer */
+ virtual bool Open(gcc_unused Error &error) override {
+ return true;
+ }
+
+ virtual void Close() override {
+ }
+
+ virtual int GetVolume(gcc_unused Error &error) override {
+ return volume;
+ }
+
+ virtual bool SetVolume(unsigned volume, Error &error) override;
};
static Mixer *
@@ -74,59 +91,40 @@ software_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused void *ao,
return new SoftwareMixer();
}
-static void
-software_mixer_finish(Mixer *data)
+bool
+SoftwareMixer::SetVolume(unsigned new_volume, gcc_unused Error &error)
{
- SoftwareMixer *sm = (SoftwareMixer *)data;
-
- delete sm;
-}
+ assert(new_volume <= 100);
-static int
-software_mixer_get_volume(Mixer *mixer, gcc_unused Error &error)
-{
- SoftwareMixer *sm = (SoftwareMixer *)mixer;
+ if (new_volume >= 100)
+ new_volume = PCM_VOLUME_1;
+ else if (new_volume > 0)
+ new_volume = pcm_float_to_volume((exp(new_volume / 25.0) - 1) /
+ (54.5981500331F - 1));
- return sm->volume;
-}
-
-static bool
-software_mixer_set_volume(Mixer *mixer, unsigned volume,
- gcc_unused Error &error)
-{
- SoftwareMixer *sm = (SoftwareMixer *)mixer;
-
- assert(volume <= 100);
-
- sm->volume = volume;
-
- if (volume >= 100)
- volume = PCM_VOLUME_1;
- else if (volume > 0)
- volume = pcm_float_to_volume((exp(volume / 25.0) - 1) /
- (54.5981500331F - 1));
-
- volume_filter_set(sm->filter, volume);
+ volume = new_volume;
+ volume_filter_set(filter, new_volume);
return true;
}
const MixerPlugin software_mixer_plugin = {
software_mixer_init,
- software_mixer_finish,
- nullptr,
- nullptr,
- software_mixer_get_volume,
- software_mixer_set_volume,
true,
};
+inline Filter *
+SoftwareMixer::GetFilter()
+{
+ assert(owns_filter);
+
+ owns_filter = false;
+ return filter;
+}
+
Filter *
software_mixer_get_filter(Mixer *mixer)
{
SoftwareMixer *sm = (SoftwareMixer *)mixer;
assert(sm->IsPlugin(software_mixer_plugin));
- assert(sm->owns_filter);
-
- sm->owns_filter = false;
- return sm->filter;
+ return sm->GetFilter();
}