filter/volume: don't use volume_level_get()
Added public methods to get and set the current volume.
This commit is contained in:
parent
d4914fc9ef
commit
86e279f886
@ -45,6 +45,7 @@ mpd_headers = \
|
|||||||
src/filter_internal.h \
|
src/filter_internal.h \
|
||||||
src/filter_plugin.h \
|
src/filter_plugin.h \
|
||||||
src/filter_registry.h \
|
src/filter_registry.h \
|
||||||
|
src/filter/volume_filter_plugin.h \
|
||||||
src/buffer2array.h \
|
src/buffer2array.h \
|
||||||
src/command.h \
|
src/command.h \
|
||||||
src/idle.h \
|
src/idle.h \
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "filter/volume_filter_plugin.h"
|
||||||
#include "filter_plugin.h"
|
#include "filter_plugin.h"
|
||||||
#include "filter_internal.h"
|
#include "filter_internal.h"
|
||||||
#include "filter_registry.h"
|
#include "filter_registry.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "pcm_buffer.h"
|
#include "pcm_buffer.h"
|
||||||
#include "pcm_volume.h"
|
#include "pcm_volume.h"
|
||||||
#include "volume.h"
|
|
||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -32,6 +32,11 @@
|
|||||||
struct volume_filter {
|
struct volume_filter {
|
||||||
struct filter filter;
|
struct filter filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current volume, from 0 to #PCM_VOLUME_1.
|
||||||
|
*/
|
||||||
|
unsigned volume;
|
||||||
|
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
|
|
||||||
struct pcm_buffer buffer;
|
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);
|
struct volume_filter *filter = g_new(struct volume_filter, 1);
|
||||||
|
|
||||||
filter_init(&filter->filter, &volume_filter_plugin);
|
filter_init(&filter->filter, &volume_filter_plugin);
|
||||||
|
filter->volume = PCM_VOLUME_1;
|
||||||
|
|
||||||
return &filter->filter;
|
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)
|
size_t *dest_size_r, GError **error_r)
|
||||||
{
|
{
|
||||||
struct volume_filter *filter = (struct volume_filter *)_filter;
|
struct volume_filter *filter = (struct volume_filter *)_filter;
|
||||||
int volume;
|
|
||||||
bool success;
|
bool success;
|
||||||
void *dest;
|
void *dest;
|
||||||
|
|
||||||
volume = volume_level_get(); /* XXX don't use volume_level_get() */
|
if (filter->volume >= PCM_VOLUME_1) {
|
||||||
if (volume < 0 || volume >= PCM_VOLUME_1) {
|
|
||||||
/* optimized special case: 100% volume = no-op */
|
/* optimized special case: 100% volume = no-op */
|
||||||
*dest_size_r = src_size;
|
*dest_size_r = src_size;
|
||||||
return src;
|
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 = pcm_buffer_get(&filter->buffer, src_size);
|
||||||
*dest_size_r = src_size;
|
*dest_size_r = src_size;
|
||||||
|
|
||||||
if (volume == 0) {
|
if (filter->volume <= 0) {
|
||||||
/* optimized special case: 0% volume = memset(0) */
|
/* optimized special case: 0% volume = memset(0) */
|
||||||
/* XXX is this valid for all sample formats? What
|
/* XXX is this valid for all sample formats? What
|
||||||
about floating point? */
|
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);
|
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) {
|
if (!success) {
|
||||||
g_set_error(error_r, volume_quark(), 0,
|
g_set_error(error_r, volume_quark(), 0,
|
||||||
"pcm_volume() has failed");
|
"pcm_volume() has failed");
|
||||||
@ -134,3 +140,27 @@ const struct filter_plugin volume_filter_plugin = {
|
|||||||
.close = volume_filter_close,
|
.close = volume_filter_close,
|
||||||
.filter = volume_filter_filter,
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
31
src/filter/volume_filter_plugin.h
Normal file
31
src/filter/volume_filter_plugin.h
Normal file
@ -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
|
@ -21,7 +21,6 @@
|
|||||||
#include "audio_parser.h"
|
#include "audio_parser.h"
|
||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
#include "filter_plugin.h"
|
#include "filter_plugin.h"
|
||||||
#include "volume.h"
|
|
||||||
#include "pcm_volume.h"
|
#include "pcm_volume.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -31,11 +30,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int volume_level_get(void)
|
|
||||||
{
|
|
||||||
return PCM_VOLUME_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct config_param *
|
static const struct config_param *
|
||||||
find_named_config_block(const char *block, const char *name)
|
find_named_config_block(const char *block, const char *name)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user