diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/gstrganalysis.c gst-plugins-bad-prepare/gst/replaygain/gstrganalysis.c
--- gst-plugins-bad-orig/gst/replaygain/gstrganalysis.c	2007-02-23 21:16:28.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/gstrganalysis.c	2007-02-27 15:19:12.000000000 +0100
@@ -25,100 +25,25 @@
  *
  * <refsect2>
  * <para>
- * GstRgAnalysis analyzes raw audio sample data in accordance with the
- * proposed <ulink url="http://replaygain.org">ReplayGain
- * standard</ulink> for calculating the ideal replay gain for music
- * tracks and albums.  The element is designed as a pass-through
- * filter that never modifies any data.  As it receives an EOS event,
- * it finalizes the ongoing analysis and generates a tag list
- * containing the results.  It is sent downstream with a TAG event and
- * posted on the message bus with a TAG message.  The EOS event is
- * forwarded as normal afterwards.  Result tag lists at least contain
- * the tags #GST_TAG_TRACK_GAIN and #GST_TAG_TRACK_PEAK.
+ * This element analyzes raw audio sample data in accordance with the proposed
+ * <ulink url="http://replaygain.org">ReplayGain standard</ulink> for
+ * calculating the ideal replay gain for music tracks and albums.  The element
+ * is designed as a pass-through filter that never modifies any data.  As it
+ * receives an EOS event, it finalizes the ongoing analysis and generates a tag
+ * list containing the results.  It is sent downstream with a tag event and
+ * posted on the message bus with a tag message.  The EOS event is forwarded as
+ * normal afterwards.  Result tag lists at least contain the tags
+ * #GST_TAG_TRACK_GAIN, #GST_TAG_TRACK_PEAK and #GST_TAG_REFERENCE_LEVEL.
  * </para>
- * <title>Album processing</title>
  * <para>
- * Analyzing several streams sequentially and assigning them a common
- * result gain is known as "album processing".  If this gain is used
- * during playback (by switching to "album mode"), all tracks receive
- * the same amplification.  This keeps the relative volume levels
- * between the tracks intact.  To enable this, set the <link
- * linkend="GstRgAnalysis--num-tracks">num-tracks</link> property to
- * the number of streams that will be processed as album tracks.
- * Every time an EOS event is received, the value of this property
- * will be decremented by one.  As it reaches zero, it is assumed that
- * the last track of the album finished.  The tag list for the final
- * stream will contain the additional tags #GST_TAG_ALBUM_GAIN and
- * #GST_TAG_ALBUM_PEAK.  All other streams just get the two track tags
- * posted because the values for the album tags are not known before
- * all tracks are analyzed.  Applications need to make sure that the
- * album gain and peak values are also associated with the other
- * tracks when storing the results.  It is thus a bit more complex to
- * implement, but should not be avoided since the album gain is
- * generally more valuable for use during playback than the track
- * gain.
- * </para>
- * <title>Skipping processing</title> 
- * <para>
- * For assisting transcoder/converter applications, the element can
- * silently skip the processing of streams that already contain the
- * necessary meta data tags.  Data will flow as usual but the element
- * will not consume CPU time and will not generate result tags.  To
- * enable possible skipping, set the <link
- * linkend="GstRgAnalysis--forced">forced</link> property to #FALSE.
- * If used in conjunction with album processing, the element will skip
- * the number of remaining album tracks if a full set of tags is found
- * for the first track.  If a subsequent track of the album is missing
- * tags, processing cannot start again.  If this is undesired, your
- * application has to scan all files beforehand and enable forcing of
- * processing if needed.
- * </para>
- * <title>Tips</title>
- * <itemizedlist>
- * <listitem><para>
- * Because the generated metadata tags become available at the end of
- * streams, downstream muxer and encoder elements are normally unable
- * to save them in their output since they generally save metadata in
- * the file header.  Therefore, it is often necessary that
- * applications read the results in a bus event handler for the tag
- * message.  Obtaining the values this way is always needed for album
- * processing since the album gain and peak values need to be
- * associated with all tracks of an album, not just the last one.
- * </para></listitem>
- * <listitem><para>
- * To perform album processing, the element has to preserve data
- * between streams.  This cannot survive a state change to the NULL or
- * READY state.  If you change your pipeline's state to NULL or READY
- * between tracks, lock the rganalysis element's state using
- * gst_element_set_locked_state() when it is in PAUSED or PLAYING.  As
- * with any other element, don't forget to unlock it again and set it
- * to the NULL state before dropping the last reference.
- * </para></listitem>
- * <listitem><para>
- * If the total number of album tracks is unknown beforehand, set the
- * num-tracks property to some large value like #G_MAXINT (or set it
- * to >= 2 before each track starts).  Before the last track ends, set
- * the property value to 1.
- * </para></listitem>
- * </itemizedlist>
- * <title>Compliance</title>
- * <para>
- * Analyzing the ReplayGain pink noise reference waveform will compute
- * a result of +6.00dB instead of the expected 0.00dB because the
- * default reference level is 89dB.  To obtain values as lined out in
- * the original proposal of ReplayGain, set the <link
- * linkend="GstRgAnalysis--reference-level">reference-level</link>
- * property to 83.  Almost all software uses 89dB as a reference
- * however, which works against the tendency of the algorithm to
- * advise to drastically lower the volume of music with a highly
- * compressed dynamic range and high average output levels.  This
- * tendency is normally to be fought during playback (if wanted), by
- * using a default pre-amp value of at least +6.00dB.  At one point,
- * the majority of analyzer implementations switched to 89dB which
- * moved this adjustment to the analyzing/metadata writing process.
- * This change has been acknowledged by the author of the ReplayGain
- * proposal, however at the time of this writing, the webpage is still
- * not updated.
+ * Because the generated metadata tags become available at the end of streams,
+ * downstream muxer and encoder elements are normally unable to save them in
+ * their output since they generally save metadata in the file header.
+ * Therefore, it is often necessary that applications read the results in a bus
+ * event handler for the tag message.  Obtaining the values this way is always
+ * needed for <link linkend="GstRgAnalysis--num-tracks">album processing</link>
+ * since the album gain and peak values need to be associated with all tracks of
+ * an album, not just the last one.
  * </para>
  * <title>Example launch lines</title>
  * <para>Analyze a simple test waveform:</para>
