audioencodingmp3lamelamemp3

LAME -- decoding and encoding audio file


I used lame for decoding from mp3 file to raw pcm file or encoding into mp3 from from raw pcm.

The question is When I use one test.0.pcm file, doing encoding and decoding over and over again(generating 0.mp3, 1.mp3,2.mp3, ... and test.1.pcm, test.2.pcm ....), although the size of for all .pcm files or all .mp3 files remain the same, but the contents are different. I tried to listen these audio files and found that 99.mp3's volume is much less than 1.mp3.

The script I use is like following:

 #!/bin/bash
 num=$1
 last=0
 now=1
 for((i=0;i<num;i++));do
     lame -r -b 64 -s 16000 -m m test.$last.pcm $last.mp3 
     lame --decode --mp3input -t -m m -s 16000 $last.mp3 test.$now.pcm 
     last=$now
     now=$[now+1]
 done

The original test.0.pcm has only 1 channel and sampling freq is 16k.

Some logs are like following, they are all same except for Replay Gain:

input:  97.mp3  (16 kHz, 1 channel, MPEG-2 Layer III)
output: test.98.pcm  (16 bit, Microsoft WAVE)
skipping initial 1105 samples (encoder+decoder delay)
skipping final 47 samples (encoder padding-decoder delay)
Frame#    49/49      64 kbps

Assuming raw pcm input file
LAME 3.100 64bits (http://lame.sf.net)
polyphase lowpass filter disabled
Encoding test.98.pcm to 98.mp3
Encoding as 16 kHz single-ch MPEG-2 Layer III (4x)  64 kbps qval=3
    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA
    49/49    (100%)|    0:00/    0:00|    0:00/    0:00|   88.200x|    0:00
----------------------------------------------------------------------------------------------------------
   kbps       mono %     long  %
   64.0      100.0       100.0
Writing LAME Tag...done
ReplayGain: +46.1dB

Noticing ReplayGain is increasing constantly but I have no knowledge about mp3 encoding method, so I am not sure if this is the reason.


Solution

  • MP3 is a lossy codec. You're going to lose quality each time you encode another generation.