162306a36Sopenharmony_ci=============================
262306a36Sopenharmony_ciNotes on Kernel OSS-Emulation
362306a36Sopenharmony_ci=============================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciJan. 22, 2004  Takashi Iwai <tiwai@suse.de>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciModules
962306a36Sopenharmony_ci=======
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciALSA provides a powerful OSS emulation on the kernel.
1262306a36Sopenharmony_ciThe OSS emulation for PCM, mixer and sequencer devices is implemented
1362306a36Sopenharmony_cias add-on kernel modules, snd-pcm-oss, snd-mixer-oss and snd-seq-oss.
1462306a36Sopenharmony_ciWhen you need to access the OSS PCM, mixer or sequencer devices, the
1562306a36Sopenharmony_cicorresponding module has to be loaded.
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciThese modules are loaded automatically when the corresponding service
1862306a36Sopenharmony_ciis called.  The alias is defined ``sound-service-x-y``, where x and y are
1962306a36Sopenharmony_cithe card number and the minor unit number.  Usually you don't have to
2062306a36Sopenharmony_cidefine these aliases by yourself.
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciOnly necessary step for auto-loading of OSS modules is to define the
2362306a36Sopenharmony_cicard alias in ``/etc/modprobe.d/alsa.conf``, such as::
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	alias sound-slot-0 snd-emu10k1
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciAs the second card, define ``sound-slot-1`` as well.
2862306a36Sopenharmony_ciNote that you can't use the aliased name as the target name (i.e.
2962306a36Sopenharmony_ci``alias sound-slot-0 snd-card-0`` doesn't work any more like the old
3062306a36Sopenharmony_cimodutils).
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ciThe currently available OSS configuration is shown in
3362306a36Sopenharmony_ci/proc/asound/oss/sndstat.  This shows in the same syntax of
3462306a36Sopenharmony_ci/dev/sndstat, which is available on the commercial OSS driver.
3562306a36Sopenharmony_ciOn ALSA, you can symlink /dev/sndstat to this proc file.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciPlease note that the devices listed in this proc file appear only
3862306a36Sopenharmony_ciafter the corresponding OSS-emulation module is loaded.  Don't worry
3962306a36Sopenharmony_cieven if "NOT ENABLED IN CONFIG" is shown in it.
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciDevice Mapping
4362306a36Sopenharmony_ci==============
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciALSA supports the following OSS device files:
4662306a36Sopenharmony_ci::
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	PCM:
4962306a36Sopenharmony_ci		/dev/dspX
5062306a36Sopenharmony_ci		/dev/adspX
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	Mixer:
5362306a36Sopenharmony_ci		/dev/mixerX
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	MIDI:
5662306a36Sopenharmony_ci		/dev/midi0X
5762306a36Sopenharmony_ci		/dev/amidi0X
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	Sequencer:
6062306a36Sopenharmony_ci		/dev/sequencer
6162306a36Sopenharmony_ci		/dev/sequencer2 (aka /dev/music)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciwhere X is the card number from 0 to 7.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci(NOTE: Some distributions have the device files like /dev/midi0 and
6662306a36Sopenharmony_ci/dev/midi1.  They are NOT for OSS but for tclmidi, which is
6762306a36Sopenharmony_cia totally different thing.)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciUnlike the real OSS, ALSA cannot use the device files more than the
7062306a36Sopenharmony_ciassigned ones.  For example, the first card cannot use /dev/dsp1 or
7162306a36Sopenharmony_ci/dev/dsp2, but only /dev/dsp0 and /dev/adsp0.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciAs seen above, PCM and MIDI may have two devices.  Usually, the first
7462306a36Sopenharmony_ciPCM device (``hw:0,0`` in ALSA) is mapped to /dev/dsp and the secondary
7562306a36Sopenharmony_cidevice (``hw:0,1``) to /dev/adsp (if available).  For MIDI, /dev/midi and
7662306a36Sopenharmony_ci/dev/amidi, respectively.
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ciYou can change this device mapping via the module options of
7962306a36Sopenharmony_cisnd-pcm-oss and snd-rawmidi.  In the case of PCM, the following
8062306a36Sopenharmony_cioptions are available for snd-pcm-oss:
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cidsp_map
8362306a36Sopenharmony_ci	PCM device number assigned to /dev/dspX
8462306a36Sopenharmony_ci	(default = 0)
8562306a36Sopenharmony_ciadsp_map
8662306a36Sopenharmony_ci	PCM device number assigned to /dev/adspX
8762306a36Sopenharmony_ci	(default = 1)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciFor example, to map the third PCM device (``hw:0,2``) to /dev/adsp0,
9062306a36Sopenharmony_cidefine like this:
9162306a36Sopenharmony_ci::
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	options snd-pcm-oss adsp_map=2
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciThe options take arrays.  For configuring the second card, specify
9662306a36Sopenharmony_citwo entries separated by comma.  For example, to map the third PCM
9762306a36Sopenharmony_cidevice on the second card to /dev/adsp1, define like below:
9862306a36Sopenharmony_ci::
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	options snd-pcm-oss adsp_map=0,2
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciTo change the mapping of MIDI devices, the following options are
10362306a36Sopenharmony_ciavailable for snd-rawmidi:
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cimidi_map
10662306a36Sopenharmony_ci	MIDI device number assigned to /dev/midi0X
10762306a36Sopenharmony_ci	(default = 0)
10862306a36Sopenharmony_ciamidi_map
10962306a36Sopenharmony_ci	MIDI device number assigned to /dev/amidi0X
11062306a36Sopenharmony_ci	(default = 1)
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciFor example, to assign the third MIDI device on the first card to
11362306a36Sopenharmony_ci/dev/midi00, define as follows:
11462306a36Sopenharmony_ci::
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci	options snd-rawmidi midi_map=2
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciPCM Mode
12062306a36Sopenharmony_ci========
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ciAs default, ALSA emulates the OSS PCM with so-called plugin layer,
12362306a36Sopenharmony_cii.e. tries to convert the sample format, rate or channels
12462306a36Sopenharmony_ciautomatically when the card doesn't support it natively.
12562306a36Sopenharmony_ciThis will lead to some problems for some applications like quake or
12662306a36Sopenharmony_ciwine, especially if they use the card only in the MMAP mode.
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciIn such a case, you can change the behavior of PCM per application by
12962306a36Sopenharmony_ciwriting a command to the proc file.  There is a proc file for each PCM
13062306a36Sopenharmony_cistream, ``/proc/asound/cardX/pcmY[cp]/oss``, where X is the card number
13162306a36Sopenharmony_ci(zero-based), Y the PCM device number (zero-based), and ``p`` is for
13262306a36Sopenharmony_ciplayback and ``c`` for capture, respectively.  Note that this proc file
13362306a36Sopenharmony_ciexists only after snd-pcm-oss module is loaded.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciThe command sequence has the following syntax:
13662306a36Sopenharmony_ci::
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	app_name fragments fragment_size [options]
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci``app_name`` is the name of application with (higher priority) or without
14162306a36Sopenharmony_cipath.
14262306a36Sopenharmony_ci``fragments`` specifies the number of fragments or zero if no specific
14362306a36Sopenharmony_cinumber is given.
14462306a36Sopenharmony_ci``fragment_size`` is the size of fragment in bytes or zero if not given.
14562306a36Sopenharmony_ci``options`` is the optional parameters.  The following options are
14662306a36Sopenharmony_ciavailable:
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_cidisable
14962306a36Sopenharmony_ci	the application tries to open a pcm device for
15062306a36Sopenharmony_ci	this channel but does not want to use it.
15162306a36Sopenharmony_cidirect
15262306a36Sopenharmony_ci	don't use plugins
15362306a36Sopenharmony_ciblock
15462306a36Sopenharmony_ci	force block open mode
15562306a36Sopenharmony_cinon-block
15662306a36Sopenharmony_ci	force non-block open mode
15762306a36Sopenharmony_cipartial-frag
15862306a36Sopenharmony_ci	write also partial fragments (affects playback only)
15962306a36Sopenharmony_cino-silence
16062306a36Sopenharmony_ci	do not fill silence ahead to avoid clicks
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ciThe ``disable`` option is useful when one stream direction (playback or
16362306a36Sopenharmony_cicapture) is not handled correctly by the application although the
16462306a36Sopenharmony_cihardware itself does support both directions.
16562306a36Sopenharmony_ciThe ``direct`` option is used, as mentioned above, to bypass the automatic
16662306a36Sopenharmony_ciconversion and useful for MMAP-applications.
16762306a36Sopenharmony_ciFor example, to playback the first PCM device without plugins for
16862306a36Sopenharmony_ciquake, send a command via echo like the following:
16962306a36Sopenharmony_ci::
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci	% echo "quake 0 0 direct" > /proc/asound/card0/pcm0p/oss
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ciWhile quake wants only playback, you may append the second command
17462306a36Sopenharmony_cito notify driver that only this direction is about to be allocated:
17562306a36Sopenharmony_ci::
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	% echo "quake 0 0 disable" > /proc/asound/card0/pcm0c/oss
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ciThe permission of proc files depend on the module options of snd.
18062306a36Sopenharmony_ciAs default it's set as root, so you'll likely need to be superuser for
18162306a36Sopenharmony_cisending the command above.
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ciThe block and non-block options are used to change the behavior of
18462306a36Sopenharmony_ciopening the device file.
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ciAs default, ALSA behaves as original OSS drivers, i.e. does not block
18762306a36Sopenharmony_cithe file when it's busy. The -EBUSY error is returned in this case.
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ciThis blocking behavior can be changed globally via nonblock_open
19062306a36Sopenharmony_cimodule option of snd-pcm-oss.  For using the blocking mode as default
19162306a36Sopenharmony_cifor OSS devices, define like the following:
19262306a36Sopenharmony_ci::
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	options snd-pcm-oss nonblock_open=0
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ciThe ``partial-frag`` and ``no-silence`` commands have been added recently.
19762306a36Sopenharmony_ciBoth commands are for optimization use only.  The former command
19862306a36Sopenharmony_cispecifies to invoke the write transfer only when the whole fragment is
19962306a36Sopenharmony_cifilled.  The latter stops writing the silence data ahead
20062306a36Sopenharmony_ciautomatically.  Both are disabled as default.
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ciYou can check the currently defined configuration by reading the proc
20362306a36Sopenharmony_cifile.  The read image can be sent to the proc file again, hence you
20462306a36Sopenharmony_cican save the current configuration
20562306a36Sopenharmony_ci::
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	% cat /proc/asound/card0/pcm0p/oss > /somewhere/oss-cfg
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ciand restore it like
21062306a36Sopenharmony_ci::
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci	% cat /somewhere/oss-cfg > /proc/asound/card0/pcm0p/oss
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ciAlso, for clearing all the current configuration, send ``erase`` command
21562306a36Sopenharmony_cias below:
21662306a36Sopenharmony_ci::
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci	% echo "erase" > /proc/asound/card0/pcm0p/oss
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ciMixer Elements
22262306a36Sopenharmony_ci==============
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ciSince ALSA has completely different mixer interface, the emulation of
22562306a36Sopenharmony_ciOSS mixer is relatively complicated.  ALSA builds up a mixer element
22662306a36Sopenharmony_cifrom several different ALSA (mixer) controls based on the name
22762306a36Sopenharmony_cistring.  For example, the volume element SOUND_MIXER_PCM is composed
22862306a36Sopenharmony_cifrom "PCM Playback Volume" and "PCM Playback Switch" controls for the
22962306a36Sopenharmony_ciplayback direction and from "PCM Capture Volume" and "PCM Capture
23062306a36Sopenharmony_ciSwitch" for the capture directory (if exists).  When the PCM volume of
23162306a36Sopenharmony_ciOSS is changed, all the volume and switch controls above are adjusted
23262306a36Sopenharmony_ciautomatically.
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ciAs default, ALSA uses the following control for OSS volumes:
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci====================	=====================	=====
23762306a36Sopenharmony_ciOSS volume		ALSA control		Index
23862306a36Sopenharmony_ci====================	=====================	=====
23962306a36Sopenharmony_ciSOUND_MIXER_VOLUME 	Master			0
24062306a36Sopenharmony_ciSOUND_MIXER_BASS	Tone Control - Bass	0
24162306a36Sopenharmony_ciSOUND_MIXER_TREBLE	Tone Control - Treble	0
24262306a36Sopenharmony_ciSOUND_MIXER_SYNTH	Synth			0
24362306a36Sopenharmony_ciSOUND_MIXER_PCM		PCM			0
24462306a36Sopenharmony_ciSOUND_MIXER_SPEAKER	PC Speaker 		0
24562306a36Sopenharmony_ciSOUND_MIXER_LINE	Line			0
24662306a36Sopenharmony_ciSOUND_MIXER_MIC		Mic 			0
24762306a36Sopenharmony_ciSOUND_MIXER_CD		CD 			0
24862306a36Sopenharmony_ciSOUND_MIXER_IMIX	Monitor Mix 		0
24962306a36Sopenharmony_ciSOUND_MIXER_ALTPCM	PCM			1
25062306a36Sopenharmony_ciSOUND_MIXER_RECLEV	(not assigned)
25162306a36Sopenharmony_ciSOUND_MIXER_IGAIN	Capture			0
25262306a36Sopenharmony_ciSOUND_MIXER_OGAIN	Playback		0
25362306a36Sopenharmony_ciSOUND_MIXER_LINE1	Aux			0
25462306a36Sopenharmony_ciSOUND_MIXER_LINE2	Aux			1
25562306a36Sopenharmony_ciSOUND_MIXER_LINE3	Aux			2
25662306a36Sopenharmony_ciSOUND_MIXER_DIGITAL1	Digital			0
25762306a36Sopenharmony_ciSOUND_MIXER_DIGITAL2	Digital			1
25862306a36Sopenharmony_ciSOUND_MIXER_DIGITAL3	Digital			2
25962306a36Sopenharmony_ciSOUND_MIXER_PHONEIN	Phone			0
26062306a36Sopenharmony_ciSOUND_MIXER_PHONEOUT	Phone			1
26162306a36Sopenharmony_ciSOUND_MIXER_VIDEO	Video			0
26262306a36Sopenharmony_ciSOUND_MIXER_RADIO	Radio			0
26362306a36Sopenharmony_ciSOUND_MIXER_MONITOR	Monitor			0
26462306a36Sopenharmony_ci====================	=====================	=====
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ciThe second column is the base-string of the corresponding ALSA
26762306a36Sopenharmony_cicontrol.  In fact, the controls with ``XXX [Playback|Capture]
26862306a36Sopenharmony_ci[Volume|Switch]`` will be checked in addition.
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ciThe current assignment of these mixer elements is listed in the proc
27162306a36Sopenharmony_cifile, /proc/asound/cardX/oss_mixer, which will be like the following
27262306a36Sopenharmony_ci::
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	VOLUME "Master" 0
27562306a36Sopenharmony_ci	BASS "" 0
27662306a36Sopenharmony_ci	TREBLE "" 0
27762306a36Sopenharmony_ci	SYNTH "" 0
27862306a36Sopenharmony_ci	PCM "PCM" 0
27962306a36Sopenharmony_ci	...
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ciwhere the first column is the OSS volume element, the second column
28262306a36Sopenharmony_cithe base-string of the corresponding ALSA control, and the third the
28362306a36Sopenharmony_cicontrol index.  When the string is empty, it means that the
28462306a36Sopenharmony_cicorresponding OSS control is not available.
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ciFor changing the assignment, you can write the configuration to this
28762306a36Sopenharmony_ciproc file.  For example, to map "Wave Playback" to the PCM volume,
28862306a36Sopenharmony_cisend the command like the following:
28962306a36Sopenharmony_ci::
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci	% echo 'VOLUME "Wave Playback" 0' > /proc/asound/card0/oss_mixer
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ciThe command is exactly as same as listed in the proc file.  You can
29462306a36Sopenharmony_cichange one or more elements, one volume per line.  In the last
29562306a36Sopenharmony_ciexample, both "Wave Playback Volume" and "Wave Playback Switch" will
29662306a36Sopenharmony_cibe affected when PCM volume is changed.
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ciLike the case of PCM proc file, the permission of proc files depend on
29962306a36Sopenharmony_cithe module options of snd.  you'll likely need to be superuser for
30062306a36Sopenharmony_cisending the command above.
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ciAs well as in the case of PCM proc file, you can save and restore the
30362306a36Sopenharmony_cicurrent mixer configuration by reading and writing the whole file
30462306a36Sopenharmony_ciimage.
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ciDuplex Streams
30862306a36Sopenharmony_ci==============
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ciNote that when attempting to use a single device file for playback and
31162306a36Sopenharmony_cicapture, the OSS API provides no way to set the format, sample rate or
31262306a36Sopenharmony_cinumber of channels different in each direction.  Thus
31362306a36Sopenharmony_ci::
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci	io_handle = open("device", O_RDWR)
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ciwill only function correctly if the values are the same in each direction.
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ciTo use different values in the two directions, use both
32062306a36Sopenharmony_ci::
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci	input_handle = open("device", O_RDONLY)
32362306a36Sopenharmony_ci	output_handle = open("device", O_WRONLY)
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ciand set the values for the corresponding handle.
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ciUnsupported Features
32962306a36Sopenharmony_ci====================
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ciMMAP on ICE1712 driver
33262306a36Sopenharmony_ci----------------------
33362306a36Sopenharmony_ciICE1712 supports only the unconventional format, interleaved
33462306a36Sopenharmony_ci10-channels 24bit (packed in 32bit) format.  Therefore you cannot mmap
33562306a36Sopenharmony_cithe buffer as the conventional (mono or 2-channels, 8 or 16bit) format
33662306a36Sopenharmony_cion OSS.
337