Surround Sound (5.1/7.1)– Bodhi with PulseAudio

This is my first detailed how to, feel free to comment or send me a private message if you have suggestions

This guide uses PulseAudio and gnome-media pacakages in order to get surround sound (both 5.1 and 7.1) out of your Bodhi machine through your HDMI connection. Surround sound is possible without these packages but is much more difficult to configure. Furthermore, “fast switching” between surround sound and on board sound is much easier with PulseAudio installed, as is keyboard shortcuts and GUI interface. Lastly, for those PulseAudio doubters, it’s gotten substantially better in the last year or so, I recommend giving it another try.

Also just found out that if you run flash it'll cut off other sound output until flash is closed, example clementine stops playing music when I start a flash video, once I close opera, clementine works again.

The guide will show how to:

  1. 1. Install packages necessary for the surround sound to work
  2. 2. Configure PulseAudio to use your 5.1 or 7.1 system
  3. 3. Show how to change between settings using PulseAudio’s GUI interface
  4. 4. Show how to create a script and use hotkeys so that you can quickly switch between configurations
  5. 5. Add gnome-sound app to startup
  6. 6. Change Volume Controls key-bindings to control new sound mixer vs. default bodhi sound mixer
  7. 7. Enable flash support

Step 1 – Installing Necessary Packages

Real Simple:

   sudo apt-get install pulseaudio gnome-media

This will install a few other packages, for me it added about 50 megs to my system

Step 2 -- Configure PulseAudio for your System

I have two methods for doing this, one is less “clean” but easier to do so I’ll explain both, starting with the easier method and you can decide which to use.

Method 1: Easier but Less “Clean”

  1. 1.Open terminal of your choice
               cd /usr/share/pulseaudio/alsa-mixer/profile-sets
               sudo leafpad default.conf
               
  1. Leadpad will open with PulseAudio’s profiles that are currently available for your system, you should see HDMI listed but it will not be surround sound, only 2.0 setup.
  1. 2.Append the code below to the bottom of the file:
[Mapping analog-mono]
device-strings = hw:%f
channel-map = mono
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-headphones analog-output-headphones-2 analog-output-mono analog-output-lfe-on-mono
paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line
priority = 1

[Mapping analog-stereo]
device-strings = front:%f hw:%f
channel-map = left,right
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-headphones analog-output-headphones-2 analog-output-mono analog-output-lfe-on-mono
paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line
priority = 10

[Mapping analog-surround-40]
device-strings = surround40:%f
channel-map = front-left,front-right,rear-left,rear-right
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-lfe-on-mono
priority = 7
direction = output

[Mapping analog-surround-41]
device-strings = surround41:%f
channel-map = front-left,front-right,rear-left,rear-right,lfe
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-lfe-on-mono
priority = 8
direction = output

[Mapping analog-surround-50]
device-strings = surround50:%f
channel-map = front-left,front-right,rear-left,rear-right,front-center
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-lfe-on-mono
priority = 7
direction = output

[Mapping analog-surround-51]
device-strings = surround51:%f
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-lfe-on-mono
priority = 8
direction = output

[Mapping analog-surround-71]
device-strings = surround71:%f
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
description = Analog Surround 7.1
paths-output = analog-output analog-output-speaker analog-output-desktop-speaker analog-output-lfe-on-mono
priority = 7
direction = output

[Mapping iec958-stereo]
device-strings = iec958:%f
channel-map = left,right
paths-input = iec958-stereo-input
paths-output = iec958-stereo-output
priority = 5

[Mapping iec958-ac3-surround-40]
device-strings = a52:%f
channel-map = front-left,front-right,rear-left,rear-right
priority = 2
direction = output

[Mapping iec958-ac3-surround-51]
device-strings = a52:%f
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 3
direction = output

[Mapping hdmi-stereo]
device-strings = hdmi:%f
description = Digital Stereo (HDMI)
paths-output = hdmi-output-0
channel-map = left,right
priority = 4
direction = output

[Mapping hdmi-surround]
description = Digital Surround 5.1 (HDMI)
device-strings = hdmi:%f
paths-output = hdmi-output-0
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 3
direction = output

[Mapping hdmi-stereo-extra1]
description = Digital Stereo (HDMI) nr 2
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = left,right
priority = 2
direction = output

[Mapping hdmi-surround-extra1]
description = Digital Surround 5.1 (HDMI) nr 2
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 1
direction = output

