From f471b4cfc5e4ad42e34f79daa81a2de217134517 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 28 Sep 2008 18:35:42 +0200 Subject: pcm_utils: added inline function pcm_dither() Merge some code into an inline function, so we can optimize it later only once. --- src/pcm_utils.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/pcm_utils.c b/src/pcm_utils.c index 90856fa1d..3eb24d882 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -24,6 +24,12 @@ #include "conf.h" #include "os_compat.h" +static inline int +pcm_dither(void) +{ + return (rand() & 511) - (rand() & 511); +} + void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format, int volume) { @@ -44,8 +50,7 @@ void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format, while (bufferSize > 0) { temp32 = *buffer16; temp32 *= volume; - temp32 += rand() & 511; - temp32 -= rand() & 511; + temp32 += pcm_dither(); temp32 += 500; temp32 /= 1000; *buffer16 = temp32 > 32767 ? 32767 : @@ -58,8 +63,7 @@ void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format, while (bufferSize > 0) { temp32 = *buffer8; temp32 *= volume; - temp32 += rand() & 511; - temp32 -= rand() & 511; + temp32 += pcm_dither(); temp32 += 500; temp32 /= 1000; *buffer8 = temp32 > 127 ? 127 : @@ -90,8 +94,7 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1, temp32 = (vol1 * (*buffer16_1) + vol2 * (*buffer16_2)); - temp32 += rand() & 511; - temp32 -= rand() & 511; + temp32 += pcm_dither(); temp32 += 500; temp32 /= 1000; *buffer16_1 = @@ -109,8 +112,7 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1, while (bufferSize1 > 0 && bufferSize2 > 0) { temp32 = (vol1 * (*buffer8_1) + vol2 * (*buffer8_2)); - temp32 += rand() & 511; - temp32 -= rand() & 511; + temp32 += pcm_dither(); temp32 += 500; temp32 /= 1000; *buffer8_1 = -- cgit v1.2.3