pcm/Volume: make PCM_VOLUME_1 a "constexpr"
This commit is contained in:
parent
5aae560683
commit
bfe020e06c
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user