[Mapping hdmi-stereo-extra2]
description = Digital Stereo (HDMI) nr 3
device-strings = hdmi:%f,2
paths-output = hdmi-output-2
channel-map = left,right
priority = 2
direction = output

[Mapping hdmi-surround-extra2]
description = Digital Surround 5.1 (HDMI) nr 3
device-strings = hdmi:%f,2
paths-output = hdmi-output-2
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 1
direction = output

[Mapping hdmi-stereo-extra3]
description = Digital Stereo (HDMI) nr 4
device-strings = hdmi:%f,3
paths-output = hdmi-output-3
channel-map = left,right
priority = 2
direction = output

[Mapping hdmi-surround-extra3]
description = Digital Surround 5.1 (HDMI) nr 4
device-strings = hdmi:%f,3
paths-output = hdmi-output-3
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 1
direction = output
  1. 3. Save, Close & Reboot

Method 2: Harder but “cleaner”

  1. 1. Open terminal of your choice
      cd /usr/share/pulseaudio/alsa-mixer/profile-sets
      sudo leafpad default.conf
      
  1. 2. Scroll through the file and find how your system handles HDMI connections,look specifically at “device- strings”, you should see something like hdmi% or a52:%f.
  1. 3. Go through the code mentioned in method 1 above, copy and paste the appropriate profile(s) to the end of your default.conf file currently open.
  2. 4. Save, Exit, Reboot

My System Example

My system uses hdmi:%f and I only have a 5.1 setup so I took the following profile from the above code:

[Mapping hdmi-surround]
description = Digital Surround 5.1 (HDMI)
device-strings = hdmi:%f
paths-output = hdmi-output-0
channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
priority = 3
direction = output

Step 3 – Switching via PulseAudio's GUI Interface

You should now have “sound” listed under accessories → preferences → sound

In here you will be able to click the “hardware” tab where, click here, under profiles you'll see a list (depending on which method you used above), switching is as easy as clicking on the profile that you want

Your HDMI is now complete, the only thing is that sound is now controlled via pulseaudio, step 6 shows how to reset your volume keys to pulse instead of default bodhi mixer. Otherwise volume is now located in applications → preferences → sound

Step 4 – Using Terminal To Switch Profiles & Creating Bash Scripts/Hotkeys

Here I will provide one example and hope that it suffices for everyone to get their setup working for them.

  1. 1. Determine Your Card #
    1. Open a terminal of your choice:
   aplay -l
  1. Look for the HDMI entry and then take note of the card number listed, I think in most cases this will either be 0 or 1.
  1. 2. Get name of profile you want to use:
   cd /usr/share/pulseaudio/alsa-mixer/profile-sets
   sudo leafpad default.conf
  1. Look through the profiles, find the one that you want to use and find out it's name which is listed next to “Mapping”.
  1. 3. Set profile using terminal:
     pactl set-card-profile # output:PROFILE
     
  1. Where # is your card number and PROFILE is the profile you determined from step 2
  1. 4. (Optional) Create a bash script and then bind it to a keyboard shortcut
    1. Open a new leafpad file, paste the following into it:
     #/bin/bash 
     sleep 2 && pactl set-card-profile # output:PROFILE
     
  1. Where # is your card number and PROFILE is the profile you determined from step 2
  1. 5. Save the file wherever you like under whatever name you like, now in terminal, cd to the same directory and do the following command:
     chmod a+x FILENAME
     
  1. where FILENAME is the name you gave the file.
  1. 6. Setup key-binding using instructions on this thread: http://forums.bodhilinux.com/index.php?/topic/3781-solved-binding-keys-to-scripts/

Step 5 – Add gnome sound applet to startup (control volume, get to preferences faster)

  1. 1. Open a terminal and enter following commands:
     cd /etc/xdg/autostart
     sudo leafpad nm-applet.desktop
     
  1. 2. Save file as something else that makes sense for pulse sound
    1. I named mine “gnome-sound.desktop”
  2. 3. Edit file, the only line that really needs to be changed is “Exec” which needs to be made to say the following:
   Exec=gnome-volume-control-applet

I recommend changing the other things that make sense as well, but that's up to you

  1. 4. Save and close the file
  1. 5. Edit .order file
     leafpad /.e/e/applications/startup/.order
     
  1. 6.Add gnome-sound-app by appending to the end of this file the complete path to the file you created in step:

Example for mine is below

/etc/xdg/autostart/gnome-sound.desktop
  1. 7. Save and reboot and you should now have a new icon in your systray

Step 6 – Set Volume Key Bindings for PulseAudio

