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