Comparativa objetiva de códecs de audio

Vicente González Ruiz

October 22, 2014

Contents

1 Finalidad
2 Procedimiento
 2.1 Sampling
 2.2 Encoding
 2.3 Decoding
 2.4 Playing
 2.5 Controlling the quality in Vorbis
 2.6 Encoding with LAME (MP3)
 2.7 The R/D (Rate/Distortion) curve
 2.8 Measuring distortion
 2.9 Measuring bit-rate
 2.10 A Vorbis’s R/D curve
 2.11 A MP3’s R/D curve
 2.12 Vorbis vs MP3
 2.13 Comparación con otros codecs de audio
3 Entregables

1 Finalidad

  1. Aprender a usar el codec Vorbis.
  2. Aprender a calcular curvas R/D (Rate/Distortion) para lossy audio codecs.

2 Procedimiento

2.1 Sampling

sudo apt−get install alsa−utils 
arecord −f cd > sample.wav # Push keys CTRL+C to finish sampling

2.2 Encoding

sudo apt−get install vorbis−tools 
oggenc sample.wav −o sample.ogg

2.3 Decoding

oggdec sample.ogg −o sample.wav

2.4 Playing

ogg123 sample.ogg 
aplay sample.wav

2.5 Controlling the quality in Vorbis

oggenc −q −1 sample.wav −o sample_m1.ogg # Lowest quality 
oggenc −q 0 sample.wav −o sample_0.ogg 
oggenc −q 1 sample.wav −o sample_1.ogg 
: 
oggenc −q 10 sample.wav −o sample_10.ogg # Highest quality

2.6 Encoding with LAME (MP3)

sudo apt−get install lame 
lame −b 32 sample.wav sample_9.mp3 # Lowest quality 
: 
lame −b 320 sample.wav sample_0.mp3 # Highest quality

2.7 The R/D (Rate/Distortion) curve

Distortion  
^  
|  * x  
|  * x  
|  *  x    * is better than x  
|   *  x  
|    *   x  
|      *    x  
|         *      x  
|                *     x  
+-----------------------> Bit-rate

2.8 Measuring distortion

 
sudo apt-get install libfftw3-dev 
wget http://www.ual.es/~vruiz/progs/snr.tar.gz 
tar xzvf snr.tar.gz 
cd snr 
source ./compile 
~/bin/snr --block_size=4096 --file_A=sample_1.wav --file_B=sample_1.wav --FFT 2> /dev/null | grep RMSE # We suppose identical headers

2.9 Measuring bit-rate

 
bytes=‘wc -c < sample.ogg‘ 
echo $bytes 
time=write_here_the_duration_in_seconds_of_the_audio 
kbps=‘echo $bytes*8/$time/1000 | bc -l‘ 
echo $kbps

2.10 A Vorbis’s R/D curve

 
#!/bin/bash 
 
sound_file=$1 
ffmpeg -i $sound_file.wav -f s16le -y $sound_file.pcm 2> /dev/null 
 
quality=-1 
while [ $quality -le 10 ]; do 
  echo $quality 
  rm -f $sound_file.ogg 
  oggenc -q $quality $sound_file.wav -o $sound_file.ogg 2> /dev/null 
  oggdec $sound_file.ogg -o $0.wav 2> /dev/null > /dev/null 
  ffmpeg -i $0.wav -f s16le -y $0.pcm 2> /dev/null 
  RMSE=‘snr --block_size=4096 --FFT --file_A=$sound_file.pcm \ 
      --file_B=$0.pcm 2> /dev/null | grep RMSE | cut -d "=" -f 2‘ 
  bitrate=‘wc -c < $sound_file.ogg‘ 
  echo $bitrate $RMSE >> $0.dat 
  let quality=quality+1 
done

2.11 A MP3’s R/D curve

 
#!/bin/bash 
 
sound_file=$1 
ffmpeg -i $sound_file.wav -f s16le -y $sound_file.pcm 2> /dev/null 
 
br=32 
while [ $br -le 320 ]; do 
  echo $br 
  rm -f $sound_file.mp3 
  lame -b $br $sound_file.wav -o $sound_file.mp3 2> /dev/null 
  lame --decode $sound_file.mp3 $0.wav 2> /dev/null > /dev/null 
  ffmpeg -i $0.wav -f s16le -y $0.pcm 2> /dev/null 
  RMSE=‘snr --block_size=4096 --FFT --file_A=$sound_file.pcm \ 
      --file_B=$0.pcm 2> /dev/null | grep RMSE | cut -d "=" -f 2‘ 
  bitrate=‘wc -c < $sound_file.mp3‘ 
  echo $bitrate $RMSE >> $0.dat 
  let br=br+32 
done

2.12 Vorbis vs MP3

 
#!/bin/bash 
 
gnuplot -p << EOF 
set title "Ogg␣Vorbis␣vs␣MP3␣LAME" 
set xlabel "File␣size␣in␣bytes" 
set ylabel "RMSE␣(Root␣Mean␣Square␣Error)" 
plot "./ogg-RD.sh.dat" with lines title "Ogg␣Vorbis", \ 
     "./mp3-RD.sh.dat" with lines title "MP3␣LAME" 
EOF

2.13 Comparación con otros codecs de audio

Modifica los scripts anteriores de forma que sea posible comparar Vorbis y MP3 con otros codificadores de audio que conozcas.

3 Entregables

Una descripción de los experimentos realizados, sus resultados y unas conclusiones.