xref: /OK3568_Linux_fs/kernel/Documentation/sound/designs/oss-emulation.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=============================
2*4882a593SmuzhiyunNotes on Kernel OSS-Emulation
3*4882a593Smuzhiyun=============================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunJan. 22, 2004  Takashi Iwai <tiwai@suse.de>
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunModules
9*4882a593Smuzhiyun=======
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunALSA provides a powerful OSS emulation on the kernel.
12*4882a593SmuzhiyunThe OSS emulation for PCM, mixer and sequencer devices is implemented
13*4882a593Smuzhiyunas add-on kernel modules, snd-pcm-oss, snd-mixer-oss and snd-seq-oss.
14*4882a593SmuzhiyunWhen you need to access the OSS PCM, mixer or sequencer devices, the
15*4882a593Smuzhiyuncorresponding module has to be loaded.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunThese modules are loaded automatically when the corresponding service
18*4882a593Smuzhiyunis called.  The alias is defined ``sound-service-x-y``, where x and y are
19*4882a593Smuzhiyunthe card number and the minor unit number.  Usually you don't have to
20*4882a593Smuzhiyundefine these aliases by yourself.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunOnly necessary step for auto-loading of OSS modules is to define the
23*4882a593Smuzhiyuncard alias in ``/etc/modprobe.d/alsa.conf``, such as::
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun	alias sound-slot-0 snd-emu10k1
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunAs the second card, define ``sound-slot-1`` as well.
28*4882a593SmuzhiyunNote that you can't use the aliased name as the target name (i.e.
29*4882a593Smuzhiyun``alias sound-slot-0 snd-card-0`` doesn't work any more like the old
30*4882a593Smuzhiyunmodutils).
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunThe currently available OSS configuration is shown in
33*4882a593Smuzhiyun/proc/asound/oss/sndstat.  This shows in the same syntax of
34*4882a593Smuzhiyun/dev/sndstat, which is available on the commercial OSS driver.
35*4882a593SmuzhiyunOn ALSA, you can symlink /dev/sndstat to this proc file.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunPlease note that the devices listed in this proc file appear only
38*4882a593Smuzhiyunafter the corresponding OSS-emulation module is loaded.  Don't worry
39*4882a593Smuzhiyuneven if "NOT ENABLED IN CONFIG" is shown in it.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunDevice Mapping
43*4882a593Smuzhiyun==============
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunALSA supports the following OSS device files:
46*4882a593Smuzhiyun::
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun	PCM:
49*4882a593Smuzhiyun		/dev/dspX
50*4882a593Smuzhiyun		/dev/adspX
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun	Mixer:
53*4882a593Smuzhiyun		/dev/mixerX
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	MIDI:
56*4882a593Smuzhiyun		/dev/midi0X
57*4882a593Smuzhiyun		/dev/amidi0X
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun	Sequencer:
60*4882a593Smuzhiyun		/dev/sequencer
61*4882a593Smuzhiyun		/dev/sequencer2 (aka /dev/music)
62*4882a593Smuzhiyun
63*4882a593Smuzhiyunwhere X is the card number from 0 to 7.
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun(NOTE: Some distributions have the device files like /dev/midi0 and
66*4882a593Smuzhiyun/dev/midi1.  They are NOT for OSS but for tclmidi, which is
67*4882a593Smuzhiyuna totally different thing.)
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunUnlike the real OSS, ALSA cannot use the device files more than the
70*4882a593Smuzhiyunassigned ones.  For example, the first card cannot use /dev/dsp1 or
71*4882a593Smuzhiyun/dev/dsp2, but only /dev/dsp0 and /dev/adsp0.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunAs seen above, PCM and MIDI may have two devices.  Usually, the first
74*4882a593SmuzhiyunPCM device (``hw:0,0`` in ALSA) is mapped to /dev/dsp and the secondary
75*4882a593Smuzhiyundevice (``hw:0,1``) to /dev/adsp (if available).  For MIDI, /dev/midi and
76*4882a593Smuzhiyun/dev/amidi, respectively.
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunYou can change this device mapping via the module options of
79*4882a593Smuzhiyunsnd-pcm-oss and snd-rawmidi.  In the case of PCM, the following
80*4882a593Smuzhiyunoptions are available for snd-pcm-oss:
81*4882a593Smuzhiyun
82*4882a593Smuzhiyundsp_map
83*4882a593Smuzhiyun	PCM device number assigned to /dev/dspX
84*4882a593Smuzhiyun	(default = 0)
85*4882a593Smuzhiyunadsp_map
86*4882a593Smuzhiyun	PCM device number assigned to /dev/adspX
87*4882a593Smuzhiyun	(default = 1)
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunFor example, to map the third PCM device (``hw:0,2``) to /dev/adsp0,
90*4882a593Smuzhiyundefine like this:
91*4882a593Smuzhiyun::
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun	options snd-pcm-oss adsp_map=2
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunThe options take arrays.  For configuring the second card, specify
96*4882a593Smuzhiyuntwo entries separated by comma.  For example, to map the third PCM
97*4882a593Smuzhiyundevice on the second card to /dev/adsp1, define like below:
98*4882a593Smuzhiyun::
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun	options snd-pcm-oss adsp_map=0,2
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunTo change the mapping of MIDI devices, the following options are
103*4882a593Smuzhiyunavailable for snd-rawmidi:
104*4882a593Smuzhiyun
105*4882a593Smuzhiyunmidi_map
106*4882a593Smuzhiyun	MIDI device number assigned to /dev/midi0X
107*4882a593Smuzhiyun	(default = 0)
108*4882a593Smuzhiyunamidi_map
109*4882a593Smuzhiyun	MIDI device number assigned to /dev/amidi0X
110*4882a593Smuzhiyun	(default = 1)
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunFor example, to assign the third MIDI device on the first card to
113*4882a593Smuzhiyun/dev/midi00, define as follows:
114*4882a593Smuzhiyun::
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun	options snd-rawmidi midi_map=2
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunPCM Mode
120*4882a593Smuzhiyun========
121*4882a593Smuzhiyun
122*4882a593SmuzhiyunAs default, ALSA emulates the OSS PCM with so-called plugin layer,
123*4882a593Smuzhiyuni.e. tries to convert the sample format, rate or channels
124*4882a593Smuzhiyunautomatically when the card doesn't support it natively.
125*4882a593SmuzhiyunThis will lead to some problems for some applications like quake or
126*4882a593Smuzhiyunwine, especially if they use the card only in the MMAP mode.
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunIn such a case, you can change the behavior of PCM per application by
129*4882a593Smuzhiyunwriting a command to the proc file.  There is a proc file for each PCM
130*4882a593Smuzhiyunstream, ``/proc/asound/cardX/pcmY[cp]/oss``, where X is the card number
131*4882a593Smuzhiyun(zero-based), Y the PCM device number (zero-based), and ``p`` is for
132*4882a593Smuzhiyunplayback and ``c`` for capture, respectively.  Note that this proc file
133*4882a593Smuzhiyunexists only after snd-pcm-oss module is loaded.
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunThe command sequence has the following syntax:
136*4882a593Smuzhiyun::
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun	app_name fragments fragment_size [options]
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun``app_name`` is the name of application with (higher priority) or without
141*4882a593Smuzhiyunpath.
142*4882a593Smuzhiyun``fragments`` specifies the number of fragments or zero if no specific
143*4882a593Smuzhiyunnumber is given.
144*4882a593Smuzhiyun``fragment_size`` is the size of fragment in bytes or zero if not given.
145*4882a593Smuzhiyun``options`` is the optional parameters.  The following options are
146*4882a593Smuzhiyunavailable:
147*4882a593Smuzhiyun
148*4882a593Smuzhiyundisable
149*4882a593Smuzhiyun	the application tries to open a pcm device for
150*4882a593Smuzhiyun	this channel but does not want to use it.
151*4882a593Smuzhiyundirect
152*4882a593Smuzhiyun	don't use plugins
153*4882a593Smuzhiyunblock
154*4882a593Smuzhiyun	force block open mode
155*4882a593Smuzhiyunnon-block
156*4882a593Smuzhiyun	force non-block open mode
157*4882a593Smuzhiyunpartial-frag
158*4882a593Smuzhiyun	write also partial fragments (affects playback only)
159*4882a593Smuzhiyunno-silence
160*4882a593Smuzhiyun	do not fill silence ahead to avoid clicks
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunThe ``disable`` option is useful when one stream direction (playback or
163*4882a593Smuzhiyuncapture) is not handled correctly by the application although the
164*4882a593Smuzhiyunhardware itself does support both directions.
165*4882a593SmuzhiyunThe ``direct`` option is used, as mentioned above, to bypass the automatic
166*4882a593Smuzhiyunconversion and useful for MMAP-applications.
167*4882a593SmuzhiyunFor example, to playback the first PCM device without plugins for
168*4882a593Smuzhiyunquake, send a command via echo like the following:
169*4882a593Smuzhiyun::
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun	% echo "quake 0 0 direct" > /proc/asound/card0/pcm0p/oss
172*4882a593Smuzhiyun
173*4882a593SmuzhiyunWhile quake wants only playback, you may append the second command
174*4882a593Smuzhiyunto notify driver that only this direction is about to be allocated:
175*4882a593Smuzhiyun::
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun	% echo "quake 0 0 disable" > /proc/asound/card0/pcm0c/oss
178*4882a593Smuzhiyun
179*4882a593SmuzhiyunThe permission of proc files depend on the module options of snd.
180*4882a593SmuzhiyunAs default it's set as root, so you'll likely need to be superuser for
181*4882a593Smuzhiyunsending the command above.
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunThe block and non-block options are used to change the behavior of
184*4882a593Smuzhiyunopening the device file.
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunAs default, ALSA behaves as original OSS drivers, i.e. does not block
187*4882a593Smuzhiyunthe file when it's busy. The -EBUSY error is returned in this case.
188*4882a593Smuzhiyun
189*4882a593SmuzhiyunThis blocking behavior can be changed globally via nonblock_open
190*4882a593Smuzhiyunmodule option of snd-pcm-oss.  For using the blocking mode as default
191*4882a593Smuzhiyunfor OSS devices, define like the following:
192*4882a593Smuzhiyun::
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun	options snd-pcm-oss nonblock_open=0
195*4882a593Smuzhiyun
196*4882a593SmuzhiyunThe ``partial-frag`` and ``no-silence`` commands have been added recently.
197*4882a593SmuzhiyunBoth commands are for optimization use only.  The former command
198*4882a593Smuzhiyunspecifies to invoke the write transfer only when the whole fragment is
199*4882a593Smuzhiyunfilled.  The latter stops writing the silence data ahead
200*4882a593Smuzhiyunautomatically.  Both are disabled as default.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunYou can check the currently defined configuration by reading the proc
203*4882a593Smuzhiyunfile.  The read image can be sent to the proc file again, hence you
204*4882a593Smuzhiyuncan save the current configuration
205*4882a593Smuzhiyun::
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun	% cat /proc/asound/card0/pcm0p/oss > /somewhere/oss-cfg
208*4882a593Smuzhiyun
209*4882a593Smuzhiyunand restore it like
210*4882a593Smuzhiyun::
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun	% cat /somewhere/oss-cfg > /proc/asound/card0/pcm0p/oss
213*4882a593Smuzhiyun
214*4882a593SmuzhiyunAlso, for clearing all the current configuration, send ``erase`` command
215*4882a593Smuzhiyunas below:
216*4882a593Smuzhiyun::
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun	% echo "erase" > /proc/asound/card0/pcm0p/oss
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun
221*4882a593SmuzhiyunMixer Elements
222*4882a593Smuzhiyun==============
223*4882a593Smuzhiyun
224*4882a593SmuzhiyunSince ALSA has completely different mixer interface, the emulation of
225*4882a593SmuzhiyunOSS mixer is relatively complicated.  ALSA builds up a mixer element
226*4882a593Smuzhiyunfrom several different ALSA (mixer) controls based on the name
227*4882a593Smuzhiyunstring.  For example, the volume element SOUND_MIXER_PCM is composed
228*4882a593Smuzhiyunfrom "PCM Playback Volume" and "PCM Playback Switch" controls for the
229*4882a593Smuzhiyunplayback direction and from "PCM Capture Volume" and "PCM Capture
230*4882a593SmuzhiyunSwitch" for the capture directory (if exists).  When the PCM volume of
231*4882a593SmuzhiyunOSS is changed, all the volume and switch controls above are adjusted
232*4882a593Smuzhiyunautomatically.
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunAs default, ALSA uses the following control for OSS volumes:
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun====================	=====================	=====
237*4882a593SmuzhiyunOSS volume		ALSA control		Index
238*4882a593Smuzhiyun====================	=====================	=====
239*4882a593SmuzhiyunSOUND_MIXER_VOLUME 	Master			0
240*4882a593SmuzhiyunSOUND_MIXER_BASS	Tone Control - Bass	0
241*4882a593SmuzhiyunSOUND_MIXER_TREBLE	Tone Control - Treble	0
242*4882a593SmuzhiyunSOUND_MIXER_SYNTH	Synth			0
243*4882a593SmuzhiyunSOUND_MIXER_PCM		PCM			0
244*4882a593SmuzhiyunSOUND_MIXER_SPEAKER	PC Speaker 		0
245*4882a593SmuzhiyunSOUND_MIXER_LINE	Line			0
246*4882a593SmuzhiyunSOUND_MIXER_MIC		Mic 			0
247*4882a593SmuzhiyunSOUND_MIXER_CD		CD 			0
248*4882a593SmuzhiyunSOUND_MIXER_IMIX	Monitor Mix 		0
249*4882a593SmuzhiyunSOUND_MIXER_ALTPCM	PCM			1
250*4882a593SmuzhiyunSOUND_MIXER_RECLEV	(not assigned)
251*4882a593SmuzhiyunSOUND_MIXER_IGAIN	Capture			0
252*4882a593SmuzhiyunSOUND_MIXER_OGAIN	Playback		0
253*4882a593SmuzhiyunSOUND_MIXER_LINE1	Aux			0
254*4882a593SmuzhiyunSOUND_MIXER_LINE2	Aux			1
255*4882a593SmuzhiyunSOUND_MIXER_LINE3	Aux			2
256*4882a593SmuzhiyunSOUND_MIXER_DIGITAL1	Digital			0
257*4882a593SmuzhiyunSOUND_MIXER_DIGITAL2	Digital			1
258*4882a593SmuzhiyunSOUND_MIXER_DIGITAL3	Digital			2
259*4882a593SmuzhiyunSOUND_MIXER_PHONEIN	Phone			0
260*4882a593SmuzhiyunSOUND_MIXER_PHONEOUT	Phone			1
261*4882a593SmuzhiyunSOUND_MIXER_VIDEO	Video			0
262*4882a593SmuzhiyunSOUND_MIXER_RADIO	Radio			0
263*4882a593SmuzhiyunSOUND_MIXER_MONITOR	Monitor			0
264*4882a593Smuzhiyun====================	=====================	=====
265*4882a593Smuzhiyun
266*4882a593SmuzhiyunThe second column is the base-string of the corresponding ALSA
267*4882a593Smuzhiyuncontrol.  In fact, the controls with ``XXX [Playback|Capture]
268*4882a593Smuzhiyun[Volume|Switch]`` will be checked in addition.
269*4882a593Smuzhiyun
270*4882a593SmuzhiyunThe current assignment of these mixer elements is listed in the proc
271*4882a593Smuzhiyunfile, /proc/asound/cardX/oss_mixer, which will be like the following
272*4882a593Smuzhiyun::
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun	VOLUME "Master" 0
275*4882a593Smuzhiyun	BASS "" 0
276*4882a593Smuzhiyun	TREBLE "" 0
277*4882a593Smuzhiyun	SYNTH "" 0
278*4882a593Smuzhiyun	PCM "PCM" 0
279*4882a593Smuzhiyun	...
280*4882a593Smuzhiyun
281*4882a593Smuzhiyunwhere the first column is the OSS volume element, the second column
282*4882a593Smuzhiyunthe base-string of the corresponding ALSA control, and the third the
283*4882a593Smuzhiyuncontrol index.  When the string is empty, it means that the
284*4882a593Smuzhiyuncorresponding OSS control is not available.
285*4882a593Smuzhiyun
286*4882a593SmuzhiyunFor changing the assignment, you can write the configuration to this
287*4882a593Smuzhiyunproc file.  For example, to map "Wave Playback" to the PCM volume,
288*4882a593Smuzhiyunsend the command like the following:
289*4882a593Smuzhiyun::
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun	% echo 'VOLUME "Wave Playback" 0' > /proc/asound/card0/oss_mixer
292*4882a593Smuzhiyun
293*4882a593SmuzhiyunThe command is exactly as same as listed in the proc file.  You can
294*4882a593Smuzhiyunchange one or more elements, one volume per line.  In the last
295*4882a593Smuzhiyunexample, both "Wave Playback Volume" and "Wave Playback Switch" will
296*4882a593Smuzhiyunbe affected when PCM volume is changed.
297*4882a593Smuzhiyun
298*4882a593SmuzhiyunLike the case of PCM proc file, the permission of proc files depend on
299*4882a593Smuzhiyunthe module options of snd.  you'll likely need to be superuser for
300*4882a593Smuzhiyunsending the command above.
301*4882a593Smuzhiyun
302*4882a593SmuzhiyunAs well as in the case of PCM proc file, you can save and restore the
303*4882a593Smuzhiyuncurrent mixer configuration by reading and writing the whole file
304*4882a593Smuzhiyunimage.
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun
307*4882a593SmuzhiyunDuplex Streams
308*4882a593Smuzhiyun==============
309*4882a593Smuzhiyun
310*4882a593SmuzhiyunNote that when attempting to use a single device file for playback and
311*4882a593Smuzhiyuncapture, the OSS API provides no way to set the format, sample rate or
312*4882a593Smuzhiyunnumber of channels different in each direction.  Thus
313*4882a593Smuzhiyun::
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun	io_handle = open("device", O_RDWR)
316*4882a593Smuzhiyun
317*4882a593Smuzhiyunwill only function correctly if the values are the same in each direction.
318*4882a593Smuzhiyun
319*4882a593SmuzhiyunTo use different values in the two directions, use both
320*4882a593Smuzhiyun::
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun	input_handle = open("device", O_RDONLY)
323*4882a593Smuzhiyun	output_handle = open("device", O_WRONLY)
324*4882a593Smuzhiyun
325*4882a593Smuzhiyunand set the values for the corresponding handle.
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun
328*4882a593SmuzhiyunUnsupported Features
329*4882a593Smuzhiyun====================
330*4882a593Smuzhiyun
331*4882a593SmuzhiyunMMAP on ICE1712 driver
332*4882a593Smuzhiyun----------------------
333*4882a593SmuzhiyunICE1712 supports only the unconventional format, interleaved
334*4882a593Smuzhiyun10-channels 24bit (packed in 32bit) format.  Therefore you cannot mmap
335*4882a593Smuzhiyunthe buffer as the conventional (mono or 2-channels, 8 or 16bit) format
336*4882a593Smuzhiyunon OSS.
337