Announcement

Collapse
No announcement yet.

Howto get true surround sound on the cheap for gaming in Ubuntu.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Howto get true surround sound on the cheap for gaming in Ubuntu.

    This is something that has been bugging me for YEARS on Linux. Now, finally, with Pulseaudio and some magic I can have this holy grail.... Yes I know this was possible for a long time, but this is just how I did it and hopefully it will help somebody.

    Audio Hardware setup:
    Gigabyte 890FXE-UD5 with onboard ALC889 chipset.
    1 optical cable
    150 dollar 5.1 surround sound RCA home theater setup from K-mart.
    2 cheap 'Studio Monitor' KJH I picked up on sale from RadioShack a couple months ago.



    The WHY:

    I want to have 'true' 5.1 surround in Linux to were my applications can individaully take advantage of every speaker. I do not want to be limited to just 2 channel out with the receiver munging the audio into surround sound. Also I do not want to be limited to just surround sound for playing DVDs and such.

    Also, generally speaking, the DACs in the receiver are going to be better then the ones in the onboard sound card.

    The PROBLEM:

    I don't want to have a billion analog lines running from my computer to my receiver. My receiver is cheap, too, and it does not support analog surround sound in on analog. It has only stereo input for analog. HOWEVER it does have COAX SPDIF in as well as two TOSLink SPDIF in.

    Unfortunately SPDIF only supports 2 PCM (uncompressed digital audio) channels. This means the best you can get is 2 channel stereo normally. Movies and such are only able to get full surround sound because they send a compressed AC3 audio stream directly to the receiver instead of having it processed by your computer.



    The SOLUTION:


    Use Pulseaudio + a52 codec to create 5.1 channels of audio and then compress it into a Ac3 that can fit over SPDIF!


    Unforutely... though Ac3 is older then dirt (it was developed for Laserdisc and the first movies using it showed up in 1999) it is patented and thus taking advantage of true surround over SPDIF is more difficult then it should be.

    SIDE NOTE FOR AUDIOPHILES:

    For best audio quality for playing back audio you will want to use regular 2-channel PCM. This is uncompressed and thus is 100% quality. AC3 is a lossy compression and although it's runs at a high bit rate so it's generally better then the run of the mill mp3s it's still not as good as PCM. Luckily it is easy to switch between outputs with PA with a touch of a button.


    The QUICK'N'DIRTY:



    FIRST STEP: Get regular 2-channel PCM SPDIF working...

    Make sure your sound card is correctly configured. If you don't already use SPDIF out then it can be irritating.

    Most cheap onboard sound cards support the Intel High Definition Audio Standard.


    The theory goes that if the hardware supports this standard then you only need one driver to support all the different hardware. In practice Linux really does use just one driver: snd_hda_intel. However each type of card has all sorts of different I/O ports. Some have front ports, some have rear, some support TOSLink, others do not. So Linux needs to detect these differences and take into account the variations in the card. Unfortunately Linux does not get it right every time. So if you cannot get 'Digital Stereo Out' working on your audio card then this may be the problem.

    It happened to me on my video card. To override the audio detection on the Linux driver I had to make /etc/modprobe.d/intel-fix.conf

    The file contains the single line:
    options snd-hda-intel model=6stack-dig

    That tells it exactly what model it is. Sometimes this may even unlock some features. I think by default Linux tries to trust the BIOS, but BIOSes suck.

    To find out what model=???? your device is you can look at the documentation at /usr/share/doc/alsa-base/driver/HD-Audio-Models.txt.gz

    If your lucky you shouldn't have to deal with any of this. You'll be able to just connect your audio card right up to your home theater receiver with COAX or TOSLink and be able to sellect 'Digital Audio Duplex (IE598)' and have it all 'just work'.




    SECOND STEP: Get AC3 encoding working:


    Like i mentioned above... Ac3 is patented technology. Even though it's older then dirt it's still a issue. Most distributions, including Ubuntu, will not include it by default. So you have to compile it.

    A decent guide is at:


    For the sake of completeness.... Basically....

    make this be /etc/asound.conf:
    pcm.a52 {
    @args [CARD]
    @args.CARD {
    type string
    }
    type rate
    slave {
    pcm {
    type a52
    bitrate 448
    channels 6
    card $CARD
    }
    rate 48000 #required somehow, otherwise nothing happens in PulseAudio
    }
    }

    You can configure the a52 Alsa plugin to have different channels and such. With 'channels 6' that gives you 5.1 surround sound.



    Compile the a52 driver...
    cd /tmp
    sudo apt-get build-dep libasound2-plugins
    sudo apt-get install libavcodec-dev libavformat-dev
    sudo apt-get source libasound2-plugins
    cd alsa-plugins-*
    sudo ./configure
    sudo make
    cd a52/.libs
    sudo cp libasound_module_pcm_a52.la libasound_module_pcm_a52.so /usr/lib/alsa-lib/
    sudo alsa reload


    Now "killall pulseaudio" and let it respawn. It will re-read the asound.conf and realize you have a52 encoder enabled.

    Now were you previously selected 'Digital Audio Duplex (IE598)' you will see that 'Digital Surround Sound 5.1 (IE598/AC3) Output' has magically appeared.

    Select that and your ready to go!!

    If your stuff is correctly configured you can now go through the 'test speaker' dialog and test each speaker individually. Or you can run this command:
    speaker-test -c6 -t wav

    That way you have a lovely female voice telling you what the speaker does. The LFE does make it sound like somebody stuff a sock in her mouth though...




    THIRD STEP (Optional): eliminate upmixing.


    By default Pulseaudio will 'upmix' stereo sound sound that it will run on all your speakers. That is to take 2 channel audio and mix it to 5 channel audio. To me this is irritating as it never sounds quite right.

    To disable 'upmixing' go and edit '/etc/pulseaudio/daemon.conf' and change the following lines from:
    resample-method = speex-float-1
    ; enable-remixing = yes
    ; enable-lfe-remixing = no
    to:
    resample-method = speex-float-1
    enable-remixing = no
    enable-lfe-remixing = yes

    That way at least I still have my subwoofer for listening to music.


    Now killall pulseaudio again to make the changes go into effect.



    FINAL STEP: Use it!!


    Fire up Nexuiz. Find the sound options and change the settings from '2 speakers' to '5'


    Now it will make it a tiny bit easier to find out were those rockets coming from before they blow you up.
Working...
X