Changing the default sound output

The typical method is to relink /dev/dsp to the desired /dev/oss/.../ device. e.g.

sudo ln -sf /dev/oss/oss_sbxfi0/pcm0 /dev/dsp

The device node matching the desired sound output can be discovered by running 'osstest' (and seeing which node produces the desired output) or by examining 'ossinfo -a' (displays list of nodes).

Modern OSs put /dev on a ramdisk (i.e. it gets erased in boot), so we need to the new correct setting remains. OSSv4.2 and above stores /dev/dsp setting in $OSSLIBDIR/etc/legacy_devices, so these should be saved automatically as long as OSS is shut down properly (You can run "sudo ossdevlinks" to save this manually).

OSSv4 before version 4.2, requires editing the $OSSLIBDIR/soundon.user file and readding the relinking command there. You will have to give the soundon.user file executable permissions using "sudo chmod +x" command. If the file doesn't exist, you may create it. This method also works in newer OSSv4 versions.

It's recommended to make vmix attach to the newly default device. vmix is OSSv4's software mixer and multiple programs will not be able to use the output at the same time if it's not attached. Since the default output was changed, vmix will have to be set to attach to the new output.

In OSS 4.1 and above, add a "vmixctl attach" command to the $OSSLIBDIR/soundon.user file (same procedure as above). You may wish to also add "vmix_no_autoattach=1" to the $OSSLIBDIR/conf/osscore.conf file. "vmixctl attach" syntax looks like this:

vmixctl attach /dev/oss/oss_sbxfi0/pcm0 /dev/oss/oss_sbxfi0/pcmin0

The second and third argument represent output and input nodes for vmix to attach to, allowing full duplex when /dev/dsp is used. However, the third argument can be omitted in some cases. See "vmixctl" manpage for explanation.

In OSS 4.0 you'll need to set vmix_masterdev in $OSSLIBDIR/conf/vmix.conf file.

Alternative: If the default output is set to an onboard soundcard and you're using another card, you can just disable onboard audio in the BIOS, and it won't be seen by OSS.

Alternative: $OSSLIBDIR/etc/installed_drivers influences the order of sound cards set by ossdetect. By removing other devices or moving the desired sound card to the first place, the default device can be modified. After the change, restart OSS and run "sudo ossdevlinks -v -r" and it will relink /dev/dsp for you.

The root directory $OSSLIBDIR can be found by checking /etc/oss.conf. It is almost always /usr/lib/oss/.

Recording sound output of a program

There are two main scenarios here:

Trying to record the entire desktop. Since more than one app may be playing, we want the total mixed output.

Trying to record one specific app. This can be accomplished using solutions for the above (if nothing else is playing), but there are some more options here.

Recording total mixed output

Many drivers offer a 'vol' mixer control. If this can be used as a recording source, than the current sound output will be recorded. Note that this is the mixed total of all sound played, not of a single program.

ossrecord -ivol blah.wav

ossmix vol.rec ON #sets 'vol' as default target, so any recording program uses it by default

Some drivers have a 'loopback' mixer control, which offers similar functionality. This can be set by ossmix or ossxmix mixer control programs.

vmix loopback driver can record the mixed output of sound played. Set vmix_loopdevs to 1 (or 2) in $OSSLIBDIR/conf/osscore.conf, and restart OSS. Then record from the newly created loopback device ("ossinfo" command will display the device list, including the new device). Note that this is the mixed total of all sound played via vmix, not of a single program.

ossrecord -s48000 -b16 -c2 -d/dev/oss/oss_hdaudio0/loop0 test.wav

Note that if vmixctl is used to (re)attach vmix, than 'ossdetect -d' is needed to be used after vmixctl to create the loop device.

Old OSSv4 versions (v4.0 before build 1016), used vmix.conf and not osscore.conf for this purpose, using the line "vmix1_numloops=1". Recording from vmix loopback didn't work in OSSv4.0 build 1016.

The recording program should expect the format, number of channels and sample rate to be the same as the ones used by vmix to "talk" to the device. The rate can be seen in the mixer (via ossxmix or ossmix) and set via the "sudo vmixctl rate" command. The number of channels is set via vmix0-channels control in the mixer (this is typically set to "Stereo"). The format is typically signed 16 bit. For example, if the above ossrecord line gives an error like: /dev/oss/oss_hdaudio0/loop0 doesn't support 2 channels (8), then vmix0-channels should be set to stereo.

Recording output of a single program

OSS wrappers can be used to record the output of a program. vsound is one such wrapper. (vsound doesn't handle output to /dev/oss/* device nodes, but all OSS-supporting programs are/can be easily made to output to /dev/dsp).

vsound ossplay test.wav

oss_userdev or oss_audioloop can also be used to record the output of a single program. Both the recorder and player will need to use the new node created by these drivers, and the recorder has to explicitly set up the appropriate format. oss_userdev can be used to serve multiple clients. See "oss_audioloop" and "oss_userdev" manpages for more information.

During use of oss_userdev, a new mixer device is created. You'll have to run "sudo ossdetect -d" in order to be able to use it.

Running a command immediately after OSS is loaded

Make sure that soundon.user has the executable bit set (it is not set by default).

One possible use of this is to have some volume controls set to a fixed level after OSS is started, regardless of their previous level last time OSS was run (by default, OSS restores the previous volume for all controls).

Using multimedia keys with OSS

First, we should check if the keys are recongnized by X11 or some other program. Run xev, and see if pressing the keys elicits a response.

If it does not, than we must make the keys be recognized by X11/WM/etc., before they can be used for anything. This is outside the scope of this wiki, but is documented at [1] and at [2]. Some WMs, once set up, will automatically connect the multimedia keys to appropriate functions.

If the above does not work or is not applicable, we can connect the keys to external scripts which will perform the appropriate function (See examples below). The method to connect external scripts to keys is better described at [3] and at [4] again.

For example in KDE, you can start the "Control Center", enter "Regional & Accessibility" -> "Input Actions", click on "New Action" and make its type "Keyboard Shortcut -> Command/URL", and then set the multimedia key to launch the script. (Names can be different due to localizations).

OSSv4.1 includes an ossmix which allows you to change volume in a relative fashion: 'ossmix vmix0-vol -- -2' and 'ossmix vmix-vol +2'. The two scripts below can be used to have this functionality in OSSv4.0:

We need to prune out the OSS emulation modules, since these might conflict with actual OSS, so run "rm -rf kernel/sound/core/oss".

Second, goto /usr/lib/oss/cuckoo, and run "make install".

You can now run "modprobe cuckoo", and test with "speaker-test" etc. whether this works.

To make this stick, we need to edit the startup script, so that it loads cuckoo after loading OSS. Edit $OSSLIBDIR/soundon.user, and add "modprobe cukoo" before "exit 0" line.

A general problem with ALSA emulation is that some programs probe for driver support in the order "ALSA, OSS". So programs that were using OSS by default may now try to use the emulation with possibly inferior results. So if there are problems after installation, make sure the program uses the OSS support rather than the emulation.