seq-oss.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. ===============================
  2. OSS Sequencer Emulation on ALSA
  3. ===============================
  4. Copyright (c) 1998,1999 by Takashi Iwai
  5. ver.0.1.8; Nov. 16, 1999
  6. Description
  7. ===========
  8. This directory contains the OSS sequencer emulation driver on ALSA. Note
  9. that this program is still in the development state.
  10. What this does - it provides the emulation of the OSS sequencer, access
  11. via ``/dev/sequencer`` and ``/dev/music`` devices.
  12. The most of applications using OSS can run if the appropriate ALSA
  13. sequencer is prepared.
  14. The following features are emulated by this driver:
  15. * Normal sequencer and MIDI events:
  16. They are converted to the ALSA sequencer events, and sent to the
  17. corresponding port.
  18. * Timer events:
  19. The timer is not selectable by ioctl. The control rate is fixed to
  20. 100 regardless of HZ. That is, even on Alpha system, a tick is always
  21. 1/100 second. The base rate and tempo can be changed in ``/dev/music``.
  22. * Patch loading:
  23. It purely depends on the synth drivers whether it's supported since
  24. the patch loading is realized by callback to the synth driver.
  25. * I/O controls:
  26. Most of controls are accepted. Some controls
  27. are dependent on the synth driver, as well as even on original OSS.
  28. Furthermore, you can find the following advanced features:
  29. * Better queue mechanism:
  30. The events are queued before processing them.
  31. * Multiple applications:
  32. You can run two or more applications simultaneously (even for OSS
  33. sequencer)!
  34. However, each MIDI device is exclusive - that is, if a MIDI device
  35. is opened once by some application, other applications can't use
  36. it. No such a restriction in synth devices.
  37. * Real-time event processing:
  38. The events can be processed in real time without using out of bound
  39. ioctl. To switch to real-time mode, send ABSTIME 0 event. The followed
  40. events will be processed in real-time without queued. To switch off the
  41. real-time mode, send RELTIME 0 event.
  42. * ``/proc`` interface:
  43. The status of applications and devices can be shown via
  44. ``/proc/asound/seq/oss`` at any time. In the later version,
  45. configuration will be changed via ``/proc`` interface, too.
  46. Installation
  47. ============
  48. Run configure script with both sequencer support (``--with-sequencer=yes``)
  49. and OSS emulation (``--with-oss=yes``) options. A module ``snd-seq-oss.o``
  50. will be created. If the synth module of your sound card supports for OSS
  51. emulation (so far, only Emu8000 driver), this module will be loaded
  52. automatically.
  53. Otherwise, you need to load this module manually.
  54. At beginning, this module probes all the MIDI ports which have been
  55. already connected to the sequencer. Once after that, the creation and deletion
  56. of ports are watched by announcement mechanism of ALSA sequencer.
  57. The available synth and MIDI devices can be found in proc interface.
  58. Run ``cat /proc/asound/seq/oss``, and check the devices. For example,
  59. if you use an AWE64 card, you'll see like the following:
  60. ::
  61. OSS sequencer emulation version 0.1.8
  62. ALSA client number 63
  63. ALSA receiver port 0
  64. Number of applications: 0
  65. Number of synth devices: 1
  66. synth 0: [EMU8000]
  67. type 0x1 : subtype 0x20 : voices 32
  68. capabilties : ioctl enabled / load_patch enabled
  69. Number of MIDI devices: 3
  70. midi 0: [Emu8000 Port-0] ALSA port 65:0
  71. capability write / opened none
  72. midi 1: [Emu8000 Port-1] ALSA port 65:1
  73. capability write / opened none
  74. midi 2: [0: MPU-401 (UART)] ALSA port 64:0
  75. capability read/write / opened none
  76. Note that the device number may be different from the information of
  77. ``/proc/asound/oss-devices`` or ones of the original OSS driver.
  78. Use the device number listed in ``/proc/asound/seq/oss``
  79. to play via OSS sequencer emulation.
  80. Using Synthesizer Devices
  81. =========================
  82. Run your favorite program. I've tested playmidi-2.4, awemidi-0.4.3, gmod-3.1
  83. and xmp-1.1.5. You can load samples via ``/dev/sequencer`` like sfxload,
  84. too.
  85. If the lowlevel driver supports multiple access to synth devices (like
  86. Emu8000 driver), two or more applications are allowed to run at the same
  87. time.
  88. Using MIDI Devices
  89. ==================
  90. So far, only MIDI output was tested. MIDI input was not checked at all,
  91. but hopefully it will work. Use the device number listed in
  92. ``/proc/asound/seq/oss``.
  93. Be aware that these numbers are mostly different from the list in
  94. ``/proc/asound/oss-devices``.
  95. Module Options
  96. ==============
  97. The following module options are available:
  98. maxqlen
  99. specifies the maximum read/write queue length. This queue is private
  100. for OSS sequencer, so that it is independent from the queue length of ALSA
  101. sequencer. Default value is 1024.
  102. seq_oss_debug
  103. specifies the debug level and accepts zero (= no debug message) or
  104. positive integer. Default value is 0.
  105. Queue Mechanism
  106. ===============
  107. OSS sequencer emulation uses an ALSA priority queue. The
  108. events from ``/dev/sequencer`` are processed and put onto the queue
  109. specified by module option.
  110. All the events from ``/dev/sequencer`` are parsed at beginning.
  111. The timing events are also parsed at this moment, so that the events may
  112. be processed in real-time. Sending an event ABSTIME 0 switches the operation
  113. mode to real-time mode, and sending an event RELTIME 0 switches it off.
  114. In the real-time mode, all events are dispatched immediately.
  115. The queued events are dispatched to the corresponding ALSA sequencer
  116. ports after scheduled time by ALSA sequencer dispatcher.
  117. If the write-queue is full, the application sleeps until a certain amount
  118. (as default one half) becomes empty in blocking mode. The synchronization
  119. to write timing was implemented, too.
  120. The input from MIDI devices or echo-back events are stored on read FIFO
  121. queue. If application reads ``/dev/sequencer`` in blocking mode, the
  122. process will be awaked.
  123. Interface to Synthesizer Device
  124. ===============================
  125. Registration
  126. ------------
  127. To register an OSS synthesizer device, use snd_seq_oss_synth_register()
  128. function:
  129. ::
  130. int snd_seq_oss_synth_register(char *name, int type, int subtype, int nvoices,
  131. snd_seq_oss_callback_t *oper, void *private_data)
  132. The arguments ``name``, ``type``, ``subtype`` and ``nvoices``
  133. are used for making the appropriate synth_info structure for ioctl. The
  134. return value is an index number of this device. This index must be remembered
  135. for unregister. If registration is failed, -errno will be returned.
  136. To release this device, call snd_seq_oss_synth_unregister() function:
  137. ::
  138. int snd_seq_oss_synth_unregister(int index)
  139. where the ``index`` is the index number returned by register function.
  140. Callbacks
  141. ---------
  142. OSS synthesizer devices have capability for sample downloading and ioctls
  143. like sample reset. In OSS emulation, these special features are realized
  144. by using callbacks. The registration argument oper is used to specify these
  145. callbacks. The following callback functions must be defined:
  146. ::
  147. snd_seq_oss_callback_t:
  148. int (*open)(snd_seq_oss_arg_t *p, void *closure);
  149. int (*close)(snd_seq_oss_arg_t *p);
  150. int (*ioctl)(snd_seq_oss_arg_t *p, unsigned int cmd, unsigned long arg);
  151. int (*load_patch)(snd_seq_oss_arg_t *p, int format, const char *buf, int offs, int count);
  152. int (*reset)(snd_seq_oss_arg_t *p);
  153. Except for ``open`` and ``close`` callbacks, they are allowed to be NULL.
  154. Each callback function takes the argument type ``snd_seq_oss_arg_t`` as the
  155. first argument.
  156. ::
  157. struct snd_seq_oss_arg_t {
  158. int app_index;
  159. int file_mode;
  160. int seq_mode;
  161. snd_seq_addr_t addr;
  162. void *private_data;
  163. int event_passing;
  164. };
  165. The first three fields, ``app_index``, ``file_mode`` and ``seq_mode``
  166. are initialized by OSS sequencer. The ``app_index`` is the application
  167. index which is unique to each application opening OSS sequencer. The
  168. ``file_mode`` is bit-flags indicating the file operation mode. See
  169. ``seq_oss.h`` for its meaning. The ``seq_mode`` is sequencer operation
  170. mode. In the current version, only ``SND_OSSSEQ_MODE_SYNTH`` is used.
  171. The next two fields, ``addr`` and ``private_data``, must be
  172. filled by the synth driver at open callback. The ``addr`` contains
  173. the address of ALSA sequencer port which is assigned to this device. If
  174. the driver allocates memory for ``private_data``, it must be released
  175. in close callback by itself.
  176. The last field, ``event_passing``, indicates how to translate note-on
  177. / off events. In ``PROCESS_EVENTS`` mode, the note 255 is regarded
  178. as velocity change, and key pressure event is passed to the port. In
  179. ``PASS_EVENTS`` mode, all note on/off events are passed to the port
  180. without modified. ``PROCESS_KEYPRESS`` mode checks the note above 128
  181. and regards it as key pressure event (mainly for Emu8000 driver).
  182. Open Callback
  183. -------------
  184. The ``open`` is called at each time this device is opened by an application
  185. using OSS sequencer. This must not be NULL. Typically, the open callback
  186. does the following procedure:
  187. #. Allocate private data record.
  188. #. Create an ALSA sequencer port.
  189. #. Set the new port address on ``arg->addr``.
  190. #. Set the private data record pointer on ``arg->private_data``.
  191. Note that the type bit-flags in port_info of this synth port must NOT contain
  192. ``TYPE_MIDI_GENERIC``
  193. bit. Instead, ``TYPE_SPECIFIC`` should be used. Also, ``CAP_SUBSCRIPTION``
  194. bit should NOT be included, too. This is necessary to tell it from other
  195. normal MIDI devices. If the open procedure succeeded, return zero. Otherwise,
  196. return -errno.
  197. Ioctl Callback
  198. --------------
  199. The ``ioctl`` callback is called when the sequencer receives device-specific
  200. ioctls. The following two ioctls should be processed by this callback:
  201. IOCTL_SEQ_RESET_SAMPLES
  202. reset all samples on memory -- return 0
  203. IOCTL_SYNTH_MEMAVL
  204. return the available memory size
  205. FM_4OP_ENABLE
  206. can be ignored usually
  207. The other ioctls are processed inside the sequencer without passing to
  208. the lowlevel driver.
  209. Load_Patch Callback
  210. -------------------
  211. The ``load_patch`` callback is used for sample-downloading. This callback
  212. must read the data on user-space and transfer to each device. Return 0
  213. if succeeded, and -errno if failed. The format argument is the patch key
  214. in patch_info record. The buf is user-space pointer where patch_info record
  215. is stored. The offs can be ignored. The count is total data size of this
  216. sample data.
  217. Close Callback
  218. --------------
  219. The ``close`` callback is called when this device is closed by the
  220. application. If any private data was allocated in open callback, it must
  221. be released in the close callback. The deletion of ALSA port should be
  222. done here, too. This callback must not be NULL.
  223. Reset Callback
  224. --------------
  225. The ``reset`` callback is called when sequencer device is reset or
  226. closed by applications. The callback should turn off the sounds on the
  227. relevant port immediately, and initialize the status of the port. If this
  228. callback is undefined, OSS seq sends a ``HEARTBEAT`` event to the
  229. port.
  230. Events
  231. ======
  232. Most of the events are processed by sequencer and translated to the adequate
  233. ALSA sequencer events, so that each synth device can receive by input_event
  234. callback of ALSA sequencer port. The following ALSA events should be
  235. implemented by the driver:
  236. ============= ===================
  237. ALSA event Original OSS events
  238. ============= ===================
  239. NOTEON SEQ_NOTEON, MIDI_NOTEON
  240. NOTE SEQ_NOTEOFF, MIDI_NOTEOFF
  241. KEYPRESS MIDI_KEY_PRESSURE
  242. CHANPRESS SEQ_AFTERTOUCH, MIDI_CHN_PRESSURE
  243. PGMCHANGE SEQ_PGMCHANGE, MIDI_PGM_CHANGE
  244. PITCHBEND SEQ_CONTROLLER(CTRL_PITCH_BENDER),
  245. MIDI_PITCH_BEND
  246. CONTROLLER MIDI_CTL_CHANGE,
  247. SEQ_BALANCE (with CTL_PAN)
  248. CONTROL14 SEQ_CONTROLLER
  249. REGPARAM SEQ_CONTROLLER(CTRL_PITCH_BENDER_RANGE)
  250. SYSEX SEQ_SYSEX
  251. ============= ===================
  252. The most of these behavior can be realized by MIDI emulation driver
  253. included in the Emu8000 lowlevel driver. In the future release, this module
  254. will be independent.
  255. Some OSS events (``SEQ_PRIVATE`` and ``SEQ_VOLUME`` events) are passed as event
  256. type SND_SEQ_OSS_PRIVATE. The OSS sequencer passes these event 8 byte
  257. packets without any modification. The lowlevel driver should process these
  258. events appropriately.
  259. Interface to MIDI Device
  260. ========================
  261. Since the OSS emulation probes the creation and deletion of ALSA MIDI
  262. sequencer ports automatically by receiving announcement from ALSA
  263. sequencer, the MIDI devices don't need to be registered explicitly
  264. like synth devices.
  265. However, the MIDI port_info registered to ALSA sequencer must include
  266. a group name ``SND_SEQ_GROUP_DEVICE`` and a capability-bit
  267. ``CAP_READ`` or ``CAP_WRITE``. Also, subscription capabilities,
  268. ``CAP_SUBS_READ`` or ``CAP_SUBS_WRITE``, must be defined, too. If
  269. these conditions are not satisfied, the port is not registered as OSS
  270. sequencer MIDI device.
  271. The events via MIDI devices are parsed in OSS sequencer and converted
  272. to the corresponding ALSA sequencer events. The input from MIDI sequencer
  273. is also converted to MIDI byte events by OSS sequencer. This works just
  274. a reverse way of seq_midi module.
  275. Known Problems / TODO's
  276. =======================
  277. * Patch loading via ALSA instrument layer is not implemented yet.