Index: libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 206)
+++ libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 212)
@@ -33,4 +33,5 @@
 */
 
+#include <math.h>
 #include <string.h>
 #include <mpc/streaminfo.h>
@@ -353,6 +354,4 @@
 	memcpy(i, &d->si, sizeof d->si);
 }
-
-#include <stdio.h>
 
 void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
@@ -471,2 +470,26 @@
 }
 
+void setReplayLevel(mpc_demux * d, float level, mpc_bool_t use_gain,
+					mpc_bool_t use_title, mpc_bool_t clip_prevention)
+{
+	float peak = use_title ? d->si.peak_title : d->si.peak_album;
+	float gain = use_title ? d->si.gain_title : d->si.gain_album;
+
+	if(!use_gain && !clip_prevention)
+		return;
+
+	if(!peak)
+		peak = 1.;
+	else
+		peak = (1 << 15) / __builtin_powf(10, peak / (20 * 256));
+
+	if(!gain)
+		gain = 1.;
+	else
+		gain = __builtin_powf(10, (level - gain / 256) / 20);
+
+	if(clip_prevention && (peak < gain || !use_gain))
+		gain = peak;
+
+	mpc_decoder_scale_output(d->d, gain);
+}
Index: libmpc/branches/r2d/libmpcdec/streaminfo.c
===================================================================
--- libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 206)
+++ libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 212)
@@ -35,4 +35,5 @@
 /// Implementation of streaminfo reading functions.
 
+#include <math.h>
 #include <mpc/mpcdec.h>
 #include <mpc/streaminfo.h>
@@ -125,4 +126,23 @@
 	si->block_pwr          = 0;
 
+	// convert gain info
+	if (si->gain_title != 0) {
+		int tmp = (int)((65. - si->gain_title / 100.) * 256);
+		if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
+		si->gain_title = (mpc_int16_t) tmp;
+	}
+
+	if (si->gain_album != 0) {
+		int tmp = (int)((65. - si->gain_album / 100.) * 256);
+		if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
+		si->gain_album = (mpc_int16_t) tmp;
+	}
+
+	if (si->peak_title != 0)
+ 		si->peak_title = (mpc_uint16_t) (__builtin_log10(si->peak_title) * 20 * 256);
+
+	if (si->peak_album != 0)
+		si->peak_album = (mpc_uint16_t) (__builtin_log10(si->peak_album) * 20 * 256);
+
 	mpc_get_encoder_string(si);
 
@@ -146,5 +166,4 @@
 
 	mpc_bits_read(&r, 8); // gain version
-	// FIXME : add gain conversion
 	si->gain_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
 	si->peak_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
