From 9d0579996c66273b87baae5ef1bde433f5c1ff71 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 7 Jan 2009 18:05:38 +0100 Subject: pcm_utils: moved code to pcm_volume.c Moved the software volume code to a separate library. --- src/pcm_utils.c | 87 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 86 deletions(-) (limited to 'src/pcm_utils.c') diff --git a/src/pcm_utils.c b/src/pcm_utils.c index 43690ef89..d619c9dd7 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -19,6 +19,7 @@ #include "pcm_utils.h" #include "pcm_channels.h" #include "pcm_prng.h" +#include "pcm_volume.h" #include "conf.h" #include "audio_format.h" @@ -30,92 +31,6 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "pcm" -static inline int -pcm_dither(void) -{ - static unsigned long state; - uint32_t r; - - r = state = prng(state); - - return (r & 511) - ((r >> 9) & 511); -} - -static void -pcm_volume_change_8(int8_t *buffer, unsigned num_samples, int volume) -{ - while (num_samples > 0) { - int32_t sample = *buffer; - - sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; - - *buffer++ = pcm_range(sample, 8); - --num_samples; - } -} - -static void -pcm_volume_change_16(int16_t *buffer, unsigned num_samples, int volume) -{ - while (num_samples > 0) { - int32_t sample = *buffer; - - sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; - - *buffer++ = pcm_range(sample, 16); - --num_samples; - } -} - -static void -pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume) -{ - while (num_samples > 0) { - int64_t sample = *buffer; - - sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; - - *buffer++ = pcm_range(sample, 24); - --num_samples; - } -} - -void pcm_volume(char *buffer, int bufferSize, - const struct audio_format *format, - int volume) -{ - if (volume == PCM_VOLUME_1) - return; - - if (volume <= 0) { - memset(buffer, 0, bufferSize); - return; - } - - switch (format->bits) { - case 8: - pcm_volume_change_8((int8_t *)buffer, bufferSize, volume); - break; - - case 16: - pcm_volume_change_16((int16_t *)buffer, bufferSize / 2, - volume); - break; - - case 24: - pcm_volume_change_24((int32_t*)buffer, bufferSize / 4, - volume); - break; - - default: - g_error("%u bits not supported by pcm_volume!\n", - format->bits); - } -} - static void pcm_add_8(int8_t *buffer1, const int8_t *buffer2, unsigned num_samples, int volume1, int volume2) -- cgit v1.2.3