diff options
author | Max Kellermann <max@duempel.org> | 2009-01-07 18:05:38 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-07 18:05:38 +0100 |
commit | 9d0579996c66273b87baae5ef1bde433f5c1ff71 (patch) | |
tree | cab168a9b18a2e6aa9eaaa8ac53093b537dbe63e /src/pcm_utils.c | |
parent | e8c323ed7e6cda5b96871d922e66f573059f8b62 (diff) | |
download | mpd-9d0579996c66273b87baae5ef1bde433f5c1ff71.tar.gz mpd-9d0579996c66273b87baae5ef1bde433f5c1ff71.tar.xz mpd-9d0579996c66273b87baae5ef1bde433f5c1ff71.zip |
pcm_utils: moved code to pcm_volume.c
Moved the software volume code to a separate library.
Diffstat (limited to '')
-rw-r--r-- | src/pcm_utils.c | 87 |
1 files changed, 1 insertions, 86 deletions
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) |