Page 1 of 18 12311 ... LastLast
Results 1 to 10 of 180

Thread: HOWTO: Surround sound in pulseaudio

  1. #1
    Join Date
    Jan 2006
    Location
    Bristol, UK
    Beans
    275
    Distro
    Ubuntu 9.10 Karmic Koala

    HOWTO: Surround sound in pulseaudio

    Update 05/11/09: Attention everyone. This guide is now OUTDATED and no longer necessary. Configuring surround sound is now ridiculously easy in Ubuntu 9.10 (Karmic) - just go into the hardware tab in sound preferences, click the device to configure, then select a surround sound profile from the drop down box. There is NO NEED to use this guide at all any more!





    Note: This guide has undergone a major revision. It does not suggest editing system-wide configuration files any more, and HAL based auto-detection should still work even if you do it the "hard way".


    Hi everyone.

    I have an m-audio revolution 7.1 sound card and after struggling for a while to get surround sound, I thought that now I've succeeded it would be a good idea to post my experiences here. If you somehow mess up your sound following this guide, don't worry, if you followed my commands you will have taken backups. To restore these, skip to the end of the guide.

    This guide assumes you actually have surround sound speakers and have them all plugged into the appropriate sockets on the sound card. If you have a standard 2.1 setup, it will in 99% of cases only have one 3.5mm jack and will appear to the computer as 2.0 speakers. Following the guide in this case is probably quite a bad idea. A good rule of thumb is, if it works in windows, you have the right hardware and all the plugs are in the right places.

    First things first: PULSEAUDIO DEFAULTS TO ONLY TWO CHANNELS!

    The above is important to note before you go messing up your asoundrc or anything like that. It is probably VERY EASY to get surround sound working just by changing one config option.

    First copy the system config files to your home directory, we want to change these settings on a per user basis. If you have already modified the config files in ~/.pulse, you don't need to do this, it will erase your modified user settings.

    Code:
    cp /etc/pulse/daemon.conf /etc/pulse/default.pa -t ~/.pulse/
    The Easy Way

    If you have one of the following combinations of speakers, you are in luck, you can do it the easy way. If you have some other combination, skip to the next section.

    2.0, 4.0, 5.0, 5.1, 7.1

    Simply open a terminal and do:

    Code:
    gedit ~/.pulse/daemon.conf
    Scroll through until you find the lines that say:

    Code:
    ; default-sample-format = s16le
    ; default-sample-rate = 44100
    ; default-sample-channels = 2
    Uncomment the default-sample-channels line (remove the ; symbol) and change the number to however many channels you have. If you have 5.1, change it to 6. If you have 4.0, change it to 4 etc... Save and exit.

    Now restart pulseaudio (easiest way is to restart ubuntu) and bingo, surround sound should be perfectly working.

    If you have a surround sound setup not listed here, you need to do it the hard way. Sorry!

    The Hard Way

    You will need to use this method if you have one of the following speaker configurations:

    2.1, 4.1, 6.0

    Or pretty much anything else that isn't listed in the easy method above.

    WARNING: This method is a bit hackish and more likely to cause problems than the officially sanctioned "easy way".

    Why is it harder?

    Pulseaudio has a somewhat weird way for users to define what channels they want. There are essentially two ways of doing it as far as I can gather. The easy way is the method outlined further above, where pulseaudio allocates the number of channels you tell it to, but in a set order. The order goes:

    FL, FR, RL, RR, CEN, LFE, SL, SR

    So if you have a subwoofer and four speakers you're really in a bit of trouble here, because if you tell pulseaudio to use 6 channels, you get low frequency subwoofer sound, but surround sound movies send sound to a centre speaker that doesn't exist, and you don't get any voice on the front speakers. But if you tell pulseaudio that you have four channels, the subwoofer gets no sound. In this case you must define what channels to use manually.

    Open a terminal and type:

    Code:
    gedit ~/.pulse/default.pa
    Ok, skip to line 32. It's the bit that looks like:

    Code:
    ### Load audio drivers statically (it's probably better to not load
    ### these drivers manually, but instead use module-hal-detect --
    ### see below -- for doing this automatically)
    #load-module module-alsa-sink
    #load-module module-alsa-source device=hw:1,0
    .endif
    Now, you need to uncomment "load-module module-alsa-sink" and change it to something resembling the following:

    Code:
    ### Load audio drivers statically (it's probably better to not load
    ### these drivers manually, but instead use module-hal-detect --
    ### see below -- for doing this automatically)
    
    ### Manual config for configuring surround sound. Comment out line below to revert to defaults.
    load-module module-alsa-sink device_id=0 channels=5 channel_map=front-left,front-right,rear-left,rear-right,lfe
    
    #load-module module-alsa-source device=hw:1,0
    .endif
    Ok, you can see above that I have used my own manual channel configuration as an example. In my setup, I have 4.1 speakers and one sound card.

    You can configure your own system by replacing my configuration line with the following template. It's important to note here that the order of these channels makes a difference. If you find that some channels are reversed, eg centre/sub is swapped with rear right/left, then you can simply change the order they are allocated to swap them back round again. Most sound cards will want these channels allocated in the usual way.

    Code:
    load-module module-alsa-sink device_id=X channels=X channel_map=x,x,x,x,x,x,x
    NOTE: One user reports:
    I have to point out only one thing: in my default.pa, when manually loading sink and source, I had to specify device=hw:0, not device=hw:0,0, nor device_id=0, otherwise I got alsa_ctl complaining about extra parameters, or surround51 unavailable (launching PA from terminal)

    For reasons why this is a problem, see this link, quoted below:

    If you select the default ALSA device to be "pulse", you need to make sure that PA doesn't try to open the "default" device for its own audio output. If you previously were loading module-alsa-sink without special device argument this means you have to change it to the raw "hw:0" devices. Example:

    load-module module-alsa-sink device=hw:0
    load-module module-alsa-source device=hw:0
    This obviously only applies to you if you have previously modified your asoundrc to make pulse your default alsa device.


    • device_id - This is of course the id of your card. If you have one sound card, this is likely to be 0, but might be different if you have more than one card.
    • channels=X - The X should be replaced by the total number of channels you wish to use
    • channel_map=x,x,x,x,x,x,x - This is a comma separated list of values that tell pulseaudio which channels to use. It's probably a good idea to stick to the same order that pulseaudio uses (listed at the beginning of the guide) but skip out which channels you don't want. Here is an exhaustive list of valid channel names:

      The currently defined channel names are: left, right, mono, center, front-left, front-right, front-center, rear-center, rear-left, rear-right, lfe, subwoofer, front-left-of-center, front-right-of-center, side-left, side-right, aux0, aux1 to aux15, top-center, top-front-left, top-front-right, top-front-center, top-rear-left, top-rear-right, top-rear-center, (Default depends on the number of channels and the driver)

      It's probably best to stick to some combination of the following:

      front-left, front-right, front-center, rear-center, rear-left, rear-right, lfe, side-left, side-right


    NOTE: If you have a subwoofer, it's almost certainly more desirable to load it as "lfe", NOT "subwoofer". "Lfe" means low frequency effects. This may seem counterintuitive, but as far as I can tell, the subwoofer channel is almost always labelled "lfe".

    When you have finished, save and exit the file. You will need to restart pulseaudio for the changes to take effect. The easiest way to do this is to restart ubuntu.

    Finished!

    When you boot up, you should have surround sound on all the channels you specified, and output channels for which there is no corresponding output device should be automagically upmixed into the other speakers. Try it out with a surround sound movie or music track. If this works, well done, you've done it. Alternatively, if you have added the pulseaudio device in your asoundrc, you can use the command:

    Code:
    speaker-test -c #channels
    Replace #channels with the number of channels you have, eg for a 5.1 channel system, put 6 here.

    If you don't get surround sound, first check the channels aren't actually muted. Open a terminal and type

    Code:
    alsamixer
    Make sure all the volumes for the channels you want are up. If your alsamixer looks like this:



    You may need to try shared or independent surround, and make sure surround is unmuted. (If anyone has more information about this, I'll include it here).

    NOTE: If you have swapped channels (eg centre/sub is swapped with rear right/left) then it's pretty easy to swap these back. This is a common problem with ICH4 and ICH5 cards, and the solution is explained on page 2 of this thread.

    If you have no sound, or it's all gone horribly wrong somehow, don't panic! Open a terminal and type the following:

    Code:
    cp /etc/pulse/default.pa ~/.pulse/default.pa && cp /etc/pulse/daemon.conf ~./pulse/daemon.conf
    Reboot ubuntu, and sound will be back how it was before.

    I hope this guide was helpful! If you have problems, please post in this thread and include the contents of ~/.asoundrc, ~/.pulse/daemon.conf and ~/.pulse/default.pa. Also useful would be the result of:

    Code:
    aplay -L && aplay -l
    You should also open a terminal and type the following:

    Code:
    pulseaudio -k && pulseaudio -vv
    then post the output here along with your configuration files. Please post the contents of the files in a text file attachment, otherwise it makes the thread very long and unreadable, thanks! Please also bear in mind I am not a developer, just a normal user, but I've got a bit of experience with pulseaudio and I'll do my best to help.

    Sam
    Last edited by sammydee; November 5th, 2009 at 05:09 PM.

  2. #2
    Join Date
    Apr 2007
    Beans
    3

    Re: HOWTO: Surround sound in pulseaudio

    Thank you very much, sammydee - I hadn't found that tidbit about pulseaudio defaulting to 2 channel, which was the ticket I needed to surround sound on my Revolution 5.1. Your just saved me additional hours of headache (or maybe gave me one, since I'll be blaring music on all four speakers once again).

  3. #3
    Join Date
    Jan 2006
    Location
    Bristol, UK
    Beans
    275
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Surround sound in pulseaudio

    Thanks Chris, glad I could save someone else the two days of searching it took me to figure this out

    I asked on the irc channel yesterday, and it appears that some time in the future this mess with the surround channels will be reolved, and sound card will be visibile in pavumeter with a list of "ports" that can be enabled and disabled at will, so you can point and click to get any combination of speakers you want. That won't be out until at least the next ubuntu release though.

  4. #4
    Join Date
    Mar 2008
    Location
    Vimercate (MI), Italy
    Beans
    126
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Surround sound in pulseaudio

    Good guide, sammydee

    I only have one problem: my center and rear channels are swapped (compared to Windows), so I hear center and lfe coming out, respectively, from rear-left and rear-right. And vice versa.

    Since I still need Windows, and there everything works correctly (drivers tell me to put some jacks here and there, and sound comes out from where it's supposed to come out), I just don't want to swap rear and center jacks everytime I boot into Ubuntu.

    I tried to remap my channels using PA's module-remap-sink, but if I choose the remapped sink as output, PA dies horribly.

    Do you know, by chance, how could I fix that? (I mean remapping channels, not PA )

    EDIT: My sound card is a Realtek ALC650, integrated into my motherboard; lspci gives
    Code:
    [m3ur1@Daemia: ~]$ lspci | grep audio
    00:1f.5 Multimedia audio controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller (rev 02)
    Here's my configuration

    /etc/pulse/default.pa (I removed comments)
    Code:
    .nofail
    
    load-sample-lazy pulse-hotplug /usr/share/sounds/startup3.wav
    
    .fail
    
    load-module module-alsa-sink device=hw:0,0 sink_name=AC97 channels=6 channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe
    load-module module-remap-sink sink_name=RealtekALC650.Playback master=AC97 channels=6 master_channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe channel_map=front-left,front-right,front-center,lfe,rear-left,rear-right
    load-module module-alsa-source device=hw:0,0 source_name=RealtekALC650.Capture channels=2
    
    .ifexists module-esound-protocol-unix.so
    load-module module-esound-protocol-unix
    .endif
    load-module module-native-protocol-unix
    
    load-module module-volume-restore
    
    load-module module-default-device-restore
    
    load-module module-rescue-streams
    
    load-module module-suspend-on-idle
    
    .ifexists module-gconf.so
    .nofail
    load-module module-gconf
    .fail
    .endif
    
    .ifexists module-x11-publish.so
    .nofail
    load-module module-x11-publish
    .fail
    .endif
    /etc/pulse/daemon.conf (again I removed comments)
    Code:
    default-sample-rate = 48000
    default-sample-channels = 6
    and, finally, my /etc/asound.conf
    Code:
    pcm.pulse {
        type pulse
    }
    ctl.pulse {
        type pulse
    }
    pcm.!default {
        type pulse
    }
    ctl.!default {
        type pulse
    }
    Using paplay from the console, if I choose RealtekALC650.Playback as output sink, I get this (and then PA dies)
    Code:
    [m3ur1@Daemia: ~]$ paplay --device=RealtekALC650.Playback sample.wav
    Connection failure: Connection terminated
    Stream errror: Connection terminated
    [m3ur1@Daemia: ~]$
    Any ideas?
    Last edited by MeURi; May 16th, 2008 at 10:14 AM. Reason: Missed hardware information
    2B OR (NOT 2B) That is the question. The answer is FF

  5. #5
    Join Date
    Jan 2006
    Location
    Bristol, UK
    Beans
    275
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Surround sound in pulseaudio

    Aside from the obvious suggestion of switching the physical jacks around and just leaving them in the wrong sockets (hey, if it works...), I'm not sure what to suggest.

    I've found the #pulseaudio channel on irc.freenode.net to be helpful sometimes, however it seems to be a bit sporadic that someone actually replies to your question.

    module-remap-sink documentation is here but it is pretty sparse. It's probably a good idea to leave comments in when you paste config files here, it makes it easier to read .

    Now I haven't tried using the remap sink function yet, but to switch lfe and centre with front left and front right you used:

    Code:
    load-module module-alsa-sink device=hw:0,0 sink_name=AC97 channels=6 channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe
    load-module module-remap-sink sink_name=RealtekALC650.Playback master=AC97 channels=6 master_channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe channel_map=front-left,front-right,front-center,lfe,rear-left,rear-right
    load-module module-alsa-source device=hw:0,0 source_name=RealtekALC650.Capture channels=2
    First, it might actually work if you just tell pulseaudio the channels in a different order and forget module-remap-sink:

    Code:
    #load sink
    load-module module-alsa-sink device=hw:0,0 sink_name=AC97 channels=6 channel_map=front-left,front-right,front-center,lfe,rear-left,rear-right
    #load source
    load-module module-alsa-source device=hw:0,0 source_name=RealtekALC650.Capture channels=2

    Failing that, I would suggest using something more like this:

    Code:
    #load sink
    load-module module-alsa-sink device=hw:0,0 sink_name=AC97 channels=6 channel_map=aux0,aux1,aux2,aux3,aux4,aux5
    # load virtual swapped sink
    load-module module-remap-sink sink_name=RealtekALC650-Playback master=AC97 channels=6 master_channel_map=aux0,aux1,aux2,aux3,aux4,aux5 channel_map=front-left,front-right,front-center,lfe,rear-left,rear-right
    # load source
    load-module module-alsa-source device=hw:0,0 source_name=RealtekALC650.Capture channels=2
    It looks a bit dirty but I think it will work. The problem I think, it that you already assigned all the channels on the first card to actual used channels, so then the virtual sink couldn't use it. I substituted aux channels in place of the real channels then remapped them with module-remap-sink.

    Let me know if you have any luck.

    sam

  6. #6
    Join Date
    Mar 2008
    Location
    Vimercate (MI), Italy
    Beans
    126
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Surround sound in pulseaudio

    Thanks for the quick reply

    I created my remapped configuration looking at PA official docs (the same link you posted), yet I kept original channels name instead of aux# because I tried something more human-readable like fl,fr,rl,rr and so on, but PA failed to start (maybe I was doing something wrong elsewhere, but changing them to the original names solved the problem)

    Well, using your naming suggestion didn't help, sadly (but PA starts without complaining)... I mean, the remapped sink should be ok, yet I got the same error using paplay, and PA dies (the same happens if I use any other app trying to reproduce sounds)

    The main issue with exchanging jacks is that I should go under my desk every time I boot into Ubuntu, watching out for dust and cables, and then again if I reboot into Windows... I mean, it's not that pleasant

    I'll try to use a different channel order and see if it works, without remap-sink

    Stay tuned
    Last edited by MeURi; May 16th, 2008 at 11:32 AM. Reason: Typo
    2B OR (NOT 2B) That is the question. The answer is FF

  7. #7
    Join Date
    Mar 2008
    Location
    Vimercate (MI), Italy
    Beans
    126
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Surround sound in pulseaudio

    Ok, PA starts without complaining, but it still seems to me that I have swapped channels

    Maybe it's just an impression, but if I use MPlayer and remap channels within it, it gives me a better feeling (better than Totem and VLC when playing 5.1 audio in DVDs or whatever)

    I tried also doing a speaker test, but I got the following:
    Code:
    [m3ur1@Daemia: ~]$ speaker-test -Dpulse -c6 -twav
    
    speaker-test 1.0.15
    
    Playback device is pulse
    Stream parameters are 48000Hz, S16_LE, 6 channels
    WAV file(s)
    Rate set to 48000Hz (requested 48000Hz)
    Buffer size range from 43 to 349525
    Period size range from 21 to 87382
    Using max buffer size 349524
    Periods = 4
    was set period_size = 87381
    was set buffer_size = 349524
    *** PULSEAUDIO: Unable to create stream.
    Unable to set hw params for playback: Input/output error
    Setting of hwparams failed: Input/output error
    speaker-test: pcm_pulse.c:115: pulse_stop: Assertion `pcm->stream' failed.
    Aborted
    2B OR (NOT 2B) That is the question. The answer is FF

  8. #8
    Join Date
    Jan 2006
    Location
    Bristol, UK
    Beans
    275
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Surround sound in pulseaudio

    I think the reversed channel order is a common problem with intel ich4 and ich5 chipsets, do you have one of these (try lspci | grep ICH)?

    It is also possible that windows has it wrong - can you swap the channels round in windows?

    Sam

  9. #9
    Join Date
    Mar 2008
    Location
    Vimercate (MI), Italy
    Beans
    126
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Surround sound in pulseaudio

    I edited my first post inserting my hardware information, but you had already replied, so I think you missed it... well, no problem

    Yes, I have an ICH4 chipset, and I'm using the onboard audio controller. I hoped to get it working Windows-like with PA... maybe it's just a matter of trial-and-error before getting it to work properly

    Under Windows I don't think I can swap channels, but I have to check; anyway, my 'problem' is posted here because I come from Windows (and still use it), if I tried Windows coming from Ubuntu, I'd probably say that Windows swaps my channels

    As far as I can use MPlayer to have a 'correct' output, I don't complain too much (since I notice channel swapping only with real 5.1 audio, not with upmixed stereo); but one question arises: if the channel swapping is a common problem, why doesn't it get corrected? No flaming purpose, here, I just wonder...

    Thanks for your replies
    2B OR (NOT 2B) That is the question. The answer is FF

  10. #10
    Join Date
    Jan 2006
    Location
    Bristol, UK
    Beans
    275
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Surround sound in pulseaudio

    It'd probably a good idea to check out the irc channel to see if they have a solution MeUri. I'll have a look now and see if I can get anything out of them.

    Sam

Page 1 of 18 12311 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •