aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-28 18:35:42 +0200
committerMax Kellermann <max@duempel.org>2008-09-28 18:35:42 +0200
commit5b5e46f5ef34bdc6c1745c4e778b116e856393c9 (patch)
treef859a0cf09c17128af370e8a6c4b981a1d620b98 /src
parent75cba9343ec4bf93d9677792c1fbf9e9f5837a72 (diff)
downloadmpd-5b5e46f5ef34bdc6c1745c4e778b116e856393c9.tar.gz
mpd-5b5e46f5ef34bdc6c1745c4e778b116e856393c9.tar.xz
mpd-5b5e46f5ef34bdc6c1745c4e778b116e856393c9.zip
pcm_utils: added inline function pcm_dither()
Merge some code into an inline function, so we can optimize it later only once.
Diffstat (limited to 'src')
-rw-r--r--src/pcm_utils.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index a9706e019..bd7192acf 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -25,6 +25,12 @@
#include "audio_format.h"
#include "os_compat.h"
+static inline int
+pcm_dither(void)
+{
+ return (rand() & 511) - (rand() & 511);
+}
+
void pcm_volumeChange(char *buffer, int bufferSize,
const struct audio_format *format,
int volume)
@@ -46,8 +52,7 @@ void pcm_volumeChange(char *buffer, int bufferSize,
while (bufferSize > 0) {
temp32 = *buffer16;
temp32 *= volume;
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
*buffer16 = temp32 > 32767 ? 32767 :
@@ -60,8 +65,7 @@ void pcm_volumeChange(char *buffer, int bufferSize,
while (bufferSize > 0) {
temp32 = *buffer8;
temp32 *= volume;
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
*buffer8 = temp32 > 127 ? 127 :
@@ -92,8 +96,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 =
@@ -111,8 +114,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 =