pcm/Volume: move code to template pcm_volume_sample()
This commit is contained in:
parent
6d21b9448a
commit
4a62cd4ad8
@ -26,6 +26,20 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
template<SampleFormat F, class Traits=SampleTraits<F>>
|
||||||
|
static inline typename Traits::value_type
|
||||||
|
pcm_volume_sample(typename Traits::value_type _sample,
|
||||||
|
int volume)
|
||||||
|
{
|
||||||
|
typename Traits::long_type sample(_sample);
|
||||||
|
|
||||||
|
sample = (sample * volume + pcm_volume_dither() +
|
||||||
|
PCM_VOLUME_1S / 2)
|
||||||
|
>> PCM_VOLUME_BITS;
|
||||||
|
|
||||||
|
return PcmClamp<F, Traits>(sample);
|
||||||
|
}
|
||||||
|
|
||||||
template<SampleFormat F, class Traits=SampleTraits<F>>
|
template<SampleFormat F, class Traits=SampleTraits<F>>
|
||||||
static void
|
static void
|
||||||
pcm_volume_change(typename Traits::pointer_type buffer,
|
pcm_volume_change(typename Traits::pointer_type buffer,
|
||||||
@ -33,13 +47,8 @@ pcm_volume_change(typename Traits::pointer_type buffer,
|
|||||||
int volume)
|
int volume)
|
||||||
{
|
{
|
||||||
while (buffer < end) {
|
while (buffer < end) {
|
||||||
typename Traits::long_type sample = *buffer;
|
const auto sample = *buffer;
|
||||||
|
*buffer++ = pcm_volume_sample<F, Traits>(sample, volume);
|
||||||
sample = (sample * volume + pcm_volume_dither() +
|
|
||||||
PCM_VOLUME_1S / 2)
|
|
||||||
>> PCM_VOLUME_BITS;
|
|
||||||
|
|
||||||
*buffer++ = PcmClamp<F, Traits>(sample);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user