How to make a multichannel MPEG-2 Audiostream

questions and suggestions may be mailed to Sven Kölsch <sven@doomnet.de>
Revision 1.0.1, 2000-04-18



New!
Download a Testfile for your equipment - converted from AC3-5.1 to 5.1-MPEG-Multichannel. Download teststream here.
(I DON'T know if it actually works, 'cause my equipment can't play it with all 6 channels - if you have success mail me)


This article describes in brief form, how you can make a multichannel (e.g. 5.1 channels) MPEG-Audiostream. This stream can be used as input for the I-Author Multiplexer in order to make an SVCD with ass-kicking 5.1 surround sound.
This document is far from perfect; it describes the way it worked for me - it may not work for you ;)
If you know another (perhaps easiser?) way to encode multichannel MPEG-Audio please let me know.

Requirements

Hardware Software

Getting started

The first thing you'll have to do is to download the sources or the binaries of the MPEG-2 Audio codec (encoder and decoder) with MC (Multichannel) support and (if you need them) the other tools.
Sources:
You can find the sourcecode here (by downloading it, you are on your own).
You can find the slightly patched sourcecode here (pcm2aiff.c patched to handle 5.1ch WAVs).

If you need the Edinburgh speech library you can find the sources here.

Binaries (the following binaries include a patched version of pcm2aiff to handle 5.1-channel WAVs):
Binaries for Linux-i486-glibc2.1 (yes, it's optimized for 486 processors ;)) can be downloaded here (.tar.gz).
Binaries for Alpha-Linux-glibc2 can be downloaded here (.tar.gz).
Binaries for MSDOS-Systems (only PCM2AIFF at the moment, sorry) (.zip)

If you need the Edinburgh speech library you can find two necessary RPM-Binaries here (for SuSE Linux systems):
Libraries and Tools (install Libraries first).
note: you need a version of libtermcap.so.2 installed (SuSE Package a1).
If you need other binaries take a look at: http://ssv1.union.utah.edu/pub/mirrors/blinux/festival/mirror.festival_home/Linux-1.4.1/RPMS/

After unzipping the binaries you will find three files in a new created subdirectory called 'mc'.
These are:
musicout(.exe)  ---> MPEG-II Decoder (Audio)
musicin.(exe)   ---> MPEG-II Encoder (Audio)
pcm2aiff.(exe)  ---> Converts PCM/WAV-files to AIFF files needed by the Encoder.
besides that, there's a subdirectory called /tables - this directory is need by musicout and musicin - so don't delete it.

Step-By-Step - How to convert a Dolby Digital 5.1 (AC3) File to MPEG-2-Multichannel 5.1

If you already have a 5.1-channel WAV-file skip steps 1 and 2.
If you already have 6 separate WAV files (one for each channel) skip steps 1 to 4.
  1. Extract your AC3 file from your VOB-File using VOB-Snoopy or something similar.
  2. Load the AC3 file in SoftEncode with the option "Decode to PCM". You should see six Waveforms on your screen.

  3. Save the results to WAV (note: save it a as a PCM-WAV _not_ AC3-WAV).
  4. Now it's time to fire up Linux
  5. Extract each channel of the 5.1-Channel WAV to a separate file using the utility ch_wave from the Edinburgh Speechlibrary:

  6. You may use the the following commandline:
    left channel:      $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_l.pcm -c 0
    center channel: $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_c.pcm -c 1
    right channel:    $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_r.pcm -c 2
    left surround:    $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_ls.pcm -c 3
    right surround:  $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_rs.pcm -c 4
    LFE channel:    $ ch_wave your-6ch-wavfile.wav -F 44100 -o your-6ch-wavfile_lfe.pcm -c 5
    alternatively you can use a little bash-script. The bash-script takes the name of your 6-channel WAV file without the extensions WAV as input and generates six files with the extension PCM and the according filenamesuffixes.
  7. Now you have 6 different PCM-Files which are named like your original WAV file but with the suffixes _l,_c,_r,_ls,_rs and _lfe
  8. Next task is to make a 6-channel-AIFF-compliant file. We use the utility pcm2aiff for that purpose:

  9. $ pcm2aiff your-6ch-wavfile -c5 -r0
    This should have generated a file named your-6ch-wavfile.aiff (MS-DOS: .aif)
  10. You can use this file as input for musicin (the encoder):
  11. Now you have two ways in using the encoder:

  12. the interactive way: start it in the same directory as your 6channel AIFF file and you are prompted for all necessary inputs.
    the direct way: set all necessary inputs in the commandline.
  13. First I will describe the direct way:

  14. you can get a list of all commandline switches by starting musicin with parameter -help ($ musicin -help)
    $ musicin -help
    ISO MPEG Audio Subgroup Software Simulation Group (1996)
    ISO 13818-3 MPEG-2 Audio Multichannel Encoder
    $Revision: 2.0 $
    musicin: unrec option h
    usage: musicin                         queries for all arguments, or
           musicin [-l lay][-m mode][-r sfrq][-b br][-B br][-d emp][-C config]
              [-x matr][-k tca][-y dynX]
              [-c][-o][-e][-w][-g][-v verb][-L][-a][-P][-D] inputPCM [outBS]
    where
     -l lay   use layer <lay> coding   (dflt    2)
     -m mode  channel mode : s/d/j/m   (dflt    r)
     -n mode  surround mode : s/d/j/m  (dflt    r)
     -r sfrq  input smpl rate in kHz   (dflt  0.0)
     -b br    total bitrate in kbps    (dflt  384)
     -B br    MPEG1 bitrate in kbps    (dflt  384)
     -d emp   de-emphasis n/5/c        (dflt    n)
     -c       mark as copyright
     -o       mark as original
     -e       add error protection
     -x matr  matrix                   (dflt 0)
     -k tca   set channel-switching    (dflt -2)
     -y dynX  set dyn_cross mode       (dflt 0)
     -w       set phantom coding       (dflt off)
     -L       set LFE on               (dflt off)
     -C mode  set configuration        (dflt 320)
     -g       set MultiLingual file    (dflt off) input ML filename = inputPCM+".ml"
     -P       set mc prediction on     (dflt off)
     -D       set dyn_cross_LR on      (dflt off)
     -n nr    number of anc data Bytes (dflt 2)
     -a       set ancillary data on    (dflt off)
     -v verb  level of verbosity 0-3         (dflt 1)
     inputPCM input PCM sound file (standard or AIFF)
     outBS    output bit stream of encoded audio (dflt inName+.mpg)
    This commandline should work in most cases
    $ musicin -m s -n d -o -L your-6ch-wavefile.aiff
    After some encoding stuff you will get a file named your-6ch-wavefile.aiff.mpg
    This IS the 6-channel MPEG-2 Multichannel Stream.
    You can multiplex it with your Video and burn it on a SVCD.
THIS DOCUMENT HAS NOT BEEN FINISHED OR REVISED YET.
IF PUT IT ONLINE JUST FOR YOUR INFORMATION.
DON'T BLAME ME, IF IT DOES NOT WORK.
A NEW VERSION OF THIS DOCUMENT WILL BE PUT ONLINE AS SOON AS I HAVE MORE TIME TO TEST IT.


© 2000 Sven Kölsch <sven@doomnet.de>