aboutsummaryrefslogtreecommitdiffstats
path: root/src/filter/VolumeFilterPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-22 23:26:52 +0100
committerMax Kellermann <max@duempel.org>2013-12-23 10:58:37 +0100
commit8edde7a4b3d652d0ac6ac3770369ddababe310a3 (patch)
tree3f0f59fd22e20853eed3e0ecee65a75fcef87155 /src/filter/VolumeFilterPlugin.cxx
parentd11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b (diff)
downloadmpd-8edde7a4b3d652d0ac6ac3770369ddababe310a3.tar.gz
mpd-8edde7a4b3d652d0ac6ac3770369ddababe310a3.tar.xz
mpd-8edde7a4b3d652d0ac6ac3770369ddababe310a3.zip
pcm/Volume: convert to class
Prepare for adding state.
Diffstat (limited to 'src/filter/VolumeFilterPlugin.cxx')
-rw-r--r--src/filter/VolumeFilterPlugin.cxx63
1 files changed, 13 insertions, 50 deletions
diff --git a/src/filter/VolumeFilterPlugin.cxx b/src/filter/VolumeFilterPlugin.cxx
index 2438e0336..8b9c6f8e9 100644
--- a/src/filter/VolumeFilterPlugin.cxx
+++ b/src/filter/VolumeFilterPlugin.cxx
@@ -23,8 +23,8 @@
#include "FilterInternal.hxx"
#include "FilterRegistry.hxx"
#include "pcm/Volume.hxx"
-#include "pcm/PcmBuffer.hxx"
#include "AudioFormat.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -32,29 +32,15 @@
#include <string.h>
class VolumeFilter final : public Filter {
- /**
- * The current volume, from 0 to #PCM_VOLUME_1.
- */
- unsigned volume;
-
- AudioFormat format;
-
- PcmBuffer buffer;
+ PcmVolume pv;
public:
- VolumeFilter()
- :volume(PCM_VOLUME_1) {}
-
unsigned GetVolume() const {
- assert(volume <= PCM_VOLUME_1);
-
- return volume;
+ return pv.GetVolume();
}
void SetVolume(unsigned _volume) {
- assert(_volume <= PCM_VOLUME_1);
-
- volume = _volume;
+ pv.SetVolume(_volume);
}
virtual AudioFormat Open(AudioFormat &af, Error &error) override;
@@ -73,50 +59,27 @@ volume_filter_init(gcc_unused const config_param &param,
}
AudioFormat
-VolumeFilter::Open(AudioFormat &audio_format, gcc_unused Error &error)
+VolumeFilter::Open(AudioFormat &audio_format, Error &error)
{
- format = audio_format;
+ if (!pv.Open(audio_format.format, error))
+ return AudioFormat::Undefined();
- return format;
+ return audio_format;
}
void
VolumeFilter::Close()
{
- buffer.Clear();
+ pv.Close();
}
const void *
VolumeFilter::FilterPCM(const void *src, size_t src_size,
- size_t *dest_size_r, Error &error)
+ size_t *dest_size_r, gcc_unused Error &error)
{
- *dest_size_r = src_size;
-
- if (volume >= PCM_VOLUME_1)
- /* optimized special case: 100% volume = no-op */
- return src;
-
- void *dest = buffer.Get(src_size);
-
- if (volume <= 0) {
- /* optimized special case: 0% volume = memset(0) */
- /* XXX is this valid for all sample formats? What
- about floating point? */
- memset(dest, 0, src_size);
- return dest;
- }
-
- memcpy(dest, src, src_size);
-
- bool success = pcm_volume(dest, src_size,
- format.format,
- volume);
- if (!success) {
- error.Set(volume_domain, "pcm_volume() has failed");
- return NULL;
- }
-
- return dest;
+ const auto dest = pv.Apply({src, src_size});
+ *dest_size_r = dest.size;
+ return dest.data;
}
const struct filter_plugin volume_filter_plugin = {