aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--src/filter/volume_filter_plugin.c42
-rw-r--r--src/filter/volume_filter_plugin.h31
-rw-r--r--test/run_filter.c6
4 files changed, 68 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index 6f0664d81..92ddcfdf6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,6 +45,7 @@ mpd_headers = \
src/filter_internal.h \
src/filter_plugin.h \
src/filter_registry.h \
+ src/filter/volume_filter_plugin.h \
src/buffer2array.h \
src/command.h \
src/idle.h \
diff --git a/src/filter/volume_filter_plugin.c b/src/filter/volume_filter_plugin.c
index 0a5e13a49..efad3362f 100644
--- a/src/filter/volume_filter_plugin.c
+++ b/src/filter/volume_filter_plugin.c
@@ -17,13 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "filter/volume_filter_plugin.h"
#include "filter_plugin.h"
#include "filter_internal.h"
#include "filter_registry.h"
#include "conf.h"
#include "pcm_buffer.h"
#include "pcm_volume.h"
-#include "volume.h"
#include "audio_format.h"
#include <assert.h>
@@ -32,6 +32,11 @@
struct volume_filter {
struct filter filter;
+ /**
+ * The current volume, from 0 to #PCM_VOLUME_1.
+ */
+ unsigned volume;
+
struct audio_format audio_format;
struct pcm_buffer buffer;
@@ -50,6 +55,8 @@ volume_filter_init(G_GNUC_UNUSED const struct config_param *param,
struct volume_filter *filter = g_new(struct volume_filter, 1);
filter_init(&filter->filter, &volume_filter_plugin);
+ filter->volume = PCM_VOLUME_1;
+
return &filter->filter;
}
@@ -92,12 +99,10 @@ volume_filter_filter(struct filter *_filter, const void *src, size_t src_size,
size_t *dest_size_r, GError **error_r)
{
struct volume_filter *filter = (struct volume_filter *)_filter;
- int volume;
bool success;
void *dest;
- volume = volume_level_get(); /* XXX don't use volume_level_get() */
- if (volume < 0 || volume >= PCM_VOLUME_1) {
+ if (filter->volume >= PCM_VOLUME_1) {
/* optimized special case: 100% volume = no-op */
*dest_size_r = src_size;
return src;
@@ -106,7 +111,7 @@ volume_filter_filter(struct filter *_filter, const void *src, size_t src_size,
dest = pcm_buffer_get(&filter->buffer, src_size);
*dest_size_r = src_size;
- if (volume == 0) {
+ if (filter->volume <= 0) {
/* optimized special case: 0% volume = memset(0) */
/* XXX is this valid for all sample formats? What
about floating point? */
@@ -116,7 +121,8 @@ volume_filter_filter(struct filter *_filter, const void *src, size_t src_size,
memcpy(dest, src, src_size);
- success = pcm_volume(dest, src_size, &filter->audio_format, volume);
+ success = pcm_volume(dest, src_size, &filter->audio_format,
+ filter->volume);
if (!success) {
g_set_error(error_r, volume_quark(), 0,
"pcm_volume() has failed");
@@ -134,3 +140,27 @@ const struct filter_plugin volume_filter_plugin = {
.close = volume_filter_close,
.filter = volume_filter_filter,
};
+
+unsigned
+volume_filter_get(const struct filter *_filter)
+{
+ const struct volume_filter *filter =
+ (const struct volume_filter *)_filter;
+
+ assert(filter->filter.plugin == &volume_filter_plugin);
+ assert(filter->volume <= PCM_VOLUME_1);
+
+ return filter->volume;
+}
+
+void
+volume_filter_set(struct filter *_filter, unsigned volume)
+{
+ struct volume_filter *filter = (struct volume_filter *)_filter;
+
+ assert(filter->filter.plugin == &volume_filter_plugin);
+ assert(volume <= PCM_VOLUME_1);
+
+ filter->volume = volume;
+}
+
diff --git a/src/filter/volume_filter_plugin.h b/src/filter/volume_filter_plugin.h
new file mode 100644
index 000000000..c064741a2
--- /dev/null
+++ b/src/filter/volume_filter_plugin.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2003-2009 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.
+ */
+
+#ifndef VOLUME_FILTER_PLUGIN_H
+#define VOLUME_FILTER_PLUGIN_H
+
+struct filter;
+
+unsigned
+volume_filter_get(const struct filter *filter);
+
+void
+volume_filter_set(struct filter *filter, unsigned volume);
+
+#endif
diff --git a/test/run_filter.c b/test/run_filter.c
index 366ebb43a..0d97207e1 100644
--- a/test/run_filter.c
+++ b/test/run_filter.c
@@ -21,7 +21,6 @@
#include "audio_parser.h"
#include "audio_format.h"
#include "filter_plugin.h"
-#include "volume.h"
#include "pcm_volume.h"
#include <glib.h>
@@ -31,11 +30,6 @@
#include <errno.h>
#include <unistd.h>
-int volume_level_get(void)
-{
- return PCM_VOLUME_1;
-}
-
static const struct config_param *
find_named_config_block(const char *block, const char *name)
{