Archive for December, 2009

Fixing garbled or popping sound on Intel sound cards in Ubuntu Karmic

December 18th, 2009

Update: this doesn’t appear to solve the problem 100%, but I am experiencing it much less often.

Enhancing my love/hate relationship (towards the ‘hate’ side) with Ubuntu is a nasty audio glitch introduced in Karmic for some Intel sound cards. Different people describe it differently: I’ve heard it described as random ‘popping,’ but my symptom is more like ‘laptop randomly starts sounding like a garbage disposal until you run $>killall pulseaudio’. I’ll be listening to an MP3 through Banshee, and randomly when it goes to the next track, every subsequent sound will sound like a train wreck until I kill the pulseaudio process. Some MP3s are more consistent than others with this problem.

Either way, I’ve found a potential fix for this problem. Here goes:

  1. Open the ALSA configuration file using GEdit as root from the terminal:

    user@computer:$ gksudo gedit /etc/modprobe.d/alsa-base.conf

  2. At the very end, you should find a line that looks like this:

    # Power down HDA controllers after 10 idle seconds
    options snd-hda-intel power_save=10 power_save_controller=N

    You want to comment out the line starting with ‘options,’ so that it looks like this:

    # Power down HDA controllers after 10 idle seconds
    #options snd-hda-intel power_save=10 power_save_controller=N
  3. Save the file and restart Pulseaudio by running:

    user@computer:$ killall pulseaudio

That should solve your sound problems.

Turn your laptop screen off with a keyboard shortcut in Ubuntu Karmic

December 18th, 2009

Back in the pre-Karmic days (or, the good ole’ days, as I call them) you could turn your laptop screen off by issuing this simple command:

user@computer:$ xset dpms force off

I had a nice script set up and mapped to a keyboard shortcut to turn my screen off whenever I wanted (say if I was using my laptop to play music and wanted to save some battery life). In Karmic, however, a regression causes this command to turn your screen off only briefly. After a few seconds, your screen will turn back on, on its own. This might be an Intel-specific problem—I have the misfortune of having an Intel video card on my Ubuntu install—but I’m not sure.

To get around this problem, I created a slightly different (and slightly less ideal) script that turns the screen off when a shortcut key is pressed, and then turns it back on after they same key is pressed again. Here’s how to get it for your own laptop:

  1. Create a new file using Nano. I put it in a directory called .scripts, you can put it wherever you like:
    user@computer:$ nano ~/.scripts/screen-off
  2. Paste the following into your new file using ctrl+shift+v:
    #!/bin/bash
    screenOffLockFile=/tmp/screen-off-lock

    if [ -f $screenOffLockFile ];
    then
            rm $screenOffLockFile
    else
            touch $screenOffLockFile
            sleep .5
            while [ -f  $screenOffLockFile ]
            do
                    xset dpms force off
                    sleep 2
            done
            xset dpms force on
    fi

    (An explanation follows). Press ctrl+x to quit Nano, then y to save your script.

  3. Make the script executable:

    user@computer:$ chmod u+x ~/.scripts/screen-off
  4. Open the System menu, go to Preferences, then Keyboard Shortcuts (or press alt+f2) and run gnome-keybinding-properties.
  5. Click Add, enter ‘Turn Off Screen’ under Name and ‘~/.scripts/screen-off’ (without quotes) under Command.
  6. After you’ve added the command, it will appear under the Custom Shortcuts header. Click on your new command to assign it a shortcut key of your choice (I use ctrl+alt+shift+s).

And that’s it. Press your shortcut key to turn your screen off, and press the shortcut key again to turn it back on.

What the script does

When you first press the shortcut key with your screen on, the script will check if there’s a certain file in your /tmp/ directory. If it doesn’t find it, it will create it and then enter an infinite loop that turns your screen off every 2 seconds if the special file still exists (thus working around Karmic’s regression). When you press the shortcut key with your screen already off, it will delete the file and do nothing else, causing the first instance of the script to exit its infinite loop (since it no longer sees the special file) and turn your screen back on again.

It’s as simple as that. It’s not as ideal as the pre-Karmic solution, but it’ll have to do until Canonical QA gets their act together.

Getting localhost to work over HTTP in VirtualBox

December 2nd, 2009

For some reason, VirtualBox doesn’t consistently resolve localhost to the host machine’s IP. Sometimes it’ll work, sometimes it’ll bounce you to the dns error page. To fix this, just add this to your c:\windows\system32\drivers\etc\hosts:

10.0.2.2 [your computer name]

That’s it–you should now be able to do things like http://localhost:8080/