Wednesday, February 10, 2010

Emacs Mouse Scrolling

I hate the default emacs wheel scrolling---each mouse wheel click is too far for me to track context. These settings go in my .emacs file so that the basic scroll is only 5 lines, Shift allows me more precision and the Control key lets me take bigger jumps.

; Mouse Wheel Scrolling
; Scroll up five lines without modifiers
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)
; Scroll up five lines with META held
(global-set-key [M-mouse-4] 'down-slightly)
(global-set-key [M-mouse-5] 'up-slightly)
; Scroll up one line with SHIFT held
(defun up-one () (interactive) (scroll-up 1))
(defun down-one () (interactive) (scroll-down 1))
(global-set-key [S-mouse-4] 'down-one)
(global-set-key [S-mouse-5] 'up-one)
; Scroll up one page with CTRL held
(defun up-a-lot () (interactive) (scroll-up))
(defun down-a-lot () (interactive) (scroll-down))
(global-set-key [C-mouse-4] 'down-a-lot)
(global-set-key [C-mouse-5] 'up-a-lot)

Tuesday, February 9, 2010

USB Sound on Ubuntu Karmic Linux

There are many guides and posts discussing how to debug/diagnose sound issues on Ubuntu/Linux. About six months ago, I bought a pair of Logitech S-150 USB Speakers thinking that these would be generally easier to manage than traditional analog speakers. Boy was I wrong. First I learned that my then-current OS, Ubuntu 9.04 Intrepid Ibex, had a version of pulseaudio which had poor support for USB speakers. After I got the speakers, I tried following various instructions to get them to work, but to no avail. My hopes were set on the next version of Ubuntu, Karmic, which was supposed to have proper support. However, when I upgraded, I was once again stuck without sound. I once again tried various sound support instructions, again with no luck. Particularly frustrating was the fact that many posts and guides seemed to ignore the possibility that you might have USB speaker ---much of the focus was on finding your sound card. But I don't have one! (well, I technically do, but it's turned off in the BIOS and I don't have speakers for it) In particular, here is the official Ubuntu sound troubleshooting guide. Note that there is basically zero discussion of USB speakers! I followed through anyway. When I looked at the Alsa card/driver matrix, I couldn't find "Logitech", but noticed the "usb-audio" driver. lsmod revealed no installed sound drivers earlier so it occurred to me that I might simply need to load the USB sound driver. Could it really be that simple? Is Ubuntu 9.10 Karmic simply not capable of loading USB sound drivers when USB speakers are attached? After modprobe, adjusting the master volume, and selecting the appropriate output device), I learned that the answer to these two questions is a resounding "Yes!" For the record, Windows XP didn't even require me to lift a finger to get the speakers working... Welp, I'm just happy to have sound again.

Here's a summary How-To for Ubuntu Karmic:

  • Run /sbin/lsmod | grep snd_usb_audio to see if you have the USB sound driver loaded.
  • If the above command shows nothing, run /sbin/modprobe snd_usb_audio to load the driver.
  • Next, open the Sound Preferences window (System > Preferences > Sound).
  • Click the "Output" tab and select "USB_Audio Analog Stereo".
  • Finally, set the "Output volume".
  • To test, run aplay /usr/share/sounds/alsa/Front_Center.wav
If you're still having trouble, read the Ubuntu sound troubleshooting guide