diff options
author | Daniel Seuthe <daniel+mpd@seuthe.org> | 2010-05-30 17:05:43 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-05-30 17:06:08 +0200 |
commit | e8310211e216a1de0b4e856496633966d106b831 (patch) | |
tree | a117c252f846b944a73a85f3f8c3299f0e7eb594 /src | |
parent | 3709b9aa11328c50dff9f7742ce8b5ef967d5d4d (diff) | |
download | mpd-e8310211e216a1de0b4e856496633966d106b831.tar.gz mpd-e8310211e216a1de0b4e856496633966d106b831.tar.xz mpd-e8310211e216a1de0b4e856496633966d106b831.zip |
filter/replay_gain: added option "replaygain_limit"
Diffstat (limited to '')
-rw-r--r-- | src/conf.c | 1 | ||||
-rw-r--r-- | src/conf.h | 1 | ||||
-rw-r--r-- | src/decoder_api.c | 3 | ||||
-rw-r--r-- | src/filter/replay_gain_filter_plugin.c | 7 | ||||
-rw-r--r-- | src/replay_gain_config.c | 5 | ||||
-rw-r--r-- | src/replay_gain_config.h | 1 | ||||
-rw-r--r-- | src/replay_gain_info.c | 20 | ||||
-rw-r--r-- | src/replay_gain_info.h | 2 |
8 files changed, 26 insertions, 14 deletions
diff --git a/src/conf.c b/src/conf.c index ab7be10a7..476884dac 100644 --- a/src/conf.c +++ b/src/conf.c @@ -72,6 +72,7 @@ static struct config_entry config_entries[] = { { .name = CONF_REPLAYGAIN, false, false }, { .name = CONF_REPLAYGAIN_PREAMP, false, false }, { .name = CONF_REPLAYGAIN_MISSING_PREAMP, false, false }, + { .name = CONF_REPLAYGAIN_LIMIT, false, false }, { .name = CONF_VOLUME_NORMALIZATION, false, false }, { .name = CONF_SAMPLERATE_CONVERTER, false, false }, { .name = CONF_AUDIO_BUFFER_SIZE, false, false }, diff --git a/src/conf.h b/src/conf.h index d79a673cc..2385af4f6 100644 --- a/src/conf.h +++ b/src/conf.h @@ -48,6 +48,7 @@ #define CONF_REPLAYGAIN "replaygain" #define CONF_REPLAYGAIN_PREAMP "replaygain_preamp" #define CONF_REPLAYGAIN_MISSING_PREAMP "replaygain_missing_preamp" +#define CONF_REPLAYGAIN_LIMIT "replaygain_limit" #define CONF_VOLUME_NORMALIZATION "volume_normalization" #define CONF_SAMPLERATE_CONVERTER "samplerate_converter" #define CONF_AUDIO_BUFFER_SIZE "audio_buffer_size" diff --git a/src/decoder_api.c b/src/decoder_api.c index 60d283052..fe34ea34a 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -420,7 +420,8 @@ decoder_replay_gain(struct decoder *decoder, return_db = 20.0 * log10f( replay_gain_tuple_scale( &replay_gain_info->tuples[replay_gain_get_real_mode()], - replay_gain_preamp)); + replay_gain_preamp, replay_gain_missing_preamp, + replay_gain_limit)); } decoder->replay_gain_info = *replay_gain_info; diff --git a/src/filter/replay_gain_filter_plugin.c b/src/filter/replay_gain_filter_plugin.c index a0133e493..4d6080b73 100644 --- a/src/filter/replay_gain_filter_plugin.c +++ b/src/filter/replay_gain_filter_plugin.c @@ -78,11 +78,8 @@ static void replay_gain_filter_update(struct replay_gain_filter *filter) { if (filter->mode != REPLAY_GAIN_OFF) { - const struct replay_gain_tuple *tuple = - &filter->info.tuples[filter->mode]; - float scale = replay_gain_tuple_defined(tuple) - ? replay_gain_tuple_scale(tuple, replay_gain_preamp) - : replay_gain_missing_preamp; + float scale = replay_gain_tuple_scale(&filter->info.tuples[filter->mode], + replay_gain_preamp, replay_gain_missing_preamp, replay_gain_limit); g_debug("scale=%f\n", (double)scale); filter->volume = pcm_float_to_volume(scale); diff --git a/src/replay_gain_config.c b/src/replay_gain_config.c index 2ef39a4b7..f82725e90 100644 --- a/src/replay_gain_config.c +++ b/src/replay_gain_config.c @@ -37,8 +37,11 @@ static const char *const replay_gain_mode_names[] = { enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF; +const bool DEFAULT_REPLAYGAIN_LIMIT = true; + float replay_gain_preamp = 1.0; float replay_gain_missing_preamp = 1.0; +bool replay_gain_limit; const char * replay_gain_get_mode_string(void) @@ -129,6 +132,8 @@ void replay_gain_global_init(void) replay_gain_missing_preamp = pow(10, f / 20.0); } + + replay_gain_limit = config_get_bool(CONF_REPLAYGAIN_LIMIT, DEFAULT_REPLAYGAIN_LIMIT); } enum replay_gain_mode replay_gain_get_real_mode(void) diff --git a/src/replay_gain_config.h b/src/replay_gain_config.h index c3a1fe610..8fb77a5f6 100644 --- a/src/replay_gain_config.h +++ b/src/replay_gain_config.h @@ -28,6 +28,7 @@ extern enum replay_gain_mode replay_gain_mode; extern float replay_gain_preamp; extern float replay_gain_missing_preamp; +extern bool replay_gain_limit; void replay_gain_global_init(void); diff --git a/src/replay_gain_info.c b/src/replay_gain_info.c index 9ab5b05fa..66f46def2 100644 --- a/src/replay_gain_info.c +++ b/src/replay_gain_info.c @@ -21,17 +21,23 @@ #include "replay_gain_info.h" float -replay_gain_tuple_scale(const struct replay_gain_tuple *tuple, float preamp) +replay_gain_tuple_scale(const struct replay_gain_tuple *tuple, float preamp, float missing_preamp, bool peak_limit) { float scale; - scale = pow(10.0, tuple->gain / 20.0); - scale *= preamp; - if (scale > 15.0) - scale = 15.0; + if (replay_gain_tuple_defined(tuple)) + { + scale = pow(10.0, tuple->gain / 20.0); + scale *= preamp; + if (scale > 15.0) + scale = 15.0; - if (scale * tuple->peak > 1.0) - scale = 1.0 / tuple->peak; + if (peak_limit) + if (scale * tuple->peak > 1.0) + scale = 1.0 / tuple->peak; + } else { + scale = missing_preamp; + } return scale; } diff --git a/src/replay_gain_info.h b/src/replay_gain_info.h index 49f375b04..83b46df84 100644 --- a/src/replay_gain_info.h +++ b/src/replay_gain_info.h @@ -62,7 +62,7 @@ replay_gain_tuple_defined(const struct replay_gain_tuple *tuple) } float -replay_gain_tuple_scale(const struct replay_gain_tuple *tuple, float preamp); +replay_gain_tuple_scale(const struct replay_gain_tuple *tuple, float preamp, float missing_preamp, bool peak_limit); /** * Attempt to auto-complete missing data. In particular, if album |