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