PDA

View Full Version : Sound on FreeBSD


corey_james
05-01-2008, 04:38 AM
Setting sound up on FreeBSD is quite simple and well documented but here's a simple how-to.

There are two ways to add sound support to FreeBSD - compile the driver into the kernel or dynamically load the driver. I'll just detail the latter as it's faster and easier.

First you will need to load the driver, if you know the driver name, you can load it straight away. If not, load the whole lot and hope one binds.

Depending which version of FreeBSD you are running it will be :
# kldload snd
or
# kldload snd_driver

If you have loaded all the sound drivers with the above command, you can see the specific driver you have loaded by doing the following

#cat /dev/sndstat
FreeBSD Audio Driver (newpcm: 32bit 2007061600/i386)
Installed devices:
pcm0: <VIA VT8237> at io 0xb400 irq 22 kld snd_via8233 [MPSAFE] (5p:1v/1r:1v channels duplex default)

In this case snd_via8233 is the driver being used.

To make sure this driver loads on boot, you'll need to edit /boot/loader.conf. In this case i would put the following in this file:
snd_via8233_load="YES"

If you want all the drivers to load ( for whatever reason ) you can put the following in loader.conf
snd_driver_load="YES"

References:
http://www.freebsddiary.org/sound.php
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/sound-setup.html

* Note: if anyone notices any errors in this how-to, please correct them

Carpetsmoker
05-01-2008, 04:43 AM
Here is a script that will load the sound drivers one by one, detect which one you're using, and add it to /boot/loader.conf.

This will work on any version of FreeBSD.

#!/bin/sh
#
# Detect sound driver

for driver in /boot/kernel/snd_*; do
driver=$(echo ${driver} | sed 's|/boot/kernel/snd_||')
if [ ${driver} = "driver.ko" ]; then
continue;
fi

kldload snd_${driver}
if [ -c /dev/mixer0 ]; then
echo "I'm smelling 'snd_${driver}'"
echo "snd_${driver}_load=\"YES\"" >> /boot/loader.conf
exit 0
fi
kldunload snd_${driver}
done

corey_james
05-01-2008, 04:44 AM
llaazzzyyyyy :P

starbuck
05-01-2008, 08:32 AM
Here is a script that will load the sound drivers one by one, detect which one you're using, and add it to /boot/loader.conf.

This will work on any version of FreeBSD.

#!/bin/sh
#
# Detect sound driver

for driver in /boot/kernel/snd_*; do
driver=$(echo ${driver} | sed 's|/boot/kernel/snd_||')
if [ ${driver} = "driver.ko" ]; then
continue;
fi

kldload snd_${driver}
if [ -c /dev/mixer0 ]; then
echo "I'm smelling 'snd_${driver}'"
echo "snd_${driver}_load=\"YES\"" >> /boot/loader.conf
exit 0
fi
kldunload snd_${driver}
done

Nice shell script. Any chance on seeing a "BSD Scripting 101" guide or a post with some useful tutorials?

corey_james
05-01-2008, 11:06 AM
starbuck - i don't mind writing one but it's hard when there's so much to scripting - PM me and we'll organise something

FloridaBSD
05-06-2008, 04:25 PM
starbuck.

IMHO your probably going to learn more from reading a manual like Unix Shell Scripting Third Addition By Sams.

anomie
05-06-2008, 04:48 PM
OT (sort of) learning material suggestions:

I'll second the suggestion to pick up a book as reference material. Personally, I really liked Sams Teach Yourself Shell Programming in 24 Hours (2nd Edition) by Sriranga Veeraraghavan. (I'd write a review on it, but someone at work stole it and I haven't read it in a couple years...)

Also, check out the Advanced Bash-Scripting Guide (http://www.tldp.org/LDP/abs/html/) from TLDP. Just keep in mind that sh != bash, exactly. :)

scottro
05-06-2008, 05:18 PM
I have a page with some links that *I* found useful.
http://home.nyc.rr.com/computertaijutsu/shellscripting.html

As was said, bash isn't shell, so think about keeping your scripts portable. For example, I wrote something on a Linux box that starts by checking if you're root. I used $UID instead of id -n, not realizing it was a bash-ism. (errm id -u, whatever.) We have some AIX machines as well, and that caused me a bit of embarrassment.

corey_james
05-06-2008, 10:13 PM
your mere existence is an embarrassment, young scottro!

DrJ
05-06-2008, 10:42 PM
... young scottro!
Move closer to the ear horn, please.