diff options
author | Max Kellermann <max@duempel.org> | 2008-11-11 16:38:12 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-11 16:38:12 +0100 |
commit | 8a40e0b495988f78ff47dea9801f09ff0d6e63bf (patch) | |
tree | 651a81f447f32a7351c391d61f558bef72369b82 /src | |
parent | cb28487d10f3748365623ee98d663505c6c74f9a (diff) | |
download | mpd-8a40e0b495988f78ff47dea9801f09ff0d6e63bf.tar.gz mpd-8a40e0b495988f78ff47dea9801f09ff0d6e63bf.tar.xz mpd-8a40e0b495988f78ff47dea9801f09ff0d6e63bf.zip |
replay_gain: use pcm_volume() to apply replay gain
The currently replay_gain_apply() implementation duplicates code from
pcm_volume(), except that it uses a floating point scale. Eliminate
all duplicated code from and make it utilize the pcm_volume() library
function. This introduces replay gain support for 24 bit audio.
Diffstat (limited to 'src')
-rw-r--r-- | src/replay_gain.c | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/src/replay_gain.c b/src/replay_gain.c index ebd8e40ca..a61818b4a 100644 --- a/src/replay_gain.c +++ b/src/replay_gain.c @@ -23,6 +23,7 @@ #include "log.h" #include "conf.h" #include "audio_format.h" +#include "pcm_utils.h" #include "os_compat.h" #include <glib.h> @@ -113,11 +114,6 @@ void replay_gain_apply(struct replay_gain_info *info, char *buffer, int size, const struct audio_format *format) { - int16_t *buffer16; - int8_t *buffer8; - int32_t temp32; - float scale; - if (replay_gain_mode == REPLAY_GAIN_OFF || !info) return; @@ -132,36 +128,5 @@ replay_gain_apply(struct replay_gain_info *info, char *buffer, int size, info->scale = calc_replay_gain_scale(tuple->gain, tuple->peak); } - if (info->scale <= 1.01 && info->scale >= 0.99) - return; - - buffer16 = (int16_t *) buffer; - buffer8 = (int8_t *) buffer; - - scale = info->scale; - - switch (format->bits) { - case 16: - while (size > 0) { - temp32 = *buffer16; - temp32 *= scale; - *buffer16 = temp32 > 32767 ? 32767 : - (temp32 < -32768 ? -32768 : temp32); - buffer16++; - size -= 2; - } - break; - case 8: - while (size > 0) { - temp32 = *buffer8; - temp32 *= scale; - *buffer8 = temp32 > 127 ? 127 : - (temp32 < -128 ? -128 : temp32); - buffer8++; - size--; - } - break; - default: - ERROR("%i bits not supported by doReplaygain!\n", format->bits); - } + pcm_volume(buffer, size, format, pcm_float_to_volume(info->scale)); } |