OT: preprocessing a mp3 file for playing in high noise environment.

Preprocessing a mp2 or mp3 file for playing in high noise environment.

Considering the recent eh.. discussions in the thread 'what kind of IC amplifiers would Kenwood use', something that turned into a discussion about companding, compressing, and expanding. Here is the script *I* use to pre-process mp3 files for transmission on a low signal to noise channel. It accepts a mp3 audio file, and first decodes it to wave, then finds the maximum amplitude. then makes the maximum amplitude 0dB, so the compressor can work correctly, then compresses the file in the same way the old NE570 chip did (CCIT attack: 3+-2ms release 13.5+-9ms).

# this script goes in /usr/local/sbin/ucompand, it accepts mp2 or mp3 files.

echo "Making wave file." mpg123 -w /tmp/q1.wav $1

echo "Getting max amplitude." sox /tmp/q1.wav -e stat 2> /tmp/stat.txt

echo "Extracting volume from stats" cat /tmp/stat.txt | awk '/Volume adjustment:/ { if (1 < 2) print $3 }' >

/tmp/vol

vol=`cat /tmp/vol` echo "volume=$vol"

if [ "$vol" == "1.000" ] then echo "Companding wave file." sox /tmp/q1.wav -t wav $1-companded-unity.wav compand 0.003,.013.5

-80,-40,-60,-30,-40,-20,0,0 1 echo "Deleting temp file." rm /tmp/q1.wav else echo "Creating unity wave file." sox /tmp/q1.wav -v $vol /tmp/q1-unity.wav echo "Deleting temp file." rm /tmp/q1.wav echo "Companding wave file." sox /tmp/q1-unity.wav -t wav $1-companded-unity.wav compand 0.003,.013.5

-80,-40,-60,-30,-40,-20,0,0 1 echo "Deleting temp file." rm /tmp/q1-unity.wav fi

echo "Ready"

exit

This is what happens if you run it:

#ucompand koppie_rait.mp2

Making wave file. High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3. Version 0.59s-mh4 (2000/Oct/27). Written and copyrights by Michael Hipp. Uses code from various people. See 'README' for more! THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

Playing MPEG stream from koppie_rait.mp2 ... MPEG 1.0 layer II, 64 kbit/s, 48000 Hz mono

[52:52] Decoding of koppie_rait.mp2 finished. Getting max amplitude. Extracting volume from stats volume=1.351 Creating unity wave file. Deleting temp file. Companding wave file. Deleting temp file. Ready ucompand_m koppie_rait.mp2 81.21s user 27.18s system 46% cpu 3:52.57 total

Oh, and this requires Linux, with mpg123, sox, awk, and cat installed (should be there by default).

The resulting file is koppie_rait.mp2-companded-unity.wav

Play it to hear everything at the same level, almost ;-)

You can process your CDs this way for playing in the car, Ferrari even.

Reply to
Jan Panteltje
Loading thread data ...

Jan Panteltje snipped-for-privacy@yahoo.com posted to sci.electronics.design:

Thanks for a simple automated way to do this.

Reply to
JosephKK

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.