@@ -127,18 +52,26 @@
  * </programlisting>
  * <para>Analyze a given file:</para>
  * <programlisting>
- * gst-launch -t filesrc location="Some file.ogg" ! decodebin ! audioconvert ! audioresample ! rganalysis ! fakesink
+ * gst-launch -t filesrc location="Some file.ogg" ! decodebin \
+ *     ! audioconvert ! audioresample ! rganalysis ! fakesink
  * </programlisting>
  * <para>Analyze the pink noise reference file:</para>
  * <programlisting>
- * gst-launch -t gnomevfssrc location=http://replaygain.hydrogenaudio.org/ref_pink.wav ! wavparse ! rganalysis ! fakesink
+ * gst-launch -t gnomevfssrc location=http://replaygain.hydrogenaudio.org/ref_pink.wav \
+ *     ! wavparse ! rganalysis ! fakesink
  * </programlisting>
+ * <para>
+ * The above launch line yields a result gain of +6 dB (instead of the expected
+ * +0 dB).  This is not in error, refer to the <link
+ * linkend="GstRgAnalysis--reference-level">reference-level</link> property
+ * documentation for more information.
+ * </para>
  * <title>Acknowledgements</title>
  * <para>
  * This element is based on code used in the <ulink
- * url="http://sjeng.org/vorbisgain.html">vorbisgain</ulink> program
- * and many others.  The relevant parts are copyrighted by David
- * Robinson, Glen Sawyer and Frank Klemm.
+ * url="http://sjeng.org/vorbisgain.html">vorbisgain</ulink> program and many
+ * others.  The relevant parts are copyrighted by David Robinson, Glen Sawyer
+ * and Frank Klemm.
  * </para>
  * </refsect2>
  */
@@ -147,11 +80,11 @@
 #include <config.h>
 #endif
 
-#include <string.h>
 #include <gst/gst.h>
 #include <gst/base/gstbasetransform.h>
 
 #include "gstrganalysis.h"
+#include "replaygain.h"
 
 GST_DEBUG_CATEGORY_STATIC (gst_rg_analysis_debug);
 #define GST_CAT_DEFAULT gst_rg_analysis_debug