Special thanks to Nasa for pointing me in the right direction with this method

  1. Create a new bash file in whatever folder you want: Example below
  2. Paste the code from below into file, save
  3. Make executable
  4. Bind keys to executable

CODE:

 leafpad ~/volume.sh

paste this code:

 
#!/bin/bash

 # PulseAudio volume changer and osd for notify-osd
 # depends on: notify-osd, pulseaudio
 # original version (v1.1) by sen
 # current version (v1.2) by wecing

 # -- config --

 VOLUME_SAVE="/dev/shm/saved_vol"
 STEP=5
 VOLUME=$(( $(pacmd dump |grep set-sink-volume |cut -d" " -f3) / 655 ))
 DEVICE=$(pacmd dump |grep "set-sink-volume" |cut -d" " -f2)
 MUTED=$(pacmd dump | grep "set-sink-mute" | cut -d " " -f3)

 # -- increase volume --
 if [[ $1 = '-i' ]] && [[ VOLUME -lt 100 ]]; then
 if [[ VOLUME+STEP -lt 100 ]]; then
 VOLUME=$((VOLUME+STEP))
 else
 VOLUME=100
 fi
 # -- decrease volume --
 elif [[ $1 = '-d' ]]&& [[ VOLUME -gt 0 ]]; then
 if [[ VOLUME-STEP -gt 0 ]]; then
 VOLUME=$((VOLUME-STEP))
 else
 VOLUME=0
 fi
 # -- toggle mute --
 elif [[ $1 = '-t' ]]; then
 if [[ ! -d $VOLUME_SAVE ]]; then
 touch $VOLUME_SAVE
 fi
 if [[ VOLUME -eq 0 ]]; then
 VOLUME=$(cat $VOLUME_SAVE)
 else
 echo $VOLUME >| $VOLUME_SAVE
 VOLUME=0
 fi
 else
 exit 1
 fi

 SET=$((VOLUME*655))
 pacmd set-sink-volume $DEVICE $SET > /dev/null
 SET_MUTED=0

 if [[ VOLUME -eq 0 ]]; then
 SET_MUTED=1
 fi

 pacmd set-sink-mute $DEVICE $SET_MUTED > /dev/null

 # -- notify-osd --

 if [[ VOLUME -eq 0 ]]; then
 ICON=notification-audio-volume-muted
 else
 if [[ VOLUME -lt 25 ]]; then
 ICON=notification-audio-volume-off
 elif [[ VOLUME -lt 50 ]]; then
 ICON=notification-audio-volume-low
 elif [[ VOLUME -lt 75 ]]; then
 ICON=notification-audio-volume-medium
 else
 ICON=notification-audio-volume-high
 fi
 fi

 notify-send "Volume" -i $ICON -h int:value:$VOLUME -h string:x-canonical-private-synchronous:1

Make executable:

 chmod a+x ~/volume.sh

Attach to key bindings:

left click on desktop → settings → All → Input → Keys

Find your media buttons, attach them to “command” and make command the following (example is for volume down & using the path that I used in this tutorial)

 bash ~/volume.sh -d

for increase use -i and for mute use -t

I highly recommend using scripts because you can do niftier bash scripts that can handle multiple things at a time. Here is an example of my “Media Script” that I run that does the following:

  1. Sets video output to HDMI and turns off laptop monitor
  2. Sets sound to HDMI output using instructions in this thread
  3. Starts my media software
  4. All binded to “start+m”
#/bin/bash
sleep 2 && xrandr --output HDMI1 --auto &
sleep 4 && xrandr --output LVDS1 --off &
sleep 6 && pactl set-card-profile 0 output:hdmi-surround &
sleep 10 && xbmc

Just like that my laptop becomes a sweet media box, another key binding reverts it back to my daily machine.

Step 7 – Enable Flash Support

Special thanks to aus9-infrequent for figuring this one out

1.

sudo leafpad /etc/asound.conf

2. paste this into it

 pcm.pulse { 
  type pulse 
  } 
 ctl.pulse { 
  type pulse 
  } 
 pcm.!default { 
  type pulse 
  } 
 ctl.!default { 
  type pulse 
  }

3. save,close, reboot

User Feedback

surround_sound=ip
Did you find this article helpful?
Yes, right on the money!
 
83%(5)
Somewhat. Needs work.
0%(0)
Not really
 
17%(1)
Not at all.
0%(0)

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

Original Author - jmadero

 
surround_sound.txt · Last modified: 2012/05/04 11:54 by jmadero · [Old revisions]


© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks