You are here: Home Nerdy Thoughts Archive HP zv5410us ALSA

ALSA

Back Top Forward
This document is for historical purposes only. It is no longer relevant.

Advanced Sound Configuration using ALSA

The Linux kernel supports sound via the Advanced Linux Sound Architecture, or ALSA. By default Debian comes with sound drivers for your sound card, modules snd_intel8x0 and snd_intel8x0m. Your system should be running these modules out of the box. To install extra features to manage ALSA:

    apt-get install alsa-base als-utils

Note that when you plug in your headphones, the sound to the built in speakers may not be automatically muted. This is because HP wants to support surround sound. The idea is that you plug surround speakers into the headphones and the front two speakers stay active. Unfortunately, this requires software to mute the internal speakers when you plug in your headphones (instead of surround sound speakers). If you are running kernel 2.6.11 or greater, alsa will allow you (via alsamixer, or gnome-alsamixer) to use an option called "Headphone Jack Sense". If this option is checked, your sound should automatically switch to your headphones when you plug them in.

In your mixer (for example aumix or gnome-alsamixer), you will have Volume (or Master), PCM, and PCM2 (or headphones). PCM2 should control your headphones, while the volume will control your speakers. PCM will control the volume to devices such as xmms.

Multimedia Keys, volume control, screen brightness, lights (hotcut keys):

Getting multimedia keys working can be quite a pain. If you are using a window environment such as KDE or GNOME, you can get many of these keys working without having to do anything. In GNOME, launch Applications->DeskTop Preferences->Keyboard Shortcuts. You can setup most of your multimedia keys from here. KDE has similar functionality. Note that screen brightness works out of the box.

If you want to use a different window manager, or have your keys work across window managers, then you will have to use a separate daemon process to manage your keybindings. One such daemon is lineakd. While you could try and apt-get it, the current version in Debian-- 0.8.2 does not work. It is not 64bit ready, so I patched it and submitted the patches needed to make it work. Until they are incorporated, you are going to have to get the source code, apply my patch and build the packages. It is a lot of work, but it works fine.

Download lineakd here:
http://prdownloads.sourceforge.net/lineak/lineakd-0.8.2.tar.gz

Now that you have it, you will also need the patch here:
lineakd-0.8.2.amd64-2.patch

Before you get started compiling, you are going to need to apt-get some X header file libraries to compile against. Just apt-get the following files:

    libx11-dev
    libsm-dev
    xlibs-static-dev
    libxi-dev
    libstdc++6-dev
    libxmu-dev
    libxt-dev
    libxv-dev

Now you are ready to patch and build. First untar the tar.gz with:
    tar -xvzf lineakd-0.8.2.tar.gz;

You should have a directory lineakd-0.8.2. Move into the directory and put the patch in the same directory (via mv).

Now run the patch and build:
    patch -p1 < lineakd-0.8.2.amd64-2.patch;
    ./configure;
    ./make;
    ./make install;

Keep the source code around, you will need to run make uninstall if you wish to remove this program-- it was not installed  by Debian, and Debian does not know about it.

Now you need to setup the program. First choose a default keyboard configuration. Do this by running, as the user you wish to use:
    lineakd -C CPR3000Z

This will install a file in the current users home directory under .lineakd/lineakd.conf. Each time you run this command it will clobber this file. If you want all users to have access to a basic file, you can copy this to /usr/local/etc/.

Now you must tailor the settings to your desires. To do this, edit the lineakd.conf file with your favorite text editor. Following is an example of the options that need to be set in the file:

    AudioLowerVolume = /usr/bin/aumix -v -2 -vq
    AudioMute =        /usr/bin/aumix -v0 -vq   
    AudioNext =        /usr/bin/xmms -f
    AudioPlay|Pause =  /usr/bin/xmms -t
    AudioPrev =        /usr/bin/xmms -r
    AudioRaiseVolume = /usr/bin/aumix -v +2 -vq
    AudioStop =        /usr/bin/xmms -s
    Help =             /usr/bin/gnome-help
    Lock =             /usr/bin/xscreensaver-command -lock
    MediaPlayer =      /usr/bin/xmms
    Photo =            /usr/bin/gimp
    Sleep =            sudo /usr/local/bin/sleep.sh
    WWW =              /usr/bin/firefox

Now the patch you installed contains modifications to the keyboard definition file. In particular, it added Help, Lock, MediaPlayer and Sleep. X will not recognize these by default. Thanks to the R3000Z email board, and some tinkering, we have a solution to get them all working. Fireup your editor and create a file called setKeys.sh. Put the following in that file:

#!/bin/bash

setkeycodes e008 237 # MediaPlayer
setkeycodes e00a 127 # Lock
setkeycodes e00b 159 # Photo
setkeycodes e031 177 # Help

Put this file in /etc/init.d/. Make sure it is executable with chmod:

    chmod 755 setKeys.sh

This tells X to load the additional keys that you need. You will need to run it each time you start the computer. To do this automatically, tell Debian to run the file each time you boot, regardless of boot level:

    update-rc.d setKeys.sh start 80 2 3 4 5 .

Do not forget the period at the end. Now manually run the script: /etc/init.d/setKeys.sh

Potential Problem: Now, what if your computer is a slightly different model? Well, things just got more complicated for you. The values I put in setkeycodes are arbitrary. They may not work for you. Here is how to get some that do. Start up your text editor with setKeys.sh file loaded. Run the setKeys.sh script from the command line. Go to the /var/log/ directory. Now run the following:

    tail -f messages
Now, press the key that you are having problems with. If it states that it needs to be set, then the value in setkeycodes is not going to work for you. To get a value for you, google, guess, or stand on your head. Then put that value into the setkey.sh script referencing the key you cannot access (also: use getkeycodes to see what is currently being used- do not use an already set value.) Run the shell script and try again. When you get no response from the messages file, then you have found a working key. Kill the tail -f process with ctrl-c. Now the value you entered in the setkeycodes is not the same value that lineakd expects. Yeah, that would be to easy, would'nt it?

To get that value-- you must use a handy program called xev.  The reason the values are different is that one is for Linux and one is for X-- near as I can figure, anyway. Run the xev program and a window should launch:

    xev
After this window launches, look at the terminal you launched it from. Every time you move the mouse or press a key, it displays what happened in the terminal window. Now press that key you have set up. Look for the keycode value. If you have a value that truly works, then the console output will display an event. Look at the value for "keycode", that is the value that will tell lineakd what key is being pressed. Armed with the keycode from xev, open the global dictionary to lineakd in /usr/local/etc/lineakkb.def. Scroll down to your keymap,
CPR3000Z. Now change the number in that file associated with your key-- for example if you wish to set the Photo button to 123, then Photo = 123. Now, when you restart lineakd, you should be in business. Whew!

To start lineakd just run:

    lineakd &

After running this, your hotcut keys should work. If you don't want to remember to run lineakd every time you start up X, then you need to put it in a start file. A long time ago, people put this stuff in a file called .xsession. Well that actually worked, so someone had to go and mess with it. If you use a window manager besides GNOME or KDE, you will need to use the .xsession file. GNOME and KDE have "special" screens that are used to configure startup programs. You can tell GNOME to start lineakd by going through Applications->Desktop Preferences->Advanced->Sessions and then clicking on the tab marked Startup Programs. Make sure to give it a really high "order"-- or GNOME will start slow. 
 
Take
a look at your lineakd.conf file. You will notice in my example, I am using a shell script to make the computer "sleep". You will also notice that I am using aumix and xmms. Set these whatever you wish-- feel free to install suspd2 or use cdtools instead of xmms, etc. In case you are wondering, here are the contents of my sleep.sh script:

#!/bin/bash
# turn the monitor off
xset dpms force off
# -Y did not come back for me, your mileage may vary...
# so we will just spin down, but not go to sleep
/sbin/hdparm -y /dev/hda
As you can see, nothing fancy. Be careful with hdparm -Y, it shuts down the harddrive all right-- I had to power cycle the machine, as it would not send an event to awaken the hard-drive once shutdown. You will need to run this script with sudo if you are not root (man sudo). Be advised that the nvidia driver will not shut down the backlight to your display. This is a known bug, either use the nv driver, or wait for a new release to fix this bug.

The lineakd script above binds the mute button to aumix. This is not very good, as the mute button will only mute- it will not restore volume. In addition, the mute button has a light that can come on whenever the computer speakers are muted. This script does not make the light work. To fix just the light, you can use a program called mute_light, or to fix both issues, you can use a python program I wrote.

To use the mute_toggler program, which does not work around alsa resetting the volume, get the code from here:
http://lists.pcxperience.com/pipermail/linuxr3000/attachments/20050107/61a34457/mute_light_button_project.tar.bin

Now this file is suffixed .bin. Could not tell you why. It is a tar.gz. So just rename it or use the force option to gunzip.

It comes with a shell script called compile.sh that not only compiles it, but copies it without asking to a /usr/local/sbin directory. If you do not want this, do not run the script as root. Now change the lineakd.conf file to read:

    AudioLowerVolume = /usr/local/sbin/mute_light -=
    AudioMute =        /usr/local/sbin/mute_light --alternate
    AudioRaiseVolume = /usr/local/sbin/mute_light -+

The light will come on when you click mute, and go off when you click it again. The volume still does not reset properly however, as this is an ALSA issue.

To use MuteToggler.py:
Download the python program here. You will also need to apt-get python-dev. After that, untar the file, go into the alsamodule directory, and type make. In the same directory run the script MuteToggler.py to toggle mute functionality. This script will properly restore your volume setting,bind it instead of aumix to your mute button in lineakd.conf.
Back Top Next

Comments (0)

Need help?
QR VCAL version3 image

Use your smartphone to scan this QR barcode. vCard 3 business card data will be uploaded to your address book.

Alternately, download the business card manually.