aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-22 17:36:21 +0100
committerMax Kellermann <max@duempel.org>2013-12-22 21:20:40 +0100
commitbfe020e06c2ba0671cdd1dacd9999c986c3168d6 (patch)
tree41a9f57e6987785ca293a8586371f04d023a32df /src
parent5aae560683318b870df9989cdcc2ac576626b234 (diff)
downloadmpd-bfe020e06c2ba0671cdd1dacd9999c986c3168d6.tar.gz
mpd-bfe020e06c2ba0671cdd1dacd9999c986c3168d6.tar.xz
mpd-bfe020e06c2ba0671cdd1dacd9999c986c3168d6.zip
pcm/Volume: make PCM_VOLUME_1 a "constexpr"
Diffstat (limited to 'src')
-rw-r--r--src/pcm/PcmMix.cxx11
-rw-r--r--src/pcm/PcmVolume.cxx6
-rw-r--r--src/pcm/PcmVolume.hxx9
3 files changed, 13 insertions, 13 deletions
diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx
index 2866aa456..ffe935a0f 100644
--- a/src/pcm/PcmMix.cxx
+++ b/src/pcm/PcmMix.cxx
@@ -36,8 +36,8 @@ PcmAddVolume(typename Traits::value_type _a, typename Traits::value_type _b,
typename Traits::long_type a(_a), b(_b);
typename Traits::value_type c = ((a * volume1 + b * volume2) +
- pcm_volume_dither() + PCM_VOLUME_1 / 2)
- / PCM_VOLUME_1;
+ pcm_volume_dither() + PCM_VOLUME_1S / 2)
+ / PCM_VOLUME_1S;
return PcmClamp<F, Traits>(c);
}
@@ -204,7 +204,6 @@ bool
pcm_mix(void *buffer1, const void *buffer2, size_t size,
SampleFormat format, float portion1)
{
- int vol1;
float s;
/* portion1 is between 0.0 and 1.0 for crossfading, MixRamp uses -1
@@ -215,8 +214,8 @@ pcm_mix(void *buffer1, const void *buffer2, size_t size,
s = sin(M_PI_2 * portion1);
s *= s;
- vol1 = s * PCM_VOLUME_1 + 0.5;
- vol1 = Clamp<int>(vol1, 0, PCM_VOLUME_1);
+ int vol1 = s * PCM_VOLUME_1S + 0.5;
+ vol1 = Clamp<int>(vol1, 0, PCM_VOLUME_1S);
- return pcm_add_vol(buffer1, buffer2, size, vol1, PCM_VOLUME_1 - vol1, format);
+ return pcm_add_vol(buffer1, buffer2, size, vol1, PCM_VOLUME_1S - vol1, format);
}
diff --git a/src/pcm/PcmVolume.cxx b/src/pcm/PcmVolume.cxx
index 8426fd57b..d2a3c51f3 100644
--- a/src/pcm/PcmVolume.cxx
+++ b/src/pcm/PcmVolume.cxx
@@ -36,8 +36,8 @@ pcm_volume_change(typename Traits::pointer_type buffer,
typename Traits::long_type sample = *buffer;
sample = (sample * volume + pcm_volume_dither() +
- PCM_VOLUME_1 / 2)
- / PCM_VOLUME_1;
+ PCM_VOLUME_1S / 2)
+ / PCM_VOLUME_1S;
*buffer++ = PcmClamp<F, Traits>(sample);
}
@@ -132,7 +132,7 @@ pcm_volume(void *buffer, size_t length,
SampleFormat format,
int volume)
{
- if (volume == PCM_VOLUME_1)
+ if (volume == PCM_VOLUME_1S)
return true;
if (volume <= 0) {
diff --git a/src/pcm/PcmVolume.hxx b/src/pcm/PcmVolume.hxx
index 8cd82acf7..502fca9ec 100644
--- a/src/pcm/PcmVolume.hxx
+++ b/src/pcm/PcmVolume.hxx
@@ -26,10 +26,11 @@
#include <stdint.h>
#include <stddef.h>
-enum {
- /** this value means "100% volume" */
- PCM_VOLUME_1 = 1024,
-};
+/**
+ * This value means "100% volume".
+ */
+static constexpr unsigned PCM_VOLUME_1 = 1024;
+static constexpr int PCM_VOLUME_1S = PCM_VOLUME_1;
struct AudioFormat;