~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/mixer/SoftwareMixerPlugin.cxx

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "config.h"
 
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"
 
30
 
 
31
#include <assert.h>
 
32
#include <math.h>
 
33
 
 
34
static Filter *
 
35
CreateVolumeFilter()
 
36
{
 
37
        Error error;
 
38
        return filter_new(&volume_filter_plugin, config_param(), error);
 
39
}
 
40
 
 
41
struct SoftwareMixer final : public Mixer {
 
42
        Filter *filter;
 
43
 
 
44
        /**
 
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.
 
49
         */
 
50
        bool owns_filter;
 
51
 
 
52
        unsigned volume;
 
53
 
 
54
        SoftwareMixer()
 
55
                :Mixer(software_mixer_plugin),
 
56
                 filter(CreateVolumeFilter()),
 
57
                 owns_filter(true),
 
58
                 volume(100)
 
59
        {
 
60
                assert(filter != nullptr);
 
61
        }
 
62
 
 
63
        ~SoftwareMixer() {
 
64
                if (owns_filter)
 
65
                        delete filter;
 
66
        }
 
67
};
 
68
 
 
69
static Mixer *
 
70
software_mixer_init(gcc_unused void *ao,
 
71
                    gcc_unused const config_param &param,
 
72
                    gcc_unused Error &error)
 
73
{
 
74
        return new SoftwareMixer();
 
75
}
 
76
 
 
77
static void
 
78
software_mixer_finish(Mixer *data)
 
79
{
 
80
        SoftwareMixer *sm = (SoftwareMixer *)data;
 
81
 
 
82
        delete sm;
 
83
}
 
84
 
 
85
static int
 
86
software_mixer_get_volume(Mixer *mixer, gcc_unused Error &error)
 
87
{
 
88
        SoftwareMixer *sm = (SoftwareMixer *)mixer;
 
89
 
 
90
        return sm->volume;
 
91
}
 
92
 
 
93
static bool
 
94
software_mixer_set_volume(Mixer *mixer, unsigned volume,
 
95
                          gcc_unused Error &error)
 
96
{
 
97
        SoftwareMixer *sm = (SoftwareMixer *)mixer;
 
98
 
 
99
        assert(volume <= 100);
 
100
 
 
101
        sm->volume = volume;
 
102
 
 
103
        if (volume >= 100)
 
104
                volume = PCM_VOLUME_1;
 
105
        else if (volume > 0)
 
106
                volume = pcm_float_to_volume((exp(volume / 25.0) - 1) /
 
107
                                             (54.5981500331F - 1));
 
108
 
 
109
        volume_filter_set(sm->filter, volume);
 
110
        return true;
 
111
}
 
112
 
 
113
const struct mixer_plugin software_mixer_plugin = {
 
114
        software_mixer_init,
 
115
        software_mixer_finish,
 
116
        nullptr,
 
117
        nullptr,
 
118
        software_mixer_get_volume,
 
119
        software_mixer_set_volume,
 
120
        true,
 
121
};
 
122
 
 
123
Filter *
 
124
software_mixer_get_filter(Mixer *mixer)
 
125
{
 
126
        SoftwareMixer *sm = (SoftwareMixer *)mixer;
 
127
        assert(sm->IsPlugin(software_mixer_plugin));
 
128
        assert(sm->owns_filter);
 
129
 
 
130
        sm->owns_filter = false;
 
131
        return sm->filter;
 
132
}