oss-emulation.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. =============================
  2. Notes on Kernel OSS-Emulation
  3. =============================
  4. Jan. 22, 2004 Takashi Iwai <[email protected]>
  5. Modules
  6. =======
  7. ALSA provides a powerful OSS emulation on the kernel.
  8. The OSS emulation for PCM, mixer and sequencer devices is implemented
  9. as add-on kernel modules, snd-pcm-oss, snd-mixer-oss and snd-seq-oss.
  10. When you need to access the OSS PCM, mixer or sequencer devices, the
  11. corresponding module has to be loaded.
  12. These modules are loaded automatically when the corresponding service
  13. is called. The alias is defined ``sound-service-x-y``, where x and y are
  14. the card number and the minor unit number. Usually you don't have to
  15. define these aliases by yourself.
  16. Only necessary step for auto-loading of OSS modules is to define the
  17. card alias in ``/etc/modprobe.d/alsa.conf``, such as::
  18. alias sound-slot-0 snd-emu10k1
  19. As the second card, define ``sound-slot-1`` as well.
  20. Note that you can't use the aliased name as the target name (i.e.
  21. ``alias sound-slot-0 snd-card-0`` doesn't work any more like the old
  22. modutils).
  23. The currently available OSS configuration is shown in
  24. /proc/asound/oss/sndstat. This shows in the same syntax of
  25. /dev/sndstat, which is available on the commercial OSS driver.
  26. On ALSA, you can symlink /dev/sndstat to this proc file.
  27. Please note that the devices listed in this proc file appear only
  28. after the corresponding OSS-emulation module is loaded. Don't worry
  29. even if "NOT ENABLED IN CONFIG" is shown in it.
  30. Device Mapping
  31. ==============
  32. ALSA supports the following OSS device files:
  33. ::
  34. PCM:
  35. /dev/dspX
  36. /dev/adspX
  37. Mixer:
  38. /dev/mixerX
  39. MIDI:
  40. /dev/midi0X
  41. /dev/amidi0X
  42. Sequencer:
  43. /dev/sequencer
  44. /dev/sequencer2 (aka /dev/music)
  45. where X is the card number from 0 to 7.
  46. (NOTE: Some distributions have the device files like /dev/midi0 and
  47. /dev/midi1. They are NOT for OSS but for tclmidi, which is
  48. a totally different thing.)
  49. Unlike the real OSS, ALSA cannot use the device files more than the
  50. assigned ones. For example, the first card cannot use /dev/dsp1 or
  51. /dev/dsp2, but only /dev/dsp0 and /dev/adsp0.
  52. As seen above, PCM and MIDI may have two devices. Usually, the first
  53. PCM device (``hw:0,0`` in ALSA) is mapped to /dev/dsp and the secondary
  54. device (``hw:0,1``) to /dev/adsp (if available). For MIDI, /dev/midi and
  55. /dev/amidi, respectively.
  56. You can change this device mapping via the module options of
  57. snd-pcm-oss and snd-rawmidi. In the case of PCM, the following
  58. options are available for snd-pcm-oss:
  59. dsp_map
  60. PCM device number assigned to /dev/dspX
  61. (default = 0)
  62. adsp_map
  63. PCM device number assigned to /dev/adspX
  64. (default = 1)
  65. For example, to map the third PCM device (``hw:0,2``) to /dev/adsp0,
  66. define like this:
  67. ::
  68. options snd-pcm-oss adsp_map=2
  69. The options take arrays. For configuring the second card, specify
  70. two entries separated by comma. For example, to map the third PCM
  71. device on the second card to /dev/adsp1, define like below:
  72. ::
  73. options snd-pcm-oss adsp_map=0,2
  74. To change the mapping of MIDI devices, the following options are
  75. available for snd-rawmidi:
  76. midi_map
  77. MIDI device number assigned to /dev/midi0X
  78. (default = 0)
  79. amidi_map
  80. MIDI device number assigned to /dev/amidi0X
  81. (default = 1)
  82. For example, to assign the third MIDI device on the first card to
  83. /dev/midi00, define as follows:
  84. ::
  85. options snd-rawmidi midi_map=2
  86. PCM Mode
  87. ========
  88. As default, ALSA emulates the OSS PCM with so-called plugin layer,
  89. i.e. tries to convert the sample format, rate or channels
  90. automatically when the card doesn't support it natively.
  91. This will lead to some problems for some applications like quake or
  92. wine, especially if they use the card only in the MMAP mode.
  93. In such a case, you can change the behavior of PCM per application by
  94. writing a command to the proc file. There is a proc file for each PCM
  95. stream, ``/proc/asound/cardX/pcmY[cp]/oss``, where X is the card number
  96. (zero-based), Y the PCM device number (zero-based), and ``p`` is for
  97. playback and ``c`` for capture, respectively. Note that this proc file
  98. exists only after snd-pcm-oss module is loaded.
  99. The command sequence has the following syntax:
  100. ::
  101. app_name fragments fragment_size [options]
  102. ``app_name`` is the name of application with (higher priority) or without
  103. path.
  104. ``fragments`` specifies the number of fragments or zero if no specific
  105. number is given.
  106. ``fragment_size`` is the size of fragment in bytes or zero if not given.
  107. ``options`` is the optional parameters. The following options are
  108. available:
  109. disable
  110. the application tries to open a pcm device for
  111. this channel but does not want to use it.
  112. direct
  113. don't use plugins
  114. block
  115. force block open mode
  116. non-block
  117. force non-block open mode
  118. partial-frag
  119. write also partial fragments (affects playback only)
  120. no-silence
  121. do not fill silence ahead to avoid clicks
  122. The ``disable`` option is useful when one stream direction (playback or
  123. capture) is not handled correctly by the application although the
  124. hardware itself does support both directions.
  125. The ``direct`` option is used, as mentioned above, to bypass the automatic
  126. conversion and useful for MMAP-applications.
  127. For example, to playback the first PCM device without plugins for
  128. quake, send a command via echo like the following:
  129. ::
  130. % echo "quake 0 0 direct" > /proc/asound/card0/pcm0p/oss
  131. While quake wants only playback, you may append the second command
  132. to notify driver that only this direction is about to be allocated:
  133. ::
  134. % echo "quake 0 0 disable" > /proc/asound/card0/pcm0c/oss
  135. The permission of proc files depend on the module options of snd.
  136. As default it's set as root, so you'll likely need to be superuser for
  137. sending the command above.
  138. The block and non-block options are used to change the behavior of
  139. opening the device file.
  140. As default, ALSA behaves as original OSS drivers, i.e. does not block
  141. the file when it's busy. The -EBUSY error is returned in this case.
  142. This blocking behavior can be changed globally via nonblock_open
  143. module option of snd-pcm-oss. For using the blocking mode as default
  144. for OSS devices, define like the following:
  145. ::
  146. options snd-pcm-oss nonblock_open=0
  147. The ``partial-frag`` and ``no-silence`` commands have been added recently.
  148. Both commands are for optimization use only. The former command
  149. specifies to invoke the write transfer only when the whole fragment is
  150. filled. The latter stops writing the silence data ahead
  151. automatically. Both are disabled as default.
  152. You can check the currently defined configuration by reading the proc
  153. file. The read image can be sent to the proc file again, hence you
  154. can save the current configuration
  155. ::
  156. % cat /proc/asound/card0/pcm0p/oss > /somewhere/oss-cfg
  157. and restore it like
  158. ::
  159. % cat /somewhere/oss-cfg > /proc/asound/card0/pcm0p/oss
  160. Also, for clearing all the current configuration, send ``erase`` command
  161. as below:
  162. ::
  163. % echo "erase" > /proc/asound/card0/pcm0p/oss
  164. Mixer Elements
  165. ==============
  166. Since ALSA has completely different mixer interface, the emulation of
  167. OSS mixer is relatively complicated. ALSA builds up a mixer element
  168. from several different ALSA (mixer) controls based on the name
  169. string. For example, the volume element SOUND_MIXER_PCM is composed
  170. from "PCM Playback Volume" and "PCM Playback Switch" controls for the
  171. playback direction and from "PCM Capture Volume" and "PCM Capture
  172. Switch" for the capture directory (if exists). When the PCM volume of
  173. OSS is changed, all the volume and switch controls above are adjusted
  174. automatically.
  175. As default, ALSA uses the following control for OSS volumes:
  176. ==================== ===================== =====
  177. OSS volume ALSA control Index
  178. ==================== ===================== =====
  179. SOUND_MIXER_VOLUME Master 0
  180. SOUND_MIXER_BASS Tone Control - Bass 0
  181. SOUND_MIXER_TREBLE Tone Control - Treble 0
  182. SOUND_MIXER_SYNTH Synth 0
  183. SOUND_MIXER_PCM PCM 0
  184. SOUND_MIXER_SPEAKER PC Speaker 0
  185. SOUND_MIXER_LINE Line 0
  186. SOUND_MIXER_MIC Mic 0
  187. SOUND_MIXER_CD CD 0
  188. SOUND_MIXER_IMIX Monitor Mix 0
  189. SOUND_MIXER_ALTPCM PCM 1
  190. SOUND_MIXER_RECLEV (not assigned)
  191. SOUND_MIXER_IGAIN Capture 0
  192. SOUND_MIXER_OGAIN Playback 0
  193. SOUND_MIXER_LINE1 Aux 0
  194. SOUND_MIXER_LINE2 Aux 1
  195. SOUND_MIXER_LINE3 Aux 2
  196. SOUND_MIXER_DIGITAL1 Digital 0
  197. SOUND_MIXER_DIGITAL2 Digital 1
  198. SOUND_MIXER_DIGITAL3 Digital 2
  199. SOUND_MIXER_PHONEIN Phone 0
  200. SOUND_MIXER_PHONEOUT Phone 1
  201. SOUND_MIXER_VIDEO Video 0
  202. SOUND_MIXER_RADIO Radio 0
  203. SOUND_MIXER_MONITOR Monitor 0
  204. ==================== ===================== =====
  205. The second column is the base-string of the corresponding ALSA
  206. control. In fact, the controls with ``XXX [Playback|Capture]
  207. [Volume|Switch]`` will be checked in addition.
  208. The current assignment of these mixer elements is listed in the proc
  209. file, /proc/asound/cardX/oss_mixer, which will be like the following
  210. ::
  211. VOLUME "Master" 0
  212. BASS "" 0
  213. TREBLE "" 0
  214. SYNTH "" 0
  215. PCM "PCM" 0
  216. ...
  217. where the first column is the OSS volume element, the second column
  218. the base-string of the corresponding ALSA control, and the third the
  219. control index. When the string is empty, it means that the
  220. corresponding OSS control is not available.
  221. For changing the assignment, you can write the configuration to this
  222. proc file. For example, to map "Wave Playback" to the PCM volume,
  223. send the command like the following:
  224. ::
  225. % echo 'VOLUME "Wave Playback" 0' > /proc/asound/card0/oss_mixer
  226. The command is exactly as same as listed in the proc file. You can
  227. change one or more elements, one volume per line. In the last
  228. example, both "Wave Playback Volume" and "Wave Playback Switch" will
  229. be affected when PCM volume is changed.
  230. Like the case of PCM proc file, the permission of proc files depend on
  231. the module options of snd. you'll likely need to be superuser for
  232. sending the command above.
  233. As well as in the case of PCM proc file, you can save and restore the
  234. current mixer configuration by reading and writing the whole file
  235. image.
  236. Duplex Streams
  237. ==============
  238. Note that when attempting to use a single device file for playback and
  239. capture, the OSS API provides no way to set the format, sample rate or
  240. number of channels different in each direction. Thus
  241. ::
  242. io_handle = open("device", O_RDWR)
  243. will only function correctly if the values are the same in each direction.
  244. To use different values in the two directions, use both
  245. ::
  246. input_handle = open("device", O_RDONLY)
  247. output_handle = open("device", O_WRONLY)
  248. and set the values for the corresponding handle.
  249. Unsupported Features
  250. ====================
  251. MMAP on ICE1712 driver
  252. ----------------------
  253. ICE1712 supports only the unconventional format, interleaved
  254. 10-channels 24bit (packed in 32bit) format. Therefore you cannot mmap
  255. the buffer as the conventional (mono or 2-channels, 8 or 16bit) format
  256. on OSS.