X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Faudio_output%2Fmixer.c;h=8935288391135d107bdeaed81bec9e0b40de8873;hb=1b43a4641d0272102153d13e4d8ced5d1a0a80ce;hp=b1a8b5d33b58fd0c8a037ce286cff279e00fe938;hpb=e870d083359f367817b4143a4f5299d07b90587d;p=vlc diff --git a/src/audio_output/mixer.c b/src/audio_output/mixer.c index b1a8b5d33b..8935288391 100644 --- a/src/audio_output/mixer.c +++ b/src/audio_output/mixer.c @@ -29,6 +29,8 @@ #endif #include +#include + #include #include #include @@ -51,7 +53,6 @@ audio_mixer_t *aout_MixerNew(vlc_object_t *obj, vlc_fourcc_t format) mixer->module = module_need(mixer, "audio mixer", NULL, false); if (mixer->module == NULL) { - msg_Err(mixer, "no suitable audio mixer"); vlc_object_release(mixer); mixer = NULL; } @@ -77,3 +78,46 @@ void aout_MixerRun(audio_mixer_t *mixer, block_t *block, float amp) { mixer->mix(mixer, block, amp); } + +/*** Replay gain ***/ +float (aout_ReplayGainSelect)(vlc_object_t *obj, const char *str, + const audio_replay_gain_t *replay_gain) +{ + float gain = 0.; + unsigned mode = AUDIO_REPLAY_GAIN_MAX; + + if (likely(str != NULL)) + { /* Find selectrf mode */ + if (!strcmp (str, "track")) + mode = AUDIO_REPLAY_GAIN_TRACK; + else + if (!strcmp (str, "album")) + mode = AUDIO_REPLAY_GAIN_ALBUM; + + /* If the selectrf mode is not available, prefer the other one */ + if (mode != AUDIO_REPLAY_GAIN_MAX && !replay_gain->pb_gain[mode]) + { + if (replay_gain->pb_gain[!mode]) + mode = !mode; + } + } + + /* */ + if (mode == AUDIO_REPLAY_GAIN_MAX) + return 1.; + + if (replay_gain->pb_gain[mode]) + gain = replay_gain->pf_gain[mode] + + var_InheritFloat (obj, "audio-replay-gain-preamp"); + else + gain = var_InheritFloat (obj, "audio-replay-gain-default"); + + float multiplier = pow (10., gain / 20.); + + if (replay_gain->pb_peak[mode] + && var_InheritBool (obj, "audio-replay-gain-peak-protection") + && replay_gain->pf_peak[mode] * multiplier > 1.0) + multiplier = 1.0f / replay_gain->pf_peak[mode]; + + return multiplier; +}