From bfef0fbff34e80a86d7b740eace597efe52136e1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 20 Oct 2011 02:33:51 +0200 Subject: pcm_volume: implement float samples --- src/pcm_volume.c | 15 +++++++++++++-- src/pcm_volume.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pcm_volume.c b/src/pcm_volume.c index f732060b2..de4bda6c9 100644 --- a/src/pcm_volume.c +++ b/src/pcm_volume.c @@ -132,6 +132,16 @@ pcm_volume_change_32(int32_t *buffer, const int32_t *end, int volume) } } +static void +pcm_volume_change_float(float *buffer, const float *end, float volume) +{ + while (buffer < end) { + float sample = *buffer; + sample *= volume; + *buffer++ = sample; + } +} + bool pcm_volume(void *buffer, size_t length, enum sample_format format, @@ -169,8 +179,9 @@ pcm_volume(void *buffer, size_t length, return true; case SAMPLE_FORMAT_FLOAT: - /* XXX */ - return false; + pcm_volume_change_float(buffer, end, + pcm_volume_to_float(volume)); + return true; } /* unreachable */ diff --git a/src/pcm_volume.h b/src/pcm_volume.h index 741c4db40..64e3c7641 100644 --- a/src/pcm_volume.h +++ b/src/pcm_volume.h @@ -43,6 +43,12 @@ pcm_float_to_volume(float volume) return volume * PCM_VOLUME_1 + 0.5; } +static inline float +pcm_volume_to_float(int volume) +{ + return (float)volume / (float)PCM_VOLUME_1; +} + /** * Returns the next volume dithering number, between -511 and +511. * This number is taken from a global PRNG, see pcm_prng(). -- cgit v1.2.3