Ubuntu On Sony Vaio FW Series

Tips & Tricks related to Sony Vaio FW series laptops

Posts Tagged ‘sound

HDMI sound output switcher for PulseAudio

with 9 comments

Here is another script which you can link for example to AV Mode button, to switch sound output to HDMI and back. First I thought I can use Alsa, but it works only with one application, other application can not play sound while another one is playing. So then I did it with PulseAudio which works correctly. This switcher works for all native Gnome/gstreamer sound applications, and some applications e.g. SMplayer refuse to switch their sound regardles what default output set in PulseAudio. If you have playing sound and then switched to HDMI, it will still play through old way and you need to restart your sound e.g. push stop/play button to point sound through new way.

First of all you need to prepare PulseAudio configuration. For some point PA does not add HDMI output to devices itself. We should add it and rename internal sound card to something readable. Open /etc/pulse/defauld.pa in editor with root privileges (e.g. sudo nano /etc/pulse/default.pa in terminal) locate line “#load-module module-pipe-sink” there. Open terminal and run this command there: aplay -l | grep -o -e "card [0-9]:.*[0-9]:" | sed -e "s/card \([0-9]\): \(.*\) \[.*device \([0-9]\).*/load-module module-alsa-sink device=hw:\1,\3 sink_name=\2/"

Command returns two lines which we need to add to default.pa file after that line you located earlier. In my case this lines look like:


#load-module module-null-sink
#load-module module-pipe-sink
load-module module-alsa-sink device=hw:0,0 sink_name=Intel
load-module module-alsa-sink device=hw:1,3 sink_name=HDMI

### Automatically load driver modules depending on the hardware available

Then you should restart PulseAudio (sudo /etc/init.d/pulseaudio restart) to changes make effect. You can check that devices added correctly by running pacmd list-sinks in terminal, you should see “name: <HDMI>” and “name <Intel>” if you have got the same names as in my case, theese names must be the same as after “sink_name” in lines you added to default.pa.

Ok, now to switcher:


#!/bin/bash
#
# Sound output switcher using Gnome,gconf,PulseAudio,Alsa,libnotify
#
# by Anton Veretenenko <anton&#91;email sign&#93;veretenenko.ru>

notify_show=1
notify_delay=500
hdmi_card_num=1
internal_card_name=Intel
hdmi_card_name=HDMI

is_hdmi_on=`amixer -c $hdmi_card_num cget numid=4,iface=MIXER,name='IEC958 Playback Switch' | grep -i -c -P -e "values=on"`

if [ "$is_hdmi_on" == "1" ]
then
 amixer -c $hdmi_card_num cset numid=4,iface=MIXER,name='IEC958 Playback Switch' off > /dev/null
 gconftool --set "/system/gstreamer/0.10/default/musicaudiosink" --type=string "pulsesink device=\"$internal_card_name\""
 gconftool --set "/system/gstreamer/0.10/default/audiosink" --type=string "pulsesink device=\"$internal_card_name\""
 gconftool --set "/system/gstreamer/0.10/default/chataudiosink" --type=string "pulsesink device=\"$internal_card_name\""
 pacmd "set-default-sink "$internal_card_name""
 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI Off" "Sound output switched to $internal_card_name"
 fi
else
 amixer -c $hdmi_card_num cset numid=4,iface=MIXER,name='IEC958 Playback Switch' on > /dev/null
 gconftool --set "/system/gstreamer/0.10/default/musicaudiosink" --type=string "pulsesink device=\"$hdmi_card_name\""
 gconftool --set "/system/gstreamer/0.10/default/audiosink" --type=string "pulsesink device=\"$hdmi_card_name\""
 gconftool --set "/system/gstreamer/0.10/default/chataudiosink" --type=string "pulsesink device=\"$hdmi_card_name\""
 pacmd "set-default-sink "$hdmi_card_name""
 if [ $notify_show -eq 1 ]
 then
  notify-send -u normal -t $notify_delay -i gnome-sound-properties "HDMI On" "Sound output switched to $hdmi_card_name"
 fi
fi

Here you need to change hdmi_card_num to number of your HDMI sound card (you can get it by aplay -l in terminal) and internal_card_name to name you found earlier and hdmi_card_name to hdmi card name which you saw after “sink_name” parameter.

This switcher will show a popup notification, like you see when changing brightness 🙂

P.S. How to link this script to AV Mode button (XF86Launch2) read in post about headphones switcher script.


Written by egaistek

July 8, 2009 at 13:22

Posted in Vaio

Tagged with , , , , , , ,

Headphones/Front switch script

