Fix compile warning.
[dragonfly.git] / sys / sys / soundcard.h
1 /*
2  * soundcard.h
3  *
4  * Copyright by Hannu Savolainen 1993
5  * Modified for the new FreeBSD sound driver by Luigi Rizzo, 1997
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above
13  *    copyright notice, this list of conditions and the following
14  *    disclaimer in the documentation and/or other materials provided
15  *    with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD: src/sys/sys/soundcard.h,v 1.33.2.4 2003/06/07 21:31:56 mbr Exp $
31  * $DragonFly: src/sys/sys/soundcard.h,v 1.3 2003/08/20 07:31:21 rob Exp $
32  */
33
34 #ifndef _SYS_SOUNDCARD_H_
35 #define _SYS_SOUNDCARD_H_
36  /*
37   * If you make modifications to this file, please contact me before
38   * distributing the modified version. There is already enough
39   * diversity in the world.
40   *
41   * Regards,
42   * Hannu Savolainen
43   * hannu@voxware.pp.fi
44   *
45   **********************************************************************
46   * PS. The Hacker's Guide to VoxWare available from
47   *     nic.funet.fi:pub/Linux/ALPHA/sound. The file is
48   *     snd-sdk-doc-0.1.ps.gz (gzipped postscript). It contains
49   *     some useful information about programming with VoxWare.
50   *     (NOTE! The pub/Linux/ALPHA/ directories are hidden. You have
51   *     to cd inside them before the files are accessible.)
52   **********************************************************************
53   */
54
55 /*
56  * SOUND_VERSION is only used by the voxware driver. Hopefully apps
57  * should not depend on it, but rather look at the capabilities
58  * of the driver in the kernel!
59  */
60 #define SOUND_VERSION  301
61 #define VOXWARE         /* does this have any use ? */
62
63 /*
64  * Supported card ID numbers (Should be somewhere else? We keep
65  * them here just for compativility with the old driver, but these
66  * constants are of little or no use).
67  */
68
69 #define SNDCARD_ADLIB          1
70 #define SNDCARD_SB             2
71 #define SNDCARD_PAS            3
72 #define SNDCARD_GUS            4
73 #define SNDCARD_MPU401         5
74 #define SNDCARD_SB16           6
75 #define SNDCARD_SB16MIDI       7
76 #define SNDCARD_UART6850       8
77 #define SNDCARD_GUS16          9
78 #define SNDCARD_MSS            10
79 #define SNDCARD_PSS            11
80 #define SNDCARD_SSCAPE         12
81 #define SNDCARD_PSS_MPU        13
82 #define SNDCARD_PSS_MSS        14
83 #define SNDCARD_SSCAPE_MSS     15
84 #define SNDCARD_TRXPRO         16
85 #define SNDCARD_TRXPRO_SB      17
86 #define SNDCARD_TRXPRO_MPU     18
87 #define SNDCARD_MAD16          19
88 #define SNDCARD_MAD16_MPU      20
89 #define SNDCARD_CS4232         21
90 #define SNDCARD_CS4232_MPU     22
91 #define SNDCARD_MAUI           23
92 #define SNDCARD_PSEUDO_MSS     24
93 #define SNDCARD_AWE32           25
94 #define SNDCARD_NSS            26
95 #define SNDCARD_UART16550      27
96 #define SNDCARD_OPL            28
97
98 #include <sys/types.h>
99 #include <machine/endian.h>
100 #ifndef _IOWR
101 #include <sys/ioccom.h>
102 #endif  /* !_IOWR */
103
104 /*
105  * The first part of this file contains the new FreeBSD sound ioctl
106  * interface. Tries to minimize the number of different ioctls, and
107  * to be reasonably general.
108  *
109  * 970821: some of the new calls have not been implemented yet.
110  */
111
112 /*
113  * the following three calls extend the generic file descriptor
114  * interface. AIONWRITE is the dual of FIONREAD, i.e. returns the max
115  * number of bytes for a write operation to be non-blocking.
116  *
117  * AIOGSIZE/AIOSSIZE are used to change the behaviour of the device,
118  * from a character device (default) to a block device. In block mode,
119  * (not to be confused with blocking mode) the main difference for the
120  * application is that select() will return only when a complete
121  * block can be read/written to the device, whereas in character mode
122  * select will return true when one byte can be exchanged. For audio
123  * devices, character mode makes select almost useless since one byte
124  * will always be ready by the next sample time (which is often only a
125  * handful of microseconds away).
126  * Use a size of 0 or 1 to return to character mode.
127  */
128 #define AIONWRITE   _IOR('A', 10, int)   /* get # bytes to write */
129 struct snd_size {
130     int play_size;
131     int rec_size;
132 };
133 #define AIOGSIZE    _IOR('A', 11, struct snd_size)/* read current blocksize */
134 #define AIOSSIZE    _IOWR('A', 11, struct snd_size)  /* sets blocksize */
135
136 /*
137  * The following constants define supported audio formats. The
138  * encoding follows voxware conventions, i.e. 1 bit for each supported
139  * format. We extend it by using bit 31 (RO) to indicate full-duplex
140  * capability, and bit 29 (RO) to indicate that the card supports/
141  * needs different formats on capture & playback channels.
142  * Bit 29 (RW) is used to indicate/ask stereo.
143  *
144  * The number of bits required to store the sample is:
145  *  o  4 bits for the IDA ADPCM format,
146  *  o  8 bits for 8-bit formats, mu-law and A-law,
147  *  o  16 bits for the 16-bit formats, and
148  *  o  32 bits for the 24/32-bit formats.
149  *  o  undefined for the MPEG audio format.
150  */
151
152 #define AFMT_QUERY      0x00000000      /* Return current format */
153 #define AFMT_MU_LAW     0x00000001      /* Logarithmic mu-law */
154 #define AFMT_A_LAW      0x00000002      /* Logarithmic A-law */
155 #define AFMT_IMA_ADPCM  0x00000004      /* A 4:1 compressed format where 16-bit
156                                          * squence represented using the
157                                          * the average 4 bits per sample */
158 #define AFMT_U8         0x00000008      /* Unsigned 8-bit */
159 #define AFMT_S16_LE     0x00000010      /* Little endian signed 16-bit */
160 #define AFMT_S16_BE     0x00000020      /* Big endian signed 16-bit */
161 #define AFMT_S8         0x00000040      /* Signed 8-bit */
162 #define AFMT_U16_LE     0x00000080      /* Little endian unsigned 16-bit */
163 #define AFMT_U16_BE     0x00000100      /* Big endian unsigned 16-bit */
164 #define AFMT_MPEG       0x00000200      /* MPEG MP2/MP3 audio */
165 #define AFMT_AC3        0x00000400      /* Dolby Digital AC3 */
166
167 #if BYTE_ORDER == LITTLE_ENDIAN
168 #define AFMT_S16_NE     AFMT_S16_LE     /* native endian signed 16 */
169 #else
170 #define AFMT_S16_NE     AFMT_S16_BE
171 #endif
172
173 /*
174  * 32-bit formats below used for 24-bit audio data where the data is stored
175  * in the 24 most significant bits and the least significant bits are not used
176  * (should be set to 0).
177  */
178 #define AFMT_S32_LE     0x00001000      /* Little endian signed 32-bit */
179 #define AFMT_S32_BE     0x00002000      /* Big endian signed 32-bit */
180 #define AFMT_U32_LE     0x00004000      /* Little endian unsigned 32-bit */
181 #define AFMT_U32_BE     0x00008000      /* Big endian unsigned 32-bit */
182
183 #define AFMT_STEREO     0x10000000      /* can do/want stereo   */
184
185 /*
186  * the following are really capabilities
187  */
188 #define AFMT_WEIRD      0x20000000      /* weird hardware...    */
189     /*
190      * AFMT_WEIRD reports that the hardware might need to operate
191      * with different formats in the playback and capture
192      * channels when operating in full duplex.
193      * As an example, SoundBlaster16 cards only support U8 in one
194      * direction and S16 in the other one, and applications should
195      * be aware of this limitation.
196      */
197 #define AFMT_FULLDUPLEX 0x80000000      /* can do full duplex   */
198
199 /*
200  * The following structure is used to get/set format and sampling rate.
201  * While it would be better to have things such as stereo, bits per
202  * sample, endiannes, etc split in different variables, it turns out
203  * that formats are not that many, and not all combinations are possible.
204  * So we followed the Voxware approach of associating one bit to each
205  * format.
206  */
207
208 typedef struct _snd_chan_param {
209     u_long      play_rate;      /* sampling rate                        */
210     u_long      rec_rate;       /* sampling rate                        */
211     u_long      play_format;    /* everything describing the format     */
212     u_long      rec_format;     /* everything describing the format     */
213 } snd_chan_param;
214 #define AIOGFMT    _IOR('f', 12, snd_chan_param)   /* get format */
215 #define AIOSFMT    _IOWR('f', 12, snd_chan_param)  /* sets format */
216
217 /*
218  * The following structure is used to get/set the mixer setting.
219  * Up to 32 mixers are supported, each one with up to 32 channels.
220  */
221 typedef struct _snd_mix_param {
222     u_char      subdev; /* which output                         */
223     u_char      line;   /* which input                          */
224     u_char      left,right; /* volumes, 0..255, 0 = mute        */
225 } snd_mix_param ;
226
227 /* XXX AIOGMIX, AIOSMIX not implemented yet */
228 #define AIOGMIX _IOWR('A', 13, snd_mix_param)   /* return mixer status */
229 #define AIOSMIX _IOWR('A', 14, snd_mix_param)   /* sets mixer status   */
230
231 /*
232  * channel specifiers used in AIOSTOP and AIOSYNC
233  */
234 #define AIOSYNC_PLAY    0x1     /* play chan */
235 #define AIOSYNC_CAPTURE 0x2     /* capture chan */
236 /* AIOSTOP stop & flush a channel, returns the residual count */
237 #define AIOSTOP _IOWR ('A', 15, int)
238
239 /* alternate method used to notify the sync condition */
240 #define AIOSYNC_SIGNAL  0x100
241 #define AIOSYNC_SELECT  0x200
242
243 /* what the 'pos' field refers to */
244 #define AIOSYNC_READY   0x400
245 #define AIOSYNC_FREE    0x800
246
247 typedef struct _snd_sync_parm {
248     long chan ; /* play or capture channel, plus modifier */
249     long pos;
250 } snd_sync_parm;
251 #define AIOSYNC _IOWR ('A', 15, snd_sync_parm)  /* misc. synchronization */
252
253 /*
254  * The following is used to return device capabilities. If the structure
255  * passed to the ioctl is zeroed, default values are returned for rate
256  * and formats, a bitmap of available mixers is returned, and values
257  * (inputs, different levels) for the first one are returned.
258  *
259  * If  formats, mixers, inputs are instantiated, then detailed info
260  * are returned depending on the call.
261  */
262 typedef struct _snd_capabilities {
263     u_long      rate_min, rate_max;     /* min-max sampling rate */
264     u_long      formats;
265     u_long      bufsize; /* DMA buffer size */
266     u_long      mixers; /* bitmap of available mixers */
267     u_long      inputs; /* bitmap of available inputs (per mixer) */
268     u_short     left, right;    /* how many levels are supported */
269 } snd_capabilities;
270 #define AIOGCAP _IOWR('A', 15, snd_capabilities)        /* get capabilities */
271
272 /*
273  * here is the old (Voxware) ioctl interface
274  */
275
276 /*
277  * IOCTL Commands for /dev/sequencer
278  */
279
280 #define SNDCTL_SEQ_RESET        _IO  ('Q', 0)
281 #define SNDCTL_SEQ_SYNC         _IO  ('Q', 1)
282 #define SNDCTL_SYNTH_INFO       _IOWR('Q', 2, struct synth_info)
283 #define SNDCTL_SEQ_CTRLRATE     _IOWR('Q', 3, int) /* Set/get timer res.(hz) */
284 #define SNDCTL_SEQ_GETOUTCOUNT  _IOR ('Q', 4, int)
285 #define SNDCTL_SEQ_GETINCOUNT   _IOR ('Q', 5, int)
286 #define SNDCTL_SEQ_PERCMODE     _IOW ('Q', 6, int)
287 #define SNDCTL_FM_LOAD_INSTR    _IOW ('Q', 7, struct sbi_instrument)    /* Valid for FM only */
288 #define SNDCTL_SEQ_TESTMIDI     _IOW ('Q', 8, int)
289 #define SNDCTL_SEQ_RESETSAMPLES _IOW ('Q', 9, int)
290 #define SNDCTL_SEQ_NRSYNTHS     _IOR ('Q',10, int)
291 #define SNDCTL_SEQ_NRMIDIS      _IOR ('Q',11, int)
292 #define SNDCTL_MIDI_INFO        _IOWR('Q',12, struct midi_info)
293 #define SNDCTL_SEQ_THRESHOLD    _IOW ('Q',13, int)
294 #define SNDCTL_SEQ_TRESHOLD     SNDCTL_SEQ_THRESHOLD    /* there was once a typo */
295 #define SNDCTL_SYNTH_MEMAVL     _IOWR('Q',14, int) /* in=dev#, out=memsize */
296 #define SNDCTL_FM_4OP_ENABLE    _IOW ('Q',15, int) /* in=dev# */
297 #define SNDCTL_PMGR_ACCESS      _IOWR('Q',16, struct patmgr_info)
298 #define SNDCTL_SEQ_PANIC        _IO  ('Q',17)
299 #define SNDCTL_SEQ_OUTOFBAND    _IOW ('Q',18, struct seq_event_rec)
300
301 struct seq_event_rec {
302         u_char arr[8];
303 };
304
305 #define SNDCTL_TMR_TIMEBASE     _IOWR('T', 1, int)
306 #define SNDCTL_TMR_START        _IO  ('T', 2)
307 #define SNDCTL_TMR_STOP         _IO  ('T', 3)
308 #define SNDCTL_TMR_CONTINUE     _IO  ('T', 4)
309 #define SNDCTL_TMR_TEMPO        _IOWR('T', 5, int)
310 #define SNDCTL_TMR_SOURCE       _IOWR('T', 6, int)
311 #   define TMR_INTERNAL         0x00000001
312 #   define TMR_EXTERNAL         0x00000002
313 #       define TMR_MODE_MIDI    0x00000010
314 #       define TMR_MODE_FSK     0x00000020
315 #       define TMR_MODE_CLS     0x00000040
316 #       define TMR_MODE_SMPTE   0x00000080
317 #define SNDCTL_TMR_METRONOME    _IOW ('T', 7, int)
318 #define SNDCTL_TMR_SELECT       _IOW ('T', 8, int)
319
320 /*
321  *      Endian aware patch key generation algorithm.
322  */
323
324 #if defined(_AIX) || defined(AIX)
325 #  define _PATCHKEY(id) (0xfd00|id)
326 #else
327 #  define _PATCHKEY(id) ((id<<8)|0xfd)
328 #endif
329
330 /*
331  *      Sample loading mechanism for internal synthesizers (/dev/sequencer)
332  *      The following patch_info structure has been designed to support
333  *      Gravis UltraSound. It tries to be universal format for uploading
334  *      sample based patches but is probably too limited.
335  */
336
337 struct patch_info {
338 /*              u_short key;             Use GUS_PATCH here */
339         short key;               /* Use GUS_PATCH here */
340 #define GUS_PATCH       _PATCHKEY(0x04)
341 #define OBSOLETE_GUS_PATCH      _PATCHKEY(0x02)
342
343         short device_no;        /* Synthesizer number */
344         short instr_no;         /* Midi pgm# */
345
346         u_long mode;
347 /*
348  * The least significant byte has the same format than the GUS .PAT
349  * files
350  */
351 #define WAVE_16_BITS    0x01    /* bit 0 = 8 or 16 bit wave data. */
352 #define WAVE_UNSIGNED   0x02    /* bit 1 = Signed - Unsigned data. */
353 #define WAVE_LOOPING    0x04    /* bit 2 = looping enabled-1. */
354 #define WAVE_BIDIR_LOOP 0x08    /* bit 3 = Set is bidirectional looping. */
355 #define WAVE_LOOP_BACK  0x10    /* bit 4 = Set is looping backward. */
356 #define WAVE_SUSTAIN_ON 0x20    /* bit 5 = Turn sustaining on. (Env. pts. 3)*/
357 #define WAVE_ENVELOPES  0x40    /* bit 6 = Enable envelopes - 1 */
358                                 /*      (use the env_rate/env_offs fields). */
359 /* Linux specific bits */
360 #define WAVE_VIBRATO    0x00010000      /* The vibrato info is valid */
361 #define WAVE_TREMOLO    0x00020000      /* The tremolo info is valid */
362 #define WAVE_SCALE      0x00040000      /* The scaling info is valid */
363 /* Other bits must be zeroed */
364
365         long len;       /* Size of the wave data in bytes */
366         long loop_start, loop_end; /* Byte offsets from the beginning */
367
368 /*
369  * The base_freq and base_note fields are used when computing the
370  * playback speed for a note. The base_note defines the tone frequency
371  * which is heard if the sample is played using the base_freq as the
372  * playback speed.
373  *
374  * The low_note and high_note fields define the minimum and maximum note
375  * frequencies for which this sample is valid. It is possible to define
376  * more than one samples for a instrument number at the same time. The
377  * low_note and high_note fields are used to select the most suitable one.
378  *
379  * The fields base_note, high_note and low_note should contain
380  * the note frequency multiplied by 1000. For example value for the
381  * middle A is 440*1000.
382  */
383
384         u_int base_freq;
385         u_long base_note;
386         u_long high_note;
387         u_long low_note;
388         int panning;    /* -128=left, 127=right */
389         int detuning;
390
391 /*      New fields introduced in version 1.99.5 */
392
393        /* Envelope. Enabled by mode bit WAVE_ENVELOPES  */
394         u_char  env_rate[ 6 ];   /* GUS HW ramping rate */
395         u_char  env_offset[ 6 ]; /* 255 == 100% */
396
397         /*
398          * The tremolo, vibrato and scale info are not supported yet.
399          * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
400          * WAVE_SCALE
401          */
402
403         u_char  tremolo_sweep;
404         u_char  tremolo_rate;
405         u_char  tremolo_depth;
406
407         u_char  vibrato_sweep;
408         u_char  vibrato_rate;
409         u_char  vibrato_depth;
410
411         int             scale_frequency;
412         u_int   scale_factor;           /* from 0 to 2048 or 0 to 2 */
413
414         int             volume;
415         int             spare[4];
416         char data[1];   /* The waveform data starts here */
417 };
418
419 struct sysex_info {
420         short key;              /* Use GUS_PATCH here */
421 #define SYSEX_PATCH     _PATCHKEY(0x05)
422 #define MAUI_PATCH      _PATCHKEY(0x06)
423         short device_no;        /* Synthesizer number */
424         long len;       /* Size of the sysex data in bytes */
425         u_char data[1]; /* Sysex data starts here */
426 };
427
428 /*
429  * Patch management interface (/dev/sequencer, /dev/patmgr#)
430  * Don't use these calls if you want to maintain compatibility with
431  * the future versions of the driver.
432  */
433
434 #define PS_NO_PATCHES           0       /* No patch support on device */
435 #define PS_MGR_NOT_OK           1       /* Plain patch support (no mgr) */
436 #define PS_MGR_OK               2       /* Patch manager supported */
437 #define PS_MANAGED              3       /* Patch manager running */
438
439 #define SNDCTL_PMGR_IFACE               _IOWR('P', 1, struct patmgr_info)
440
441 /*
442  * The patmgr_info is a fixed size structure which is used for two
443  * different purposes. The intended use is for communication between
444  * the application using /dev/sequencer and the patch manager daemon
445  * associated with a synthesizer device (ioctl(SNDCTL_PMGR_ACCESS)).
446  *
447  * This structure is also used with ioctl(SNDCTL_PGMR_IFACE) which allows
448  * a patch manager daemon to read and write device parameters. This
449  * ioctl available through /dev/sequencer also. Avoid using it since it's
450  * extremely hardware dependent. In addition access trough /dev/sequencer
451  * may confuse the patch manager daemon.
452  */
453
454 struct patmgr_info {    /* Note! size must be < 4k since kmalloc() is used */
455           u_long key;   /* Don't worry. Reserved for communication
456                                    between the patch manager and the driver. */
457 #define PM_K_EVENT              1 /* Event from the /dev/sequencer driver */
458 #define PM_K_COMMAND            2 /* Request from a application */
459 #define PM_K_RESPONSE           3 /* From patmgr to application */
460 #define PM_ERROR                4 /* Error returned by the patmgr */
461           int device;
462           int command;
463
464 /*
465  * Commands 0x000 to 0xfff reserved for patch manager programs
466  */
467 #define PM_GET_DEVTYPE  1       /* Returns type of the patch mgr interface of dev */
468 #define         PMTYPE_FM2      1       /* 2 OP fm */
469 #define         PMTYPE_FM4      2       /* Mixed 4 or 2 op FM (OPL-3) */
470 #define         PMTYPE_WAVE     3       /* Wave table synthesizer (GUS) */
471 #define PM_GET_NRPGM    2       /* Returns max # of midi programs in parm1 */
472 #define PM_GET_PGMMAP   3       /* Returns map of loaded midi programs in data8 */
473 #define PM_GET_PGM_PATCHES 4    /* Return list of patches of a program (parm1) */
474 #define PM_GET_PATCH    5       /* Return patch header of patch parm1 */
475 #define PM_SET_PATCH    6       /* Set patch header of patch parm1 */
476 #define PM_READ_PATCH   7       /* Read patch (wave) data */
477 #define PM_WRITE_PATCH  8       /* Write patch (wave) data */
478
479 /*
480  * Commands 0x1000 to 0xffff are for communication between the patch manager
481  * and the client
482  */
483 #define _PM_LOAD_PATCH  0x100
484
485 /*
486  * Commands above 0xffff reserved for device specific use
487  */
488
489         long parm1;
490         long parm2;
491         long parm3;
492
493         union {
494                 u_char data8[4000];
495                 u_short data16[2000];
496                 u_long data32[1000];
497                 struct patch_info patch;
498         } data;
499 };
500
501 /*
502  * When a patch manager daemon is present, it will be informed by the
503  * driver when something important happens. For example when the
504  * /dev/sequencer is opened or closed. A record with key == PM_K_EVENT is
505  * returned. The command field contains the event type:
506  */
507 #define PM_E_OPENED             1       /* /dev/sequencer opened */
508 #define PM_E_CLOSED             2       /* /dev/sequencer closed */
509 #define PM_E_PATCH_RESET        3       /* SNDCTL_RESETSAMPLES called */
510 #define PM_E_PATCH_LOADED       4       /* A patch has been loaded by appl */
511
512 /*
513  * /dev/sequencer input events.
514  *
515  * The data written to the /dev/sequencer is a stream of events. Events
516  * are records of 4 or 8 bytes. The first byte defines the size.
517  * Any number of events can be written with a write call. There
518  * is a set of macros for sending these events. Use these macros if you
519  * want to maximize portability of your program.
520  *
521  * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
522  * (All input events are currently 4 bytes long. Be prepared to support
523  * 8 byte events also. If you receive any event having first byte >= 128,
524  * it's a 8 byte event.
525  *
526  * The events are documented at the end of this file.
527  *
528  * Normal events (4 bytes)
529  * There is also a 8 byte version of most of the 4 byte events. The
530  * 8 byte one is recommended.
531  */
532 #define SEQ_NOTEOFF             0
533 #define SEQ_FMNOTEOFF           SEQ_NOTEOFF     /* Just old name */
534 #define SEQ_NOTEON              1
535 #define SEQ_FMNOTEON            SEQ_NOTEON
536 #define SEQ_WAIT                TMR_WAIT_ABS
537 #define SEQ_PGMCHANGE           3
538 #define SEQ_FMPGMCHANGE         SEQ_PGMCHANGE
539 #define SEQ_SYNCTIMER           TMR_START
540 #define SEQ_MIDIPUTC            5
541 #define SEQ_DRUMON              6       /*** OBSOLETE ***/
542 #define SEQ_DRUMOFF             7       /*** OBSOLETE ***/
543 #define SEQ_ECHO                TMR_ECHO        /* For synching programs with output */
544 #define SEQ_AFTERTOUCH          9
545 #define SEQ_CONTROLLER          10
546
547 /*
548  *      Midi controller numbers
549  *
550  * Controllers 0 to 31 (0x00 to 0x1f) and 32 to 63 (0x20 to 0x3f)
551  * are continuous controllers.
552  * In the MIDI 1.0 these controllers are sent using two messages.
553  * Controller numbers 0 to 31 are used to send the MSB and the
554  * controller numbers 32 to 63 are for the LSB. Note that just 7 bits
555  * are used in MIDI bytes.
556  */
557
558 #define CTL_BANK_SELECT         0x00
559 #define CTL_MODWHEEL            0x01
560 #define CTL_BREATH              0x02
561 /*      undefined               0x03 */
562 #define CTL_FOOT                0x04
563 #define CTL_PORTAMENTO_TIME     0x05
564 #define CTL_DATA_ENTRY          0x06
565 #define CTL_MAIN_VOLUME         0x07
566 #define CTL_BALANCE             0x08
567 /*      undefined               0x09 */
568 #define CTL_PAN                 0x0a
569 #define CTL_EXPRESSION          0x0b
570 /*      undefined               0x0c - 0x0f */
571 #define CTL_GENERAL_PURPOSE1    0x10
572 #define CTL_GENERAL_PURPOSE2    0x11
573 #define CTL_GENERAL_PURPOSE3    0x12
574 #define CTL_GENERAL_PURPOSE4    0x13
575 /*      undefined               0x14 - 0x1f */
576
577 /*      undefined               0x20 */
578
579 /*
580  * The controller numbers 0x21 to 0x3f are reserved for the
581  * least significant bytes of the controllers 0x00 to 0x1f.
582  * These controllers are not recognised by the driver.
583  *
584  * Controllers 64 to 69 (0x40 to 0x45) are on/off switches.
585  * 0=OFF and 127=ON (intermediate values are possible)
586  */
587 #define CTL_DAMPER_PEDAL        0x40
588 #define CTL_SUSTAIN             CTL_DAMPER_PEDAL        /* Alias */
589 #define CTL_HOLD                CTL_DAMPER_PEDAL        /* Alias */
590 #define CTL_PORTAMENTO          0x41
591 #define CTL_SOSTENUTO           0x42
592 #define CTL_SOFT_PEDAL          0x43
593 /*      undefined               0x44 */
594 #define CTL_HOLD2               0x45
595 /*      undefined               0x46 - 0x4f */
596
597 #define CTL_GENERAL_PURPOSE5    0x50
598 #define CTL_GENERAL_PURPOSE6    0x51
599 #define CTL_GENERAL_PURPOSE7    0x52
600 #define CTL_GENERAL_PURPOSE8    0x53
601 /*      undefined               0x54 - 0x5a */
602 #define CTL_EXT_EFF_DEPTH       0x5b
603 #define CTL_TREMOLO_DEPTH       0x5c
604 #define CTL_CHORUS_DEPTH        0x5d
605 #define CTL_DETUNE_DEPTH        0x5e
606 #define CTL_CELESTE_DEPTH       CTL_DETUNE_DEPTH /* Alias for the above one */
607 #define CTL_PHASER_DEPTH        0x5f
608 #define CTL_DATA_INCREMENT      0x60
609 #define CTL_DATA_DECREMENT      0x61
610 #define CTL_NONREG_PARM_NUM_LSB 0x62
611 #define CTL_NONREG_PARM_NUM_MSB 0x63
612 #define CTL_REGIST_PARM_NUM_LSB 0x64
613 #define CTL_REGIST_PARM_NUM_MSB 0x65
614 /*      undefined               0x66 - 0x78 */
615 /*      reserved                0x79 - 0x7f */
616
617 /* Pseudo controllers (not midi compatible) */
618 #define CTRL_PITCH_BENDER       255
619 #define CTRL_PITCH_BENDER_RANGE 254
620 #define CTRL_EXPRESSION         253     /* Obsolete */
621 #define CTRL_MAIN_VOLUME        252     /* Obsolete */
622
623 #define SEQ_BALANCE             11
624 #define SEQ_VOLMODE             12
625
626 /*
627  * Volume mode decides how volumes are used
628  */
629
630 #define VOL_METHOD_ADAGIO       1
631 #define VOL_METHOD_LINEAR       2
632
633 /*
634  * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
635  *       input events.
636  */
637
638 /*
639  * Event codes 0xf0 to 0xfc are reserved for future extensions.
640  */
641
642 #define SEQ_FULLSIZE            0xfd    /* Long events */
643 /*
644  * SEQ_FULLSIZE events are used for loading patches/samples to the
645  * synthesizer devices. These events are passed directly to the driver
646  * of the associated synthesizer device. There is no limit to the size
647  * of the extended events. These events are not queued but executed
648  * immediately when the write() is called (execution can take several
649  * seconds of time).
650  *
651  * When a SEQ_FULLSIZE message is written to the device, it must
652  * be written using exactly one write() call. Other events cannot
653  * be mixed to the same write.
654  *
655  * For FM synths (YM3812/OPL3) use struct sbi_instrument and write
656  * it to the /dev/sequencer. Don't write other data together with
657  * the instrument structure Set the key field of the structure to
658  * FM_PATCH. The device field is used to route the patch to the
659  * corresponding device.
660  *
661  * For Gravis UltraSound use struct patch_info. Initialize the key field
662  * to GUS_PATCH.
663  */
664 #define SEQ_PRIVATE     0xfe    /* Low level HW dependent events (8 bytes) */
665 #define SEQ_EXTENDED    0xff    /* Extended events (8 bytes) OBSOLETE */
666
667 /*
668  * Record for FM patches
669  */
670
671 typedef u_char sbi_instr_data[32];
672
673 struct sbi_instrument {
674         u_short key;    /* FM_PATCH or OPL3_PATCH */
675 #define FM_PATCH        _PATCHKEY(0x01)
676 #define OPL3_PATCH      _PATCHKEY(0x03)
677         short           device;         /* Synth# (0-4) */
678         int             channel;        /* Program# to be initialized  */
679         sbi_instr_data  operators;      /* Reg. settings for operator cells
680                                          * (.SBI format)        */
681 };
682
683 struct synth_info {     /* Read only */
684         char    name[30];
685         int     device;         /* 0-N. INITIALIZE BEFORE CALLING */
686         int     synth_type;
687 #define SYNTH_TYPE_FM                   0
688 #define SYNTH_TYPE_SAMPLE               1
689 #define SYNTH_TYPE_MIDI                 2       /* Midi interface */
690
691         int     synth_subtype;
692 #define FM_TYPE_ADLIB                   0x00
693 #define FM_TYPE_OPL3                    0x01
694
695 #define SAMPLE_TYPE_BASIC               0x10
696 #define SAMPLE_TYPE_GUS                 SAMPLE_TYPE_BASIC
697 #define SAMPLE_TYPE_AWE32               0x20
698
699         int     perc_mode;      /* No longer supported */
700         int     nr_voices;
701         int     nr_drums;       /* Obsolete field */
702         int     instr_bank_size;
703         u_long  capabilities;
704 #define SYNTH_CAP_PERCMODE      0x00000001 /* No longer used */
705 #define SYNTH_CAP_OPL3          0x00000002 /* Set if OPL3 supported */
706 #define SYNTH_CAP_INPUT         0x00000004 /* Input (MIDI) device */
707         int     dummies[19];    /* Reserve space */
708 };
709
710 struct sound_timer_info {
711         char name[32];
712         int caps;
713 };
714
715 #define MIDI_CAP_MPU401         1               /* MPU-401 intelligent mode */
716
717 struct midi_info {
718         char            name[30];
719         int             device;         /* 0-N. INITIALIZE BEFORE CALLING */
720         u_long  capabilities;   /* To be defined later */
721         int             dev_type;
722         int             dummies[18];    /* Reserve space */
723 };
724
725 /*
726  * ioctl commands for the /dev/midi##
727  */
728 typedef struct {
729         u_char cmd;
730         char nr_args, nr_returns;
731         u_char data[30];
732 } mpu_command_rec;
733
734 #define SNDCTL_MIDI_PRETIME     _IOWR('m', 0, int)
735 #define SNDCTL_MIDI_MPUMODE     _IOWR('m', 1, int)
736 #define SNDCTL_MIDI_MPUCMD      _IOWR('m', 2, mpu_command_rec)
737 #define MIOSPASSTHRU            _IOWR('m', 3, int)
738 #define MIOGPASSTHRU            _IOWR('m', 4, int)
739
740 /*
741  * IOCTL commands for /dev/dsp and /dev/audio
742  */
743
744 #define SNDCTL_DSP_RESET        _IO  ('P', 0)
745 #define SNDCTL_DSP_SYNC         _IO  ('P', 1)
746 #define SNDCTL_DSP_SPEED        _IOWR('P', 2, int)
747 #define SNDCTL_DSP_STEREO       _IOWR('P', 3, int)
748 #define SNDCTL_DSP_GETBLKSIZE   _IOR('P', 4, int)
749 #define SNDCTL_DSP_SETBLKSIZE   _IOW('P', 4, int)
750 #define SNDCTL_DSP_SETFMT       _IOWR('P',5, int) /* Selects ONE fmt*/
751
752 /*
753  * SOUND_PCM_WRITE_CHANNELS is not that different
754  * from SNDCTL_DSP_STEREO
755  */
756 #define SOUND_PCM_WRITE_CHANNELS        _IOWR('P', 6, int)
757 #define SNDCTL_DSP_CHANNELS     SOUND_PCM_WRITE_CHANNELS
758 #define SOUND_PCM_WRITE_FILTER  _IOWR('P', 7, int)
759 #define SNDCTL_DSP_POST         _IO  ('P', 8)
760
761 /*
762  * SNDCTL_DSP_SETBLKSIZE and the following two calls mostly do
763  * the same thing, i.e. set the block size used in DMA transfers.
764  */
765 #define SNDCTL_DSP_SUBDIVIDE    _IOWR('P', 9, int)
766 #define SNDCTL_DSP_SETFRAGMENT  _IOWR('P',10, int)
767
768
769 #define SNDCTL_DSP_GETFMTS      _IOR ('P',11, int) /* Returns a mask */
770 /*
771  * Buffer status queries.
772  */
773 typedef struct audio_buf_info {
774     int fragments;      /* # of avail. frags (partly used ones not counted) */
775     int fragstotal;     /* Total # of fragments allocated */
776     int fragsize;       /* Size of a fragment in bytes */
777
778     int bytes;  /* Avail. space in bytes (includes partly used fragments) */
779                 /* Note! 'bytes' could be more than fragments*fragsize */
780 } audio_buf_info;
781
782 #define SNDCTL_DSP_GETOSPACE    _IOR ('P',12, audio_buf_info)
783 #define SNDCTL_DSP_GETISPACE    _IOR ('P',13, audio_buf_info)
784
785 /*
786  * SNDCTL_DSP_NONBLOCK is the same (but less powerful, since the
787  * action cannot be undone) of FIONBIO. The same can be achieved
788  * by opening the device with O_NDELAY
789  */
790 #define SNDCTL_DSP_NONBLOCK     _IO  ('P',14)
791
792 #define SNDCTL_DSP_GETCAPS      _IOR ('P',15, int)
793 #define DSP_CAP_REVISION        0x000000ff /* revision level (0 to 255) */
794 #define DSP_CAP_DUPLEX          0x00000100 /* Full duplex record/playback */
795 #define DSP_CAP_REALTIME        0x00000200 /* Real time capability */
796 #define DSP_CAP_BATCH           0x00000400
797     /*
798      * Device has some kind of internal buffers which may
799      * cause some delays and decrease precision of timing
800      */
801 #define DSP_CAP_COPROC          0x00000800
802     /* Has a coprocessor, sometimes it's a DSP but usually not */
803 #define DSP_CAP_TRIGGER         0x00001000 /* Supports SETTRIGGER */
804 #define DSP_CAP_MMAP 0x00002000 /* Supports mmap() */
805
806 /*
807  * What do these function do ?
808  */
809 #define SNDCTL_DSP_GETTRIGGER   _IOR ('P',16, int)
810 #define SNDCTL_DSP_SETTRIGGER   _IOW ('P',16, int)
811 #define PCM_ENABLE_INPUT        0x00000001
812 #define PCM_ENABLE_OUTPUT       0x00000002
813
814 typedef struct count_info {
815         int bytes;      /* Total # of bytes processed */
816         int blocks;     /* # of fragment transitions since last time */
817         int ptr;        /* Current DMA pointer value */
818 } count_info;
819
820 /*
821  * GETIPTR and GETISPACE are not that different... same for out.
822  */
823 #define SNDCTL_DSP_GETIPTR      _IOR ('P',17, count_info)
824 #define SNDCTL_DSP_GETOPTR      _IOR ('P',18, count_info)
825
826 typedef struct buffmem_desc {
827         caddr_t buffer;
828         int size;
829 } buffmem_desc;
830
831 #define SNDCTL_DSP_MAPINBUF     _IOR ('P', 19, buffmem_desc)
832 #define SNDCTL_DSP_MAPOUTBUF    _IOR ('P', 20, buffmem_desc)
833 #define SNDCTL_DSP_SETSYNCRO    _IO  ('P', 21)
834 #define SNDCTL_DSP_SETDUPLEX    _IO  ('P', 22)
835 #define SNDCTL_DSP_GETODELAY    _IOR ('P', 23, int)
836
837 /*
838  * I guess these are the readonly version of the same
839  * functions that exist above as SNDCTL_DSP_...
840  */
841 #define SOUND_PCM_READ_RATE     _IOR ('P', 2, int)
842 #define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int)
843 #define SOUND_PCM_READ_BITS     _IOR ('P', 5, int)
844 #define SOUND_PCM_READ_FILTER   _IOR ('P', 7, int)
845
846 /*
847  * ioctl calls to be used in communication with coprocessors and
848  * DSP chips.
849  */
850
851 typedef struct copr_buffer {
852         int command;    /* Set to 0 if not used */
853         int flags;
854 #define CPF_NONE                0x0000
855 #define CPF_FIRST               0x0001  /* First block */
856 #define CPF_LAST                0x0002  /* Last block */
857         int len;
858         int offs;       /* If required by the device (0 if not used) */
859
860         u_char data[4000]; /* NOTE! 4000 is not 4k */
861 } copr_buffer;
862
863 typedef struct copr_debug_buf {
864         int command;    /* Used internally. Set to 0 */
865         int parm1;
866         int parm2;
867         int flags;
868         int len;        /* Length of data in bytes */
869 } copr_debug_buf;
870
871 typedef struct copr_msg {
872         int len;
873         u_char data[4000];
874 } copr_msg;
875
876 #define SNDCTL_COPR_RESET       _IO  ('C',  0)
877 #define SNDCTL_COPR_LOAD        _IOWR('C',  1, copr_buffer)
878 #define SNDCTL_COPR_RDATA       _IOWR('C',  2, copr_debug_buf)
879 #define SNDCTL_COPR_RCODE       _IOWR('C',  3, copr_debug_buf)
880 #define SNDCTL_COPR_WDATA       _IOW ('C',  4, copr_debug_buf)
881 #define SNDCTL_COPR_WCODE       _IOW ('C',  5, copr_debug_buf)
882 #define SNDCTL_COPR_RUN         _IOWR('C',  6, copr_debug_buf)
883 #define SNDCTL_COPR_HALT        _IOWR('C',  7, copr_debug_buf)
884 #define SNDCTL_COPR_SENDMSG     _IOW ('C',  8, copr_msg)
885 #define SNDCTL_COPR_RCVMSG      _IOR ('C',  9, copr_msg)
886
887 /*
888  * IOCTL commands for /dev/mixer
889  */
890
891 /*
892  * Mixer devices
893  *
894  * There can be up to 20 different analog mixer channels. The
895  * SOUND_MIXER_NRDEVICES gives the currently supported maximum.
896  * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells
897  * the devices supported by the particular mixer.
898  */
899
900 #define SOUND_MIXER_NRDEVICES   25
901 #define SOUND_MIXER_VOLUME      0       /* Master output level */
902 #define SOUND_MIXER_BASS        1       /* Treble level of all output channels */
903 #define SOUND_MIXER_TREBLE      2       /* Bass level of all output channels */
904 #define SOUND_MIXER_SYNTH       3       /* Volume of synthesier input */
905 #define SOUND_MIXER_PCM         4       /* Output level for the audio device */
906 #define SOUND_MIXER_SPEAKER     5       /* Output level for the PC speaker
907                                          * signals */
908 #define SOUND_MIXER_LINE        6       /* Volume level for the line in jack */
909 #define SOUND_MIXER_MIC         7       /* Volume for the signal coming from
910                                          * the microphone jack */
911 #define SOUND_MIXER_CD          8       /* Volume level for the input signal
912                                          * connected to the CD audio input */
913 #define SOUND_MIXER_IMIX        9       /* Recording monitor. It controls the
914                                          * output volume of the selected
915                                          * recording sources while recording */
916 #define SOUND_MIXER_ALTPCM      10      /* Volume of the alternative codec
917                                          * device */
918 #define SOUND_MIXER_RECLEV      11      /* Global recording level */
919 #define SOUND_MIXER_IGAIN       12      /* Input gain */
920 #define SOUND_MIXER_OGAIN       13      /* Output gain */
921 /*
922  * The AD1848 codec and compatibles have three line level inputs
923  * (line, aux1 and aux2). Since each card manufacturer have assigned
924  * different meanings to these inputs, it's inpractical to assign
925  * specific meanings (line, cd, synth etc.) to them.
926  */
927 #define SOUND_MIXER_LINE1       14      /* Input source 1  (aux1) */
928 #define SOUND_MIXER_LINE2       15      /* Input source 2  (aux2) */
929 #define SOUND_MIXER_LINE3       16      /* Input source 3  (line) */
930 #define SOUND_MIXER_DIGITAL1    17      /* Digital (input) 1 */
931 #define SOUND_MIXER_DIGITAL2    18      /* Digital (input) 2 */
932 #define SOUND_MIXER_DIGITAL3    19      /* Digital (input) 3 */
933 #define SOUND_MIXER_PHONEIN     20      /* Phone input */
934 #define SOUND_MIXER_PHONEOUT    21      /* Phone output */
935 #define SOUND_MIXER_VIDEO       22      /* Video/TV (audio) in */
936 #define SOUND_MIXER_RADIO       23      /* Radio in */
937 #define SOUND_MIXER_MONITOR     24      /* Monitor (usually mic) volume */
938
939
940 /*
941  * Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX)
942  * Not counted to SOUND_MIXER_NRDEVICES, but use the same number space
943  */
944 #define SOUND_ONOFF_MIN         28
945 #define SOUND_ONOFF_MAX         30
946 #define SOUND_MIXER_MUTE        28      /* 0 or 1 */
947 #define SOUND_MIXER_ENHANCE     29      /* Enhanced stereo (0, 40, 60 or 80) */
948 #define SOUND_MIXER_LOUD        30      /* 0 or 1 */
949
950 /* Note!        Number 31 cannot be used since the sign bit is reserved */
951 #define SOUND_MIXER_NONE        31
952
953 #define SOUND_DEVICE_LABELS     { \
954         "Vol  ", "Bass ", "Trebl", "Synth", "Pcm  ", "Spkr ", "Line ", \
955         "Mic  ", "CD   ", "Mix  ", "Pcm2 ", "Rec  ", "IGain", "OGain", \
956         "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \
957         "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"}
958
959 #define SOUND_DEVICE_NAMES      { \
960         "vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
961         "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \
962         "line1", "line2", "line3", "dig1", "dig2", "dig3", \
963         "phin", "phout", "video", "radio", "monitor"}
964
965 /*      Device bitmask identifiers      */
966
967 #define SOUND_MIXER_RECSRC      0xff    /* 1 bit per recording source */
968 #define SOUND_MIXER_DEVMASK     0xfe    /* 1 bit per supported device */
969 #define SOUND_MIXER_RECMASK     0xfd    /* 1 bit per supp. recording source */
970 #define SOUND_MIXER_CAPS        0xfc
971 #define SOUND_CAP_EXCL_INPUT    0x00000001      /* Only 1 rec. src at a time */
972 #define SOUND_MIXER_STEREODEVS  0xfb    /* Mixer channels supporting stereo */
973
974 /*      Device mask bits        */
975
976 #define SOUND_MASK_VOLUME       (1 << SOUND_MIXER_VOLUME)
977 #define SOUND_MASK_BASS         (1 << SOUND_MIXER_BASS)
978 #define SOUND_MASK_TREBLE       (1 << SOUND_MIXER_TREBLE)
979 #define SOUND_MASK_SYNTH        (1 << SOUND_MIXER_SYNTH)
980 #define SOUND_MASK_PCM          (1 << SOUND_MIXER_PCM)
981 #define SOUND_MASK_SPEAKER      (1 << SOUND_MIXER_SPEAKER)
982 #define SOUND_MASK_LINE         (1 << SOUND_MIXER_LINE)
983 #define SOUND_MASK_MIC          (1 << SOUND_MIXER_MIC)
984 #define SOUND_MASK_CD           (1 << SOUND_MIXER_CD)
985 #define SOUND_MASK_IMIX         (1 << SOUND_MIXER_IMIX)
986 #define SOUND_MASK_ALTPCM       (1 << SOUND_MIXER_ALTPCM)
987 #define SOUND_MASK_RECLEV       (1 << SOUND_MIXER_RECLEV)
988 #define SOUND_MASK_IGAIN        (1 << SOUND_MIXER_IGAIN)
989 #define SOUND_MASK_OGAIN        (1 << SOUND_MIXER_OGAIN)
990 #define SOUND_MASK_LINE1        (1 << SOUND_MIXER_LINE1)
991 #define SOUND_MASK_LINE2        (1 << SOUND_MIXER_LINE2)
992 #define SOUND_MASK_LINE3        (1 << SOUND_MIXER_LINE3)
993 #define SOUND_MASK_DIGITAL1     (1 << SOUND_MIXER_DIGITAL1)
994 #define SOUND_MASK_DIGITAL2     (1 << SOUND_MIXER_DIGITAL2)
995 #define SOUND_MASK_DIGITAL3     (1 << SOUND_MIXER_DIGITAL3)
996 #define SOUND_MASK_PHONEIN      (1 << SOUND_MIXER_PHONEIN)
997 #define SOUND_MASK_PHONEOUT     (1 << SOUND_MIXER_PHONEOUT)
998 #define SOUND_MASK_RADIO        (1 << SOUND_MIXER_RADIO)
999 #define SOUND_MASK_VIDEO        (1 << SOUND_MIXER_VIDEO)
1000 #define SOUND_MASK_MONITOR      (1 << SOUND_MIXER_MONITOR)
1001
1002 /* Obsolete macros */
1003 #define SOUND_MASK_MUTE         (1 << SOUND_MIXER_MUTE)
1004 #define SOUND_MASK_ENHANCE      (1 << SOUND_MIXER_ENHANCE)
1005 #define SOUND_MASK_LOUD         (1 << SOUND_MIXER_LOUD)
1006
1007 #define MIXER_READ(dev)         _IOR('M', dev, int)
1008 #define SOUND_MIXER_READ_VOLUME         MIXER_READ(SOUND_MIXER_VOLUME)
1009 #define SOUND_MIXER_READ_BASS           MIXER_READ(SOUND_MIXER_BASS)
1010 #define SOUND_MIXER_READ_TREBLE         MIXER_READ(SOUND_MIXER_TREBLE)
1011 #define SOUND_MIXER_READ_SYNTH          MIXER_READ(SOUND_MIXER_SYNTH)
1012 #define SOUND_MIXER_READ_PCM            MIXER_READ(SOUND_MIXER_PCM)
1013 #define SOUND_MIXER_READ_SPEAKER        MIXER_READ(SOUND_MIXER_SPEAKER)
1014 #define SOUND_MIXER_READ_LINE           MIXER_READ(SOUND_MIXER_LINE)
1015 #define SOUND_MIXER_READ_MIC            MIXER_READ(SOUND_MIXER_MIC)
1016 #define SOUND_MIXER_READ_CD             MIXER_READ(SOUND_MIXER_CD)
1017 #define SOUND_MIXER_READ_IMIX           MIXER_READ(SOUND_MIXER_IMIX)
1018 #define SOUND_MIXER_READ_ALTPCM         MIXER_READ(SOUND_MIXER_ALTPCM)
1019 #define SOUND_MIXER_READ_RECLEV         MIXER_READ(SOUND_MIXER_RECLEV)
1020 #define SOUND_MIXER_READ_IGAIN          MIXER_READ(SOUND_MIXER_IGAIN)
1021 #define SOUND_MIXER_READ_OGAIN          MIXER_READ(SOUND_MIXER_OGAIN)
1022 #define SOUND_MIXER_READ_LINE1          MIXER_READ(SOUND_MIXER_LINE1)
1023 #define SOUND_MIXER_READ_LINE2          MIXER_READ(SOUND_MIXER_LINE2)
1024 #define SOUND_MIXER_READ_LINE3          MIXER_READ(SOUND_MIXER_LINE3)
1025
1026 /* Obsolete macros */
1027 #define SOUND_MIXER_READ_MUTE           MIXER_READ(SOUND_MIXER_MUTE)
1028 #define SOUND_MIXER_READ_ENHANCE        MIXER_READ(SOUND_MIXER_ENHANCE)
1029 #define SOUND_MIXER_READ_LOUD           MIXER_READ(SOUND_MIXER_LOUD)
1030
1031 #define SOUND_MIXER_READ_RECSRC         MIXER_READ(SOUND_MIXER_RECSRC)
1032 #define SOUND_MIXER_READ_DEVMASK        MIXER_READ(SOUND_MIXER_DEVMASK)
1033 #define SOUND_MIXER_READ_RECMASK        MIXER_READ(SOUND_MIXER_RECMASK)
1034 #define SOUND_MIXER_READ_STEREODEVS     MIXER_READ(SOUND_MIXER_STEREODEVS)
1035 #define SOUND_MIXER_READ_CAPS           MIXER_READ(SOUND_MIXER_CAPS)
1036
1037 #define MIXER_WRITE(dev)                _IOWR('M', dev, int)
1038 #define SOUND_MIXER_WRITE_VOLUME        MIXER_WRITE(SOUND_MIXER_VOLUME)
1039 #define SOUND_MIXER_WRITE_BASS          MIXER_WRITE(SOUND_MIXER_BASS)
1040 #define SOUND_MIXER_WRITE_TREBLE        MIXER_WRITE(SOUND_MIXER_TREBLE)
1041 #define SOUND_MIXER_WRITE_SYNTH         MIXER_WRITE(SOUND_MIXER_SYNTH)
1042 #define SOUND_MIXER_WRITE_PCM           MIXER_WRITE(SOUND_MIXER_PCM)
1043 #define SOUND_MIXER_WRITE_SPEAKER       MIXER_WRITE(SOUND_MIXER_SPEAKER)
1044 #define SOUND_MIXER_WRITE_LINE          MIXER_WRITE(SOUND_MIXER_LINE)
1045 #define SOUND_MIXER_WRITE_MIC           MIXER_WRITE(SOUND_MIXER_MIC)
1046 #define SOUND_MIXER_WRITE_CD            MIXER_WRITE(SOUND_MIXER_CD)
1047 #define SOUND_MIXER_WRITE_IMIX          MIXER_WRITE(SOUND_MIXER_IMIX)
1048 #define SOUND_MIXER_WRITE_ALTPCM        MIXER_WRITE(SOUND_MIXER_ALTPCM)
1049 #define SOUND_MIXER_WRITE_RECLEV        MIXER_WRITE(SOUND_MIXER_RECLEV)
1050 #define SOUND_MIXER_WRITE_IGAIN         MIXER_WRITE(SOUND_MIXER_IGAIN)
1051 #define SOUND_MIXER_WRITE_OGAIN         MIXER_WRITE(SOUND_MIXER_OGAIN)
1052 #define SOUND_MIXER_WRITE_LINE1         MIXER_WRITE(SOUND_MIXER_LINE1)
1053 #define SOUND_MIXER_WRITE_LINE2         MIXER_WRITE(SOUND_MIXER_LINE2)
1054 #define SOUND_MIXER_WRITE_LINE3         MIXER_WRITE(SOUND_MIXER_LINE3)
1055 #define SOUND_MIXER_WRITE_MUTE          MIXER_WRITE(SOUND_MIXER_MUTE)
1056 #define SOUND_MIXER_WRITE_ENHANCE       MIXER_WRITE(SOUND_MIXER_ENHANCE)
1057 #define SOUND_MIXER_WRITE_LOUD          MIXER_WRITE(SOUND_MIXER_LOUD)
1058
1059 #define SOUND_MIXER_WRITE_RECSRC        MIXER_WRITE(SOUND_MIXER_RECSRC)
1060
1061 #define LEFT_CHN        0
1062 #define RIGHT_CHN       1
1063
1064 /*
1065  * Level 2 event types for /dev/sequencer
1066  */
1067
1068 /*
1069  * The 4 most significant bits of byte 0 specify the class of
1070  * the event:
1071  *
1072  *      0x8X = system level events,
1073  *      0x9X = device/port specific events, event[1] = device/port,
1074  *              The last 4 bits give the subtype:
1075  *                      0x02    = Channel event (event[3] = chn).
1076  *                      0x01    = note event (event[4] = note).
1077  *                      (0x01 is not used alone but always with bit 0x02).
1078  *             event[2] = MIDI message code (0x80=note off etc.)
1079  *
1080  */
1081
1082 #define EV_SEQ_LOCAL            0x80
1083 #define EV_TIMING               0x81
1084 #define EV_CHN_COMMON           0x92
1085 #define EV_CHN_VOICE            0x93
1086 #define EV_SYSEX                0x94
1087 /*
1088  * Event types 200 to 220 are reserved for application use.
1089  * These numbers will not be used by the driver.
1090  */
1091
1092 /*
1093  * Events for event type EV_CHN_VOICE
1094  */
1095
1096 #define MIDI_NOTEOFF            0x80
1097 #define MIDI_NOTEON             0x90
1098 #define MIDI_KEY_PRESSURE       0xA0
1099
1100 /*
1101  * Events for event type EV_CHN_COMMON
1102  */
1103
1104 #define MIDI_CTL_CHANGE         0xB0
1105 #define MIDI_PGM_CHANGE         0xC0
1106 #define MIDI_CHN_PRESSURE       0xD0
1107 #define MIDI_PITCH_BEND         0xE0
1108
1109 #define MIDI_SYSTEM_PREFIX      0xF0
1110
1111 /*
1112  * Timer event types
1113  */
1114 #define TMR_WAIT_REL            1       /* Time relative to the prev time */
1115 #define TMR_WAIT_ABS            2       /* Absolute time since TMR_START */
1116 #define TMR_STOP                3
1117 #define TMR_START               4
1118 #define TMR_CONTINUE            5
1119 #define TMR_TEMPO               6
1120 #define TMR_ECHO                8
1121 #define TMR_CLOCK               9       /* MIDI clock */
1122 #define TMR_SPP                 10      /* Song position pointer */
1123 #define TMR_TIMESIG             11      /* Time signature */
1124
1125 /*
1126  *      Local event types
1127  */
1128 #define LOCL_STARTAUDIO         1
1129
1130 #if (!defined(_KERNEL) && !defined(INKERNEL)) || defined(USE_SEQ_MACROS)
1131 /*
1132  *      Some convenience macros to simplify programming of the
1133  *      /dev/sequencer interface
1134  *
1135  *      These macros define the API which should be used when possible.
1136  */
1137
1138 #ifndef USE_SIMPLE_MACROS
1139 void seqbuf_dump (void);        /* This function must be provided by programs */
1140
1141 /* Sample seqbuf_dump() implementation:
1142  *
1143  *      SEQ_DEFINEBUF (2048);   -- Defines a buffer for 2048 bytes
1144  *
1145  *      int seqfd;              -- The file descriptor for /dev/sequencer.
1146  *
1147  *      void
1148  *      seqbuf_dump ()
1149  *      {
1150  *        if (_seqbufptr)
1151  *          if (write (seqfd, _seqbuf, _seqbufptr) == -1)
1152  *            {
1153  *              perror ("write /dev/sequencer");
1154  *              exit (-1);
1155  *            }
1156  *        _seqbufptr = 0;
1157  *      }
1158  */
1159
1160 #define SEQ_DEFINEBUF(len)              \
1161         u_char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0
1162 #define SEQ_USE_EXTBUF()                \
1163         extern u_char _seqbuf[]; \
1164         extern int _seqbuflen;extern int _seqbufptr
1165 #define SEQ_DECLAREBUF()                SEQ_USE_EXTBUF()
1166 #define SEQ_PM_DEFINES                  struct patmgr_info _pm_info
1167 #define _SEQ_NEEDBUF(len)               \
1168         if ((_seqbufptr+(len)) > _seqbuflen) \
1169                 seqbuf_dump()
1170 #define _SEQ_ADVBUF(len)                _seqbufptr += len
1171 #define SEQ_DUMPBUF                     seqbuf_dump
1172 #else
1173 /*
1174  * This variation of the sequencer macros is used just to format one event
1175  * using fixed buffer.
1176  *
1177  * The program using the macro library must define the following macros before
1178  * using this library.
1179  *
1180  * #define _seqbuf               name of the buffer (u_char[])
1181  * #define _SEQ_ADVBUF(len)      If the applic needs to know the exact
1182  *                               size of the event, this macro can be used.
1183  *                               Otherwise this must be defined as empty.
1184  * #define _seqbufptr            Define the name of index variable or 0 if
1185  *                               not required.
1186  */
1187 #define _SEQ_NEEDBUF(len)       /* empty */
1188 #endif
1189
1190 #define PM_LOAD_PATCH(dev, bank, pgm)   \
1191         (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
1192         _pm_info.device=dev, _pm_info.data.data8[0]=pgm, \
1193         _pm_info.parm1 = bank, _pm_info.parm2 = 1, \
1194         ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
1195 #define PM_LOAD_PATCHES(dev, bank, pgm) \
1196         (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
1197         _pm_info.device=dev, bcopy( pgm, _pm_info.data.data8,  128), \
1198         _pm_info.parm1 = bank, _pm_info.parm2 = 128, \
1199         ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
1200
1201 #define SEQ_VOLUME_MODE(dev, mode)      { \
1202         _SEQ_NEEDBUF(8);\
1203         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1204         _seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\
1205         _seqbuf[_seqbufptr+2] = (dev);\
1206         _seqbuf[_seqbufptr+3] = (mode);\
1207         _seqbuf[_seqbufptr+4] = 0;\
1208         _seqbuf[_seqbufptr+5] = 0;\
1209         _seqbuf[_seqbufptr+6] = 0;\
1210         _seqbuf[_seqbufptr+7] = 0;\
1211         _SEQ_ADVBUF(8);}
1212
1213 /*
1214  * Midi voice messages
1215  */
1216
1217 #define _CHN_VOICE(dev, event, chn, note, parm)  { \
1218         _SEQ_NEEDBUF(8);\
1219         _seqbuf[_seqbufptr] = EV_CHN_VOICE;\
1220         _seqbuf[_seqbufptr+1] = (dev);\
1221         _seqbuf[_seqbufptr+2] = (event);\
1222         _seqbuf[_seqbufptr+3] = (chn);\
1223         _seqbuf[_seqbufptr+4] = (note);\
1224         _seqbuf[_seqbufptr+5] = (parm);\
1225         _seqbuf[_seqbufptr+6] = (0);\
1226         _seqbuf[_seqbufptr+7] = 0;\
1227         _SEQ_ADVBUF(8);}
1228
1229 #define SEQ_START_NOTE(dev, chn, note, vol) \
1230                 _CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol)
1231
1232 #define SEQ_STOP_NOTE(dev, chn, note, vol) \
1233                 _CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol)
1234
1235 #define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \
1236                 _CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure)
1237
1238 /*
1239  * Midi channel messages
1240  */
1241
1242 #define _CHN_COMMON(dev, event, chn, p1, p2, w14) { \
1243         _SEQ_NEEDBUF(8);\
1244         _seqbuf[_seqbufptr] = EV_CHN_COMMON;\
1245         _seqbuf[_seqbufptr+1] = (dev);\
1246         _seqbuf[_seqbufptr+2] = (event);\
1247         _seqbuf[_seqbufptr+3] = (chn);\
1248         _seqbuf[_seqbufptr+4] = (p1);\
1249         _seqbuf[_seqbufptr+5] = (p2);\
1250         *(short *)&_seqbuf[_seqbufptr+6] = (w14);\
1251         _SEQ_ADVBUF(8);}
1252 /*
1253  * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits
1254  * sending any MIDI bytes but it's absolutely not possible. Trying to do
1255  * so _will_ cause problems with MPU401 intelligent mode).
1256  *
1257  * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be
1258  * sent by calling SEQ_SYSEX() several times (there must be no other events
1259  * between them). First sysex fragment must have 0xf0 in the first byte
1260  * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte
1261  * between these sysex start and end markers cannot be larger than 0x7f. Also
1262  * lengths of each fragments (except the last one) must be 6.
1263  *
1264  * Breaking the above rules may work with some MIDI ports but is likely to
1265  * cause fatal problems with some other devices (such as MPU401).
1266  */
1267 #define SEQ_SYSEX(dev, buf, len) { \
1268         int i, l=(len); if (l>6)l=6;\
1269         _SEQ_NEEDBUF(8);\
1270         _seqbuf[_seqbufptr] = EV_SYSEX;\
1271         for(i=0;i<l;i++)_seqbuf[_seqbufptr+i+1] = (buf)[i];\
1272         for(i=l;i<6;i++)_seqbuf[_seqbufptr+i+1] = 0xff;\
1273         _SEQ_ADVBUF(8);}
1274
1275 #define SEQ_CHN_PRESSURE(dev, chn, pressure) \
1276         _CHN_COMMON(dev, MIDI_CHN_PRESSURE, chn, pressure, 0, 0)
1277
1278 #define SEQ_SET_PATCH(dev, chn, patch) \
1279         _CHN_COMMON(dev, MIDI_PGM_CHANGE, chn, patch, 0, 0)
1280
1281 #define SEQ_CONTROL(dev, chn, controller, value) \
1282         _CHN_COMMON(dev, MIDI_CTL_CHANGE, chn, controller, 0, value)
1283
1284 #define SEQ_BENDER(dev, chn, value) \
1285         _CHN_COMMON(dev, MIDI_PITCH_BEND, chn, 0, 0, value)
1286
1287
1288 #define SEQ_V2_X_CONTROL(dev, voice, controller, value) { \
1289         _SEQ_NEEDBUF(8);\
1290         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1291         _seqbuf[_seqbufptr+1] = SEQ_CONTROLLER;\
1292         _seqbuf[_seqbufptr+2] = (dev);\
1293         _seqbuf[_seqbufptr+3] = (voice);\
1294         _seqbuf[_seqbufptr+4] = (controller);\
1295         *(short *)&_seqbuf[_seqbufptr+5] = (value);\
1296         _seqbuf[_seqbufptr+7] = 0;\
1297         _SEQ_ADVBUF(8);}
1298
1299 /*
1300  * The following 5 macros are incorrectly implemented and obsolete.
1301  * Use SEQ_BENDER and SEQ_CONTROL (with proper controller) instead.
1302  */
1303
1304 #define SEQ_PITCHBEND(dev, voice, value) \
1305         SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER, value)
1306 #define SEQ_BENDER_RANGE(dev, voice, value) \
1307         SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value)
1308 #define SEQ_EXPRESSION(dev, voice, value) \
1309         SEQ_CONTROL(dev, voice, CTL_EXPRESSION, value*128)
1310 #define SEQ_MAIN_VOLUME(dev, voice, value) \
1311         SEQ_CONTROL(dev, voice, CTL_MAIN_VOLUME, (value*16383)/100)
1312 #define SEQ_PANNING(dev, voice, pos) \
1313         SEQ_CONTROL(dev, voice, CTL_PAN, (pos+128) / 2)
1314
1315 /*
1316  * Timing and syncronization macros
1317  */
1318
1319 #define _TIMER_EVENT(ev, parm)          { \
1320         _SEQ_NEEDBUF(8);\
1321         _seqbuf[_seqbufptr+0] = EV_TIMING; \
1322         _seqbuf[_seqbufptr+1] = (ev); \
1323         _seqbuf[_seqbufptr+2] = 0;\
1324         _seqbuf[_seqbufptr+3] = 0;\
1325         *(u_int *)&_seqbuf[_seqbufptr+4] = (parm); \
1326         _SEQ_ADVBUF(8); \
1327         }
1328
1329 #define SEQ_START_TIMER()               _TIMER_EVENT(TMR_START, 0)
1330 #define SEQ_STOP_TIMER()                _TIMER_EVENT(TMR_STOP, 0)
1331 #define SEQ_CONTINUE_TIMER()            _TIMER_EVENT(TMR_CONTINUE, 0)
1332 #define SEQ_WAIT_TIME(ticks)            _TIMER_EVENT(TMR_WAIT_ABS, ticks)
1333 #define SEQ_DELTA_TIME(ticks)           _TIMER_EVENT(TMR_WAIT_REL, ticks)
1334 #define SEQ_ECHO_BACK(key)              _TIMER_EVENT(TMR_ECHO, key)
1335 #define SEQ_SET_TEMPO(value)            _TIMER_EVENT(TMR_TEMPO, value)
1336 #define SEQ_SONGPOS(pos)                _TIMER_EVENT(TMR_SPP, pos)
1337 #define SEQ_TIME_SIGNATURE(sig)         _TIMER_EVENT(TMR_TIMESIG, sig)
1338
1339 /*
1340  * Local control events
1341  */
1342
1343 #define _LOCAL_EVENT(ev, parm)          { \
1344         _SEQ_NEEDBUF(8);\
1345         _seqbuf[_seqbufptr+0] = EV_SEQ_LOCAL; \
1346         _seqbuf[_seqbufptr+1] = (ev); \
1347         _seqbuf[_seqbufptr+2] = 0;\
1348         _seqbuf[_seqbufptr+3] = 0;\
1349         *(u_int *)&_seqbuf[_seqbufptr+4] = (parm); \
1350         _SEQ_ADVBUF(8); \
1351         }
1352
1353 #define SEQ_PLAYAUDIO(devmask)          _LOCAL_EVENT(LOCL_STARTAUDIO, devmask)
1354 /*
1355  * Events for the level 1 interface only 
1356  */
1357
1358 #define SEQ_MIDIOUT(device, byte)       { \
1359         _SEQ_NEEDBUF(4);\
1360         _seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\
1361         _seqbuf[_seqbufptr+1] = (byte);\
1362         _seqbuf[_seqbufptr+2] = (device);\
1363         _seqbuf[_seqbufptr+3] = 0;\
1364         _SEQ_ADVBUF(4);}
1365
1366 /*
1367  * Patch loading.
1368  */
1369 #define SEQ_WRPATCH(patchx, len)        { \
1370         if (_seqbufptr) seqbuf_dump(); \
1371         if (write(seqfd, (char*)(patchx), len)==-1) \
1372            perror("Write patch: /dev/sequencer"); \
1373         }
1374
1375 #define SEQ_WRPATCH2(patchx, len)       \
1376         ( seqbuf_dump(), write(seqfd, (char*)(patchx), len) )
1377
1378 #endif
1379
1380 /*
1381  * Here I have moved all the aliases for ioctl names.
1382  */
1383
1384 #define SNDCTL_DSP_SAMPLESIZE   SNDCTL_DSP_SETFMT
1385 #define SOUND_PCM_WRITE_BITS    SNDCTL_DSP_SETFMT
1386 #define SOUND_PCM_SETFMT        SNDCTL_DSP_SETFMT
1387
1388 #define SOUND_PCM_WRITE_RATE    SNDCTL_DSP_SPEED
1389 #define SOUND_PCM_POST          SNDCTL_DSP_POST
1390 #define SOUND_PCM_RESET         SNDCTL_DSP_RESET
1391 #define SOUND_PCM_SYNC          SNDCTL_DSP_SYNC
1392 #define SOUND_PCM_SUBDIVIDE     SNDCTL_DSP_SUBDIVIDE
1393 #define SOUND_PCM_SETFRAGMENT   SNDCTL_DSP_SETFRAGMENT
1394 #define SOUND_PCM_GETFMTS       SNDCTL_DSP_GETFMTS
1395 #define SOUND_PCM_GETOSPACE     SNDCTL_DSP_GETOSPACE
1396 #define SOUND_PCM_GETISPACE     SNDCTL_DSP_GETISPACE
1397 #define SOUND_PCM_NONBLOCK      SNDCTL_DSP_NONBLOCK
1398 #define SOUND_PCM_GETCAPS       SNDCTL_DSP_GETCAPS
1399 #define SOUND_PCM_GETTRIGGER    SNDCTL_DSP_GETTRIGGER
1400 #define SOUND_PCM_SETTRIGGER    SNDCTL_DSP_SETTRIGGER
1401 #define SOUND_PCM_SETSYNCRO     SNDCTL_DSP_SETSYNCRO
1402 #define SOUND_PCM_GETIPTR       SNDCTL_DSP_GETIPTR
1403 #define SOUND_PCM_GETOPTR       SNDCTL_DSP_GETOPTR
1404 #define SOUND_PCM_MAPINBUF      SNDCTL_DSP_MAPINBUF
1405 #define SOUND_PCM_MAPOUTBUF     SNDCTL_DSP_MAPOUTBUF
1406
1407 #endif  /* !_SYS_SOUNDCARD_H_ */