1*0c266c4bSTakashi Iwai============================= 2*0c266c4bSTakashi IwaiNotes on Kernel OSS-Emulation 3*0c266c4bSTakashi Iwai============================= 4*0c266c4bSTakashi Iwai 5*0c266c4bSTakashi IwaiJan. 22, 2004 Takashi Iwai <tiwai@suse.de> 6*0c266c4bSTakashi Iwai 7*0c266c4bSTakashi Iwai 8*0c266c4bSTakashi IwaiModules 9*0c266c4bSTakashi Iwai======= 10*0c266c4bSTakashi Iwai 11*0c266c4bSTakashi IwaiALSA provides a powerful OSS emulation on the kernel. 12*0c266c4bSTakashi IwaiThe OSS emulation for PCM, mixer and sequencer devices is implemented 13*0c266c4bSTakashi Iwaias add-on kernel modules, snd-pcm-oss, snd-mixer-oss and snd-seq-oss. 14*0c266c4bSTakashi IwaiWhen you need to access the OSS PCM, mixer or sequencer devices, the 15*0c266c4bSTakashi Iwaicorresponding module has to be loaded. 16*0c266c4bSTakashi Iwai 17*0c266c4bSTakashi IwaiThese modules are loaded automatically when the corresponding service 18*0c266c4bSTakashi Iwaiis called. The alias is defined ``sound-service-x-y``, where x and y are 19*0c266c4bSTakashi Iwaithe card number and the minor unit number. Usually you don't have to 20*0c266c4bSTakashi Iwaidefine these aliases by yourself. 21*0c266c4bSTakashi Iwai 22*0c266c4bSTakashi IwaiOnly necessary step for auto-loading of OSS modules is to define the 23*0c266c4bSTakashi Iwaicard alias in ``/etc/modprobe.d/alsa.conf``, such as:: 24*0c266c4bSTakashi Iwai 25*0c266c4bSTakashi Iwai alias sound-slot-0 snd-emu10k1 26*0c266c4bSTakashi Iwai 27*0c266c4bSTakashi IwaiAs the second card, define ``sound-slot-1`` as well. 28*0c266c4bSTakashi IwaiNote that you can't use the aliased name as the target name (i.e. 29*0c266c4bSTakashi Iwai``alias sound-slot-0 snd-card-0`` doesn't work any more like the old 30*0c266c4bSTakashi Iwaimodutils). 31*0c266c4bSTakashi Iwai 32*0c266c4bSTakashi IwaiThe currently available OSS configuration is shown in 33*0c266c4bSTakashi Iwai/proc/asound/oss/sndstat. This shows in the same syntax of 34*0c266c4bSTakashi Iwai/dev/sndstat, which is available on the commercial OSS driver. 35*0c266c4bSTakashi IwaiOn ALSA, you can symlink /dev/sndstat to this proc file. 36*0c266c4bSTakashi Iwai 37*0c266c4bSTakashi IwaiPlease note that the devices listed in this proc file appear only 38*0c266c4bSTakashi Iwaiafter the corresponding OSS-emulation module is loaded. Don't worry 39*0c266c4bSTakashi Iwaieven if "NOT ENABLED IN CONFIG" is shown in it. 40*0c266c4bSTakashi Iwai 41*0c266c4bSTakashi Iwai 42*0c266c4bSTakashi IwaiDevice Mapping 43*0c266c4bSTakashi Iwai============== 44*0c266c4bSTakashi Iwai 45*0c266c4bSTakashi IwaiALSA supports the following OSS device files: 46*0c266c4bSTakashi Iwai:: 47*0c266c4bSTakashi Iwai 48*0c266c4bSTakashi Iwai PCM: 49*0c266c4bSTakashi Iwai /dev/dspX 50*0c266c4bSTakashi Iwai /dev/adspX 51*0c266c4bSTakashi Iwai 52*0c266c4bSTakashi Iwai Mixer: 53*0c266c4bSTakashi Iwai /dev/mixerX 54*0c266c4bSTakashi Iwai 55*0c266c4bSTakashi Iwai MIDI: 56*0c266c4bSTakashi Iwai /dev/midi0X 57*0c266c4bSTakashi Iwai /dev/amidi0X 58*0c266c4bSTakashi Iwai 59*0c266c4bSTakashi Iwai Sequencer: 60*0c266c4bSTakashi Iwai /dev/sequencer 61*0c266c4bSTakashi Iwai /dev/sequencer2 (aka /dev/music) 62*0c266c4bSTakashi Iwai 63*0c266c4bSTakashi Iwaiwhere X is the card number from 0 to 7. 64*0c266c4bSTakashi Iwai 65*0c266c4bSTakashi Iwai(NOTE: Some distributions have the device files like /dev/midi0 and 66*0c266c4bSTakashi Iwai/dev/midi1. They are NOT for OSS but for tclmidi, which is 67*0c266c4bSTakashi Iwaia totally different thing.) 68*0c266c4bSTakashi Iwai 69*0c266c4bSTakashi IwaiUnlike the real OSS, ALSA cannot use the device files more than the 70*0c266c4bSTakashi Iwaiassigned ones. For example, the first card cannot use /dev/dsp1 or 71*0c266c4bSTakashi Iwai/dev/dsp2, but only /dev/dsp0 and /dev/adsp0. 72*0c266c4bSTakashi Iwai 73*0c266c4bSTakashi IwaiAs seen above, PCM and MIDI may have two devices. Usually, the first 74*0c266c4bSTakashi IwaiPCM device (``hw:0,0`` in ALSA) is mapped to /dev/dsp and the secondary 75*0c266c4bSTakashi Iwaidevice (``hw:0,1``) to /dev/adsp (if available). For MIDI, /dev/midi and 76*0c266c4bSTakashi Iwai/dev/amidi, respectively. 77*0c266c4bSTakashi Iwai 78*0c266c4bSTakashi IwaiYou can change this device mapping via the module options of 79*0c266c4bSTakashi Iwaisnd-pcm-oss and snd-rawmidi. In the case of PCM, the following 80*0c266c4bSTakashi Iwaioptions are available for snd-pcm-oss: 81*0c266c4bSTakashi Iwai 82*0c266c4bSTakashi Iwaidsp_map 83*0c266c4bSTakashi Iwai PCM device number assigned to /dev/dspX 84*0c266c4bSTakashi Iwai (default = 0) 85*0c266c4bSTakashi Iwaiadsp_map 86*0c266c4bSTakashi Iwai PCM device number assigned to /dev/adspX 87*0c266c4bSTakashi Iwai (default = 1) 88*0c266c4bSTakashi Iwai 89*0c266c4bSTakashi IwaiFor example, to map the third PCM device (``hw:0,2``) to /dev/adsp0, 90*0c266c4bSTakashi Iwaidefine like this: 91*0c266c4bSTakashi Iwai:: 92*0c266c4bSTakashi Iwai 93*0c266c4bSTakashi Iwai options snd-pcm-oss adsp_map=2 94*0c266c4bSTakashi Iwai 95*0c266c4bSTakashi IwaiThe options take arrays. For configuring the second card, specify 96*0c266c4bSTakashi Iwaitwo entries separated by comma. For example, to map the third PCM 97*0c266c4bSTakashi Iwaidevice on the second card to /dev/adsp1, define like below: 98*0c266c4bSTakashi Iwai:: 99*0c266c4bSTakashi Iwai 100*0c266c4bSTakashi Iwai options snd-pcm-oss adsp_map=0,2 101*0c266c4bSTakashi Iwai 102*0c266c4bSTakashi IwaiTo change the mapping of MIDI devices, the following options are 103*0c266c4bSTakashi Iwaiavailable for snd-rawmidi: 104*0c266c4bSTakashi Iwai 105*0c266c4bSTakashi Iwaimidi_map 106*0c266c4bSTakashi Iwai MIDI device number assigned to /dev/midi0X 107*0c266c4bSTakashi Iwai (default = 0) 108*0c266c4bSTakashi Iwaiamidi_map 109*0c266c4bSTakashi Iwai MIDI device number assigned to /dev/amidi0X 110*0c266c4bSTakashi Iwai (default = 1) 111*0c266c4bSTakashi Iwai 112*0c266c4bSTakashi IwaiFor example, to assign the third MIDI device on the first card to 113*0c266c4bSTakashi Iwai/dev/midi00, define as follows: 114*0c266c4bSTakashi Iwai:: 115*0c266c4bSTakashi Iwai 116*0c266c4bSTakashi Iwai options snd-rawmidi midi_map=2 117*0c266c4bSTakashi Iwai 118*0c266c4bSTakashi Iwai 119*0c266c4bSTakashi IwaiPCM Mode 120*0c266c4bSTakashi Iwai======== 121*0c266c4bSTakashi Iwai 122*0c266c4bSTakashi IwaiAs default, ALSA emulates the OSS PCM with so-called plugin layer, 123*0c266c4bSTakashi Iwaii.e. tries to convert the sample format, rate or channels 124*0c266c4bSTakashi Iwaiautomatically when the card doesn't support it natively. 125*0c266c4bSTakashi IwaiThis will lead to some problems for some applications like quake or 126*0c266c4bSTakashi Iwaiwine, especially if they use the card only in the MMAP mode. 127*0c266c4bSTakashi Iwai 128*0c266c4bSTakashi IwaiIn such a case, you can change the behavior of PCM per application by 129*0c266c4bSTakashi Iwaiwriting a command to the proc file. There is a proc file for each PCM 130*0c266c4bSTakashi Iwaistream, ``/proc/asound/cardX/pcmY[cp]/oss``, where X is the card number 131*0c266c4bSTakashi Iwai(zero-based), Y the PCM device number (zero-based), and ``p`` is for 132*0c266c4bSTakashi Iwaiplayback and ``c`` for capture, respectively. Note that this proc file 133*0c266c4bSTakashi Iwaiexists only after snd-pcm-oss module is loaded. 134*0c266c4bSTakashi Iwai 135*0c266c4bSTakashi IwaiThe command sequence has the following syntax: 136*0c266c4bSTakashi Iwai:: 137*0c266c4bSTakashi Iwai 138*0c266c4bSTakashi Iwai app_name fragments fragment_size [options] 139*0c266c4bSTakashi Iwai 140*0c266c4bSTakashi Iwai``app_name`` is the name of application with (higher priority) or without 141*0c266c4bSTakashi Iwaipath. 142*0c266c4bSTakashi Iwai``fragments`` specifies the number of fragments or zero if no specific 143*0c266c4bSTakashi Iwainumber is given. 144*0c266c4bSTakashi Iwai``fragment_size`` is the size of fragment in bytes or zero if not given. 145*0c266c4bSTakashi Iwai``options`` is the optional parameters. The following options are 146*0c266c4bSTakashi Iwaiavailable: 147*0c266c4bSTakashi Iwai 148*0c266c4bSTakashi Iwaidisable 149*0c266c4bSTakashi Iwai the application tries to open a pcm device for 150*0c266c4bSTakashi Iwai this channel but does not want to use it. 151*0c266c4bSTakashi Iwaidirect 152*0c266c4bSTakashi Iwai don't use plugins 153*0c266c4bSTakashi Iwaiblock 154*0c266c4bSTakashi Iwai force block open mode 155*0c266c4bSTakashi Iwainon-block 156*0c266c4bSTakashi Iwai force non-block open mode 157*0c266c4bSTakashi Iwaipartial-frag 158*0c266c4bSTakashi Iwai write also partial fragments (affects playback only) 159*0c266c4bSTakashi Iwaino-silence 160*0c266c4bSTakashi Iwai do not fill silence ahead to avoid clicks 161*0c266c4bSTakashi Iwai 162*0c266c4bSTakashi IwaiThe ``disable`` option is useful when one stream direction (playback or 163*0c266c4bSTakashi Iwaicapture) is not handled correctly by the application although the 164*0c266c4bSTakashi Iwaihardware itself does support both directions. 165*0c266c4bSTakashi IwaiThe ``direct`` option is used, as mentioned above, to bypass the automatic 166*0c266c4bSTakashi Iwaiconversion and useful for MMAP-applications. 167*0c266c4bSTakashi IwaiFor example, to playback the first PCM device without plugins for 168*0c266c4bSTakashi Iwaiquake, send a command via echo like the following: 169*0c266c4bSTakashi Iwai:: 170*0c266c4bSTakashi Iwai 171*0c266c4bSTakashi Iwai % echo "quake 0 0 direct" > /proc/asound/card0/pcm0p/oss 172*0c266c4bSTakashi Iwai 173*0c266c4bSTakashi IwaiWhile quake wants only playback, you may append the second command 174*0c266c4bSTakashi Iwaito notify driver that only this direction is about to be allocated: 175*0c266c4bSTakashi Iwai:: 176*0c266c4bSTakashi Iwai 177*0c266c4bSTakashi Iwai % echo "quake 0 0 disable" > /proc/asound/card0/pcm0c/oss 178*0c266c4bSTakashi Iwai 179*0c266c4bSTakashi IwaiThe permission of proc files depend on the module options of snd. 180*0c266c4bSTakashi IwaiAs default it's set as root, so you'll likely need to be superuser for 181*0c266c4bSTakashi Iwaisending the command above. 182*0c266c4bSTakashi Iwai 183*0c266c4bSTakashi IwaiThe block and non-block options are used to change the behavior of 184*0c266c4bSTakashi Iwaiopening the device file. 185*0c266c4bSTakashi Iwai 186*0c266c4bSTakashi IwaiAs default, ALSA behaves as original OSS drivers, i.e. does not block 187*0c266c4bSTakashi Iwaithe file when it's busy. The -EBUSY error is returned in this case. 188*0c266c4bSTakashi Iwai 189*0c266c4bSTakashi IwaiThis blocking behavior can be changed globally via nonblock_open 190*0c266c4bSTakashi Iwaimodule option of snd-pcm-oss. For using the blocking mode as default 191*0c266c4bSTakashi Iwaifor OSS devices, define like the following: 192*0c266c4bSTakashi Iwai:: 193*0c266c4bSTakashi Iwai 194*0c266c4bSTakashi Iwai options snd-pcm-oss nonblock_open=0 195*0c266c4bSTakashi Iwai 196*0c266c4bSTakashi IwaiThe ``partial-frag`` and ``no-silence`` commands have been added recently. 197*0c266c4bSTakashi IwaiBoth commands are for optimization use only. The former command 198*0c266c4bSTakashi Iwaispecifies to invoke the write transfer only when the whole fragment is 199*0c266c4bSTakashi Iwaifilled. The latter stops writing the silence data ahead 200*0c266c4bSTakashi Iwaiautomatically. Both are disabled as default. 201*0c266c4bSTakashi Iwai 202*0c266c4bSTakashi IwaiYou can check the currently defined configuration by reading the proc 203*0c266c4bSTakashi Iwaifile. The read image can be sent to the proc file again, hence you 204*0c266c4bSTakashi Iwaican save the current configuration 205*0c266c4bSTakashi Iwai:: 206*0c266c4bSTakashi Iwai 207*0c266c4bSTakashi Iwai % cat /proc/asound/card0/pcm0p/oss > /somewhere/oss-cfg 208*0c266c4bSTakashi Iwai 209*0c266c4bSTakashi Iwaiand restore it like 210*0c266c4bSTakashi Iwai:: 211*0c266c4bSTakashi Iwai 212*0c266c4bSTakashi Iwai % cat /somewhere/oss-cfg > /proc/asound/card0/pcm0p/oss 213*0c266c4bSTakashi Iwai 214*0c266c4bSTakashi IwaiAlso, for clearing all the current configuration, send ``erase`` command 215*0c266c4bSTakashi Iwaias below: 216*0c266c4bSTakashi Iwai:: 217*0c266c4bSTakashi Iwai 218*0c266c4bSTakashi Iwai % echo "erase" > /proc/asound/card0/pcm0p/oss 219*0c266c4bSTakashi Iwai 220*0c266c4bSTakashi Iwai 221*0c266c4bSTakashi IwaiMixer Elements 222*0c266c4bSTakashi Iwai============== 223*0c266c4bSTakashi Iwai 224*0c266c4bSTakashi IwaiSince ALSA has completely different mixer interface, the emulation of 225*0c266c4bSTakashi IwaiOSS mixer is relatively complicated. ALSA builds up a mixer element 226*0c266c4bSTakashi Iwaifrom several different ALSA (mixer) controls based on the name 227*0c266c4bSTakashi Iwaistring. For example, the volume element SOUND_MIXER_PCM is composed 228*0c266c4bSTakashi Iwaifrom "PCM Playback Volume" and "PCM Playback Switch" controls for the 229*0c266c4bSTakashi Iwaiplayback direction and from "PCM Capture Volume" and "PCM Capture 230*0c266c4bSTakashi IwaiSwitch" for the capture directory (if exists). When the PCM volume of 231*0c266c4bSTakashi IwaiOSS is changed, all the volume and switch controls above are adjusted 232*0c266c4bSTakashi Iwaiautomatically. 233*0c266c4bSTakashi Iwai 234*0c266c4bSTakashi IwaiAs default, ALSA uses the following control for OSS volumes: 235*0c266c4bSTakashi Iwai 236*0c266c4bSTakashi Iwai==================== ===================== ===== 237*0c266c4bSTakashi IwaiOSS volume ALSA control Index 238*0c266c4bSTakashi Iwai==================== ===================== ===== 239*0c266c4bSTakashi IwaiSOUND_MIXER_VOLUME Master 0 240*0c266c4bSTakashi IwaiSOUND_MIXER_BASS Tone Control - Bass 0 241*0c266c4bSTakashi IwaiSOUND_MIXER_TREBLE Tone Control - Treble 0 242*0c266c4bSTakashi IwaiSOUND_MIXER_SYNTH Synth 0 243*0c266c4bSTakashi IwaiSOUND_MIXER_PCM PCM 0 244*0c266c4bSTakashi IwaiSOUND_MIXER_SPEAKER PC Speaker 0 245*0c266c4bSTakashi IwaiSOUND_MIXER_LINE Line 0 246*0c266c4bSTakashi IwaiSOUND_MIXER_MIC Mic 0 247*0c266c4bSTakashi IwaiSOUND_MIXER_CD CD 0 248*0c266c4bSTakashi IwaiSOUND_MIXER_IMIX Monitor Mix 0 249*0c266c4bSTakashi IwaiSOUND_MIXER_ALTPCM PCM 1 250*0c266c4bSTakashi IwaiSOUND_MIXER_RECLEV (not assigned) 251*0c266c4bSTakashi IwaiSOUND_MIXER_IGAIN Capture 0 252*0c266c4bSTakashi IwaiSOUND_MIXER_OGAIN Playback 0 253*0c266c4bSTakashi IwaiSOUND_MIXER_LINE1 Aux 0 254*0c266c4bSTakashi IwaiSOUND_MIXER_LINE2 Aux 1 255*0c266c4bSTakashi IwaiSOUND_MIXER_LINE3 Aux 2 256*0c266c4bSTakashi IwaiSOUND_MIXER_DIGITAL1 Digital 0 257*0c266c4bSTakashi IwaiSOUND_MIXER_DIGITAL2 Digital 1 258*0c266c4bSTakashi IwaiSOUND_MIXER_DIGITAL3 Digital 2 259*0c266c4bSTakashi IwaiSOUND_MIXER_PHONEIN Phone 0 260*0c266c4bSTakashi IwaiSOUND_MIXER_PHONEOUT Phone 1 261*0c266c4bSTakashi IwaiSOUND_MIXER_VIDEO Video 0 262*0c266c4bSTakashi IwaiSOUND_MIXER_RADIO Radio 0 263*0c266c4bSTakashi IwaiSOUND_MIXER_MONITOR Monitor 0 264*0c266c4bSTakashi Iwai==================== ===================== ===== 265*0c266c4bSTakashi Iwai 266*0c266c4bSTakashi IwaiThe second column is the base-string of the corresponding ALSA 267*0c266c4bSTakashi Iwaicontrol. In fact, the controls with ``XXX [Playback|Capture] 268*0c266c4bSTakashi Iwai[Volume|Switch]`` will be checked in addition. 269*0c266c4bSTakashi Iwai 270*0c266c4bSTakashi IwaiThe current assignment of these mixer elements is listed in the proc 271*0c266c4bSTakashi Iwaifile, /proc/asound/cardX/oss_mixer, which will be like the following 272*0c266c4bSTakashi Iwai:: 273*0c266c4bSTakashi Iwai 274*0c266c4bSTakashi Iwai VOLUME "Master" 0 275*0c266c4bSTakashi Iwai BASS "" 0 276*0c266c4bSTakashi Iwai TREBLE "" 0 277*0c266c4bSTakashi Iwai SYNTH "" 0 278*0c266c4bSTakashi Iwai PCM "PCM" 0 279*0c266c4bSTakashi Iwai ... 280*0c266c4bSTakashi Iwai 281*0c266c4bSTakashi Iwaiwhere the first column is the OSS volume element, the second column 282*0c266c4bSTakashi Iwaithe base-string of the corresponding ALSA control, and the third the 283*0c266c4bSTakashi Iwaicontrol index. When the string is empty, it means that the 284*0c266c4bSTakashi Iwaicorresponding OSS control is not available. 285*0c266c4bSTakashi Iwai 286*0c266c4bSTakashi IwaiFor changing the assignment, you can write the configuration to this 287*0c266c4bSTakashi Iwaiproc file. For example, to map "Wave Playback" to the PCM volume, 288*0c266c4bSTakashi Iwaisend the command like the following: 289*0c266c4bSTakashi Iwai:: 290*0c266c4bSTakashi Iwai 291*0c266c4bSTakashi Iwai % echo 'VOLUME "Wave Playback" 0' > /proc/asound/card0/oss_mixer 292*0c266c4bSTakashi Iwai 293*0c266c4bSTakashi IwaiThe command is exactly as same as listed in the proc file. You can 294*0c266c4bSTakashi Iwaichange one or more elements, one volume per line. In the last 295*0c266c4bSTakashi Iwaiexample, both "Wave Playback Volume" and "Wave Playback Switch" will 296*0c266c4bSTakashi Iwaibe affected when PCM volume is changed. 297*0c266c4bSTakashi Iwai 298*0c266c4bSTakashi IwaiLike the case of PCM proc file, the permission of proc files depend on 299*0c266c4bSTakashi Iwaithe module options of snd. you'll likely need to be superuser for 300*0c266c4bSTakashi Iwaisending the command above. 301*0c266c4bSTakashi Iwai 302*0c266c4bSTakashi IwaiAs well as in the case of PCM proc file, you can save and restore the 303*0c266c4bSTakashi Iwaicurrent mixer configuration by reading and writing the whole file 304*0c266c4bSTakashi Iwaiimage. 305*0c266c4bSTakashi Iwai 306*0c266c4bSTakashi Iwai 307*0c266c4bSTakashi IwaiDuplex Streams 308*0c266c4bSTakashi Iwai============== 309*0c266c4bSTakashi Iwai 310*0c266c4bSTakashi IwaiNote that when attempting to use a single device file for playback and 311*0c266c4bSTakashi Iwaicapture, the OSS API provides no way to set the format, sample rate or 312*0c266c4bSTakashi Iwainumber of channels different in each direction. Thus 313*0c266c4bSTakashi Iwai:: 314*0c266c4bSTakashi Iwai 315*0c266c4bSTakashi Iwai io_handle = open("device", O_RDWR) 316*0c266c4bSTakashi Iwai 317*0c266c4bSTakashi Iwaiwill only function correctly if the values are the same in each direction. 318*0c266c4bSTakashi Iwai 319*0c266c4bSTakashi IwaiTo use different values in the two directions, use both 320*0c266c4bSTakashi Iwai:: 321*0c266c4bSTakashi Iwai 322*0c266c4bSTakashi Iwai input_handle = open("device", O_RDONLY) 323*0c266c4bSTakashi Iwai output_handle = open("device", O_WRONLY) 324*0c266c4bSTakashi Iwai 325*0c266c4bSTakashi Iwaiand set the values for the corresponding handle. 326*0c266c4bSTakashi Iwai 327*0c266c4bSTakashi Iwai 328*0c266c4bSTakashi IwaiUnsupported Features 329*0c266c4bSTakashi Iwai==================== 330*0c266c4bSTakashi Iwai 331*0c266c4bSTakashi IwaiMMAP on ICE1712 driver 332*0c266c4bSTakashi Iwai---------------------- 333*0c266c4bSTakashi IwaiICE1712 supports only the unconventional format, interleaved 334*0c266c4bSTakashi Iwai10-channels 24bit (packed in 32bit) format. Therefore you cannot mmap 335*0c266c4bSTakashi Iwaithe buffer as the conventional (mono or 2-channels, 8 or 16bit) format 336*0c266c4bSTakashi Iwaion OSS. 337