1 #ifndef SOUNDCARD_H
2 #define SOUNDCARD_H
3 /*
4  * Copyright by Hannu Savolainen 1993-1997
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer. 2.
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 
28 /*
29  * OSS interface version. With versions earlier than 3.6 this value is
30  * an integer with value less than 361. In versions 3.6 and later
31  * it's a six digit hexadecimal value. For example value
32  * of 0x030600 represents OSS version 3.6.0.
33  * Use ioctl(fd, OSS_GETVERSION, &int) to get the version number of
34  * the currently active driver.
35  */
36 #define SOUND_VERSION	0x030802
37 #define OPEN_SOUND_SYSTEM
38 
39 /* In Linux we need to be prepared for cross compiling */
40 #include <linux/ioctl.h>
41 
42 /*
43  *	Supported card ID numbers (Should be somewhere else?)
44  */
45 
46 #define SNDCARD_ADLIB		1
47 #define SNDCARD_SB		2
48 #define SNDCARD_PAS		3
49 #define SNDCARD_GUS		4
50 #define SNDCARD_MPU401		5
51 #define SNDCARD_SB16		6
52 #define SNDCARD_SB16MIDI	7
53 #define SNDCARD_UART6850	8
54 #define SNDCARD_GUS16		9
55 #define SNDCARD_MSS		10
56 #define SNDCARD_PSS     	11
57 #define SNDCARD_SSCAPE		12
58 #define SNDCARD_PSS_MPU     	13
59 #define SNDCARD_PSS_MSS     	14
60 #define SNDCARD_SSCAPE_MSS	15
61 #define SNDCARD_TRXPRO		16
62 #define SNDCARD_TRXPRO_SB	17
63 #define SNDCARD_TRXPRO_MPU	18
64 #define SNDCARD_MAD16		19
65 #define SNDCARD_MAD16_MPU	20
66 #define SNDCARD_CS4232		21
67 #define SNDCARD_CS4232_MPU	22
68 #define SNDCARD_MAUI		23
69 #define SNDCARD_PSEUDO_MSS	24
70 #define SNDCARD_GUSPNP		25
71 #define SNDCARD_UART401		26
72 /* Sound card numbers 27 to N are reserved. Don't add more numbers here. */
73 
74 /***********************************
75  * IOCTL Commands for /dev/sequencer
76  */
77 
78 #ifndef _SIOWR
79 #if defined(_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__sparc__) && !defined(__INCioctlh) && !defined(__Lynx__)))
80 /* Use already defined ioctl defines if they exist (except with Sun or Sparc) */
81 #define	SIOCPARM_MASK	IOCPARM_MASK
82 #define	SIOC_VOID	IOC_VOID
83 #define	SIOC_OUT	IOC_OUT
84 #define	SIOC_IN		IOC_IN
85 #define	SIOC_INOUT	IOC_INOUT
86 #define _SIOC_SIZE	_IOC_SIZE
87 #define _SIOC_DIR	_IOC_DIR
88 #define _SIOC_NONE	_IOC_NONE
89 #define _SIOC_READ	_IOC_READ
90 #define _SIOC_WRITE	_IOC_WRITE
91 #define	_SIO		_IO
92 #define	_SIOR		_IOR
93 #define	_SIOW		_IOW
94 #define	_SIOWR		_IOWR
95 #else
96 
97 /* Ioctl's have the command encoded in the lower word,
98  * and the size of any in or out parameters in the upper
99  * word.  The high 2 bits of the upper word are used
100  * to encode the in/out status of the parameter; for now
101  * we restrict parameters to at most 8191 bytes.
102  */
103 /* #define	SIOCTYPE		(0xff<<8) */
104 #define	SIOCPARM_MASK	0x1fff		/* parameters must be < 8192 bytes */
105 #define	SIOC_VOID	0x00000000	/* no parameters */
106 #define	SIOC_OUT	0x20000000	/* copy out parameters */
107 #define	SIOC_IN		0x40000000	/* copy in parameters */
108 #define	SIOC_INOUT	(SIOC_IN|SIOC_OUT)
109 /* the 0x20000000 is so we can distinguish new ioctl's from old */
110 #define	_SIO(x,y)	((int)(SIOC_VOID|(x<<8)|y))
111 #define	_SIOR(x,y,t)	((int)(SIOC_OUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
112 #define	_SIOW(x,y,t)	((int)(SIOC_IN|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
113 /* this should be _SIORW, but stdio got there first */
114 #define	_SIOWR(x,y,t)	((int)(SIOC_INOUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
115 #define _SIOC_SIZE(x)	((x>>16)&SIOCPARM_MASK)
116 #define _SIOC_DIR(x)	(x & 0xf0000000)
117 #define _SIOC_NONE	SIOC_VOID
118 #define _SIOC_READ	SIOC_OUT
119 #define _SIOC_WRITE	SIOC_IN
120 #  endif /* _IOWR */
121 #endif  /* !_SIOWR */
122 
123 #define SNDCTL_SEQ_RESET		_SIO  ('Q', 0)
124 #define SNDCTL_SEQ_SYNC			_SIO  ('Q', 1)
125 #define SNDCTL_SYNTH_INFO		_SIOWR('Q', 2, struct synth_info)
126 #define SNDCTL_SEQ_CTRLRATE		_SIOWR('Q', 3, int)	/* Set/get timer resolution (HZ) */
127 #define SNDCTL_SEQ_GETOUTCOUNT		_SIOR ('Q', 4, int)
128 #define SNDCTL_SEQ_GETINCOUNT		_SIOR ('Q', 5, int)
129 #define SNDCTL_SEQ_PERCMODE		_SIOW ('Q', 6, int)
130 #define SNDCTL_FM_LOAD_INSTR		_SIOW ('Q', 7, struct sbi_instrument)	/* Obsolete. Don't use!!!!!! */
131 #define SNDCTL_SEQ_TESTMIDI		_SIOW ('Q', 8, int)
132 #define SNDCTL_SEQ_RESETSAMPLES		_SIOW ('Q', 9, int)
133 #define SNDCTL_SEQ_NRSYNTHS		_SIOR ('Q',10, int)
134 #define SNDCTL_SEQ_NRMIDIS		_SIOR ('Q',11, int)
135 #define SNDCTL_MIDI_INFO		_SIOWR('Q',12, struct midi_info)
136 #define SNDCTL_SEQ_THRESHOLD		_SIOW ('Q',13, int)
137 #define SNDCTL_SYNTH_MEMAVL		_SIOWR('Q',14, int)	/* in=dev#, out=memsize */
138 #define SNDCTL_FM_4OP_ENABLE		_SIOW ('Q',15, int)	/* in=dev# */
139 #define SNDCTL_SEQ_PANIC		_SIO  ('Q',17)
140 #define SNDCTL_SEQ_OUTOFBAND		_SIOW ('Q',18, struct seq_event_rec)
141 #define SNDCTL_SEQ_GETTIME		_SIOR ('Q',19, int)
142 #define SNDCTL_SYNTH_ID			_SIOWR('Q',20, struct synth_info)
143 #define SNDCTL_SYNTH_CONTROL		_SIOWR('Q',21, struct synth_control)
144 #define SNDCTL_SYNTH_REMOVESAMPLE	_SIOWR('Q',22, struct remove_sample)
145 
146 typedef struct synth_control
147 {
148 	int devno;	/* Synthesizer # */
149 	char data[4000]; /* Device spesific command/data record */
150 }synth_control;
151 
152 typedef struct remove_sample
153 {
154 	int devno;	/* Synthesizer # */
155 	int bankno;	/* MIDI bank # (0=General MIDI) */
156 	int instrno;	/* MIDI instrument number */
157 } remove_sample;
158 
159 typedef struct seq_event_rec {
160 		unsigned char arr[8];
161 } seq_event_rec;
162 
163 #define SNDCTL_TMR_TIMEBASE		_SIOWR('T', 1, int)
164 #define SNDCTL_TMR_START		_SIO  ('T', 2)
165 #define SNDCTL_TMR_STOP			_SIO  ('T', 3)
166 #define SNDCTL_TMR_CONTINUE		_SIO  ('T', 4)
167 #define SNDCTL_TMR_TEMPO		_SIOWR('T', 5, int)
168 #define SNDCTL_TMR_SOURCE		_SIOWR('T', 6, int)
169 #	define TMR_INTERNAL		0x00000001
170 #	define TMR_EXTERNAL		0x00000002
171 #		define TMR_MODE_MIDI	0x00000010
172 #		define TMR_MODE_FSK	0x00000020
173 #		define TMR_MODE_CLS	0x00000040
174 #		define TMR_MODE_SMPTE	0x00000080
175 #define SNDCTL_TMR_METRONOME		_SIOW ('T', 7, int)
176 #define SNDCTL_TMR_SELECT		_SIOW ('T', 8, int)
177 
178 /*
179  * Some big endian/little endian handling macros
180  */
181 
182 #if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(PPC) || defined(__mc68000__)
183 /* Big endian machines */
184 #  define _PATCHKEY(id) (0xfd00|id)
185 #  define AFMT_S16_NE AFMT_S16_BE
186 #else
187 #  define _PATCHKEY(id) ((id<<8)|0xfd)
188 #  define AFMT_S16_NE AFMT_S16_LE
189 #endif
190 
191 /*
192  *	Sample loading mechanism for internal synthesizers (/dev/sequencer)
193  *	The following patch_info structure has been designed to support
194  *	Gravis UltraSound. It tries to be universal format for uploading
195  *	sample based patches but is probably too limited.
196  *
197  *      (PBD) As Hannu guessed, the GUS structure is too limited for
198  *      the WaveFront, but this is the right place for a constant definition.
199  */
200 
201 struct patch_info {
202 		unsigned short key;		/* Use WAVE_PATCH here */
203 #define WAVE_PATCH	   _PATCHKEY(0x04)
204 #define GUS_PATCH	   WAVE_PATCH
205 #define WAVEFRONT_PATCH    _PATCHKEY(0x06)
206 
207 		short device_no;	/* Synthesizer number */
208 		short instr_no;		/* Midi pgm# */
209 
210 		unsigned int mode;
211 /*
212  * The least significant byte has the same format than the GUS .PAT
213  * files
214  */
215 #define WAVE_16_BITS	0x01	/* bit 0 = 8 or 16 bit wave data. */
216 #define WAVE_UNSIGNED	0x02	/* bit 1 = Signed - Unsigned data. */
217 #define WAVE_LOOPING	0x04	/* bit 2 = looping enabled-1. */
218 #define WAVE_BIDIR_LOOP	0x08	/* bit 3 = Set is bidirectional looping. */
219 #define WAVE_LOOP_BACK	0x10	/* bit 4 = Set is looping backward. */
220 #define WAVE_SUSTAIN_ON	0x20	/* bit 5 = Turn sustaining on. (Env. pts. 3)*/
221 #define WAVE_ENVELOPES	0x40	/* bit 6 = Enable envelopes - 1 */
222 #define WAVE_FAST_RELEASE 0x80	/* bit 7 = Shut off immediately after note off */
223 				/* 	(use the env_rate/env_offs fields). */
224 /* Linux specific bits */
225 #define WAVE_VIBRATO	0x00010000	/* The vibrato info is valid */
226 #define WAVE_TREMOLO	0x00020000	/* The tremolo info is valid */
227 #define WAVE_SCALE	0x00040000	/* The scaling info is valid */
228 #define WAVE_FRACTIONS	0x00080000	/* Fraction information is valid */
229 /* Reserved bits */
230 #define WAVE_ROM	0x40000000	/* For future use */
231 #define WAVE_MULAW	0x20000000	/* For future use */
232 /* Other bits must be zeroed */
233 
234 		int len;	/* Size of the wave data in bytes */
235 		int loop_start, loop_end; /* Byte offsets from the beginning */
236 
237 /*
238  * The base_freq and base_note fields are used when computing the
239  * playback speed for a note. The base_note defines the tone frequency
240  * which is heard if the sample is played using the base_freq as the
241  * playback speed.
242  *
243  * The low_note and high_note fields define the minimum and maximum note
244  * frequencies for which this sample is valid. It is possible to define
245  * more than one samples for an instrument number at the same time. The
246  * low_note and high_note fields are used to select the most suitable one.
247  *
248  * The fields base_note, high_note and low_note should contain
249  * the note frequency multiplied by 1000. For example value for the
250  * middle A is 440*1000.
251  */
252 
253 		unsigned int base_freq;
254 		unsigned int base_note;
255 		unsigned int high_note;
256 		unsigned int low_note;
257 		int panning;	/* -128=left, 127=right */
258 		int detuning;
259 
260 /*	New fields introduced in version 1.99.5	*/
261 
262        /* Envelope. Enabled by mode bit WAVE_ENVELOPES	*/
263 		unsigned char	env_rate[ 6 ];	 /* GUS HW ramping rate */
264 		unsigned char	env_offset[ 6 ]; /* 255 == 100% */
265 
266 	/*
267 	 * The tremolo, vibrato and scale info are not supported yet.
268 	 * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
269 	 * WAVE_SCALE
270 	 */
271 
272 		unsigned char	tremolo_sweep;
273 		unsigned char	tremolo_rate;
274 		unsigned char	tremolo_depth;
275 
276 		unsigned char	vibrato_sweep;
277 		unsigned char	vibrato_rate;
278 		unsigned char	vibrato_depth;
279 
280 		int		scale_frequency;
281 		unsigned int	scale_factor;		/* from 0 to 2048 or 0 to 2 */
282 
283 	        int		volume;
284 		int		fractions;
285 		int		reserved1;
286 	        int		spare[2];
287 		char data[1];	/* The waveform data starts here */
288 	};
289 
290 struct sysex_info {
291 		short key;		/* Use SYSEX_PATCH or MAUI_PATCH here */
292 #define SYSEX_PATCH	_PATCHKEY(0x05)
293 #define MAUI_PATCH	_PATCHKEY(0x06)
294 		short device_no;	/* Synthesizer number */
295 		int len;	/* Size of the sysex data in bytes */
296 		unsigned char data[1];	/* Sysex data starts here */
297 	};
298 
299 /*
300  * /dev/sequencer input events.
301  *
302  * The data written to the /dev/sequencer is a stream of events. Events
303  * are records of 4 or 8 bytes. The first byte defines the size.
304  * Any number of events can be written with a write call. There
305  * is a set of macros for sending these events. Use these macros if you
306  * want to maximize portability of your program.
307  *
308  * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
309  * (All input events are currently 4 bytes long. Be prepared to support
310  * 8 byte events also. If you receive any event having first byte >= 128,
311  * it's a 8 byte event.
312  *
313  * The events are documented at the end of this file.
314  *
315  * Normal events (4 bytes)
316  * There is also a 8 byte version of most of the 4 byte events. The
317  * 8 byte one is recommended.
318  */
319 #define SEQ_NOTEOFF		0
320 #define SEQ_FMNOTEOFF		SEQ_NOTEOFF	/* Just old name */
321 #define SEQ_NOTEON		1
322 #define	SEQ_FMNOTEON		SEQ_NOTEON
323 #define SEQ_WAIT		TMR_WAIT_ABS
324 #define SEQ_PGMCHANGE		3
325 #define SEQ_FMPGMCHANGE		SEQ_PGMCHANGE
326 #define SEQ_SYNCTIMER		TMR_START
327 #define SEQ_MIDIPUTC		5
328 #define SEQ_DRUMON		6	/*** OBSOLETE ***/
329 #define SEQ_DRUMOFF		7	/*** OBSOLETE ***/
330 #define SEQ_ECHO		TMR_ECHO	/* For synching programs with output */
331 #define SEQ_AFTERTOUCH		9
332 #define SEQ_CONTROLLER		10
333 
334 /*******************************************
335  *	Midi controller numbers
336  *******************************************
337  * Controllers 0 to 31 (0x00 to 0x1f) and
338  * 32 to 63 (0x20 to 0x3f) are continuous
339  * controllers.
340  * In the MIDI 1.0 these controllers are sent using
341  * two messages. Controller numbers 0 to 31 are used
342  * to send the MSB and the controller numbers 32 to 63
343  * are for the LSB. Note that just 7 bits are used in MIDI bytes.
344  */
345 
346 #define	   CTL_BANK_SELECT		0x00
347 #define	   CTL_MODWHEEL			0x01
348 #define    CTL_BREATH			0x02
349 /*		undefined		0x03 */
350 #define    CTL_FOOT			0x04
351 #define    CTL_PORTAMENTO_TIME		0x05
352 #define    CTL_DATA_ENTRY		0x06
353 #define    CTL_MAIN_VOLUME		0x07
354 #define    CTL_BALANCE			0x08
355 /*		undefined		0x09 */
356 #define    CTL_PAN			0x0a
357 #define    CTL_EXPRESSION		0x0b
358 /*		undefined		0x0c */
359 /*		undefined		0x0d */
360 /*		undefined		0x0e */
361 /*		undefined		0x0f */
362 #define    CTL_GENERAL_PURPOSE1	0x10
363 #define    CTL_GENERAL_PURPOSE2	0x11
364 #define    CTL_GENERAL_PURPOSE3	0x12
365 #define    CTL_GENERAL_PURPOSE4	0x13
366 /*		undefined		0x14 - 0x1f */
367 
368 /*		undefined		0x20 */
369 /* The controller numbers 0x21 to 0x3f are reserved for the */
370 /* least significant bytes of the controllers 0x00 to 0x1f. */
371 /* These controllers are not recognised by the driver. */
372 
373 /* Controllers 64 to 69 (0x40 to 0x45) are on/off switches. */
374 /* 0=OFF and 127=ON (intermediate values are possible) */
375 #define    CTL_DAMPER_PEDAL		0x40
376 #define    CTL_SUSTAIN			0x40	/* Alias */
377 #define    CTL_HOLD			0x40	/* Alias */
378 #define    CTL_PORTAMENTO		0x41
379 #define    CTL_SOSTENUTO		0x42
380 #define    CTL_SOFT_PEDAL		0x43
381 /*		undefined		0x44 */
382 #define    CTL_HOLD2			0x45
383 /*		undefined		0x46 - 0x4f */
384 
385 #define    CTL_GENERAL_PURPOSE5	0x50
386 #define    CTL_GENERAL_PURPOSE6	0x51
387 #define    CTL_GENERAL_PURPOSE7	0x52
388 #define    CTL_GENERAL_PURPOSE8	0x53
389 /*		undefined		0x54 - 0x5a */
390 #define    CTL_EXT_EFF_DEPTH		0x5b
391 #define    CTL_TREMOLO_DEPTH		0x5c
392 #define    CTL_CHORUS_DEPTH		0x5d
393 #define    CTL_DETUNE_DEPTH		0x5e
394 #define    CTL_CELESTE_DEPTH		0x5e	/* Alias for the above one */
395 #define    CTL_PHASER_DEPTH		0x5f
396 #define    CTL_DATA_INCREMENT		0x60
397 #define    CTL_DATA_DECREMENT		0x61
398 #define    CTL_NONREG_PARM_NUM_LSB	0x62
399 #define    CTL_NONREG_PARM_NUM_MSB	0x63
400 #define    CTL_REGIST_PARM_NUM_LSB	0x64
401 #define    CTL_REGIST_PARM_NUM_MSB	0x65
402 /*		undefined		0x66 - 0x78 */
403 /*		reserved		0x79 - 0x7f */
404 
405 /* Pseudo controllers (not midi compatible) */
406 #define    CTRL_PITCH_BENDER		255
407 #define    CTRL_PITCH_BENDER_RANGE	254
408 #define    CTRL_EXPRESSION		253	/* Obsolete */
409 #define    CTRL_MAIN_VOLUME		252	/* Obsolete */
410 #define SEQ_BALANCE		11
411 #define SEQ_VOLMODE             12
412 
413 /*
414  * Volume mode decides how volumes are used
415  */
416 
417 #define VOL_METHOD_ADAGIO	1
418 #define VOL_METHOD_LINEAR	2
419 
420 /*
421  * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
422  *	 input events.
423  */
424 
425 /*
426  * Event codes 0xf0 to 0xfc are reserved for future extensions.
427  */
428 
429 #define SEQ_FULLSIZE		0xfd	/* Long events */
430 /*
431  *	SEQ_FULLSIZE events are used for loading patches/samples to the
432  *	synthesizer devices. These events are passed directly to the driver
433  *	of the associated synthesizer device. There is no limit to the size
434  *	of the extended events. These events are not queued but executed
435  *	immediately when the write() is called (execution can take several
436  *	seconds of time).
437  *
438  *	When a SEQ_FULLSIZE message is written to the device, it must
439  *	be written using exactly one write() call. Other events cannot
440  *	be mixed to the same write.
441  *
442  *	For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the
443  *	/dev/sequencer. Don't write other data together with the instrument structure
444  *	Set the key field of the structure to FM_PATCH. The device field is used to
445  *	route the patch to the corresponding device.
446  *
447  *	For wave table use struct patch_info. Initialize the key field
448  *      to WAVE_PATCH.
449  */
450 #define SEQ_PRIVATE		0xfe	/* Low level HW dependent events (8 bytes) */
451 #define SEQ_EXTENDED		0xff	/* Extended events (8 bytes) OBSOLETE */
452 
453 /*
454  * Record for FM patches
455  */
456 
457 typedef unsigned char sbi_instr_data[32];
458 
459 struct sbi_instrument {
460 		unsigned short	key;	/* FM_PATCH or OPL3_PATCH */
461 #define FM_PATCH	_PATCHKEY(0x01)
462 #define OPL3_PATCH	_PATCHKEY(0x03)
463 		short		device;		/*	Synth# (0-4)	*/
464 		int 		channel;	/*	Program# to be initialized 	*/
465 		sbi_instr_data	operators;	/*	Register settings for operator cells (.SBI format)	*/
466 	};
467 
468 struct synth_info {	/* Read only */
469 		char	name[30];
470 		int	device;		/* 0-N. INITIALIZE BEFORE CALLING */
471 		int	synth_type;
472 #define SYNTH_TYPE_FM			0
473 #define SYNTH_TYPE_SAMPLE		1
474 #define SYNTH_TYPE_MIDI			2	/* Midi interface */
475 
476 		int	synth_subtype;
477 #define FM_TYPE_ADLIB			0x00
478 #define FM_TYPE_OPL3			0x01
479 #define MIDI_TYPE_MPU401		0x401
480 
481 #define SAMPLE_TYPE_BASIC		0x10
482 #define SAMPLE_TYPE_GUS			SAMPLE_TYPE_BASIC
483 #define SAMPLE_TYPE_WAVEFRONT           0x11
484 
485 		int	perc_mode;	/* No longer supported */
486 		int	nr_voices;
487 		int	nr_drums;	/* Obsolete field */
488 		int	instr_bank_size;
489 		unsigned int	capabilities;
490 #define SYNTH_CAP_PERCMODE		0x00000001 /* No longer used */
491 #define SYNTH_CAP_OPL3			0x00000002 /* Set if OPL3 supported */
492 #define SYNTH_CAP_INPUT			0x00000004 /* Input (MIDI) device */
493 		int	dummies[19];	/* Reserve space */
494 	};
495 
496 struct sound_timer_info {
497 		char name[32];
498 		int caps;
499 	};
500 
501 #define MIDI_CAP_MPU401		1		/* MPU-401 intelligent mode */
502 
503 struct midi_info {
504 		char		name[30];
505 		int		device;		/* 0-N. INITIALIZE BEFORE CALLING */
506 		unsigned int	capabilities;	/* To be defined later */
507 		int		dev_type;
508 		int		dummies[18];	/* Reserve space */
509 	};
510 
511 /********************************************
512  * ioctl commands for the /dev/midi##
513  */
514 typedef struct {
515 		unsigned char cmd;
516 		char nr_args, nr_returns;
517 		unsigned char data[30];
518 	} mpu_command_rec;
519 
520 #define SNDCTL_MIDI_PRETIME		_SIOWR('m', 0, int)
521 #define SNDCTL_MIDI_MPUMODE		_SIOWR('m', 1, int)
522 #define SNDCTL_MIDI_MPUCMD		_SIOWR('m', 2, mpu_command_rec)
523 
524 /********************************************
525  * IOCTL commands for /dev/dsp and /dev/audio
526  */
527 
528 #define SNDCTL_DSP_RESET		_SIO  ('P', 0)
529 #define SNDCTL_DSP_SYNC			_SIO  ('P', 1)
530 #define SNDCTL_DSP_SPEED		_SIOWR('P', 2, int)
531 #define SNDCTL_DSP_STEREO		_SIOWR('P', 3, int)
532 #define SNDCTL_DSP_GETBLKSIZE		_SIOWR('P', 4, int)
533 #define SNDCTL_DSP_SAMPLESIZE		SNDCTL_DSP_SETFMT
534 #define SNDCTL_DSP_CHANNELS		_SIOWR('P', 6, int)
535 #define SOUND_PCM_WRITE_CHANNELS	SNDCTL_DSP_CHANNELS
536 #define SOUND_PCM_WRITE_FILTER		_SIOWR('P', 7, int)
537 #define SNDCTL_DSP_POST			_SIO  ('P', 8)
538 #define SNDCTL_DSP_SUBDIVIDE		_SIOWR('P', 9, int)
539 #define SNDCTL_DSP_SETFRAGMENT		_SIOWR('P',10, int)
540 
541 /*	Audio data formats (Note! U8=8 and S16_LE=16 for compatibility) */
542 #define SNDCTL_DSP_GETFMTS		_SIOR ('P',11, int) /* Returns a mask */
543 #define SNDCTL_DSP_SETFMT		_SIOWR('P',5, int) /* Selects ONE fmt*/
544 #	define AFMT_QUERY		0x00000000	/* Return current fmt */
545 #	define AFMT_MU_LAW		0x00000001
546 #	define AFMT_A_LAW		0x00000002
547 #	define AFMT_IMA_ADPCM		0x00000004
548 #	define AFMT_U8			0x00000008
549 #	define AFMT_S16_LE		0x00000010	/* Little endian signed 16*/
550 #	define AFMT_S16_BE		0x00000020	/* Big endian signed 16 */
551 #	define AFMT_S8			0x00000040
552 #	define AFMT_U16_LE		0x00000080	/* Little endian U16 */
553 #	define AFMT_U16_BE		0x00000100	/* Big endian U16 */
554 #	define AFMT_MPEG		0x00000200	/* MPEG (2) audio */
555 #	define AFMT_AC3		0x00000400	/* Dolby Digital AC3 */
556 
557 /* because they *do* exist and we want to use them --Monty */
558 #	define AFMT_S24_LE	        0x00000800
559 #	define AFMT_S24_BE	        0x00001000
560 #	define AFMT_U24_LE	        0x00002000
561 #	define AFMT_U24_BE	        0x00004000
562 #	define AFMT_S32_LE	        0x00008000
563 #	define AFMT_S32_BE	        0x00010000
564 #	define AFMT_U32_LE	        0x00020000
565 #	define AFMT_U32_BE	        0x00040000
566 
567 /*
568  * Buffer status queries.
569  */
570 typedef struct audio_buf_info {
571 			int fragments;	/* # of available fragments (partially usend ones not counted) */
572 			int fragstotal;	/* Total # of fragments allocated */
573 			int fragsize;	/* Size of a fragment in bytes */
574 
575 			int bytes;	/* Available space in bytes (includes partially used fragments) */
576 			/* Note! 'bytes' could be more than fragments*fragsize */
577 		} audio_buf_info;
578 
579 #define SNDCTL_DSP_GETOSPACE		_SIOR ('P',12, audio_buf_info)
580 #define SNDCTL_DSP_GETISPACE		_SIOR ('P',13, audio_buf_info)
581 #define SNDCTL_DSP_NONBLOCK		_SIO  ('P',14)
582 #define SNDCTL_DSP_GETCAPS		_SIOR ('P',15, int)
583 #	define DSP_CAP_REVISION		0x000000ff	/* Bits for revision level (0 to 255) */
584 #	define DSP_CAP_DUPLEX		0x00000100	/* Full duplex record/playback */
585 #	define DSP_CAP_REALTIME		0x00000200	/* Real time capability */
586 #	define DSP_CAP_BATCH		0x00000400	/* Device has some kind of */
587 							/* internal buffers which may */
588 							/* cause some delays and */
589 							/* decrease precision of timing */
590 #	define DSP_CAP_COPROC		0x00000800	/* Has a coprocessor */
591 							/* Sometimes it's a DSP */
592 							/* but usually not */
593 #	define DSP_CAP_TRIGGER		0x00001000	/* Supports SETTRIGGER */
594 #	define DSP_CAP_MMAP		0x00002000	/* Supports mmap() */
595 #	define DSP_CAP_MULTI		0x00004000	/* support multiple open */
596 #	define DSP_CAP_BIND		0x00008000	/* channel binding to front/rear/cneter/lfe */
597 
598 
599 #define SNDCTL_DSP_GETTRIGGER		_SIOR ('P',16, int)
600 #define SNDCTL_DSP_SETTRIGGER		_SIOW ('P',16, int)
601 #	define PCM_ENABLE_INPUT		0x00000001
602 #	define PCM_ENABLE_OUTPUT		0x00000002
603 
604 typedef struct count_info {
605 		int bytes;	/* Total # of bytes processed */
606 		int blocks;	/* # of fragment transitions since last time */
607 		int ptr;	/* Current DMA pointer value */
608 	} count_info;
609 
610 #define SNDCTL_DSP_GETIPTR		_SIOR ('P',17, count_info)
611 #define SNDCTL_DSP_GETOPTR		_SIOR ('P',18, count_info)
612 
613 typedef struct buffmem_desc {
614 		unsigned *buffer;
615 		int size;
616 	} buffmem_desc;
617 #define SNDCTL_DSP_MAPINBUF		_SIOR ('P', 19, buffmem_desc)
618 #define SNDCTL_DSP_MAPOUTBUF		_SIOR ('P', 20, buffmem_desc)
619 #define SNDCTL_DSP_SETSYNCRO		_SIO  ('P', 21)
620 #define SNDCTL_DSP_SETDUPLEX		_SIO  ('P', 22)
621 #define SNDCTL_DSP_GETODELAY		_SIOR ('P', 23, int)
622 
623 #define SNDCTL_DSP_GETCHANNELMASK		_SIOWR('P', 64, int)
624 #define SNDCTL_DSP_BIND_CHANNEL		_SIOWR('P', 65, int)
625 #	define DSP_BIND_QUERY		0x00000000
626 #	define DSP_BIND_FRONT		0x00000001
627 #	define DSP_BIND_SURR		0x00000002
628 #	define DSP_BIND_CENTER_LFE	0x00000004
629 #	define DSP_BIND_HANDSET		0x00000008
630 #	define DSP_BIND_MIC		0x00000010
631 #	define DSP_BIND_MODEM1		0x00000020
632 #	define DSP_BIND_MODEM2		0x00000040
633 #	define DSP_BIND_I2S		0x00000080
634 #	define DSP_BIND_SPDIF		0x00000100
635 
636 #define SNDCTL_DSP_SETSPDIF		_SIOW ('P', 66, int)
637 #define SNDCTL_DSP_GETSPDIF		_SIOR ('P', 67, int)
638 #	define SPDIF_PRO	0x0001
639 #	define SPDIF_N_AUD	0x0002
640 #	define SPDIF_COPY	0x0004
641 #	define SPDIF_PRE	0x0008
642 #	define SPDIF_CC		0x07f0
643 #	define SPDIF_L		0x0800
644 #	define SPDIF_DRS	0x4000
645 #	define SPDIF_V		0x8000
646 
647 /*
648  * Application's profile defines the way how playback underrun situations should be handled.
649  *
650  *	APF_NORMAL (the default) and APF_NETWORK make the driver to cleanup the
651  *	playback buffer whenever an underrun occurs. This consumes some time
652  *	prevents looping the existing buffer.
653  *	APF_CPUINTENS is intended to be set by CPU intensive applications which
654  *	are likely to run out of time occasionally. In this mode the buffer cleanup is
655  *	disabled which saves CPU time but also let's the previous buffer content to
656  *	be played during the "pause" after the underrun.
657  */
658 #define SNDCTL_DSP_PROFILE		_SIOW ('P', 23, int)
659 #define	  APF_NORMAL	0	/* Normal applications */
660 #define	  APF_NETWORK	1	/* Underruns probably caused by an "external" delay */
661 #define   APF_CPUINTENS 2	/* Underruns probably caused by "overheating" the CPU */
662 
663 #define SOUND_PCM_READ_RATE		_SIOR ('P', 2, int)
664 #define SOUND_PCM_READ_CHANNELS		_SIOR ('P', 6, int)
665 #define SOUND_PCM_READ_BITS		_SIOR ('P', 5, int)
666 #define SOUND_PCM_READ_FILTER		_SIOR ('P', 7, int)
667 
668 /* Some alias names */
669 #define SOUND_PCM_WRITE_BITS		SNDCTL_DSP_SETFMT
670 #define SOUND_PCM_WRITE_RATE		SNDCTL_DSP_SPEED
671 #define SOUND_PCM_POST			SNDCTL_DSP_POST
672 #define SOUND_PCM_RESET			SNDCTL_DSP_RESET
673 #define SOUND_PCM_SYNC			SNDCTL_DSP_SYNC
674 #define SOUND_PCM_SUBDIVIDE		SNDCTL_DSP_SUBDIVIDE
675 #define SOUND_PCM_SETFRAGMENT		SNDCTL_DSP_SETFRAGMENT
676 #define SOUND_PCM_GETFMTS		SNDCTL_DSP_GETFMTS
677 #define SOUND_PCM_SETFMT		SNDCTL_DSP_SETFMT
678 #define SOUND_PCM_GETOSPACE		SNDCTL_DSP_GETOSPACE
679 #define SOUND_PCM_GETISPACE		SNDCTL_DSP_GETISPACE
680 #define SOUND_PCM_NONBLOCK		SNDCTL_DSP_NONBLOCK
681 #define SOUND_PCM_GETCAPS		SNDCTL_DSP_GETCAPS
682 #define SOUND_PCM_GETTRIGGER		SNDCTL_DSP_GETTRIGGER
683 #define SOUND_PCM_SETTRIGGER		SNDCTL_DSP_SETTRIGGER
684 #define SOUND_PCM_SETSYNCRO		SNDCTL_DSP_SETSYNCRO
685 #define SOUND_PCM_GETIPTR		SNDCTL_DSP_GETIPTR
686 #define SOUND_PCM_GETOPTR		SNDCTL_DSP_GETOPTR
687 #define SOUND_PCM_MAPINBUF		SNDCTL_DSP_MAPINBUF
688 #define SOUND_PCM_MAPOUTBUF		SNDCTL_DSP_MAPOUTBUF
689 
690 /*
691  * ioctl calls to be used in communication with coprocessors and
692  * DSP chips.
693  */
694 
695 typedef struct copr_buffer {
696 		int command;	/* Set to 0 if not used */
697 		int flags;
698 #define CPF_NONE		0x0000
699 #define CPF_FIRST		0x0001	/* First block */
700 #define CPF_LAST		0x0002	/* Last block */
701 		int len;
702 		int offs;	/* If required by the device (0 if not used) */
703 
704 		unsigned char data[4000]; /* NOTE! 4000 is not 4k */
705 	} copr_buffer;
706 
707 typedef struct copr_debug_buf {
708 		int command;	/* Used internally. Set to 0 */
709 		int parm1;
710 		int parm2;
711 		int flags;
712 		int len;	/* Length of data in bytes */
713 	} copr_debug_buf;
714 
715 typedef struct copr_msg {
716 		int len;
717 		unsigned char data[4000];
718 	} copr_msg;
719 
720 #define SNDCTL_COPR_RESET             _SIO  ('C',  0)
721 #define SNDCTL_COPR_LOAD	      _SIOWR('C',  1, copr_buffer)
722 #define SNDCTL_COPR_RDATA	      _SIOWR('C',  2, copr_debug_buf)
723 #define SNDCTL_COPR_RCODE	      _SIOWR('C',  3, copr_debug_buf)
724 #define SNDCTL_COPR_WDATA	      _SIOW ('C',  4, copr_debug_buf)
725 #define SNDCTL_COPR_WCODE	      _SIOW ('C',  5, copr_debug_buf)
726 #define SNDCTL_COPR_RUN		      _SIOWR('C',  6, copr_debug_buf)
727 #define SNDCTL_COPR_HALT	      _SIOWR('C',  7, copr_debug_buf)
728 #define SNDCTL_COPR_SENDMSG	      _SIOWR('C',  8, copr_msg)
729 #define SNDCTL_COPR_RCVMSG	      _SIOR ('C',  9, copr_msg)
730 
731 /*********************************************
732  * IOCTL commands for /dev/mixer
733  */
734 
735 /*
736  * Mixer devices
737  *
738  * There can be up to 20 different analog mixer channels. The
739  * SOUND_MIXER_NRDEVICES gives the currently supported maximum.
740  * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells
741  * the devices supported by the particular mixer.
742  */
743 
744 #define SOUND_MIXER_NRDEVICES	25
745 #define SOUND_MIXER_VOLUME	0
746 #define SOUND_MIXER_BASS	1
747 #define SOUND_MIXER_TREBLE	2
748 #define SOUND_MIXER_SYNTH	3
749 #define SOUND_MIXER_PCM		4
750 #define SOUND_MIXER_SPEAKER	5
751 #define SOUND_MIXER_LINE	6
752 #define SOUND_MIXER_MIC		7
753 #define SOUND_MIXER_CD		8
754 #define SOUND_MIXER_IMIX	9	/*  Recording monitor  */
755 #define SOUND_MIXER_ALTPCM	10
756 #define SOUND_MIXER_RECLEV	11	/* Recording level */
757 #define SOUND_MIXER_IGAIN	12	/* Input gain */
758 #define SOUND_MIXER_OGAIN	13	/* Output gain */
759 /*
760  * The AD1848 codec and compatibles have three line level inputs
761  * (line, aux1 and aux2). Since each card manufacturer have assigned
762  * different meanings to these inputs, it's inpractical to assign
763  * specific meanings (line, cd, synth etc.) to them.
764  */
765 #define SOUND_MIXER_LINE1	14	/* Input source 1  (aux1) */
766 #define SOUND_MIXER_LINE2	15	/* Input source 2  (aux2) */
767 #define SOUND_MIXER_LINE3	16	/* Input source 3  (line) */
768 #define SOUND_MIXER_DIGITAL1	17	/* Digital (input) 1 */
769 #define SOUND_MIXER_DIGITAL2	18	/* Digital (input) 2 */
770 #define SOUND_MIXER_DIGITAL3	19	/* Digital (input) 3 */
771 #define SOUND_MIXER_PHONEIN	20	/* Phone input */
772 #define SOUND_MIXER_PHONEOUT	21	/* Phone output */
773 #define SOUND_MIXER_VIDEO	22	/* Video/TV (audio) in */
774 #define SOUND_MIXER_RADIO	23	/* Radio in */
775 #define SOUND_MIXER_MONITOR	24	/* Monitor (usually mic) volume */
776 
777 /* Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) */
778 /* Not counted to SOUND_MIXER_NRDEVICES, but use the same number space */
779 #define SOUND_ONOFF_MIN		28
780 #define SOUND_ONOFF_MAX		30
781 
782 /* Note!	Number 31 cannot be used since the sign bit is reserved */
783 #define SOUND_MIXER_NONE	31
784 
785 /*
786  * The following unsupported macros are no longer functional.
787  * Use SOUND_MIXER_PRIVATE# macros in future.
788  */
789 #define SOUND_MIXER_ENHANCE	SOUND_MIXER_NONE
790 #define SOUND_MIXER_MUTE	SOUND_MIXER_NONE
791 #define SOUND_MIXER_LOUD	SOUND_MIXER_NONE
792 
793 
794 #define SOUND_DEVICE_LABELS	{"Vol  ", "Bass ", "Trebl", "Synth", "Pcm  ", "Spkr ", "Line ", \
795 				 "Mic  ", "CD   ", "Mix  ", "Pcm2 ", "Rec  ", "IGain", "OGain", \
796 				 "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \
797 				 "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"}
798 
799 #define SOUND_DEVICE_NAMES	{"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
800 				 "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \
801 				 "line1", "line2", "line3", "dig1", "dig2", "dig3", \
802 				 "phin", "phout", "video", "radio", "monitor"}
803 
804 /*	Device bitmask identifiers	*/
805 
806 #define SOUND_MIXER_RECSRC	0xff	/* Arg contains a bit for each recording source */
807 #define SOUND_MIXER_DEVMASK	0xfe	/* Arg contains a bit for each supported device */
808 #define SOUND_MIXER_RECMASK	0xfd	/* Arg contains a bit for each supported recording source */
809 #define SOUND_MIXER_CAPS	0xfc
810 #	define SOUND_CAP_EXCL_INPUT	0x00000001	/* Only one recording source at a time */
811 #define SOUND_MIXER_STEREODEVS	0xfb	/* Mixer channels supporting stereo */
812 #define SOUND_MIXER_OUTSRC	0xfa	/* Arg contains a bit for each input source to output */
813 #define SOUND_MIXER_OUTMASK	0xf9	/* Arg contains a bit for each supported input source to output */
814 
815 /*	Device mask bits	*/
816 
817 #define SOUND_MASK_VOLUME	(1 << SOUND_MIXER_VOLUME)
818 #define SOUND_MASK_BASS		(1 << SOUND_MIXER_BASS)
819 #define SOUND_MASK_TREBLE	(1 << SOUND_MIXER_TREBLE)
820 #define SOUND_MASK_SYNTH	(1 << SOUND_MIXER_SYNTH)
821 #define SOUND_MASK_PCM		(1 << SOUND_MIXER_PCM)
822 #define SOUND_MASK_SPEAKER	(1 << SOUND_MIXER_SPEAKER)
823 #define SOUND_MASK_LINE		(1 << SOUND_MIXER_LINE)
824 #define SOUND_MASK_MIC		(1 << SOUND_MIXER_MIC)
825 #define SOUND_MASK_CD		(1 << SOUND_MIXER_CD)
826 #define SOUND_MASK_IMIX		(1 << SOUND_MIXER_IMIX)
827 #define SOUND_MASK_ALTPCM	(1 << SOUND_MIXER_ALTPCM)
828 #define SOUND_MASK_RECLEV	(1 << SOUND_MIXER_RECLEV)
829 #define SOUND_MASK_IGAIN	(1 << SOUND_MIXER_IGAIN)
830 #define SOUND_MASK_OGAIN	(1 << SOUND_MIXER_OGAIN)
831 #define SOUND_MASK_LINE1	(1 << SOUND_MIXER_LINE1)
832 #define SOUND_MASK_LINE2	(1 << SOUND_MIXER_LINE2)
833 #define SOUND_MASK_LINE3	(1 << SOUND_MIXER_LINE3)
834 #define SOUND_MASK_DIGITAL1	(1 << SOUND_MIXER_DIGITAL1)
835 #define SOUND_MASK_DIGITAL2	(1 << SOUND_MIXER_DIGITAL2)
836 #define SOUND_MASK_DIGITAL3	(1 << SOUND_MIXER_DIGITAL3)
837 #define SOUND_MASK_PHONEIN	(1 << SOUND_MIXER_PHONEIN)
838 #define SOUND_MASK_PHONEOUT	(1 << SOUND_MIXER_PHONEOUT)
839 #define SOUND_MASK_RADIO	(1 << SOUND_MIXER_RADIO)
840 #define SOUND_MASK_VIDEO	(1 << SOUND_MIXER_VIDEO)
841 #define SOUND_MASK_MONITOR	(1 << SOUND_MIXER_MONITOR)
842 
843 /* Obsolete macros */
844 #define SOUND_MASK_MUTE		(1 << SOUND_MIXER_MUTE)
845 #define SOUND_MASK_ENHANCE	(1 << SOUND_MIXER_ENHANCE)
846 #define SOUND_MASK_LOUD		(1 << SOUND_MIXER_LOUD)
847 
848 #define MIXER_READ(dev)		_SIOR('M', dev, int)
849 #define SOUND_MIXER_READ_VOLUME		MIXER_READ(SOUND_MIXER_VOLUME)
850 #define SOUND_MIXER_READ_BASS		MIXER_READ(SOUND_MIXER_BASS)
851 #define SOUND_MIXER_READ_TREBLE		MIXER_READ(SOUND_MIXER_TREBLE)
852 #define SOUND_MIXER_READ_SYNTH		MIXER_READ(SOUND_MIXER_SYNTH)
853 #define SOUND_MIXER_READ_PCM		MIXER_READ(SOUND_MIXER_PCM)
854 #define SOUND_MIXER_READ_SPEAKER	MIXER_READ(SOUND_MIXER_SPEAKER)
855 #define SOUND_MIXER_READ_LINE		MIXER_READ(SOUND_MIXER_LINE)
856 #define SOUND_MIXER_READ_MIC		MIXER_READ(SOUND_MIXER_MIC)
857 #define SOUND_MIXER_READ_CD		MIXER_READ(SOUND_MIXER_CD)
858 #define SOUND_MIXER_READ_IMIX		MIXER_READ(SOUND_MIXER_IMIX)
859 #define SOUND_MIXER_READ_ALTPCM		MIXER_READ(SOUND_MIXER_ALTPCM)
860 #define SOUND_MIXER_READ_RECLEV		MIXER_READ(SOUND_MIXER_RECLEV)
861 #define SOUND_MIXER_READ_IGAIN		MIXER_READ(SOUND_MIXER_IGAIN)
862 #define SOUND_MIXER_READ_OGAIN		MIXER_READ(SOUND_MIXER_OGAIN)
863 #define SOUND_MIXER_READ_LINE1		MIXER_READ(SOUND_MIXER_LINE1)
864 #define SOUND_MIXER_READ_LINE2		MIXER_READ(SOUND_MIXER_LINE2)
865 #define SOUND_MIXER_READ_LINE3		MIXER_READ(SOUND_MIXER_LINE3)
866 
867 /* Obsolete macros */
868 #define SOUND_MIXER_READ_MUTE		MIXER_READ(SOUND_MIXER_MUTE)
869 #define SOUND_MIXER_READ_ENHANCE	MIXER_READ(SOUND_MIXER_ENHANCE)
870 #define SOUND_MIXER_READ_LOUD		MIXER_READ(SOUND_MIXER_LOUD)
871 
872 #define SOUND_MIXER_READ_RECSRC		MIXER_READ(SOUND_MIXER_RECSRC)
873 #define SOUND_MIXER_READ_DEVMASK	MIXER_READ(SOUND_MIXER_DEVMASK)
874 #define SOUND_MIXER_READ_RECMASK	MIXER_READ(SOUND_MIXER_RECMASK)
875 #define SOUND_MIXER_READ_STEREODEVS	MIXER_READ(SOUND_MIXER_STEREODEVS)
876 #define SOUND_MIXER_READ_CAPS		MIXER_READ(SOUND_MIXER_CAPS)
877 
878 #define MIXER_WRITE(dev)		_SIOWR('M', dev, int)
879 #define SOUND_MIXER_WRITE_VOLUME	MIXER_WRITE(SOUND_MIXER_VOLUME)
880 #define SOUND_MIXER_WRITE_BASS		MIXER_WRITE(SOUND_MIXER_BASS)
881 #define SOUND_MIXER_WRITE_TREBLE	MIXER_WRITE(SOUND_MIXER_TREBLE)
882 #define SOUND_MIXER_WRITE_SYNTH		MIXER_WRITE(SOUND_MIXER_SYNTH)
883 #define SOUND_MIXER_WRITE_PCM		MIXER_WRITE(SOUND_MIXER_PCM)
884 #define SOUND_MIXER_WRITE_SPEAKER	MIXER_WRITE(SOUND_MIXER_SPEAKER)
885 #define SOUND_MIXER_WRITE_LINE		MIXER_WRITE(SOUND_MIXER_LINE)
886 #define SOUND_MIXER_WRITE_MIC		MIXER_WRITE(SOUND_MIXER_MIC)
887 #define SOUND_MIXER_WRITE_CD		MIXER_WRITE(SOUND_MIXER_CD)
888 #define SOUND_MIXER_WRITE_IMIX		MIXER_WRITE(SOUND_MIXER_IMIX)
889 #define SOUND_MIXER_WRITE_ALTPCM	MIXER_WRITE(SOUND_MIXER_ALTPCM)
890 #define SOUND_MIXER_WRITE_RECLEV	MIXER_WRITE(SOUND_MIXER_RECLEV)
891 #define SOUND_MIXER_WRITE_IGAIN		MIXER_WRITE(SOUND_MIXER_IGAIN)
892 #define SOUND_MIXER_WRITE_OGAIN		MIXER_WRITE(SOUND_MIXER_OGAIN)
893 #define SOUND_MIXER_WRITE_LINE1		MIXER_WRITE(SOUND_MIXER_LINE1)
894 #define SOUND_MIXER_WRITE_LINE2		MIXER_WRITE(SOUND_MIXER_LINE2)
895 #define SOUND_MIXER_WRITE_LINE3		MIXER_WRITE(SOUND_MIXER_LINE3)
896 
897 /* Obsolete macros */
898 #define SOUND_MIXER_WRITE_MUTE		MIXER_WRITE(SOUND_MIXER_MUTE)
899 #define SOUND_MIXER_WRITE_ENHANCE	MIXER_WRITE(SOUND_MIXER_ENHANCE)
900 #define SOUND_MIXER_WRITE_LOUD		MIXER_WRITE(SOUND_MIXER_LOUD)
901 
902 #define SOUND_MIXER_WRITE_RECSRC	MIXER_WRITE(SOUND_MIXER_RECSRC)
903 
904 typedef struct mixer_info
905 {
906   char id[16];
907   char name[32];
908   int  modify_counter;
909   int fillers[10];
910 } mixer_info;
911 
912 typedef struct _old_mixer_info /* Obsolete */
913 {
914   char id[16];
915   char name[32];
916 } _old_mixer_info;
917 
918 #define SOUND_MIXER_INFO		_SIOR ('M', 101, mixer_info)
919 #define SOUND_OLD_MIXER_INFO		_SIOR ('M', 101, _old_mixer_info)
920 
921 /*
922  * A mechanism for accessing "proprietary" mixer features. This method
923  * permits passing 128 bytes of arbitrary data between a mixer application
924  * and the mixer driver. Interpretation of the record is defined by
925  * the particular mixer driver.
926  */
927 typedef unsigned char mixer_record[128];
928 
929 #define SOUND_MIXER_ACCESS		_SIOWR('M', 102, mixer_record)
930 
931 /*
932  * Two ioctls for special souncard function
933  */
934 #define SOUND_MIXER_AGC  _SIOWR('M', 103, int)
935 #define SOUND_MIXER_3DSE  _SIOWR('M', 104, int)
936 
937 /*
938  * The SOUND_MIXER_PRIVATE# commands can be redefined by low level drivers.
939  * These features can be used when accessing device specific features.
940  */
941 #define SOUND_MIXER_PRIVATE1		_SIOWR('M', 111, int)
942 #define SOUND_MIXER_PRIVATE2		_SIOWR('M', 112, int)
943 #define SOUND_MIXER_PRIVATE3		_SIOWR('M', 113, int)
944 #define SOUND_MIXER_PRIVATE4		_SIOWR('M', 114, int)
945 #define SOUND_MIXER_PRIVATE5		_SIOWR('M', 115, int)
946 
947 /*
948  * SOUND_MIXER_GETLEVELS and SOUND_MIXER_SETLEVELS calls can be used
949  * for querying current mixer settings from the driver and for loading
950  * default volume settings _prior_ activating the mixer (loading
951  * doesn't affect current state of the mixer hardware). These calls
952  * are for internal use only.
953  */
954 
955 typedef struct mixer_vol_table {
956   int num;	/* Index to volume table */
957   char name[32];
958   int levels[32];
959 } mixer_vol_table;
960 
961 #define SOUND_MIXER_GETLEVELS		_SIOWR('M', 116, mixer_vol_table)
962 #define SOUND_MIXER_SETLEVELS		_SIOWR('M', 117, mixer_vol_table)
963 
964 /*
965  * An ioctl for identifying the driver version. It will return value
966  * of the SOUND_VERSION macro used when compiling the driver.
967  * This call was introduced in OSS version 3.6 and it will not work
968  * with earlier versions (returns EINVAL).
969  */
970 #define OSS_GETVERSION			_SIOR ('M', 118, int)
971 
972 /*
973  * Level 2 event types for /dev/sequencer
974  */
975 
976 /*
977  * The 4 most significant bits of byte 0 specify the class of
978  * the event:
979  *
980  *	0x8X = system level events,
981  *	0x9X = device/port specific events, event[1] = device/port,
982  *		The last 4 bits give the subtype:
983  *			0x02	= Channel event (event[3] = chn).
984  *			0x01	= note event (event[4] = note).
985  *			(0x01 is not used alone but always with bit 0x02).
986  *	       event[2] = MIDI message code (0x80=note off etc.)
987  *
988  */
989 
990 #define EV_SEQ_LOCAL		0x80
991 #define EV_TIMING		0x81
992 #define EV_CHN_COMMON		0x92
993 #define EV_CHN_VOICE		0x93
994 #define EV_SYSEX		0x94
995 /*
996  * Event types 200 to 220 are reserved for application use.
997  * These numbers will not be used by the driver.
998  */
999 
1000 /*
1001  * Events for event type EV_CHN_VOICE
1002  */
1003 
1004 #define MIDI_NOTEOFF		0x80
1005 #define MIDI_NOTEON		0x90
1006 #define MIDI_KEY_PRESSURE	0xA0
1007 
1008 /*
1009  * Events for event type EV_CHN_COMMON
1010  */
1011 
1012 #define MIDI_CTL_CHANGE		0xB0
1013 #define MIDI_PGM_CHANGE		0xC0
1014 #define MIDI_CHN_PRESSURE	0xD0
1015 #define MIDI_PITCH_BEND		0xE0
1016 
1017 #define MIDI_SYSTEM_PREFIX	0xF0
1018 
1019 /*
1020  * Timer event types
1021  */
1022 #define TMR_WAIT_REL		1	/* Time relative to the prev time */
1023 #define TMR_WAIT_ABS		2	/* Absolute time since TMR_START */
1024 #define TMR_STOP		3
1025 #define TMR_START		4
1026 #define TMR_CONTINUE		5
1027 #define TMR_TEMPO		6
1028 #define TMR_ECHO		8
1029 #define TMR_CLOCK		9	/* MIDI clock */
1030 #define TMR_SPP			10	/* Song position pointer */
1031 #define TMR_TIMESIG		11	/* Time signature */
1032 
1033 /*
1034  *	Local event types
1035  */
1036 #define LOCL_STARTAUDIO		1
1037 
1038 #if (!defined(__KERNEL__) && !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL)) || defined(USE_SEQ_MACROS)
1039 /*
1040  *	Some convenience macros to simplify programming of the
1041  *	/dev/sequencer interface
1042  *
1043  *	These macros define the API which should be used when possible.
1044  */
1045 #define SEQ_DECLAREBUF()		SEQ_USE_EXTBUF()
1046 
1047 void seqbuf_dump(void);	/* This function must be provided by programs */
1048 
1049 extern int OSS_init(int seqfd, int buflen);
1050 extern void OSS_seqbuf_dump(int fd, unsigned char *buf, int buflen);
1051 extern void OSS_seq_advbuf(int len, int fd, unsigned char *buf, int buflen);
1052 extern void OSS_seq_needbuf(int len, int fd, unsigned char *buf, int buflen);
1053 extern void OSS_patch_caching(int dev, int chn, int patch,
1054 			      int fd, unsigned char *buf, int buflen);
1055 extern void OSS_drum_caching(int dev, int chn, int patch,
1056 			      int fd, unsigned char *buf, int buflen);
1057 extern void OSS_write_patch(int fd, unsigned char *buf, int len);
1058 extern int OSS_write_patch2(int fd, unsigned char *buf, int len);
1059 
1060 #define SEQ_PM_DEFINES int __foo_bar___
1061 #ifdef OSSLIB
1062 #  define SEQ_USE_EXTBUF() \
1063 		extern unsigned char *_seqbuf; \
1064 		extern int _seqbuflen;extern int _seqbufptr
1065 #  define SEQ_DEFINEBUF(len) SEQ_USE_EXTBUF();static int _requested_seqbuflen=len
1066 #  define _SEQ_ADVBUF(len) OSS_seq_advbuf(len, seqfd, _seqbuf, _seqbuflen)
1067 #  define _SEQ_NEEDBUF(len) OSS_seq_needbuf(len, seqfd, _seqbuf, _seqbuflen)
1068 #  define SEQ_DUMPBUF() OSS_seqbuf_dump(seqfd, _seqbuf, _seqbuflen)
1069 
1070 #  define SEQ_LOAD_GMINSTR(dev, instr) \
1071 		OSS_patch_caching(dev, -1, instr, seqfd, _seqbuf, _seqbuflen)
1072 #  define SEQ_LOAD_GMDRUM(dev, drum) \
1073 		OSS_drum_caching(dev, -1, drum, seqfd, _seqbuf, _seqbuflen)
1074 #else /* !OSSLIB */
1075 
1076 #  define SEQ_LOAD_GMINSTR(dev, instr)
1077 #  define SEQ_LOAD_GMDRUM(dev, drum)
1078 
1079 #  define SEQ_USE_EXTBUF() \
1080 		extern unsigned char _seqbuf[]; \
1081 		extern int _seqbuflen;extern int _seqbufptr
1082 
1083 #ifndef USE_SIMPLE_MACROS
1084 /* Sample seqbuf_dump() implementation:
1085  *
1086  *	SEQ_DEFINEBUF (2048);	-- Defines a buffer for 2048 bytes
1087  *
1088  *	int seqfd;		-- The file descriptor for /dev/sequencer.
1089  *
1090  *	void
1091  *	seqbuf_dump ()
1092  *	{
1093  *	  if (_seqbufptr)
1094  *	    if (write (seqfd, _seqbuf, _seqbufptr) == -1)
1095  *	      {
1096  *		perror ("write /dev/sequencer");
1097  *		exit (-1);
1098  *	      }
1099  *	  _seqbufptr = 0;
1100  *	}
1101  */
1102 
1103 #define SEQ_DEFINEBUF(len)		unsigned char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0
1104 #define _SEQ_NEEDBUF(len)		if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump()
1105 #define _SEQ_ADVBUF(len)		_seqbufptr += len
1106 #define SEQ_DUMPBUF			seqbuf_dump
1107 #else
1108 /*
1109  * This variation of the sequencer macros is used just to format one event
1110  * using fixed buffer.
1111  *
1112  * The program using the macro library must define the following macros before
1113  * using this library.
1114  *
1115  * #define _seqbuf 		 name of the buffer (unsigned char[])
1116  * #define _SEQ_ADVBUF(len)	 If the applic needs to know the exact
1117  *				 size of the event, this macro can be used.
1118  *				 Otherwise this must be defined as empty.
1119  * #define _seqbufptr		 Define the name of index variable or 0 if
1120  *				 not required.
1121  */
1122 #define _SEQ_NEEDBUF(len)	/* empty */
1123 #endif
1124 #endif /* !OSSLIB */
1125 
1126 #define SEQ_VOLUME_MODE(dev, mode)	{_SEQ_NEEDBUF(8);\
1127 					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1128 					_seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\
1129 					_seqbuf[_seqbufptr+2] = (dev);\
1130 					_seqbuf[_seqbufptr+3] = (mode);\
1131 					_seqbuf[_seqbufptr+4] = 0;\
1132 					_seqbuf[_seqbufptr+5] = 0;\
1133 					_seqbuf[_seqbufptr+6] = 0;\
1134 					_seqbuf[_seqbufptr+7] = 0;\
1135 					_SEQ_ADVBUF(8);}
1136 
1137 /*
1138  * Midi voice messages
1139  */
1140 
1141 #define _CHN_VOICE(dev, event, chn, note, parm) \
1142 					{_SEQ_NEEDBUF(8);\
1143 					_seqbuf[_seqbufptr] = EV_CHN_VOICE;\
1144 					_seqbuf[_seqbufptr+1] = (dev);\
1145 					_seqbuf[_seqbufptr+2] = (event);\
1146 					_seqbuf[_seqbufptr+3] = (chn);\
1147 					_seqbuf[_seqbufptr+4] = (note);\
1148 					_seqbuf[_seqbufptr+5] = (parm);\
1149 					_seqbuf[_seqbufptr+6] = (0);\
1150 					_seqbuf[_seqbufptr+7] = 0;\
1151 					_SEQ_ADVBUF(8);}
1152 
1153 #define SEQ_START_NOTE(dev, chn, note, vol) \
1154 		_CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol)
1155 
1156 #define SEQ_STOP_NOTE(dev, chn, note, vol) \
1157 		_CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol)
1158 
1159 #define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \
1160 		_CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure)
1161 
1162 /*
1163  * Midi channel messages
1164  */
1165 
1166 #define _CHN_COMMON(dev, event, chn, p1, p2, w14) \
1167 					{_SEQ_NEEDBUF(8);\
1168 					_seqbuf[_seqbufptr] = EV_CHN_COMMON;\
1169 					_seqbuf[_seqbufptr+1] = (dev);\
1170 					_seqbuf[_seqbufptr+2] = (event);\
1171 					_seqbuf[_seqbufptr+3] = (chn);\
1172 					_seqbuf[_seqbufptr+4] = (p1);\
1173 					_seqbuf[_seqbufptr+5] = (p2);\
1174 					*(short *)&_seqbuf[_seqbufptr+6] = (w14);\
1175 					_SEQ_ADVBUF(8);}
1176 /*
1177  * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits
1178  * sending any MIDI bytes but it's absolutely not possible. Trying to do
1179  * so _will_ cause problems with MPU401 intelligent mode).
1180  *
1181  * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be
1182  * sent by calling SEQ_SYSEX() several times (there must be no other events
1183  * between them). First sysex fragment must have 0xf0 in the first byte
1184  * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte
1185  * between these sysex start and end markers cannot be larger than 0x7f. Also
1186  * lengths of each fragments (except the last one) must be 6.
1187  *
1188  * Breaking the above rules may work with some MIDI ports but is likely to
1189  * cause fatal problems with some other devices (such as MPU401).
1190  */
1191 #define SEQ_SYSEX(dev, buf, len) \
1192 					{int ii, ll=(len); \
1193 					 unsigned char *bufp=buf;\
1194 					 if (ll>6)ll=6;\
1195 					_SEQ_NEEDBUF(8);\
1196 					_seqbuf[_seqbufptr] = EV_SYSEX;\
1197 					_seqbuf[_seqbufptr+1] = (dev);\
1198 					for(ii=0;ii<ll;ii++)\
1199 					   _seqbuf[_seqbufptr+ii+2] = bufp[ii];\
1200 					for(ii=ll;ii<6;ii++)\
1201 					   _seqbuf[_seqbufptr+ii+2] = 0xff;\
1202 					_SEQ_ADVBUF(8);}
1203 
1204 #define SEQ_CHN_PRESSURE(dev, chn, pressure) \
1205 		_CHN_COMMON(dev, MIDI_CHN_PRESSURE, chn, pressure, 0, 0)
1206 
1207 #define SEQ_SET_PATCH SEQ_PGM_CHANGE
1208 #ifdef OSSLIB
1209 #   define SEQ_PGM_CHANGE(dev, chn, patch) \
1210 		{OSS_patch_caching(dev, chn, patch, seqfd, _seqbuf, _seqbuflen); \
1211 		 _CHN_COMMON(dev, MIDI_PGM_CHANGE, chn, patch, 0, 0);}
1212 #else
1213 #   define SEQ_PGM_CHANGE(dev, chn, patch) \
1214 		_CHN_COMMON(dev, MIDI_PGM_CHANGE, chn, patch, 0, 0)
1215 #endif
1216 
1217 #define SEQ_CONTROL(dev, chn, controller, value) \
1218 		_CHN_COMMON(dev, MIDI_CTL_CHANGE, chn, controller, 0, value)
1219 
1220 #define SEQ_BENDER(dev, chn, value) \
1221 		_CHN_COMMON(dev, MIDI_PITCH_BEND, chn, 0, 0, value)
1222 
1223 
1224 #define SEQ_V2_X_CONTROL(dev, voice, controller, value)	{_SEQ_NEEDBUF(8);\
1225 					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1226 					_seqbuf[_seqbufptr+1] = SEQ_CONTROLLER;\
1227 					_seqbuf[_seqbufptr+2] = (dev);\
1228 					_seqbuf[_seqbufptr+3] = (voice);\
1229 					_seqbuf[_seqbufptr+4] = (controller);\
1230 					_seqbuf[_seqbufptr+5] = ((value)&0xff);\
1231 					_seqbuf[_seqbufptr+6] = ((value>>8)&0xff);\
1232 					_seqbuf[_seqbufptr+7] = 0;\
1233 					_SEQ_ADVBUF(8);}
1234 /*
1235  * The following 5 macros are incorrectly implemented and obsolete.
1236  * Use SEQ_BENDER and SEQ_CONTROL (with proper controller) instead.
1237  */
1238 #define SEQ_PITCHBEND(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER, value)
1239 #define SEQ_BENDER_RANGE(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value)
1240 #define SEQ_EXPRESSION(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_EXPRESSION, value*128)
1241 #define SEQ_MAIN_VOLUME(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_MAIN_VOLUME, (value*16383)/100)
1242 #define SEQ_PANNING(dev, voice, pos) SEQ_CONTROL(dev, voice, CTL_PAN, (pos+128) / 2)
1243 
1244 /*
1245  * Timing and syncronization macros
1246  */
1247 
1248 #define _TIMER_EVENT(ev, parm)		{_SEQ_NEEDBUF(8);\
1249 				 	_seqbuf[_seqbufptr+0] = EV_TIMING; \
1250 				 	_seqbuf[_seqbufptr+1] = (ev); \
1251 					_seqbuf[_seqbufptr+2] = 0;\
1252 					_seqbuf[_seqbufptr+3] = 0;\
1253 				 	*(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \
1254 					_SEQ_ADVBUF(8);}
1255 
1256 #define SEQ_START_TIMER()		_TIMER_EVENT(TMR_START, 0)
1257 #define SEQ_STOP_TIMER()		_TIMER_EVENT(TMR_STOP, 0)
1258 #define SEQ_CONTINUE_TIMER()		_TIMER_EVENT(TMR_CONTINUE, 0)
1259 #define SEQ_WAIT_TIME(ticks)		_TIMER_EVENT(TMR_WAIT_ABS, ticks)
1260 #define SEQ_DELTA_TIME(ticks)		_TIMER_EVENT(TMR_WAIT_REL, ticks)
1261 #define SEQ_ECHO_BACK(key)		_TIMER_EVENT(TMR_ECHO, key)
1262 #define SEQ_SET_TEMPO(value)		_TIMER_EVENT(TMR_TEMPO, value)
1263 #define SEQ_SONGPOS(pos)		_TIMER_EVENT(TMR_SPP, pos)
1264 #define SEQ_TIME_SIGNATURE(sig)		_TIMER_EVENT(TMR_TIMESIG, sig)
1265 
1266 /*
1267  * Local control events
1268  */
1269 
1270 #define _LOCAL_EVENT(ev, parm)		{_SEQ_NEEDBUF(8);\
1271 				 	_seqbuf[_seqbufptr+0] = EV_SEQ_LOCAL; \
1272 				 	_seqbuf[_seqbufptr+1] = (ev); \
1273 					_seqbuf[_seqbufptr+2] = 0;\
1274 					_seqbuf[_seqbufptr+3] = 0;\
1275 				 	*(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \
1276 					_SEQ_ADVBUF(8);}
1277 
1278 #define SEQ_PLAYAUDIO(devmask)		_LOCAL_EVENT(LOCL_STARTAUDIO, devmask)
1279 /*
1280  * Events for the level 1 interface only
1281  */
1282 
1283 #define SEQ_MIDIOUT(device, byte)	{_SEQ_NEEDBUF(4);\
1284 					_seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\
1285 					_seqbuf[_seqbufptr+1] = (byte);\
1286 					_seqbuf[_seqbufptr+2] = (device);\
1287 					_seqbuf[_seqbufptr+3] = 0;\
1288 					_SEQ_ADVBUF(4);}
1289 
1290 /*
1291  * Patch loading.
1292  */
1293 #ifdef OSSLIB
1294 #   define SEQ_WRPATCH(patchx, len) \
1295 		OSS_write_patch(seqfd, (char*)(patchx), len)
1296 #   define SEQ_WRPATCH2(patchx, len) \
1297 		OSS_write_patch2(seqfd, (char*)(patchx), len)
1298 #else
1299 #   define SEQ_WRPATCH(patchx, len) \
1300 		{if (_seqbufptr) SEQ_DUMPBUF();\
1301 		 if (write(seqfd, (char*)(patchx), len)==-1) \
1302 		    perror("Write patch: /dev/sequencer");}
1303 #   define SEQ_WRPATCH2(patchx, len) \
1304 		(SEQ_DUMPBUF(), write(seqfd, (char*)(patchx), len))
1305 #endif
1306 
1307 #endif
1308 #endif
1309