seq_oss.html 15 KB

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