Hi,
I came across a problem with the way left and right input channel
scaling works and I have patched LAME to fix it for me. I am posting the
patch in case this makes more sense to all concerned than the previous
way of doing it and that others may benefit.
I am using a hacked version of Darkice to make MP3 streams for live
broadcasting via LAME. I am sending two languages at once, the original
"stage" sound in one channel and a translation in the other. Here are
the three streams I am making...
1) Stereo (not joint stereo!) 24kbps
2) Stage sound 8kbps
3) Translation with a little bit of stage sound mixed in 8kbps.
The two 8kbps streams are for clients in countries such as India where
10kbps is all you get from your ISP on a good day! Clients in Europe and
US etc can get the 24kbps stream and adjust their balance control to get
the best mix for their own taste.
The problem:
When in MONO mode, LAME merges the two channels before the left/right
scaling. The left scale acts on the remaining signal and the right scale
is ignored.
The solution:
The scaling operation is simply moved before the channel merge
operation. Also, all these operations are moved before the re-sample
operation otherwise the signal would have be re-sampled on two channels
even in MONO mode which would be a waste of CPU time.
Regards,
SimonB.
? mac/Makefile
Index: libmp3lame/lame.c
===================================================================
RCS file: /cvsroot/lame/lame/libmp3lame/lame.c,v
retrieving revision 1.183
diff -u -r1.183 lame.c
--- libmp3lame/lame.c 25 May 2002 23:30:35 -0000 1.183
+++ libmp3lame/lame.c 4 Jun 2002 13:12:23 -0000
@@ -745,7 +745,7 @@
/* mode = -1 (not set by user) or
- * mode = MONO (because of only 1 input channel).
+ * mode = MONO (because of only 1 input channel).
* If mode has been set, then select between STEREO or J-STEREO
* At higher quality (lower compression) use STEREO instead of
J-STEREO.
* (unless the user explicitly specified a mode)
@@ -1518,6 +1518,42 @@
in_buffer[1]=buffer_r;
+ /* Apply user defined re-scaling */
+
+ /* user selected scaling of the samples */
+ if (gfp->scale != 0 && gfp->scale != 1.0) {
+ for (i=0 ; i<nsamples; ++i) {
+ in_buffer[0][i] *= gfp->scale;
+ if (gfc->channels_out == 2)
+ in_buffer[1][i] *= gfp->scale;
+ }
+ }
+
+ cvs server: Diffing libmp3lame/i386
/* user selected scaling of the channel 0 (left) samples */
+ if (gfp->scale_left != 0 && gfp->scale_left != 1.0) {
+ for (i=0 ; i<nsamples; ++i) {
+ in_buffer[0][i] *= gfp->scale_left;
+ }
+ }
+
+ /* user selected scaling of the channel 1 (right) samples */
+ if (gfp->scale_right != 0 && gfp->scale_right != 1.0) {
+ for (i=0 ; i<nsamples; ++i) {
+ in_buffer[1][i] *= gfp->scale_right;
+ }
+ }
+
+ /* Downsample to Mono if 2 channels in and 1 channel out */
+ if (gfp->num_channels == 2 && gfc->channels_out == 1) {
+ for (i=0; i<nsamples; ++i) {
+ in_buffer[0][i] =
+ 0.5 * ((FLOAT8) in_buffer[0][i] + in_buffer[1][i]);
+ in_buffer[1][i] = 0.0;
+ }
+ }
+
+
+
/* some sanity checks */
#if ENCDELAY < MDCTDELAY
# error ENCDELAY is less than MDCTDELAY, see encoder.h
@@ -1533,22 +1569,12 @@
mfbuf[0] = gfc->mfbuf[0];
mfbuf[1] = gfc->mfbuf[1];
- if (gfp->num_channels == 2 && gfc->channels_out == 1) {
- /* downsample to mono */
- for (i = 0; i < nsamples; ++i) {
- in_buffer[0][i] =
- 0.5 * ((FLOAT8) in_buffer[0][i] + in_buffer[1][i]);
- in_buffer[1][i] = 0.0;
- }
- }
-
-
while (nsamples > 0) {
int n_in = 0; /* number of input samples processed with
fill_buffer */
int n_out = 0; /* number of samples output with
fill_buffer */
/* n_in <> n_out if we are resampling */
- /* copy in new samples into mfbuf, with resampling & scaling if
necessary */
+ /* copy in new samples into mfbuf, with resampling */
fill_buffer(gfp, mfbuf, in_buffer, nsamples, &n_in, &n_out);
/* update in_buffer counters */
Index: libmp3lame/util.c
===================================================================
RCS file: /cvsroot/lame/lame/libmp3lame/util.c,v
retrieving revision 1.95
diff -u -r1.95 util.c
--- libmp3lame/util.c 7 May 2002 20:15:13 -0000 1.95
+++ libmp3lame/util.c 4 Jun 2002 13:12:23 -0000
@@ -492,7 +492,7 @@
-/* copy in new samples from in_buffer into mfbuf, with resampling &
scaling
+/* copy in new samples from in_buffer into mfbuf, with resampling
if necessary. n_in = number of samples from the input buffer that
were used. n_out = number of samples copied into mfbuf */
@@ -523,33 +523,7 @@
}
}
- /* user selected scaling of the samples */
- if (gfp->scale != 0 && gfp->scale != 1.0) {
- for (i=0 ; i<*n_out; ++i) {
- mfbuf[0][gfc->mf_size+i] *= gfp->scale;
- if (gfc->channels_out == 2)
- mfbuf[1][gfc->mf_size + i] *= gfp->scale;
- }
- }
-
- /* user selected scaling of the channel 0 (left) samples */
- if (gfp->scale_left != 0 && gfp->scale_left != 1.0) {
- for (i=0 ; i<*n_out; ++i) {
- mfbuf[0][gfc->mf_size+i] *= gfp->scale_left;
- }
- }
-
- /* user selected scaling of the channel 1 (right) samples */
- if (gfc->channels_out == 2) {
- if (gfp->scale_right != 0 && gfp->scale_right != 1.0) {
- for (i=0 ; i<*n_out; ++i) {
- mfbuf[1][gfc->mf_size + i] *= gfp->scale_right;
- }
- }
- }
}
-
-
int fill_buffer_resample(
_______________________________________________
mp3encoder mailing list
[EMAIL PROTECTED]
http://minnie.tuhs.org/mailman/listinfo/mp3encoder