Commit cf90f819 authored by J. Alexander Treuman's avatar J. Alexander Treuman

Adding on the fly volume normalization support. Code originally from mplayer,…

Adding on the fly volume normalization support. Code originally from mplayer, ported by syscrash, cleaned up by avuton, and further cleaned up by me (jat). git-svn-id: https://svn.musicpd.org/mpd/trunk@4424 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent c4d1344f
...@@ -92,6 +92,9 @@ Musepack, and MP3 (through ID3v2 replaygain tags, not APEv2) are supported. ...@@ -92,6 +92,9 @@ Musepack, and MP3 (through ID3v2 replaygain tags, not APEv2) are supported.
.B replaygain_preamp <-15 to 15> .B replaygain_preamp <-15 to 15>
This is the gain (in dB) applied to songs with replaygain tags. This is the gain (in dB) applied to songs with replaygain tags.
.TP .TP
.B volume_normalization <yes or no>
If yes, mpd will normalize the volume of songs as they play. Default is no.
.TP
.B audio_buffer_size <size in KiB> .B audio_buffer_size <size in KiB>
This specifies the size of the audio output buffer that mpd uses. The default This specifies the size of the audio output buffer that mpd uses. The default
is 2048. is 2048.
......
...@@ -126,7 +126,7 @@ pid_file "~/.mpd/mpd.pid" ...@@ -126,7 +126,7 @@ pid_file "~/.mpd/mpd.pid"
########################################################## ##########################################################
################# REPLAYGAIN ############################# ################# Normalization ##########################
# #
# Use Replay Gain (album or track) # Use Replay Gain (album or track)
# http://www.replaygain.org # http://www.replaygain.org
...@@ -138,6 +138,13 @@ pid_file "~/.mpd/mpd.pid" ...@@ -138,6 +138,13 @@ pid_file "~/.mpd/mpd.pid"
# #
#replaygain_preamp "0" #replaygain_preamp "0"
# #
# Normalization increases the amplitude of the audio
# waveform to the maximum level without introducing any
# distortion into the recording. This option will
# normalize when replaygain is not on, utilizing the
# CPU for calculation.
#
#volume_normalization "yes"
########################################################## ##########################################################
......
...@@ -49,6 +49,7 @@ mpd_headers = \ ...@@ -49,6 +49,7 @@ mpd_headers = \
metadataChunk.h \ metadataChunk.h \
mpd_types.h \ mpd_types.h \
myfprintf.h \ myfprintf.h \
normalize.h \
outputBuffer.h \ outputBuffer.h \
path.h \ path.h \
pcm_utils.h \ pcm_utils.h \
...@@ -93,6 +94,7 @@ mpd_SOURCES = \ ...@@ -93,6 +94,7 @@ mpd_SOURCES = \
main.c \ main.c \
metadataChunk.c \ metadataChunk.c \
myfprintf.c \ myfprintf.c \
normalize.c \
outputBuffer.c \ outputBuffer.c \
path.c \ path.c \
pcm_utils.c \ pcm_utils.c \
......
...@@ -171,6 +171,7 @@ void initConf(void) ...@@ -171,6 +171,7 @@ void initConf(void)
registerConfigParam(CONF_REPLAYGAIN_PREAMP, 0, 0); registerConfigParam(CONF_REPLAYGAIN_PREAMP, 0, 0);
registerConfigParam(CONF_METADATA_TO_USE, 0, 0); registerConfigParam(CONF_METADATA_TO_USE, 0, 0);
registerConfigParam(CONF_ID3V1_ENCODING, 0, 0); registerConfigParam(CONF_ID3V1_ENCODING, 0, 0);
registerConfigParam(CONF_VOLUME_NORMALIZATION, 0, 0);
} }
static void addBlockParam(ConfigParam * param, char *name, char *value, static void addBlockParam(ConfigParam * param, char *name, char *value,
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#define CONF_HTTP_PREBUFFER_SIZE "http_prebuffer_size" #define CONF_HTTP_PREBUFFER_SIZE "http_prebuffer_size"
#define CONF_METADATA_TO_USE "metadata_to_use" #define CONF_METADATA_TO_USE "metadata_to_use"
#define CONF_ID3V1_ENCODING "id3v1_encoding" #define CONF_ID3V1_ENCODING "id3v1_encoding"
#define CONF_VOLUME_NORMALIZATION "volume_normalization"
typedef struct _BlockParam { typedef struct _BlockParam {
char *name; char *name;
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "playerData.h" #include "playerData.h"
#include "utils.h" #include "utils.h"
#include "log.h" #include "log.h"
#include "normalize.h"
#include "conf.h"
#include <string.h> #include <string.h>
...@@ -76,6 +78,22 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream, ...@@ -76,6 +78,22 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
size_t datalen; size_t datalen;
static char *convBuffer = NULL; static char *convBuffer = NULL;
static long convBufferLen = 0; static long convBufferLen = 0;
static int normalEnable = -1;
ConfigParam *param;
if (normalEnable == -1) {
normalEnable = getBoolConfigParam(CONF_VOLUME_NORMALIZATION);
if (normalEnable == -1) {
/* not set */
normalEnable = 0;
} else if (normalEnable < 0) {
param = getConfigParam(CONF_VOLUME_NORMALIZATION);
WARNING("%s is not \"yes\" or \"no\" on line %i, "
"disabling\n", CONF_VOLUME_NORMALIZATION,
param->line);
normalEnable = 0;
}
}
if (cmpAudioFormat(&(cb->audioFormat), &(dc->audioFormat)) == 0) { if (cmpAudioFormat(&(cb->audioFormat), &(dc->audioFormat)) == 0) {
data = dataIn; data = dataIn;
...@@ -99,6 +117,8 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream, ...@@ -99,6 +117,8 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
if (replayGainInfo) { if (replayGainInfo) {
doReplayGain(replayGainInfo, data, datalen, &cb->audioFormat); doReplayGain(replayGainInfo, data, datalen, &cb->audioFormat);
} else if (normalEnable) {
normalizeData(data, datalen, &cb->audioFormat);
} }
while (datalen) { while (datalen) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment