Speed Dreams with Dolby Digital audio

Information about the inner-side magic

Moderator: kilo

Speed Dreams with Dolby Digital audio

Postby mungewell » Wed Jun 05, 2013 2:54 am

I recent aquired a Dolby Surround amplifier and speakers cheap from Kijiji to use for my race rig, and as it took a little while to figure out how to get these playing nicely with Speed Dreams I'd thought I write it up here.

For reference I am using SpeedDreams SVN (not that should matter), on Xubuntu 13.04 with a USB sound card and optical connection to the amp. The amp supports DTS and DolbyDigital, I shall use the later to get multichannel sound.

Firstly it is important to note that multichannel digital audio 'cheats' and reconfigures the usual SPDIF/PCM signal into an encoded stream. ie. it's not just 6 channels of wav data going over the link. First I would suggest that you ensure that your sound card and amp actually support this mode by using the hardware output of Mplayer (or the like).

You can get some pre-encoded samples here:
http://www.digital-digest.com/movies/movie_index.php?type=dolby

Type either of the following (you might have to change the 'hw=1' number depending on your system)
Code: Select all
simon@bigbox:~/dolby$ mplayer -ac hwac3 -ao alsa:device=hw=1 dolbyrain.vob
simon@bigbox:~/dolby$ mplayer -ac hwdts -ao alsa:device=hw=1 dtspiano.vob


Ubuntu does not ship with the 'A52' encoder installed, this is what converts the multi-channel WAV audio into that Dolby Digital stream mentioned earlier. There is a set of instructions on how to enable the encoder here:
http://opensource.creative.com/pipermail/openal/2008-May/011165.html

Correction (but I'll leave build instructions in-case you want to build it): you don't need to build the 'A52' codec on Ubuntu any more, it's included in the 'libasound2-plugins-extra' package. http://packages.ubuntu.com/raring/libasound2-plugins-extra.

In summary
Code: Select all
apt-get source libasound2-plugins
sudo apt-get build-dep libasound2-plugins
sudo apt-get install libavcodec-dev
cd alsa-plugins-1.0.15
./configure
make
sudo make install


I found that these mostly worked OK, but I had a couple of issues:
    1. The source would not build giving errors "X--tag=CC: command not found", fixed by deleting the 'ltmain.sh' file and running 'autoreconf', then 'configure' and 'make' again
    2. When installed the modules were put in the wrong place. My system is 64bit and expects to find them in '/usr/lib/x86_64-linux-gnu/alsa-lib/' but install puts them in '/usr/lib/alsa-lib/'. I just copied them across, but I think you can fix that with a option to 'configure'

The next stage is to set up Alsa to know about the device, this took a little messing but eventually I ended up with the following '.asoundrc' file (again change card number to match your device)
Code: Select all
# iec958:CARD=Device,DEV=0

pcm_slave.convert48k {
        pcm "iec958"
        rate 48000
}

pcm.iec958_playback {
        type plug
        slave convert48k
}

pcm.!default {
        type hw
        card Device
}

ctl.!default {
        type hw           
        card Device
}

pcm.a52encode {
        type a52
        format S16_LE
        channels 6
        rate 48000
        bitrate 448
        card "Device"
}

pcm.dolbydigital {
        type plug
        slave.pcm "a52encode"
        slave.channels 6
}


You will note that output rate is 48000Hz (rather than 44100Hz), I was getting choppy sound with 44100. Since devices are defined as 'plug' Alsa will automatically resample the output/wav files.

Now you need to configure OpenAL to use the appropriate number of channels, there is a GUI tool 'alsoft-conf' which can be installed. Simply fill in the correct back end, number of speakers and move the speakers to match the relative location of yours.
alsoft-conf-dolby.png


That's it! Switch your amp into Dolby mode and you should be good for some extensive testing...
Simon
You do not have the required permissions to view the files attached to this post.
Last edited by mungewell on Wed Jul 17, 2013 7:22 pm, edited 1 time in total.
mungewell
 
Posts: 307
Joined: Fri May 20, 2011 4:05 pm
Location: Southen Alberta, Canada

Re: Speed Dreams with Dolby Digital audio

Postby mungewell » Thu Jun 20, 2013 6:48 am

After a really long time trying to figure out how to capture the AC3/A52 stream to disk I think I have it... attached '.asoundrc' has option for outputing to 'dolby.ac3' or 'downmix.wav' files and both of these play back nicely on my amp.

Amp in DolbyDigital mode:
Code: Select all
simon@bigbox:~$ mplayer -ac hwac3 -ao alsa:device=hw=1 /storage/captures/dolby.ac3
MPlayer svn r34540 (Ubuntu), built with gcc-4.7 (C) 2000-2012 MPlayer Team

Playing /storage/captures/dolby.ac3.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[spdif @ 0x7f5975dea8c0]max_analyze_duration reached
[spdif @ 0x7f5975dea8c0]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: audio (ac3), -aid 0
Load subtitles in /storage/captures/
==========================================================================
Forced audio codec: hwac3
Opening audio decoder: [hwac3] AC3/DTS pass-through S/PDIF
hwac3: switched to AC3, 448000 bps, 48000 Hz

AUDIO: 48000 Hz, 2 ch, ac3be, 448.0 kbit/29.17% (ratio: 56000->192000)
Selected audio codec: [hwac3] afm: hwac3 (AC3 through S/PDIF)
==========================================================================
[AO_ALSA] alsa-lib: conf.c:4571:(parse_args) Unknown parameter AES0
[AO_ALSA] alsa-lib: conf.c:4704:(snd_config_expand) Parse arguments error: No such file or directory
[AO_ALSA] alsa-lib: pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM hw:1,AES0=6
[AO_ALSA] Format ac3be is not supported by hardware, trying default.
AO: [alsa] 48000Hz 2ch ac3le (2 bytes per sample)


Amp in ProLogic mode:
Code: Select all
simon@bigbox:~$ mplayer -ao alsa /storage/captures/downmix.wav
MPlayer svn r34540 (Ubuntu), built with gcc-4.7 (C) 2000-2012 MPlayer Team

Playing /storage/captures/downmix.wav.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
Audio only file format detected.
Load subtitles in /storage/captures/
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 1411.2 kbit/100.00% (ratio: 176400->176400)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)
You do not have the required permissions to view the files attached to this post.
mungewell
 
Posts: 307
Joined: Fri May 20, 2011 4:05 pm
Location: Southen Alberta, Canada

Re: Speed Dreams with Dolby Digital audio

Postby mungewell » Wed Jun 26, 2013 8:05 pm

Another few 'gems'.... you don't need to build the 'A52' codec on Ubuntu any more, it's included in the 'libasound2-plugins-extra' package. http://packages.ubuntu.com/raring/libasound2-plugins-extra.

I managed to take my captured files, encode the PNGs and mutliplex them together with
Code: Select all
$ avconv -i downmix.mp3 -i dolby.ac3 -r 30 -i pngs/sd-0001-000%05d.png -c:v libx264 -profile:v high -crf 23 -pix_fmt yuv420p  -acodec copy -map 2 -map 0 -map 1  -r 30 karwada.mkv
...
$ avconv -i karwada.mkv
avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:20:06 with gcc 4.7.2
[matroska,webm @ 0x14edb00] Estimating duration from bitrate, this may be inaccurate
Input #0, matroska,webm, from 'karwada.mkv':
  Metadata:
    ENCODER         : Lavf53.21.1
  Duration: 00:04:45.08, start: 0.000000, bitrate: 576 kb/s
    Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, PAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s (default)
    Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s (default)



And you can play these with mplayer (as above) or with VLC, to spec which audio stream use the following command line
Code: Select all
cvlc --aout alsa --alsa-audio-device iec958:CARD=Device,DEV=0 --spdif --audio-track 1 karwada.mkv
mungewell
 
Posts: 307
Joined: Fri May 20, 2011 4:05 pm
Location: Southen Alberta, Canada

Re: Speed Dreams with Dolby Digital audio

Postby bakechad » Wed Jul 17, 2013 3:18 am

Played Torcs off and on for years, just started playing SD and it is great!

First, thanks for posting this info. This is great to have one spot without having to track it all down.

But most importantly, how does is sound. Is it worth the effort for SD? For other applications?

Thanks

Chad
bakechad
 
Posts: 1
Joined: Wed Jul 17, 2013 3:08 am

Re: Speed Dreams with Dolby Digital audio

Postby mungewell » Wed Jul 17, 2013 7:07 pm

The spacial aspect is great, but there's plenty more work needed on actual samples. Overall setting it up wasn't too much of a hassle.

What we need is an audio geek to take it and work it all out. Obviously this is no small task, but OpenSource is all about incremental improvements.
mungewell
 
Posts: 307
Joined: Fri May 20, 2011 4:05 pm
Location: Southen Alberta, Canada


Return to SD Physics & Internals

Who is online

Users browsing this forum: No registered users and 2 guests

cron