Use ALSA for OSX Sounds


A follow up to a much earlier post using the same idea I’ve modified my old command line shell script to handle .m4a and partially .aif files. The catalyst was my neighbor on the other side of my cube wall. He got tired of hearing my Kopete blips and I’ll admit they do sound annoying. So now I opted for the much softer TokyoTrainStationAdiumSoundset from Apple’s adium IM client. Pulling these sounds over was the fun part. Using Konqueror, I drill into my Mac with the “fish://” protocol and navigate to /Applications/Internet/Adium.app/Contents/Resources/Sounds where all of my Adium sound sets await, eager to invade my hungry little ear drums. I copy them to a folder locally. (Alternatively I could have opened the Adium application bundle in Finder by command tapping or right clicking or two-finger tapping and choosing “Show Bundle Contents”. I could then use MacFuse/MacFusion which is always broken after a run of Mac Janitor and mount my Linux box to push the files over.) I then dump my earlier shell script somewhere in my path (I named it alsa-play this time) and use it to configure Pidgin. (The same will work with Kopete though I’m using Pidgin now because Kopete has been acting very funny. The big problem is that Kopete refuses to communicate with my buddy’s WinXP install of Pidgin… so many variables, so little time to chase them all!) I apt-get install faad which is a command line tool for decoding Apple audio files. Here’s the painful part, figuring out which command line parameters to pass to both faad and aplay. (aplay is the command line tool for jamming audio 1s and 0s into your sound card which, in turn, shoves these 1s and 0s down the thin black cable connected to your speakers which eventually convert the numbers into sound by rattling those pricey paper cones located inside their towers. Its amazing how much I’ve learned about audio… can you tell how much I love the study of sound?) After various iterations of producing garbled nonsense from failed commands I learned that I was missing an “-f cd” flag on aplay. Who would have known? I’m not even sure I remember what the flag means. Here’s the finished script. (Remember it assumes you have faad, oggdec, and mpg123 installed for conversion puurposes.)

#!/bin/bash

case $1 in

   *.m4a|*.aac|*.aif) faad -w -q $1 | aplay -q -t wav -f cd
   ;;

   *.ogg) oggdec -Q -o - "$1" | aplay -q &
   ;;

   *.wav|*.voc|*.wav|*.au|*.raw) aplay -q $1 &
   ;;

   *.mp3) mpg321 -o alsa $1 &
   ;;

   *) echo "unsupported file type $1"
   ;;
esac