@@ -254,18 +187,93 @@ gst_rg_analysis_class_init (GstRgAnalysi
   gobject_class->set_property = gst_rg_analysis_set_property;
   gobject_class->get_property = gst_rg_analysis_get_property;
 
+  /**
+   * GstRgAnalysis:num-tracks:
+   *
+   * Number of remaining album tracks.
+   * 
+   * Analyzing several streams sequentially and assigning them a common result
+   * gain is known as "album processing".  If this gain is used during playback
+   * (by switching to "album mode"), all tracks of an album receive the same
+   * amplification.  This keeps the relative volume levels between the tracks
+   * intact.  To enable this, set this property to the number of streams that
+   * will be processed as album tracks.
+   *
+   * Every time an EOS event is received, the value of this property is
+   * decremented by one.  As it reaches zero, it is assumed that the last track
+   * of the album finished.  The tag list for the final stream will contain the
+   * additional tags #GST_TAG_ALBUM_GAIN and #GST_TAG_ALBUM_PEAK.  All other
+   * streams just get the two track tags posted because the values for the album
+   * tags are not known before all tracks are analyzed.  Applications need to
+   * ensure that the album gain and peak values are also associated with the
+   * other tracks when storing the results.
+   *
+   * If the total number of album tracks is unknown beforehand, just ensure that
+   * the value is greater than 1 before each track starts.  Then before the end
+   * of the last track, set it to the value 1.
+   *
+   * To perform album processing, the element has to preserve data between
+   * streams.  This cannot survive a state change to the NULL or READY state.
+   * If you change your pipeline's state to NULL or READY between tracks, lock
+   * the element's state using gst_element_set_locked_state() when it is in
+   * PAUSED or PLAYING.
+   */
   g_object_class_install_property (gobject_class, PROP_NUM_TRACKS,
       g_param_spec_int ("num-tracks", "Number of album tracks",
-          "Number of remaining tracks in the album",
-          0, G_MAXINT, 0, G_PARAM_READWRITE));
+          "Number of remaining album tracks", 0, G_MAXINT, 0,
+	  G_PARAM_READWRITE));
+  /**
+   * GstRgAnalysis:forced:
+   *
+   * Whether to analyze streams even when ReplayGain tags exist.
+   *
+   * For assisting transcoder/converter applications, the element can silently
+   * skip the processing of streams that already contain the necessary tags.
+   * Data will flow as usual but the element will not consume CPU time and will
+   * not generate result tags.  To enable possible skipping, set this property
+   * to #FALSE.
+   *
+   * If used in conjunction with <link linkend="GstRgAnalysis--num-tracks">album
+   * processing</link>, the element will skip the number of remaining album
+   * tracks if a full set of tags is found for the first track.  If a subsequent
+   * track of the album is missing tags, processing cannot start again.  If this
+   * is undesired, the application has to scan all files beforehand and enable
+   * forcing of processing if needed.
+   */
   g_object_class_install_property (gobject_class, PROP_FORCED,
-      g_param_spec_boolean ("forced", "Force processing",
-          "Analyze streams even when ReplayGain tags exist",
+      g_param_spec_boolean ("forced", "Forced",
+          "Analyze even if ReplayGain tags exist",
           FORCED_DEFAULT, G_PARAM_READWRITE));
+  /**
+   * GstRgAnalysis:reference-level:
+   *
+   * Reference level [dB].
+   *
+   * Analyzing the ReplayGain pink noise reference waveform computes a result of
+   * +6 dB instead of the expected 0 dB.  This is because the default reference
+   * level is 89 dB.  To obtain values as lined out in the original proposal of
+   * ReplayGain, set this property to 83.
+   *
+   * Almost all software uses 89 dB as a reference however, and this value has
+   * become the new official value.  That is to say, while the change has been
+   * acclaimed by the author of the ReplayGain proposal, the <ulink
+   * url="http://replaygain.org">webpage</ulink> is still outdated at the time
+   * of this writing.
+   *
+   * The value was changed because the original proposal recommends a default
+   * pre-amp value of +6 dB for playback.  This seemed a bit odd, as it means
+   * that the algorithm has the general tendency to produce adjustment values
+   * that are 6 dB too low.  Bumping the reference level by 6 dB compensated for
+   * this.
+   *
+   * The problem of the reference level being ambiguous for lack of concise
+   * standardization is to be solved by adopting the #GST_TAG_REFERENCE_LEVEL
+   * tag, which allows to store the used value alongside the gain values.
+   */
   g_object_class_install_property (gobject_class, PROP_REFERENCE_LEVEL,
       g_param_spec_double ("reference-level", "Reference level",
-          "Reference level in dB (83.0 for original proposal)",
-          0.0, G_MAXDOUBLE, RG_REFERENCE_LEVEL, G_PARAM_READWRITE));
+          "Reference level [dB]", 0.0, 150., RG_REFERENCE_LEVEL,
+	  G_PARAM_READWRITE));
 
   trans_class = (GstBaseTransformClass *) klass;
   trans_class->start = GST_DEBUG_FUNCPTR (gst_rg_analysis_start);
@@ -346,7 +354,7 @@ gst_rg_analysis_start (GstBaseTransform 
   filter->ctx = rg_analysis_new ();
   filter->analyze = NULL;
 
-  GST_DEBUG_OBJECT (filter, "Started");
+  GST_LOG_OBJECT (filter, "started");
 
   return TRUE;
 }