with 4 comments

I’m not defining a “hippo” model for “snd-hda-intel” to make headphones detection about we talk earlier. Because I’m using my headphones plug very rarely, I decided to write a shell script to switch sound to headphone and back and link it to to S1 button. This information could help you if you want to make S1 button to do something else too.

Here is a switch script, when you run it, it detects if headphones are switched on then it switch it off and vice-versa. Front mixer channel will be switched off if headphones switched on and vice-versa.


#!/bin/bash
# by Anton Veretenenko <anton&#91;email sign&#93;veretenenko.ru>

is_front_on=`amixer -c 0 cget numid=2,iface=MIXER,name='Front Playback Switch' | grep -i -c -P -e "values=on,on"`

if [ "$is_front_on" == "1" ]
then
 amixer -c 0 cset numid=2,iface=MIXER,name='Front Playback Switch' off
 amixer -c 0 cset numid=3,iface=MIXER,name='Headphone Playback Switch' on
else
 amixer -c 0 cset numid=2,iface=MIXER,name='Front Playback Switch' on
 amixer -c 0 cset numid=3,iface=MIXER,name='Headphone Playback Switch' off
fi

To link S1 button to this script (make a shortcut) you need to delete shortcut from System->Preferences->Keyboard Shortcuts for this button, if you have it. I guess you saw that S1 button named as “XF86Launch1” in keyboard shortcuts, you need this name later.

Open gconf-editor (Alt+F2, type gconf-editor, Run). On the left tree select apps->metacity->global_keybindings the on the right you should see a list of keys, select one you like (I choose “run_command_1”) and edit it (right click, Edit Key), enter name of S1 button (“XF86Launch1”) into value field. Then select “keybinding_commands”  on the left.

Edit “command_1” key, into value field you should enter path to the script, in my case it is “/home/egaistek/scripts/alsa-front-mute”. That’s all, it should work now.

P.S. Do not forget to add executable permissions to a script file (chmod +x in terminal or File->Properties, Permissions tab, set “Allow executing file as program” in Nautilus/File Explorer)

P.P.S. This works only for Gnome without Compiz running. If you want to add shortcuts with Compiz, use Compiz configuration tools.

Written by egaistek

July 7, 2009 at 07:49

Posted in Vaio

Tagged with , , , , ,

Headphones detection, auto switch off laptop speakers

with 26 comments

Thanks to Sean Carlos for pointing us.

Add this line into /etc/modprobe.d/options file:

options snd-hda-intel model=hippo

Then reboot and try to plug in your headphones.

Written by egaistek

January 3, 2009 at 07:12

Posted in Vaio

Tagged with ,

Make it Surround

with 7 comments

If you have movies with 5.1 or 4 channels, e.g. DVD, Blue-Ray etc. You can listen all this channels in you headphones! Without any expensive sound system.

Our Realtek chip which is installed in FW series have Virtual Surround technology based on HRTF.

Windows drivers have a switch to enable it in settings. But for Ubuntu it’s a little bit different. Ubuntu have ALSA audio system/drivers and have special plugin for HRTF which is not installed by default. You need to install alsa plugins package libasound2-plugins. Then open/create a file in your home directory named .asoundrc and type this text inside:

pcm.!surround51 {
        type vdownmix
        slave.pcm default
}

pcm.!surround40 {
        type vdownmix
        slave.pcm default
}

Now if player using all channels, vdownmix plugin downmix all channels into 2.

Here is how to enable all channels in SMPlayer (based on MPlayer). Goto Option->Preferences, on the left select General, select Audio tab and change there Channels by default to 6.

P.S. You can test surround with this command in terminal:


speaker-test -Dsurround51 -c6 -l1 -twav

This will make sound for each channel.

UPD: If you have some problems about can not open device etc, try this:


sudo alsa force-reload

Written by egaistek

September 15, 2008 at 05:49

Posted in Vaio

Tagged with , , , ,

The Sound

with 29 comments

I’m working on sound now. We have Realtek ALC262 sound chip in our laptop.

Headphones works with front speakers together, if you select headphones in mixer on switches tab. To enable headphones only, you should mute Front channel in mixer. (on my older vaio laptop front speakers are muted when i plug in headphones automatically)

I still not able to make builtin microphone work..

UPD: Microphone plugged in front jack is working ok.

UPD2: Add options snd-hda-intel model=hippo into /etc/modprobe.d/options to enable headphones jack detection, thanks to Sean Carlos.

Written by egaistek

September 13, 2008 at 02:59

Posted in Vaio

Tagged with , , , ,