Difference between revisions of "Tips And Tricks"
m (→ossvol: correct typo) |
(→Changing the default sound output) |
||
Line 11: | Line 11: | ||
=== Changing the default sound output === | === Changing the default sound output === | ||
<span id="Changing the default sound output used for /dev/dsp"></span> | <span id="Changing the default sound output used for /dev/dsp"></span> | ||
− | # The typical method is to relink /dev/dsp to the desired /dev/oss/.../ device. e.g. | + | #* The typical method is to relink /dev/dsp to the desired /dev/oss/.../ device. e.g. |
− | #:: ln -sf /dev/oss/oss_sbxfi0/pcm0 /dev/dsp | + | #:: 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). | #: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 [[Tips And Tricks#OSSLIBDIR|$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 [[Tips And Tricks#OSSLIBDIR|$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. |
+ | #* In OSS 4.1 and above, it's best to also add a "vmixctl attach" command to the soundon.user file to make sure vmix is attached to the new device and to add "vmix_no_autoattach=1" to the [[Tips And Tricks#OSSLIBDIR|$OSSLIBDIR]]/conf/osscore.conf file. "vmixctl attach" syntax looks like this: | ||
#:: vmixctl attach /dev/oss/oss_sbxfi0/pcm0 /dev/oss/oss_sbxfi0/pcmin0 | #:: 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. | #: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. |
Revision as of 14:08, 7 July 2009
Contents
Starting ossxmix minimized to tray on desktop startup
The '-b' option starts ossxmix in the background - minimized to tray if tray support is compiled in, iconfied window if not. The '-S' option prevents ossxmix from trying to use a system tray. ossxmix -Sb' will always start an iconified window.
- KDE: create a desktop shortcut in ~/.kde/Autostart with the command 'ossxmix -b'.
- Alternative: create a desktop shortcut in the same place, with the command "ossxmix -Sb'. Go to Applications->"Advanced options" and select "Place in system tray".
- Gnome: go to "Control center"->"Session"->"Startup Programs" and add "ossxmix -b".
- Note that the quoted names can be slightly different on some systems due to localizations.
- X11 in general: edit the Xsession file. Make sure the tray program runs before ossxmix, or use the '-S' switch as well.
- See [1] for info on other environments.
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.
- In OSS 4.1 and above, it's best to also add a "vmixctl attach" command to the soundon.user file to make sure vmix is attached to the new device and to 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.
- 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.
- 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 several methods to achieve this:
- 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
- Some drivers have a 'loopback' mixer control, which offers similar functionality.
- (This method doesn't work in OSS4.0 build 1016) vmix loopback driver can record the mixed output of sound played. Set vmix1_numloops to 1 (or more) in vmix.conf, and restart OSS. Then record from the newly created loopback 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_ich0/loop0 test.wav
- 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. In the case of oss_userdev, the recorder has to be run using a udserver, the example one in tutorials/sndkit/udserver should do.
Running a command immediately after OSS is loaded
This can be done using this procedure:
- Edit the $OSSLIBDIR/soundon.user file and add that command.
- 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/once the keys are recognized, does it work out of the box?
- If not, it may be a function of old gstreamer version. Gnome uses gstremaer for this, but older gstreamer didn't support OSSv4. See Configuring_Applications_for_OSSv4#Gnome_Volume_Applet for a possible solution.
- 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 [4] and at [5] 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).
External scripts which can control volume
mute.sh
#!/bin/sh CTRL=vmix0-vol VOLUME=$(cat $HOME/.volume) CURRENT=$(ossmix | grep $CTRL | awk '{print $4}' | awk -F : '{print $1}') if [ $CURRENT = "0.0" ]; then ossmix $CTRL $VOLUME > $HOME/.volume else VOLUME=$(ossmix | grep $CTRL | awk '{print $4}' | awk -F : '{print $1}') ossmix $CTRL 0 echo $VOLUME > $HOME/.volume fi
ossvol
If you want the ability to mute and then unmute/increase volume at the same time the following script is one option. (This script relies on OSSv4.1 functionality - see note on ossmix below).
#!/bin/bash # # ossvol is a simple script to manage oss volume levels and muting. # # Script by: Daniel J Griffiths <ghost1227@archlinux.us> # Configure stuff VOLSTORE=~/.volume CHANNEL="vmix0-outvol" ARGUMENT=$2 # You shouldn't have to edit below here. err() { echo "$1" exit 1 } usage() { echo "usage: ossvol [option] [argument]" echo echo "Options:" echo " -i, --increase - increase volume by [argument]" echo " -d, --decrease - decrease volume by [argument]" echo " -t, --toggle - toggle mute on and off" echo " -h, --help - display this" exit } toggle() { if [ -f $VOLSTORE ]; then ossmix $CHANNEL `cat $VOLSTORE` rm $VOLSTORE else VOLUME=$(ossmix $CHANNEL | awk '{print $10}' | awk -F : '{print $1}') ossmix $CHANNEL 0 echo $VOLUME > $VOLSTORE fi } increase() { if [ -f $VOLSTORE ]; then TMPVOL=`cat $VOLSTORE` NEWVOL=`expr $TMPVOL + $ARGUMENT` ossmix $CHANNEL +$NEWVOL rm $VOLSTORE else ossmix $CHANNEL +$ARGUMENT fi } decrease() { if [ -f $VOLSTORE ]; then TMPVOL=`cat $VOLSTORE` NEWVOL=`expr $TMPVOL - $ARGUMENT` ossmix $CHANNEL -- -$NEWVOL rm $VOLSTORE else ossmix $CHANNEL -- -$ARGUMENT fi } case "$1" in '-i'|'--increase') increase ;; '-d'|'--decrease') decrease ;; '-t'|'--toggle') toggle ;; |'-h'|'--help') usage ;; *) err "Unrecognized option \`$1', see ossvol --help" ;; esac
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:
lowervolume.sh
#!/bin/sh CTRL=vmix0-vol VOL=$(ossmix | grep $CTRL | awk '{print $4}' | awk -F : '{print $1}') VOL=$(echo $VOL | awk '{print $1-2}') ossmix -- $CTRL $VOL
raisevolume.sh
#!/bin/sh CTRL=vmix0-vol VOL=$(ossmix | grep $CTRL | awk '{print $4}' | awk -F : '{print $1}') VOL=$(echo $VOL | awk '{print $1+2}') ossmix $CTRL $VOL
You may wish to modify a different mixer control than vmix0-vol. In that case, you will need to change the value of CTRL above.