1 /* GStreamer ReplayGain volume adjustment
3 * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
5 * gstrgvolume.c: Element to apply ReplayGain volume adjustment
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * SECTION:element-rgvolume
25 * @see_also: <link linkend="GstRgLimiter">rglimiter</link>,
26 * <link linkend="GstRgAnalysis">rganalysis</link>
30 * This element applies volume changes to streams as lined out in the proposed
31 * <ulink url="http://replaygain.org">ReplayGain standard</ulink>. It
32 * interprets the ReplayGain meta data tags and carries out the adjustment (by
33 * using a volume element internally). The relevant tags are:
35 * <listitem>#GST_TAG_TRACK_GAIN</listitem>
36 * <listitem>#GST_TAG_TRACK_PEAK</listitem>
37 * <listitem>#GST_TAG_ALBUM_GAIN</listitem>
38 * <listitem>#GST_TAG_ALBUM_PEAK</listitem>
39 * <listitem>#GST_TAG_REFERENCE_LEVEL</listitem>
41 * The information carried by these tags must have been calculated beforehand by
42 * performing the ReplayGain analysis. This is implemented by the <link
43 * linkend="GstRgAnalysis">rganalysis</link> element.
46 * The signal compression/limiting recommendations outlined in the proposed
47 * standard are not implemented by this element. This has to be handled by
48 * separate elements because applications might want to have additional filters
49 * between the volume adjustment and the limiting stage. A basic limiter is
50 * included with this plugin: The <link linkend="GstRgLimiter">rglimiter</link>
51 * element applies -6 dB hard limiting as mentioned in the ReplayGain standard.
53 * <title>Example launch line</title>
54 * <para>Playback of a file:</para>
56 * gst-launch filesrc location="Filename.ext" ! decodebin ! audioconvert \
57 * ! rgvolume ! audioconvert ! audioresample ! alsasink
67 #include <gst/pbutils/pbutils.h>
70 #include "gstrgvolume.h"
71 #include "replaygain.h"
73 GST_DEBUG_CATEGORY_STATIC (gst_rg_volume_debug);
74 #define GST_CAT_DEFAULT gst_rg_volume_debug
87 #define DEFAULT_ALBUM_MODE TRUE
88 #define DEFAULT_HEADROOM 0.0
89 #define DEFAULT_PRE_AMP 0.0
90 #define DEFAULT_FALLBACK_GAIN 0.0
92 #define DB_TO_LINEAR(x) pow (10., (x) / 20.)
93 #define LINEAR_TO_DB(x) (20. * log10 (x))
95 #define GAIN_FORMAT "+.02f dB"
96 #define PEAK_FORMAT ".06f"
98 #define VALID_GAIN(x) ((x) > -60.00 && (x) < 60.00)
99 #define VALID_PEAK(x) ((x) > 0.)
101 /* Same template caps as GstVolume, for I don't like having just ANY caps. */
103 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
104 GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-raw-float, "
105 "rate = (int) [ 1, MAX ], "
106 "channels = (int) [ 1, MAX ], "
107 "endianness = (int) BYTE_ORDER, "
110 "channels = (int) [ 1, MAX ], "
111 "rate = (int) [ 1, MAX ], "
112 "endianness = (int) BYTE_ORDER, "
113 "width = (int) 16, " "depth = (int) 16, " "signed = (bool) TRUE"));
115 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
116 GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-raw-float, "
117 "rate = (int) [ 1, MAX ], "
118 "channels = (int) [ 1, MAX ], "
119 "endianness = (int) BYTE_ORDER, "
122 "channels = (int) [ 1, MAX ], "
123 "rate = (int) [ 1, MAX ], "
124 "endianness = (int) BYTE_ORDER, "
125 "width = (int) 16, " "depth = (int) 16, " "signed = (bool) TRUE"));
127 GST_BOILERPLATE (GstRgVolume, gst_rg_volume, GstBin, GST_TYPE_BIN);
129 static void gst_rg_volume_class_init (GstRgVolumeClass * klass);
130 static void gst_rg_volume_init (GstRgVolume * self, GstRgVolumeClass * gclass);
132 static void gst_rg_volume_set_property (GObject * object, guint prop_id,
133 const GValue * value, GParamSpec * pspec);
134 static void gst_rg_volume_get_property (GObject * object, guint prop_id,
135 GValue * value, GParamSpec * pspec);
136 static void gst_rg_volume_dispose (GObject * object);
138 static GstStateChangeReturn gst_rg_volume_change_state (GstElement * element,
139 GstStateChange transition);
140 static gboolean gst_rg_volume_sink_event (GstPad * pad, GstEvent * event);
142 static GstEvent *gst_rg_volume_tag_event (GstRgVolume * self, GstEvent * event);
143 static void gst_rg_volume_reset (GstRgVolume * self);
144 static void gst_rg_volume_update_gain (GstRgVolume * self);
145 static inline void gst_rg_volume_determine_gain (GstRgVolume * self,
146 gdouble * target_gain, gdouble * result_gain);
149 gst_rg_volume_base_init (gpointer g_class)
151 GstElementClass *element_class = g_class;
153 static const GstElementDetails element_details = {
155 "Filter/Effect/Audio",
156 "Apply ReplayGain volume adjustment",
157 "Ren\xc3\xa9 Stadler <mail@renestadler.de>"
160 gst_element_class_add_pad_template (element_class,
161 gst_static_pad_template_get (&src_template));
162 gst_element_class_add_pad_template (element_class,
163 gst_static_pad_template_get (&sink_template));
164 gst_element_class_set_details (element_class, &element_details);
166 GST_DEBUG_CATEGORY_INIT (gst_rg_volume_debug, "rgvolume", 0,
167 "ReplayGain volume element");
171 gst_rg_volume_class_init (GstRgVolumeClass * klass)
173 GObjectClass *gobject_class;
174 GstElementClass *element_class;
175 GstBinClass *bin_class;
177 gobject_class = (GObjectClass *) klass;
179 gobject_class->set_property = gst_rg_volume_set_property;
180 gobject_class->get_property = gst_rg_volume_get_property;
181 gobject_class->dispose = gst_rg_volume_dispose;
184 * GstRgVolume:album-mode:
186 * Whether to prefer album gain over track gain.
188 * If set to %TRUE, use album gain instead of track gain if both are
189 * available. This keeps the relative loudness levels of tracks from the same
192 * If set to %FALSE, track mode is used instead. This effectively leads to
193 * more extensive normalization.
195 * If album mode is enabled but the album gain tag is absent in the stream,
196 * the track gain is used instead. If both gain tags are missing, the value
197 * of the <link linkend="GstRgVolume--fallback-gain">fallback-gain</link>
198 * property is used instead.
200 g_object_class_install_property (gobject_class, PROP_ALBUM_MODE,
201 g_param_spec_boolean ("album-mode", "Album mode",
202 "Prefer album over track gain", DEFAULT_ALBUM_MODE,
205 * GstRgVolume:headroom:
207 * Extra headroom [dB]. This controls the amount by which the output can
208 * exceed digital full scale.
210 * Only set this to a value greater than 0.0 if signal compression/limiting of
211 * a suitable form is applied to the output (or output is brought into the
212 * correct range by some other transformation).
214 * This element internally uses a volume element, which also supports
215 * operating on integer audio formats. These formats do not allow exceeding
216 * digital full scale. If extra headroom is used, make sure that the raw
217 * audio data format is floating point (audio/x-raw-float). Otherwise,
218 * clipping distortion might be introduced as part of the volume adjustment
221 g_object_class_install_property (gobject_class, PROP_HEADROOM,
222 g_param_spec_double ("headroom", "Headroom", "Extra headroom [dB]",
223 0., 60., DEFAULT_HEADROOM, G_PARAM_READWRITE));
225 * GstRgVolume:pre-amp:
227 * Additional gain to apply globally [dB]. This controls the trade-off
228 * between uniformity of normalization and utilization of available dynamic
231 * Note that the default value is 0 dB because the ReplayGain reference value
232 * was adjusted by +6 dB (from 83 to 89 dB). At the time of this writing, the
233 * <ulink url="http://replaygain.org">webpage</ulink> is still outdated and
234 * does not reflect this change however. Where the original proposal states
235 * that a proper default pre-amp value is +6 dB, this translates to the used 0
238 g_object_class_install_property (gobject_class, PROP_PRE_AMP,
239 g_param_spec_double ("pre-amp", "Pre-amp", "Extra gain [dB]",
240 -60., 60., DEFAULT_PRE_AMP, G_PARAM_READWRITE));
242 * GstRgVolume:fallback-gain:
244 * Fallback gain [dB] for streams missing ReplayGain tags.
246 g_object_class_install_property (gobject_class, PROP_FALLBACK_GAIN,
247 g_param_spec_double ("fallback-gain", "Fallback gain",
248 "Gain for streams missing tags [dB]",
249 -60., 60., DEFAULT_FALLBACK_GAIN, G_PARAM_READWRITE));
251 * GstRgVolume:result-gain:
253 * Applied gain [dB]. This gain is applied to processed buffer data.
255 * This is set to the <link linkend="GstRgVolume--target-gain">target
256 * gain</link> if amplification by that amount can be applied safely.
257 * "Safely" means that the volume adjustment does not inflict clipping
258 * distortion. Should this not be the case, the result gain is set to an
259 * appropriately reduced value (by applying peak normalization). The proposed
260 * standard calls this "clipping prevention".
262 * The difference between target and result gain reflects the necessary amount
263 * of reduction. Applications can make use of this information to temporarily
264 * reduce the <link linkend="GstRgVolume--pre-amp">pre-amp</link> for
265 * subsequent streams, as recommended by the ReplayGain standard.
267 * Note that target and result gain differing for a great majority of streams
268 * indicates a problem: What happens in this case is that most streams receive
269 * peak normalization instead of amplification by the ideal replay gain. To
270 * prevent this, the <link linkend="GstRgVolume--pre-amp">pre-amp</link> has
271 * to be lowered and/or a limiter has to be used which facilitates the use of
272 * <link linkend="GstRgVolume--headroom">headroom</link>.
274 g_object_class_install_property (gobject_class, PROP_RESULT_GAIN,
275 g_param_spec_double ("result-gain", "Result-gain", "Applied gain [dB]",
276 -120., 120., 0., G_PARAM_READABLE));
278 * GstRgVolume:target-gain:
280 * Applicable gain [dB]. This gain is supposed to be applied.
282 * Depending on the value of the <link
283 * linkend="GstRgVolume--album-mode">album-mode</link> property and the
284 * presence of ReplayGain tags in the stream, this is set according to one of
285 * these simple formulas:
288 * <listitem><link linkend="GstRgVolume--pre-amp">pre-amp</link> + album gain
289 * of the stream</listitem>
290 * <listitem><link linkend="GstRgVolume--pre-amp">pre-amp</link> + track gain
291 * of the stream</listitem>
292 * <listitem><link linkend="GstRgVolume--pre-amp">pre-amp</link> + <link
293 * linkend="GstRgVolume--fallback-gain">fallback gain</link></listitem>
296 g_object_class_install_property (gobject_class, PROP_TARGET_GAIN,
297 g_param_spec_double ("target-gain", "Target-gain",
298 "Applicable gain [dB]", -120., 120., 0., G_PARAM_READABLE));
300 element_class = (GstElementClass *) klass;
301 element_class->change_state = GST_DEBUG_FUNCPTR (gst_rg_volume_change_state);
303 bin_class = (GstBinClass *) klass;
304 /* Setting these to NULL makes gst_bin_add and _remove refuse to let anyone
305 * mess with our internals. */
306 bin_class->add_element = NULL;
307 bin_class->remove_element = NULL;
311 gst_rg_volume_init (GstRgVolume * self, GstRgVolumeClass * gclass)
313 GObjectClass *volume_class;
314 GstPad *volume_pad, *ghost_pad;
316 self->album_mode = DEFAULT_ALBUM_MODE;
317 self->headroom = DEFAULT_HEADROOM;
318 self->pre_amp = DEFAULT_PRE_AMP;
319 self->fallback_gain = DEFAULT_FALLBACK_GAIN;
320 self->target_gain = 0.0;
321 self->result_gain = 0.0;
323 self->volume_element = gst_element_factory_make ("volume", "rgvolume-volume");
324 if (G_UNLIKELY (self->volume_element == NULL)) {
327 GST_WARNING_OBJECT (self, "could not create volume element");
328 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (self), "volume");
329 gst_element_post_message (GST_ELEMENT_CAST (self), msg);
331 /* Nothing else to do, we will refuse the state change from NULL to READY to
332 * indicate that something went very wrong. It is doubtful that someone
333 * attempts changing our state though, since we end up having no pads! */
337 volume_class = G_OBJECT_GET_CLASS (G_OBJECT (self->volume_element));
338 self->max_volume = G_PARAM_SPEC_DOUBLE
339 (g_object_class_find_property (volume_class, "volume"))->maximum;
341 GST_BIN_CLASS (parent_class)->add_element (GST_BIN_CAST (self),
342 self->volume_element);
344 volume_pad = gst_element_get_pad (self->volume_element, "sink");
345 ghost_pad = gst_ghost_pad_new_from_template ("sink", volume_pad,
346 gst_pad_get_pad_template (volume_pad));
347 gst_object_unref (volume_pad);
348 gst_pad_set_event_function (ghost_pad, gst_rg_volume_sink_event);
349 gst_element_add_pad (GST_ELEMENT_CAST (self), ghost_pad);
351 volume_pad = gst_element_get_pad (self->volume_element, "src");
352 ghost_pad = gst_ghost_pad_new_from_template ("src", volume_pad,
353 gst_pad_get_pad_template (volume_pad));
354 gst_object_unref (volume_pad);
355 gst_element_add_pad (GST_ELEMENT_CAST (self), ghost_pad);
359 gst_rg_volume_set_property (GObject * object, guint prop_id,
360 const GValue * value, GParamSpec * pspec)
362 GstRgVolume *self = GST_RG_VOLUME (object);
365 case PROP_ALBUM_MODE:
366 self->album_mode = g_value_get_boolean (value);
369 self->headroom = g_value_get_double (value);
372 self->pre_amp = g_value_get_double (value);
374 case PROP_FALLBACK_GAIN:
375 self->fallback_gain = g_value_get_double (value);
378 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
382 gst_rg_volume_update_gain (self);
386 gst_rg_volume_get_property (GObject * object, guint prop_id,
387 GValue * value, GParamSpec * pspec)
389 GstRgVolume *self = GST_RG_VOLUME (object);
392 case PROP_ALBUM_MODE:
393 g_value_set_boolean (value, self->album_mode);
396 g_value_set_double (value, self->headroom);
399 g_value_set_double (value, self->pre_amp);
401 case PROP_FALLBACK_GAIN:
402 g_value_set_double (value, self->fallback_gain);
404 case PROP_TARGET_GAIN:
405 g_value_set_double (value, self->target_gain);
407 case PROP_RESULT_GAIN:
408 g_value_set_double (value, self->result_gain);
411 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
417 gst_rg_volume_dispose (GObject * object)
419 GstRgVolume *self = GST_RG_VOLUME (object);
421 if (self->volume_element != NULL) {
422 /* Manually remove our child using the bin implementation of remove_element.
423 * This is needed because we prevent gst_bin_remove from working, which the
424 * parent dispose handler would use if we had any children left. */
425 GST_BIN_CLASS (parent_class)->remove_element (GST_BIN_CAST (self),
426 self->volume_element);
427 self->volume_element = NULL;
430 G_OBJECT_CLASS (parent_class)->dispose (object);
433 static GstStateChangeReturn
434 gst_rg_volume_change_state (GstElement * element, GstStateChange transition)
436 GstRgVolume *self = GST_RG_VOLUME (element);
437 GstStateChangeReturn res;
439 switch (transition) {
440 case GST_STATE_CHANGE_NULL_TO_READY:
442 if (G_UNLIKELY (self->volume_element == NULL)) {
443 /* Creating our child volume element in _init failed. */
444 return GST_STATE_CHANGE_FAILURE;
448 case GST_STATE_CHANGE_READY_TO_PAUSED:
450 gst_rg_volume_reset (self);
457 res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
462 /* Event function for the ghost sink pad. */
464 gst_rg_volume_sink_event (GstPad * pad, GstEvent * event)
467 GstPad *volume_sink_pad;
468 GstEvent *send_event = event;
471 self = GST_RG_VOLUME (gst_pad_get_parent_element (pad));
472 volume_sink_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
474 switch (GST_EVENT_TYPE (event)) {
477 GST_LOG_OBJECT (self, "received tag event");
479 send_event = gst_rg_volume_tag_event (self, event);
481 if (send_event == NULL)
482 GST_LOG_OBJECT (self, "all tags handled, dropping event");
488 gst_rg_volume_reset (self);
495 if (G_LIKELY (send_event != NULL))
496 res = gst_pad_send_event (volume_sink_pad, send_event);
500 gst_object_unref (volume_sink_pad);
501 gst_object_unref (self);
506 gst_rg_volume_tag_event (GstRgVolume * self, GstEvent * event)
508 GstTagList *tag_list;
509 gboolean has_track_gain, has_track_peak, has_album_gain, has_album_peak;
510 gboolean has_ref_level;
512 g_return_val_if_fail (event != NULL, NULL);
513 g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG, event);
515 gst_event_parse_tag (event, &tag_list);
517 if (gst_tag_list_is_empty (tag_list))
520 has_track_gain = gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN,
522 has_track_peak = gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK,
524 has_album_gain = gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN,
526 has_album_peak = gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK,
528 has_ref_level = gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
529 &self->reference_level);
531 if (!has_track_gain && !has_track_peak && !has_album_gain && !has_album_peak)
534 if (has_ref_level && (has_track_gain || has_album_gain)
535 && (ABS (self->reference_level - RG_REFERENCE_LEVEL) > 1.e-6)) {
536 /* Log a message stating the amount of adjustment that is applied below. */
537 GST_DEBUG_OBJECT (self,
538 "compensating for reference level difference by %" GAIN_FORMAT,
539 RG_REFERENCE_LEVEL - self->reference_level);
541 if (has_track_gain) {
542 self->track_gain += RG_REFERENCE_LEVEL - self->reference_level;
544 if (has_album_gain) {
545 self->album_gain += RG_REFERENCE_LEVEL - self->reference_level;
548 /* Ignore values that are obviously invalid. */
549 if (G_UNLIKELY (has_track_gain && !VALID_GAIN (self->track_gain))) {
550 GST_DEBUG_OBJECT (self,
551 "ignoring bogus track gain value %" GAIN_FORMAT, self->track_gain);
552 has_track_gain = FALSE;
554 if (G_UNLIKELY (has_track_peak && !VALID_PEAK (self->track_peak))) {
555 GST_DEBUG_OBJECT (self,
556 "ignoring bogus track peak value %" PEAK_FORMAT, self->track_peak);
557 has_track_peak = FALSE;
559 if (G_UNLIKELY (has_album_gain && !VALID_GAIN (self->album_gain))) {
560 GST_DEBUG_OBJECT (self,
561 "ignoring bogus album gain value %" GAIN_FORMAT, self->album_gain);
562 has_album_gain = FALSE;
564 if (G_UNLIKELY (has_album_peak && !VALID_PEAK (self->album_peak))) {
565 GST_DEBUG_OBJECT (self,
566 "ignoring bogus album peak value %" PEAK_FORMAT, self->album_peak);
567 has_album_peak = FALSE;
570 self->has_track_gain |= has_track_gain;
571 self->has_track_peak |= has_track_peak;
572 self->has_album_gain |= has_album_gain;
573 self->has_album_peak |= has_album_peak;
575 event = (GstEvent *) gst_mini_object_make_writable (GST_MINI_OBJECT (event));
576 gst_event_parse_tag (event, &tag_list);
578 gst_tag_list_remove_tag (tag_list, GST_TAG_TRACK_GAIN);
579 gst_tag_list_remove_tag (tag_list, GST_TAG_TRACK_PEAK);
580 gst_tag_list_remove_tag (tag_list, GST_TAG_ALBUM_GAIN);
581 gst_tag_list_remove_tag (tag_list, GST_TAG_ALBUM_PEAK);
582 gst_tag_list_remove_tag (tag_list, GST_TAG_REFERENCE_LEVEL);
584 gst_rg_volume_update_gain (self);
586 if (gst_tag_list_is_empty (tag_list)) {
587 gst_event_unref (event);
595 gst_rg_volume_reset (GstRgVolume * self)
597 self->has_track_gain = FALSE;
598 self->has_track_peak = FALSE;
599 self->has_album_gain = FALSE;
600 self->has_album_peak = FALSE;
602 self->reference_level = RG_REFERENCE_LEVEL;
604 gst_rg_volume_update_gain (self);
608 gst_rg_volume_update_gain (GstRgVolume * self)
610 gdouble target_gain, result_gain, result_volume;
611 gboolean target_gain_changed, result_gain_changed;
613 gst_rg_volume_determine_gain (self, &target_gain, &result_gain);
615 result_volume = DB_TO_LINEAR (result_gain);
617 /* Ensure that the result volume is within the range that the volume element
618 * can handle. Currently, the limit is 10. (+20 dB), which should not be
620 if (G_UNLIKELY (result_volume > self->max_volume)) {
621 GST_INFO_OBJECT (self,
622 "cannot handle result gain of %" GAIN_FORMAT " (%0.6f), adjusting",
623 result_gain, result_volume);
625 result_volume = self->max_volume;
626 result_gain = LINEAR_TO_DB (result_volume);
629 /* Direct comparison is OK in this case. */
630 if (target_gain == result_gain) {
631 GST_INFO_OBJECT (self,
632 "result gain is %" GAIN_FORMAT " (%0.6f), matching target",
633 result_gain, result_volume);
635 GST_INFO_OBJECT (self,
636 "result gain is %" GAIN_FORMAT " (%0.6f), target is %" GAIN_FORMAT,
637 result_gain, result_volume, target_gain);
640 target_gain_changed = (self->target_gain != target_gain);
641 result_gain_changed = (self->result_gain != result_gain);
643 self->target_gain = target_gain;
644 self->result_gain = result_gain;
646 g_object_set (self->volume_element, "volume", result_volume, NULL);
648 if (target_gain_changed)
649 g_object_notify ((GObject *) self, "target-gain");
650 if (result_gain_changed)
651 g_object_notify ((GObject *) self, "result-gain");
655 gst_rg_volume_determine_gain (GstRgVolume * self, gdouble * target_gain,
656 gdouble * result_gain)
660 if (!self->has_track_gain && !self->has_album_gain) {
662 GST_DEBUG_OBJECT (self, "using fallback gain");
663 gain = self->fallback_gain;
666 } else if ((self->album_mode && self->has_album_gain)
667 || (!self->album_mode && !self->has_track_gain)) {
669 gain = self->album_gain;
670 if (G_LIKELY (self->has_album_peak)) {
671 peak = self->album_peak;
673 GST_DEBUG_OBJECT (self, "album peak missing, assuming 1.0");
676 /* Falling back from track to album gain shouldn't really happen. */
677 if (G_UNLIKELY (!self->album_mode))
678 GST_INFO_OBJECT (self, "falling back to album gain");
681 /* !album_mode && !has_album_gain || album_mode && has_track_gain */
683 gain = self->track_gain;
684 if (G_LIKELY (self->has_track_peak)) {
685 peak = self->track_peak;
687 GST_DEBUG_OBJECT (self, "track peak missing, assuming 1.0");
690 if (self->album_mode)
691 GST_INFO_OBJECT (self, "falling back to track gain");
694 gain += self->pre_amp;
699 if (LINEAR_TO_DB (peak) + gain > self->headroom) {
700 *result_gain = LINEAR_TO_DB (1. / peak) + self->headroom;