@@ -357,7 +365,7 @@ gst_rg_analysis_set_caps (GstBaseTransfo
 {
   GstRgAnalysis *filter = GST_RG_ANALYSIS (base);
   GstStructure *structure;
-  const gchar *mime_type;
+  const gchar *name;
   gint n_channels, sample_rate, sample_bit_size, sample_size;
 
   g_return_val_if_fail (filter->ctx != NULL, FALSE);
@@ -367,7 +375,7 @@ gst_rg_analysis_set_caps (GstBaseTransfo
       in_caps, out_caps);
 
   structure = gst_caps_get_structure (in_caps, 0);
-  mime_type = gst_structure_get_name (structure);
+  name = gst_structure_get_name (structure);
 
   if (!gst_structure_get_int (structure, "width", &sample_bit_size)
       || !gst_structure_get_int (structure, "channels", &n_channels)
@@ -381,7 +389,7 @@ gst_rg_analysis_set_caps (GstBaseTransfo
     goto invalid_format;
   sample_size = sample_bit_size / 8;
 
-  if (strcmp (mime_type, "audio/x-raw-float") == 0) {
+  if (g_str_equal (name, "audio/x-raw-float")) {
 
     if (sample_size != sizeof (gfloat))
       goto invalid_format;
@@ -398,7 +406,7 @@ gst_rg_analysis_set_caps (GstBaseTransfo
     else
       goto invalid_format;
 
-  } else if (strcmp (mime_type, "audio/x-raw-int") == 0) {
+  } else if (g_str_equal (name, "audio/x-raw-int")) {
 
     if (sample_size != sizeof (gint16))
       goto invalid_format;
@@ -437,13 +445,13 @@ gst_rg_analysis_transform_ip (GstBaseTra
 {
   GstRgAnalysis *filter = GST_RG_ANALYSIS (base);
 
-  g_return_val_if_fail (filter->ctx != NULL, GST_FLOW_ERROR);
-  g_return_val_if_fail (filter->analyze != NULL, GST_FLOW_ERROR);
+  g_return_val_if_fail (filter->ctx != NULL, GST_FLOW_WRONG_STATE);
+  g_return_val_if_fail (filter->analyze != NULL, GST_FLOW_NOT_NEGOTIATED);
 
   if (filter->skip)
     return GST_FLOW_OK;
 
-  GST_DEBUG_OBJECT (filter, "Processing buffer of size %u",
+  GST_LOG_OBJECT (filter, "processing buffer of size %u",
       GST_BUFFER_SIZE (buf));
 
   filter->analyze (filter->ctx, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf),
@@ -463,11 +471,11 @@ gst_rg_analysis_event (GstBaseTransform 
 
     case GST_EVENT_EOS:
     {
-      GST_DEBUG_OBJECT (filter, "Received EOS event");
+      GST_LOG_OBJECT (filter, "received EOS event");
 
       gst_rg_analysis_handle_eos (filter);
 
-      GST_DEBUG_OBJECT (filter, "Passing on EOS event");
+      GST_LOG_OBJECT (filter, "passing on EOS event");
 
       break;
     }
@@ -498,7 +506,7 @@ gst_rg_analysis_stop (GstBaseTransform *
   rg_analysis_destroy (filter->ctx);
   filter->ctx = NULL;
 
-  GST_DEBUG_OBJECT (filter, "Stopped");
+  GST_LOG_OBJECT (filter, "stopped");
 
   return TRUE;
 }
@@ -514,13 +522,13 @@ gst_rg_analysis_handle_tags (GstRgAnalys
     filter->ignore_tags = FALSE;
 
   if (filter->skip && album_processing) {
-    GST_INFO_OBJECT (filter, "Ignoring TAG event: Skipping album");
+    GST_DEBUG_OBJECT (filter, "ignoring tag event: skipping album");
     return;
   } else if (filter->skip) {
-    GST_INFO_OBJECT (filter, "Ignoring TAG event: Skipping track");
+    GST_DEBUG_OBJECT (filter, "ignoring tag event: skipping track");
     return;
   } else if (filter->ignore_tags) {
-    GST_INFO_OBJECT (filter, "Ignoring TAG event: Cannot skip anyways");
+    GST_DEBUG_OBJECT (filter, "ignoring tag event: cannot skip anyways");
     return;
   }
 
@@ -534,30 +542,31 @@ gst_rg_analysis_handle_tags (GstRgAnalys
       GST_TAG_ALBUM_PEAK, &dummy);
 
   if (!(filter->has_track_gain && filter->has_track_peak)) {
-    GST_INFO_OBJECT (filter, "Track tags not complete yet");
+    GST_DEBUG_OBJECT (filter, "track tags not complete yet");
     return;
   }
 
   if (album_processing && !(filter->has_album_gain && filter->has_album_peak)) {
-    GST_INFO_OBJECT (filter, "Album tags not complete yet");
+    GST_DEBUG_OBJECT (filter, "album tags not complete yet");
     return;
   }
 
   if (filter->forced) {
-    GST_INFO_OBJECT (filter,
-        "Existing tags are sufficient, but processing anyway (forced)");
+    GST_DEBUG_OBJECT (filter,
+        "existing tags are sufficient, but processing anyway (forced)");
     return;
   }
 
   filter->skip = TRUE;
   rg_analysis_reset (filter->ctx);
 
-  if (!album_processing)
-    GST_INFO_OBJECT (filter,
-        "Existing tags are sufficient, will not process this track");
-  else
-    GST_INFO_OBJECT (filter,
-        "Existing tags are sufficient, will not process this album");
+  if (!album_processing) {
+    GST_DEBUG_OBJECT (filter,
+        "existing tags are sufficient, will not process this track");
+  } else {
+    GST_DEBUG_OBJECT (filter,
+        "existing tags are sufficient, will not process this album");
+  }
 }
 
 static void
@@ -599,7 +608,9 @@ gst_rg_analysis_handle_eos (GstRgAnalysi
       rg_analysis_reset_album (filter->ctx);
 
     if (track_success || album_success) {
-      GST_DEBUG_OBJECT (filter, "Posting tag list with results");
+      GST_LOG_OBJECT (filter, "posting tag list with results");
+       gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
+	   GST_TAG_REFERENCE_LEVEL, filter->reference_level, NULL);
       /* This steals our reference to the list: */
       gst_element_found_tags_for_pad (GST_ELEMENT (filter),
           GST_BASE_TRANSFORM_SRC_PAD (GST_BASE_TRANSFORM (filter)), tag_list);
@@ -609,11 +620,12 @@ gst_rg_analysis_handle_eos (GstRgAnalysi
   if (album_processing) {
     filter->num_tracks--;
 
-    if (!album_finished)
-      GST_INFO_OBJECT (filter, "Album not finished yet (num-tracks is now %u)",
+    if (!album_finished) {
+      GST_DEBUG_OBJECT (filter, "album not finished yet (num-tracks is now %u)",
           filter->num_tracks);
-    else
-      GST_INFO_OBJECT (filter, "Album finished (num-tracks is now 0)");
+    } else {
+      GST_DEBUG_OBJECT (filter, "album finished (num-tracks is now 0)");
+    }
   }
 
   if (album_processing)
@@ -631,10 +643,10 @@ gst_rg_analysis_track_result (GstRgAnaly
 
   if (track_success) {
     track_gain += filter->reference_level - RG_REFERENCE_LEVEL;
-    GST_INFO_OBJECT (filter, "Track gain is %+.2f dB, peak %.6f", track_gain,
+    GST_INFO_OBJECT (filter, "track gain is %+.2f dB, peak %.6f", track_gain,
         track_peak);
   } else {
-    GST_INFO_OBJECT (filter, "Track was too short to analyze");
+    GST_INFO_OBJECT (filter, "track was too short to analyze");
   }
 
   if (track_success) {
@@ -658,10 +670,10 @@ gst_rg_analysis_album_result (GstRgAnaly
 
   if (album_success) {
     album_gain += filter->reference_level - RG_REFERENCE_LEVEL;
-    GST_INFO_OBJECT (filter, "Album gain is %+.2f dB, peak %.6f", album_gain,
+    GST_INFO_OBJECT (filter, "album gain is %+.2f dB, peak %.6f", album_gain,
         album_peak);
   } else {
-    GST_INFO_OBJECT (filter, "Album was too short to analyze");
+    GST_INFO_OBJECT (filter, "album was too short to analyze");
   }
 
   if (album_success) {
@@ -673,14 +685,3 @@ gst_rg_analysis_album_result (GstRgAnaly
 
   return album_success;
 }
-
-static gboolean
-plugin_init (GstPlugin * plugin)
-{
-  return gst_element_register (plugin, "rganalysis", GST_RANK_NONE,
-      GST_TYPE_RG_ANALYSIS);
-}
-
-GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "replaygain",
-    "ReplayGain analysis", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,
-    GST_PACKAGE_ORIGIN);
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/gstrganalysis.h gst-plugins-bad-prepare/gst/replaygain/gstrganalysis.h
--- gst-plugins-bad-orig/gst/replaygain/gstrganalysis.h	2007-02-23 21:16:28.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/gstrganalysis.h	2007-02-23 21:17:50.000000000 +0100
@@ -78,6 +78,8 @@ struct _GstRgAnalysisClass
   GstBaseTransformClass parent_class;
 };
 
+GType gst_rg_analysis_get_type (void);
+
 G_END_DECLS
 
 #endif /* __GST_RG_ANALYSIS_H__ */
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/Makefile.am gst-plugins-bad-prepare/gst/replaygain/Makefile.am
--- gst-plugins-bad-orig/gst/replaygain/Makefile.am	2007-02-26 00:35:24.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/Makefile.am	2007-02-26 00:54:56.000000000 +0100
@@ -2,6 +2,7 @@ plugin_LTLIBRARIES = libgstreplaygain.la
 
 libgstreplaygain_la_SOURCES = \
 	gstrganalysis.c       \
+	replaygain.c          \
 	rganalysis.c
 libgstreplaygain_la_CFLAGS  = $(GST_CFLAGS) $(GST_BASE_CFLAGS)
 libgstreplaygain_la_LIBADD  = $(GST_LIBS) $(GST_BASE_LIBS) $(LIBM)
@@ -10,4 +11,5 @@ libgstreplaygain_la_LDFLAGS = $(GST_PLUG
 # headers we need but don't want installed
 noinst_HEADERS =         \
 	gstrganalysis.h  \
+	replaygain.h     \
 	rganalysis.h
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/replaygain.c gst-plugins-bad-prepare/gst/replaygain/replaygain.c
--- gst-plugins-bad-orig/gst/replaygain/replaygain.c	1970-01-01 01:00:00.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/replaygain.c	2007-02-23 22:58:46.000000000 +0100
@@ -0,0 +1,43 @@
+/* GStreamer ReplayGain plugin
+ *
+ * Copyright (C) 2006 Rene Stadler <mail@renestadler.de>
+ * 
+ * replaygain.c: Plugin providing ReplayGain related elements
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gst/gst.h>
+
+#include "gstrganalysis.h"
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "rganalysis", GST_RANK_NONE,
+          GST_TYPE_RG_ANALYSIS))
+    return FALSE;
+
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "replaygain",
+    "ReplayGain volume normalization", plugin_init, VERSION, GST_LICENSE,
+    GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/replaygain.h gst-plugins-bad-prepare/gst/replaygain/replaygain.h
--- gst-plugins-bad-orig/gst/replaygain/replaygain.h	1970-01-01 01:00:00.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/replaygain.h	2007-02-23 21:17:50.000000000 +0100
@@ -0,0 +1,36 @@
+/* GStreamer ReplayGain plugin
+ *
+ * Copyright (C) 2006 Rene Stadler <mail@renestadler.de>
+ *
+ * replaygain.h: Plugin providing ReplayGain related elements
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef __REPLAYGAIN_H__
+#define __REPLAYGAIN_H__
+
+G_BEGIN_DECLS
+
+/* Reference level (in dBSPL).  The 2001 proposal specifies 83.  This was
+ * changed later in all implementations to 89, which is the new, offical value:
+ * David Robinson acknowledged the change but didn't update the website yet. */
+
+#define RG_REFERENCE_LEVEL 89.
+
+G_END_DECLS
+
+#endif /* __REPLAYGAIN_H__ */
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/gst/replaygain/rganalysis.h gst-plugins-bad-prepare/gst/replaygain/rganalysis.h
--- gst-plugins-bad-orig/gst/replaygain/rganalysis.h	2007-02-23 21:16:28.000000000 +0100
+++ gst-plugins-bad-prepare/gst/replaygain/rganalysis.h	2007-02-23 21:17:50.000000000 +0100
@@ -29,8 +29,6 @@
 
 G_BEGIN_DECLS
 
-#define RG_REFERENCE_LEVEL 89.
-
 typedef struct _RgAnalysisCtx RgAnalysisCtx;
 
 RgAnalysisCtx *rg_analysis_new (void);
diff -Naurp -x .svn -x inspect -x gst-plugins-bad-plugins.args -x gst-plugins-bad-plugins.hierarchy gst-plugins-bad-orig/tests/check/elements/rganalysis.c gst-plugins-bad-prepare/tests/check/elements/rganalysis.c
--- gst-plugins-bad-orig/tests/check/elements/rganalysis.c	2007-02-23 21:16:28.000000000 +0100
+++ gst-plugins-bad-prepare/tests/check/elements/rganalysis.c	2007-02-23 21:17:50.000000000 +0100
@@ -20,77 +20,72 @@
  * 02110-1301 USA
  */
 
-/* Some things to note about the RMS window length of the analysis
- * algorithm and thus the implementation used in the element:
- * Processing divides input data into 50ms windows at some point.
- * Some details about this that normally do not matter:
+/* Some things to note about the RMS window length of the analysis algorithm and
+ * thus the implementation used in the element: Processing divides input data
+ * into 50ms windows at some point.  Some details about this that normally do
+ * not matter:
  *
- *  1. At the end of a stream, the remainder of data that did not fill
- *     up the last 50ms window is simply discarded.
+ *  1. At the end of a stream, the remainder of data that did not fill up the
+ *     last 50ms window is simply discarded.
  *
- *  2. If the sample rate changes during a stream, the currently
- *     running window is discarded and the equal loudness filter gets
- *     reset as if a new stream started.
+ *  2. If the sample rate changes during a stream, the currently running window
+ *     is discarded and the equal loudness filter gets reset as if a new stream
+ *     started.
  *
- *  3. For the album gain, it is not entirely correct to think of
- *     obtaining it like "as if all the tracks are analyzed as one
- *     track".  There isn't a separate window being tracked for album
- *     processing, so at stream (track) end, the remaining unfilled
- *     window does not contribute to the album gain either.
+ *  3. For the album gain, it is not entirely correct to think of obtaining it
+ *     like "as if all the tracks are analyzed as one track".  There isn't a
+ *     separate window being tracked for album processing, so at stream (track)
+ *     end, the remaining unfilled window does not contribute to the album gain
+ *     either.
  *
- *  4. If a waveform with a result gain G is concatenated to itself
- *     and the result processed as a track, the gain can be different
- *     from G if and only if the duration of the original waveform is
- *     not an integer multiple of 50ms.  If the original waveform gets
- *     processed as a single track and then the same data again as a
- *     subsequent track, the album result gain will always match G
- *     (this is implied by 3.).
+ *  4. If a waveform with a result gain G is concatenated to itself and the
+ *     result processed as a track, the gain can be different from G if and only
+ *     if the duration of the original waveform is not an integer multiple of
+ *     50ms.  If the original waveform gets processed as a single track and then
+ *     the same data again as a subsequent track, the album result gain will
+ *     always match G (this is implied by 3.).
  *
- *  5. A stream shorter than 50ms cannot be analyzed.  At 8000 and
- *     48000 Hz, this corresponds to 400 resp. 2400 frames.  If a
- *     stream is shorter than 50ms, the element will not generate tags
- *     at EOS (only if an album finished, but only album tags are
- *     generated then).  This is not an erroneous condition, the
- *     element should behave normally.
+ *  5. A stream shorter than 50ms cannot be analyzed.  At 8000 and 48000 Hz,
+ *     this corresponds to 400 resp. 2400 frames.  If a stream is shorter than
+ *     50ms, the element will not generate tags at EOS (only if an album
+ *     finished, but only album tags are generated then).  This is not an
+ *     erroneous condition, the element should behave normally.
  *
- * The limitations outlined in 1.-4. do not apply to the peak values.
- * Every single sample is accounted for when looking for the peak.
- * Thus the album peak is guaranteed to be the maximum value of all
- * track peaks.
+ * The limitations outlined in 1.-4. do not apply to the peak values.  Every
+ * single sample is accounted for when looking for the peak.  Thus the album
+ * peak is guaranteed to be the maximum value of all track peaks.
  *
- * In normal day-to-day use, these little facts are unlikely to be
- * relevant, but they have to be kept in mind for writing the tests
- * here.
+ * In normal day-to-day use, these little facts are unlikely to be relevant, but
+ * they have to be kept in mind for writing the tests here.
  */
 
 #include <gst/check/gstcheck.h>
 
 GList *buffers = NULL;
 
-/* For ease of programming we use globals to keep refs for our floating
- * src and sink pads we create; otherwise we always have to do get_pad,
- * get_peer, and then remove references in every test function */
+/* For ease of programming we use globals to keep refs for our floating src and
+ * sink pads we create; otherwise we always have to do get_pad, get_peer, and
+ * then remove references in every test function */
 static GstPad *mysrcpad, *mysinkpad;
 
-/* Mapping from supported sample rates to the correct result gain for
- * the following test waveform: 20 * 512 samples with a quarter-full
- * amplitude of toggling sign, changing every 48 samples and starting
- * with the positive value.
+/* Mapping from supported sample rates to the correct result gain for the
+ * following test waveform: 20 * 512 samples with a quarter-full amplitude of
+ * toggling sign, changing every 48 samples and starting with the positive
+ * value.
  *
- * Even if we would generate a wave describing a signal with the same
- * frequency at each sampling rate, the results would vary (slightly).
- * Hence the simple generation method, since we cannot use a constant
- * value as expected result anyways.  For all sample rates, changing
- * the sign every 48 frames gives a sane frequency.  Buffers
- * containing data that forms such a waveform is created using the
- * test_buffer_square_{float,int16}_{mono,stereo} functions below.
+ * Even if we would generate a wave describing a signal with the same frequency
+ * at each sampling rate, the results would vary (slightly).  Hence the simple
+ * generation method, since we cannot use a constant value as expected result
+ * anyways.  For all sample rates, changing the sign every 48 frames gives a
+ * sane frequency.  Buffers containing data that forms such a waveform is
+ * created using the test_buffer_square_{float,int16}_{mono,stereo} functions
+ * below.
  *
- * The results have been checked against what the metaflac and
- * wavegain programs generate for such a stream.  If you want to
- * verify these, be sure that the metaflac program does not produce
- * incorrect results in your environment: I found a strange bug in the
- * (defacto) reference code for the analysis that sometimes leads to
- * incorrect RMS window lengths. */
+ * The results have been checked against what the metaflac and wavegain programs
+ * generate for such a stream.  If you want to verify these, be sure that the
+ * metaflac program does not produce incorrect results in your environment: I
+ * found a strange bug in the (defacto) reference code for the analysis that
+ * sometimes leads to incorrect RMS window lengths. */
 
 struct rate_test
 {
@@ -212,11 +207,10 @@ send_eos_event (GstElement * element)
   fail_unless (gst_pad_send_event (pad, event),
       "Cannot send EOS event: Not handled.");
 
-  /* There is no sink element, so _we_ post the EOS message on the bus
-   * here.  Of course we generate any EOS ourselves, but this allows
-   * us to poll for the EOS message in poll_eos if we expect the
-   * element to _not_ generate a TAG message.  That's better than
-   * waiting for a timeout to lapse. */
+  /* There is no sink element, so _we_ post the EOS message on the bus here.  Of
+   * course we generate any EOS ourselves, but this allows us to poll for the
+   * EOS message in poll_eos if we expect the element to _not_ generate a TAG
+   * message.  That's better than waiting for a timeout to lapse. */
   fail_unless (gst_bus_post (bus, gst_message_new_eos (NULL)));
 
   gst_object_unref (bus);
@@ -251,8 +245,8 @@ poll_eos (GstElement * element)
   gst_object_unref (bus);
 }
 
-/* This also polls for EOS since the TAG message comes right before
- * the end of streams. */
+/* This also polls for EOS since the TAG message comes right before the end of
+ * streams. */
 
 static GstTagList *
 poll_tags (GstElement * element)
@@ -749,14 +743,13 @@ GST_END_TEST;
 
 /* Tests for correctness of the peak values. */
 
-/* Float peak test.  For stereo, one channel has the constant value of
- * -1.369, the other one 0.0.  This tests many things: The result peak
- * value should occur on any channel.  The peak is of course the
- * absolute amplitude, so 1.369 should be the result.  This will also
- * detect if the code uses the absolute value during the comparison.
- * If it is buggy it will return 0.0 since 0.0 > -1.369.  Furthermore,
- * this makes sure that there is no problem with headroom (exceeding
- * 0dBFS).  In the wild you get float samples > 1.0 from stuff like
+/* Float peak test.  For stereo, one channel has the constant value of -1.369,
+ * the other one 0.0.  This tests many things: The result peak value should
+ * occur on any channel.  The peak is of course the absolute amplitude, so 1.369
+ * should be the result.  This will also detect if the code uses the absolute
+ * value during the comparison.  If it is buggy it will return 0.0 since 0.0 >
+ * -1.369.  Furthermore, this makes sure that there is no problem with headroom
+ * (exceeding 0dBFS).  In the wild you get float samples > 1.0 from stuff like
  * vorbis. */
 
 GST_START_TEST (test_peak_float)
@@ -1089,11 +1082,10 @@ GST_START_TEST (test_peak_track_album)
 
 GST_END_TEST;
 
-/* Disabling album processing before the end of the album.  Probably a
- * rare edge case and applications should not rely on this to work.
- * They need to send the element to the READY state to clear up after
- * an aborted album anyway since they might need to process another
- * album afterwards. */
+/* Disabling album processing before the end of the album.  Probably a rare edge
+ * case and applications should not rely on this to work.  They need to send the
+ * element to the READY state to clear up after an aborted album anyway since
+ * they might need to process another album afterwards. */
 
 GST_START_TEST (test_peak_album_abort_to_track)
 {
@@ -1136,8 +1128,8 @@ GST_START_TEST (test_gain_album)
   g_object_set (element, "num-tracks", 3, NULL);
   set_playing_state (element);
 
-  /* The three tracks are constructed such that if any of these is in
-   * fact ignored for the album gain, the album gain will differ. */
+  /* The three tracks are constructed such that if any of these is in fact
+   * ignored for the album gain, the album gain will differ. */
 
   accumulator = 0;
   for (i = 8; i--;)
@@ -1268,12 +1260,11 @@ GST_START_TEST (test_forced_separate)
 
 GST_END_TEST;
 
-/* A TAG event is sent _after_ data has already been processed.  In
- * real pipelines, this could happen if there is more than one
- * rganalysis element (by accident).  While it would have analyzed all
- * the data prior to receiving the event, I expect it to not post its
- * results if not forced.  This test is almost equivalent to
- * test_forced. */
+/* A TAG event is sent _after_ data has already been processed.  In real
+ * pipelines, this could happen if there is more than one rganalysis element (by
+ * accident).  While it would have analyzed all the data prior to receiving the
+ * event, I expect it to not post its results if not forced.  This test is
+ * almost equivalent to test_forced. */
 
 GST_START_TEST (test_forced_after_data)
 {
@@ -1311,8 +1302,8 @@ GST_START_TEST (test_forced_after_data)
 
 GST_END_TEST;
 
-/* Like test_forced, but *analyze* an album afterwards.  The two tests
- * following this one check the *skipping* of albums. */
+/* Like test_forced, but *analyze* an album afterwards.  The two tests following
+ * this one check the *skipping* of albums. */
 
 GST_START_TEST (test_forced_album)
 {
@@ -1441,9 +1432,8 @@ GST_START_TEST (test_forced_album_no_ski
   gst_tag_list_free (tag_list);
   fail_unless_num_tracks (element, 1);
 
-  /* The second track has indeed full tags, but although being not
-   * forced, this one has to be processed because album processing is
-   * on. */
+  /* The second track has indeed full tags, but although being not forced, this
+   * one has to be processed because album processing is on. */
   tag_list = gst_tag_list_new ();
   /* Provided values are totally arbitrary. */
   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
@@ -1515,10 +1505,10 @@ GST_START_TEST (test_reference_level)
 {
   GstElement *element = setup_rganalysis ();
   GstTagList *tag_list;
+  gdouble ref_level;
   gint accumulator = 0;
   gint i;
 
-  g_object_set (element, "reference-level", 83., "num-tracks", 2, NULL);
   set_playing_state (element);
 
   for (i = 20; i--;)
@@ -1527,8 +1517,26 @@ GST_START_TEST (test_reference_level)
   send_eos_event (element);
   tag_list = poll_tags (element);
   fail_unless_track_peak (tag_list, 0.25);
+  fail_unless_track_gain (tag_list, get_expected_gain (44100));
+  fail_if_album_tags (tag_list);
+  fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
+	  &ref_level) && MATCH_GAIN (ref_level, 89.),
+      "Incorrect reference level tag");
+  gst_tag_list_free (tag_list);
+  
+  g_object_set (element, "reference-level", 83., "num-tracks", 2, NULL);
+
+  for (i = 20; i--;)
+    push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
+            0.25, 0.25));
+  send_eos_event (element);
+  tag_list = poll_tags (element);
+  fail_unless_track_peak (tag_list, 0.25);
   fail_unless_track_gain (tag_list, get_expected_gain (44100) - 6.);
   fail_if_album_tags (tag_list);
+  fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
+	  &ref_level) && MATCH_GAIN (ref_level, 83.),
+      "Incorrect reference level tag");
   gst_tag_list_free (tag_list);
 
   accumulator = 0;
@@ -1543,6 +1551,9 @@ GST_START_TEST (test_reference_level)
   /* We provided the same waveform twice, with a reset separating
    * them.  Therefore, the album gain matches the track gain. */
   fail_unless_album_gain (tag_list, get_expected_gain (44100) - 6.);
+  fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
+	  &ref_level) && MATCH_GAIN (ref_level, 83.),
+      "Incorrect reference level tag");
   gst_tag_list_free (tag_list);
 
   cleanup_rganalysis (element);
