soundcard.h revision 1402
1#ifndef _SOUNDCARD_H_
2#define _SOUNDCARD_H_
3/*
4 * Copyright by Hannu Savolainen 1993
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 */
29
30 /*
31  * If you make modifications to this file, please contact me before
32  * distributing the modified version. There is already enough
33  * divercity in the world.
34  *
35  * Regards,
36  * Hannu Savolainen
37  * hannu@voxware.pp.fi, Hannu.Savolainen@helsinki.fi
38  */
39
40#define SOUND_VERSION   205
41#define VOXWARE
42
43#include <sys/ioctl.h>
44
45/*
46 *	Supported card ID numbers (Should be somewhere else?)
47 */
48
49#define SNDCARD_ADLIB	1
50#define SNDCARD_SB	2
51#define SNDCARD_PAS	3
52#define SNDCARD_GUS	4
53#define SNDCARD_MPU401	5
54#define SNDCARD_SB16	6
55#define SNDCARD_SB16MIDI 7
56
57/***********************************
58 * IOCTL Commands for /dev/sequencer
59 */
60
61#ifndef _IOWR
62/*	@(#)ioctlp.h */
63
64/* Ioctl's have the command encoded in the lower word,
65 * and the size of any in or out parameters in the upper
66 * word.  The high 2 bits of the upper word are used
67 * to encode the in/out status of the parameter; for now
68 * we restrict parameters to at most 128 bytes.
69 */
70/* #define	IOCTYPE		(0xff<<8) */
71#define	IOCPARM_MASK	0x7f		/* parameters must be < 128 bytes */
72#define	IOC_VOID	0x00000000	/* no parameters */
73#define	IOC_OUT		0x20000000	/* copy out parameters */
74#define	IOC_IN		0x40000000	/* copy in parameters */
75#define	IOC_INOUT	(IOC_IN|IOC_OUT)
76/* the 0x20000000 is so we can distinguish new ioctl's from old */
77#define	_IO(x,y)	((int)(IOC_VOID|(x<<8)|y))
78#define	_IOR(x,y,t)	((int)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
79#define	_IOW(x,y,t)	((int)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
80/* this should be _IORW, but stdio got there first */
81#define	_IOWR(x,y,t)	((int)(IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
82#endif  /* !_IOWR */
83
84#define SNDCTL_SEQ_RESET		_IO  ('Q', 0)
85#define SNDCTL_SEQ_SYNC			_IO  ('Q', 1)
86#define SNDCTL_SYNTH_INFO		_IOWR('Q', 2, struct synth_info)
87#define SNDCTL_SEQ_CTRLRATE		_IOWR('Q', 3, int)	/* Set/get timer resolution (HZ) */
88#define SNDCTL_SEQ_GETOUTCOUNT		_IOR ('Q', 4, int)
89#define SNDCTL_SEQ_GETINCOUNT		_IOR ('Q', 5, int)
90#define SNDCTL_SEQ_PERCMODE		_IOW ('Q', 6, int)
91#define SNDCTL_FM_LOAD_INSTR		_IOW ('Q', 7, struct sbi_instrument)	/* Valid for FM only */
92#define SNDCTL_SEQ_TESTMIDI		_IOW ('Q', 8, int)
93#define SNDCTL_SEQ_RESETSAMPLES		_IOW ('Q', 9, int)
94#define SNDCTL_SEQ_NRSYNTHS		_IOR ('Q',10, int)
95#define SNDCTL_SEQ_NRMIDIS		_IOR ('Q',11, int)
96#define SNDCTL_MIDI_INFO		_IOWR('Q',12, struct midi_info)
97#define SNDCTL_SEQ_TRESHOLD		_IOW ('Q',13, int)
98#define SNDCTL_SYNTH_MEMAVL		_IOWR('Q',14, int)	/* in=dev#, out=memsize */
99#define SNDCTL_FM_4OP_ENABLE		_IOW ('Q',15, int)	/* in=dev# */
100#define SNDCTL_PMGR_ACCESS		_IOWR('Q',16, struct patmgr_info)
101
102/*
103 *	Sample loading mechanism for internal synthesizers (/dev/sequencer)
104 *	The following patch_info structure has been designed to support
105 *	Gravis UltraSound. It tries to be universal format for uploading
106 *	sample based patches but is propably too limited.
107 */
108
109struct patch_info {
110		short key;		/* Use GUS_PATCH here */
111#define GUS_PATCH	0x04fd
112#define OBSOLETE_GUS_PATCH	0x02fd
113		short device_no;	/* Synthesizer number */
114		short instr_no;		/* Midi pgm# */
115
116		unsigned long mode;
117/*
118 * The least significant byte has the same format than the GUS .PAT
119 * files
120 */
121#define WAVE_16_BITS	0x01	/* bit 0 = 8 or 16 bit wave data. */
122#define WAVE_UNSIGNED	0x02	/* bit 1 = Signed - Unsigned data. */
123#define WAVE_LOOPING	0x04	/* bit 2 = looping enabled-1. */
124#define WAVE_BIDIR_LOOP	0x08	/* bit 3 = Set is bidirectional looping. */
125#define WAVE_LOOP_BACK	0x10	/* bit 4 = Set is looping backward. */
126#define WAVE_SUSTAIN_ON	0x20	/* bit 5 = Turn sustaining on. (Env. pts. 3)*/
127#define WAVE_ENVELOPES	0x40	/* bit 6 = Enable envelopes - 1 */
128				/* 	(use the env_rate/env_offs fields). */
129/* Linux specific bits */
130#define WAVE_VIBRATO	0x00010000	/* The vibrato info is valid */
131#define WAVE_TREMOLO	0x00020000	/* The tremolo info is valid */
132#define WAVE_SCALE	0x00040000	/* The scaling info is valid */
133/* Other bits must be zeroed */
134
135		long len;	/* Size of the wave data in bytes */
136		long loop_start, loop_end; /* Byte offsets from the beginning */
137
138/*
139 * The base_freq and base_note fields are used when computing the
140 * playback speed for a note. The base_note defines the tone frequency
141 * which is heard if the sample is played using the base_freq as the
142 * playback speed.
143 *
144 * The low_note and high_note fields define the minimum and maximum note
145 * frequencies for which this sample is valid. It is possible to define
146 * more than one samples for a instrument number at the same time. The
147 * low_note and high_note fields are used to select the most suitable one.
148 *
149 * The fields base_note, high_note and low_note should contain
150 * the note frequency multiplied by 1000. For example value for the
151 * middle A is 440*1000.
152 */
153
154		unsigned int base_freq;
155		unsigned long base_note;
156		unsigned long high_note;
157		unsigned long low_note;
158		int panning;	/* -128=left, 127=right */
159		int detuning;
160
161/*	New fields introduced in version 1.99.5	*/
162
163       /* Envelope. Enabled by mode bit WAVE_ENVELOPES	*/
164		unsigned char	env_rate[ 6 ];	 /* GUS HW ramping rate */
165		unsigned char	env_offset[ 6 ]; /* 255 == 100% */
166
167	/*
168	 * The tremolo, vibrato and scale info are not supported yet.
169	 * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
170	 * WAVE_SCALE
171	 */
172
173		unsigned char	tremolo_sweep;
174		unsigned char	tremolo_rate;
175		unsigned char	tremolo_depth;
176
177		unsigned char	vibrato_sweep;
178		unsigned char	vibrato_rate;
179		unsigned char	vibrato_depth;
180
181		int		scale_frequency;
182		unsigned int	scale_factor;		/* from 0 to 2048 or 0 to 2 */
183
184	        int		volume;
185	        int		spare[4];
186		char data[1];	/* The waveform data starts here */
187	};
188
189
190/*
191 * Patch management interface (/dev/sequencer, /dev/patmgr#)
192 * Don't use these calls if you want to maintain compatibility with
193 * the future versions of the driver.
194 */
195
196#define 	PS_NO_PATCHES		0	/* No patch support on device */
197#define		PS_MGR_NOT_OK		1	/* Plain patch support (no mgr) */
198#define		PS_MGR_OK		2	/* Patch manager supported */
199#define		PS_MANAGED		3	/* Patch manager running */
200
201#define SNDCTL_PMGR_IFACE		_IOWR('P', 1, struct patmgr_info)
202
203/*
204 * The patmgr_info is a fixed size structure which is used for two
205 * different purposes. The intended use is for communication between
206 * the application using /dev/sequencer and the patch manager daemon
207 * associated with a synthesizer device (ioctl(SNDCTL_PMGR_ACCESS)).
208 *
209 * This structure is also used with ioctl(SNDCTL_PGMR_IFACE) which allows
210 * a patch manager daemon to read and write device parameters. This
211 * ioctl available through /dev/sequencer also. Avoid using it since it's
212 * extremely hardware dependent. In addition access trough /dev/sequencer
213 * may confuse the patch manager daemon.
214 */
215
216struct patmgr_info {	/* Note! size must be < 4k since kmalloc() is used */
217	  unsigned long key;	/* Don't worry. Reserved for communication
218	  			   between the patch manager and the driver. */
219#define PM_K_EVENT		1 /* Event from the /dev/sequencer driver */
220#define PM_K_COMMAND		2 /* Request from a application */
221#define PM_K_RESPONSE		3 /* From patmgr to application */
222#define PM_ERROR		4 /* Error returned by the patmgr */
223	  int device;
224	  int command;
225
226/*
227 * Commands 0x000 to 0xfff reserved for patch manager programs
228 */
229#define PM_GET_DEVTYPE	1	/* Returns type of the patch mgr interface of dev */
230#define		PMTYPE_FM2	1	/* 2 OP fm */
231#define		PMTYPE_FM4	2	/* Mixed 4 or 2 op FM (OPL-3) */
232#define		PMTYPE_WAVE	3	/* Wave table synthesizer (GUS) */
233#define PM_GET_NRPGM	2	/* Returns max # of midi programs in parm1 */
234#define PM_GET_PGMMAP	3	/* Returns map of loaded midi programs in data8 */
235#define PM_GET_PGM_PATCHES 4	/* Return list of patches of a program (parm1) */
236#define PM_GET_PATCH	5	/* Return patch header of patch parm1 */
237#define PM_SET_PATCH	6	/* Set patch header of patch parm1 */
238#define PM_READ_PATCH	7	/* Read patch (wave) data */
239#define PM_WRITE_PATCH	8	/* Write patch (wave) data */
240
241/*
242 * Commands 0x1000 to 0xffff are for communication between the patch manager
243 * and the client
244 */
245#define _PM_LOAD_PATCH	0x100
246
247/*
248 * Commands above 0xffff reserved for device specific use
249 */
250
251	  long parm1;
252	  long parm2;
253	  long parm3;
254
255	  union {
256		unsigned char data8[4000];
257		unsigned short data16[2000];
258		unsigned long data32[1000];
259		struct patch_info patch;
260	  } data;
261	};
262
263/*
264 * When a patch manager daemon is present, it will be informed by the
265 * driver when something important happens. For example when the
266 * /dev/sequencer is opened or closed. A record with key == PM_K_EVENT is
267 * returned. The command field contains the event type:
268 */
269#define PM_E_OPENED		1	/* /dev/sequencer opened */
270#define PM_E_CLOSED		2	/* /dev/sequencer closed */
271#define PM_E_PATCH_RESET	3	/* SNDCTL_RESETSAMPLES called */
272#define PM_E_PATCH_LOADED	4	/* A patch has been loaded by appl */
273
274/*
275 * /dev/sequencer input events.
276 *
277 * The data written to the /dev/sequencer is a stream of events. Events
278 * are records of 4 or 8 bytes. The first byte defines the size.
279 * Any number of events can be written with a write call. There
280 * is a set of macros for sending these events. Use these macros if you
281 * want to maximize portability of your program.
282 *
283 * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
284 * (All input events are currently 4 bytes long. Be prepared to support
285 * 8 byte events also. If you receive any event having first byte >= 0xf0,
286 * it's a 8 byte event.
287 *
288 * The events are documented at the end of this file.
289 *
290 * Normal events (4 bytes)
291 * There is also a 8 byte version of most of the 4 byte events. The
292 * 8 byte one is recommended.
293 */
294#define SEQ_NOTEOFF		0
295#define SEQ_FMNOTEOFF		SEQ_NOTEOFF	/* Just old name */
296#define SEQ_NOTEON		1
297#define	SEQ_FMNOTEON		SEQ_NOTEON
298#define SEQ_WAIT		2
299#define SEQ_PGMCHANGE		3
300#define SEQ_FMPGMCHANGE		SEQ_PGMCHANGE
301#define SEQ_SYNCTIMER		4
302#define SEQ_MIDIPUTC		5
303#define SEQ_DRUMON		6	/*** OBSOLETE ***/
304#define SEQ_DRUMOFF		7	/*** OBSOLETE ***/
305#define SEQ_ECHO		8	/* For synching programs with output */
306#define SEQ_AFTERTOUCH		9
307#define SEQ_CONTROLLER		10
308#define    CTRL_PITCH_BENDER		255
309#define    CTRL_PITCH_BENDER_RANGE	254
310#define    CTRL_EXPRESSION		253
311#define    CTRL_MAIN_VOLUME		252
312#define SEQ_BALANCE		11
313#define SEQ_VOLMODE             12
314
315/*
316 * Volume mode decides how volumes are used
317 */
318
319#define VOL_METHOD_ADAGIO	1
320#define VOL_METHOD_LINEAR	2
321
322/*
323 * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
324 *	 input events.
325 */
326
327/*
328 * Event codes 0xf0 to 0xfc are reserved for future extensions.
329 */
330
331#define SEQ_FULLSIZE		0xfd	/* Long events */
332/*
333 *	SEQ_FULLSIZE events are used for loading patches/samples to the
334 *	synthesizer devices. These events are passed directly to the driver
335 *	of the associated synthesizer device. There is no limit to the size
336 *	of the extended events. These events are not queued but executed
337 *	immediately when the write() is called (execution can take several
338 *	seconds of time).
339 *
340 *	When a SEQ_FULLSIZE message is written to the device, it must
341 *	be written using exactly one write() call. Other events cannot
342 *	be mixed to the same write.
343 *
344 *	For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the
345 *	/dev/sequencer. Don't write other data together with the instrument structure
346 *	Set the key field of the structure to FM_PATCH. The device field is used to
347 *	route the patch to the corresponding device.
348 *
349 *	For Gravis UltraSound use struct patch_info. Initialize the key field
350 *      to GUS_PATCH.
351 */
352#define SEQ_PRIVATE		0xfe	/* Low level HW dependent events (8 bytes) */
353#define SEQ_EXTENDED		0xff	/* Extended events (8 bytes) */
354
355/*
356 *	Extended events for synthesizers (8 bytes)
357 *
358 *	Format:
359 *
360 *		b0	= SEQ_EXTENDED
361 *		b1	= command
362 *		b2	= device
363 *		b3-b7	= parameters
364 *
365 *	Command				b3	b4	b5	b6	b7
366 *	----------------------------------------------------------------------------
367 *	SEQ_NOTEON			voice	note	volume	0	0
368 *	SEQ_NOTEOFF			voice	note	volume	0	0
369 *	SEQ_PGMCHANGE			voice	pgm	0	0	0
370 *	SEQ_DRUMON			(voice)	drum#	volume	0	0
371 *	SEQ_DRUMOFF			(voice)	drum#	volume	0	0
372 */
373
374/*
375 * Record for FM patches
376 */
377
378typedef unsigned char sbi_instr_data[32];
379
380struct sbi_instrument {
381		unsigned short	key;		/* 	Initialize to FM_PATCH or OPL3_PATCH */
382#define FM_PATCH	0x01fd
383#define OPL3_PATCH	0x03fd
384		short		device;		/*	Synth# (0-4)	*/
385		int 		channel;	/*	Program# to be initialized 	*/
386		sbi_instr_data	operators;	/*	Register settings for operator cells (.SBI format)	*/
387	};
388
389struct synth_info {	/* Read only */
390		char	name[30];
391		int	device;		/* 0-N. INITIALIZE BEFORE CALLING */
392		int	synth_type;
393#define SYNTH_TYPE_FM			0
394#define SYNTH_TYPE_SAMPLE		1
395
396		int	synth_subtype;
397#define FM_TYPE_ADLIB			0x00
398#define FM_TYPE_OPL3			0x01
399
400#define SAMPLE_TYPE_GUS			0x10
401
402		int	perc_mode;	/* No longer supported */
403		int	nr_voices;
404		int	nr_drums;	/* Obsolete field */
405		int	instr_bank_size;
406		unsigned long	capabilities;
407#define SYNTH_CAP_PERCMODE		0x00000001 /* No longer used */
408#define SYNTH_CAP_OPL3			0x00000002 /* Set if OPL3 supported */
409		int	dummies[19];	/* Reserve space */
410	};
411
412struct midi_info {
413		char		name[30];
414		int		device;		/* 0-N. INITIALIZE BEFORE CALLING */
415		unsigned long	capabilities;	/* To be defined later */
416		int		dev_type;
417		int		dummies[18];	/* Reserve space */
418	};
419
420/********************************************
421 * IOCTL commands for /dev/dsp and /dev/audio
422 */
423
424#define SNDCTL_DSP_RESET		_IO  ('P', 0)
425#define SNDCTL_DSP_SYNC			_IO  ('P', 1)
426#define SNDCTL_DSP_SPEED		_IOWR('P', 2, int)
427#define SNDCTL_DSP_STEREO		_IOWR('P', 3, int)
428#define SNDCTL_DSP_GETBLKSIZE		_IOWR('P', 4, int)
429#define SNDCTL_DSP_SAMPLESIZE		_IOWR('P', 5, int)	/* 8, 12 or 16 */
430#define SOUND_PCM_WRITE_CHANNELS	_IOWR('P', 6, int)
431#define SOUND_PCM_WRITE_FILTER		_IOWR('P', 7, int)
432#define SNDCTL_DSP_POST			_IO  ('P', 8)
433#define SNDCTL_DSP_SUBDIVIDE		_IOWR('P', 9, int)
434
435#define SOUND_PCM_READ_RATE		_IOR ('P', 2, int)
436#define SOUND_PCM_READ_CHANNELS		_IOR ('P', 6, int)
437#define SOUND_PCM_READ_BITS		_IOR ('P', 5, int)
438#define SOUND_PCM_READ_FILTER		_IOR ('P', 7, int)
439
440/* Some alias names */
441#define SOUND_PCM_WRITE_BITS		SNDCTL_DSP_SAMPLESIZE
442#define SOUND_PCM_WRITE_RATE		SNDCTL_DSP_SPEED
443#define SOUND_PCM_POST			SNDCTL_DSP_POST
444#define SOUND_PCM_RESET			SNDCTL_DSP_RESET
445#define SOUND_PCM_SYNC			SNDCTL_DSP_SYNC
446#define SOUND_PCM_SUBDIVIDE		SNDCTL_DSP_SUBDIVIDE
447
448/*********************************************
449 * IOCTL commands for /dev/mixer
450 */
451
452/*
453 * Mixer devices
454 *
455 * There can be up to 20 different analog mixer channels. The
456 * SOUND_MIXER_NRDEVICES gives the currently supported maximum.
457 * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells
458 * the devices supported by the particular mixer.
459 */
460
461#define SOUND_MIXER_NRDEVICES	12
462#define SOUND_MIXER_VOLUME	0
463#define SOUND_MIXER_BASS	1
464#define SOUND_MIXER_TREBLE	2
465#define SOUND_MIXER_SYNTH	3
466#define SOUND_MIXER_PCM		4
467#define SOUND_MIXER_SPEAKER	5
468#define SOUND_MIXER_LINE	6
469#define SOUND_MIXER_MIC		7
470#define SOUND_MIXER_CD		8
471#define SOUND_MIXER_IMIX	9	/*  Recording monitor  */
472#define SOUND_MIXER_ALTPCM	10
473#define SOUND_MIXER_RECLEV	11	/* Recording level */
474
475/* Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) */
476/* Not counted to SOUND_MIXER_NRDEVICES, but use the same number space */
477#define SOUND_ONOFF_MIN		28
478#define SOUND_ONOFF_MAX		30
479#define SOUND_MIXER_MUTE	28	/* 0 or 1 */
480#define SOUND_MIXER_ENHANCE	29	/* Enhanced stereo (0, 40, 60 or 80) */
481#define SOUND_MIXER_LOUD	30	/* 0 or 1 */
482
483/* Note!	Number 31 cannot be used since the sign bit is reserved */
484
485#define SOUND_DEVICE_LABELS	{"Vol  ", "Bass ", "Trebl", "Synth", "Pcm  ", "Spkr ", "Line ", \
486				 "Mic  ", "CD   ", "Mix  ", "Pcm2 ", "rec"}
487
488#define SOUND_DEVICE_NAMES	{"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
489				 "mic", "cd", "mix", "pcm2", "rec"}
490
491/*	Device bitmask identifiers	*/
492
493#define SOUND_MIXER_RECSRC	0xff	/* Arg contains a bit for each recording source */
494#define SOUND_MIXER_DEVMASK	0xfe	/* Arg contains a bit for each supported device */
495#define SOUND_MIXER_RECMASK	0xfd	/* Arg contains a bit for each supported recording source */
496#define SOUND_MIXER_CAPS	0xfc
497	#define SOUND_CAP_EXCL_INPUT	0x00000001	/* Only one recording source at a time */
498#define SOUND_MIXER_STEREODEVS	0xfb	/* Mixer channels supporting stereo */
499
500/*	Device mask bits	*/
501
502#define SOUND_MASK_VOLUME	(1 << SOUND_MIXER_VOLUME)
503#define SOUND_MASK_BASS		(1 << SOUND_MIXER_BASS)
504#define SOUND_MASK_TREBLE	(1 << SOUND_MIXER_TREBLE)
505#define SOUND_MASK_SYNTH	(1 << SOUND_MIXER_SYNTH)
506#define SOUND_MASK_PCM		(1 << SOUND_MIXER_PCM)
507#define SOUND_MASK_SPEAKER	(1 << SOUND_MIXER_SPEAKER)
508#define SOUND_MASK_LINE		(1 << SOUND_MIXER_LINE)
509#define SOUND_MASK_MIC		(1 << SOUND_MIXER_MIC)
510#define SOUND_MASK_CD		(1 << SOUND_MIXER_CD)
511#define SOUND_MASK_IMIX		(1 << SOUND_MIXER_IMIX)
512#define SOUND_MASK_ALTPCM	(1 << SOUND_MIXER_ALTPCM)
513#define SOUND_MASK_RECLEV	(1 << SOUND_MIXER_RECLEV)
514
515#define SOUND_MASK_MUTE		(1 << SOUND_MIXER_MUTE)
516#define SOUND_MASK_ENHANCE	(1 << SOUND_MIXER_ENHANCE)
517#define SOUND_MASK_LOUD		(1 << SOUND_MIXER_LOUD)
518
519#define MIXER_READ(dev)		_IOR('M', dev, int)
520#define SOUND_MIXER_READ_VOLUME		MIXER_READ(SOUND_MIXER_VOLUME)
521#define SOUND_MIXER_READ_BASS		MIXER_READ(SOUND_MIXER_BASS)
522#define SOUND_MIXER_READ_TREBLE		MIXER_READ(SOUND_MIXER_TREBLE)
523#define SOUND_MIXER_READ_SYNTH		MIXER_READ(SOUND_MIXER_SYNTH)
524#define SOUND_MIXER_READ_PCM		MIXER_READ(SOUND_MIXER_PCM)
525#define SOUND_MIXER_READ_SPEAKER	MIXER_READ(SOUND_MIXER_SPEAKER)
526#define SOUND_MIXER_READ_LINE		MIXER_READ(SOUND_MIXER_LINE)
527#define SOUND_MIXER_READ_MIC		MIXER_READ(SOUND_MIXER_MIC)
528#define SOUND_MIXER_READ_CD		MIXER_READ(SOUND_MIXER_CD)
529#define SOUND_MIXER_READ_IMIX		MIXER_READ(SOUND_MIXER_IMIX)
530#define SOUND_MIXER_READ_ALTPCM		MIXER_READ(SOUND_MIXER_ALTPCM)
531#define SOUND_MIXER_READ_RECLEV		MIXER_READ(SOUND_MIXER_RECLEV)
532#define SOUND_MIXER_READ_MUTE		MIXER_READ(SOUND_MIXER_MUTE)
533#define SOUND_MIXER_READ_ENHANCE	MIXER_READ(SOUND_MIXER_ENHANCE)
534#define SOUND_MIXER_READ_LOUD		MIXER_READ(SOUND_MIXER_LOUD)
535
536#define SOUND_MIXER_READ_RECSRC		MIXER_READ(SOUND_MIXER_RECSRC)
537#define SOUND_MIXER_READ_DEVMASK	MIXER_READ(SOUND_MIXER_DEVMASK)
538#define SOUND_MIXER_READ_RECMASK	MIXER_READ(SOUND_MIXER_RECMASK)
539#define SOUND_MIXER_READ_STEREODEVS	MIXER_READ(SOUND_MIXER_STEREODEVS)
540#define SOUND_MIXER_READ_CAPS		MIXER_READ(SOUND_MIXER_CAPS)
541
542#define MIXER_WRITE(dev)		_IOWR('M', dev, int)
543#define SOUND_MIXER_WRITE_VOLUME	MIXER_WRITE(SOUND_MIXER_VOLUME)
544#define SOUND_MIXER_WRITE_BASS		MIXER_WRITE(SOUND_MIXER_BASS)
545#define SOUND_MIXER_WRITE_TREBLE	MIXER_WRITE(SOUND_MIXER_TREBLE)
546#define SOUND_MIXER_WRITE_SYNTH		MIXER_WRITE(SOUND_MIXER_SYNTH)
547#define SOUND_MIXER_WRITE_PCM		MIXER_WRITE(SOUND_MIXER_PCM)
548#define SOUND_MIXER_WRITE_SPEAKER	MIXER_WRITE(SOUND_MIXER_SPEAKER)
549#define SOUND_MIXER_WRITE_LINE		MIXER_WRITE(SOUND_MIXER_LINE)
550#define SOUND_MIXER_WRITE_MIC		MIXER_WRITE(SOUND_MIXER_MIC)
551#define SOUND_MIXER_WRITE_CD		MIXER_WRITE(SOUND_MIXER_CD)
552#define SOUND_MIXER_WRITE_IMIX		MIXER_WRITE(SOUND_MIXER_IMIX)
553#define SOUND_MIXER_WRITE_ALTPCM	MIXER_WRITE(SOUND_MIXER_ALTPCM)
554#define SOUND_MIXER_WRITE_RECLEV	MIXER_WRITE(SOUND_MIXER_RECLEV)
555#define SOUND_MIXER_WRITE_MUTE		MIXER_WRITE(SOUND_MIXER_MUTE)
556#define SOUND_MIXER_WRITE_ENHANCE	MIXER_WRITE(SOUND_MIXER_ENHANCE)
557#define SOUND_MIXER_WRITE_LOUD		MIXER_WRITE(SOUND_MIXER_LOUD)
558
559#define SOUND_MIXER_WRITE_RECSRC	MIXER_WRITE(SOUND_MIXER_RECSRC)
560
561/*
562 *	The following mixer ioctl calls are compatible with the BSD driver by
563 *	  Steve Haehnichen <shaehnic@ucsd.edu>
564 *
565 * Since this interface is entirely SB specific, it will be dropped in the
566 * near future.
567 */
568
569typedef unsigned char S_BYTE;
570typedef unsigned char S_FLAG;
571struct stereo_vol
572{
573  S_BYTE l;			/* Left volume */
574  S_BYTE r;			/* Right volume */
575};
576
577#define MIXER_IOCTL_SET_LEVELS 		_IOW ('s', 20, struct sb_mixer_levels)
578#define MIXER_IOCTL_SET_PARAMS 		_IOW ('s', 21, struct sb_mixer_params)
579#define MIXER_IOCTL_READ_LEVELS 	_IOR ('s', 22, struct sb_mixer_levels)
580#define MIXER_IOCTL_READ_PARAMS 	_IOR ('s', 23, struct sb_mixer_params)
581#define MIXER_IOCTL_RESET		_IO  ('s', 24)
582
583/*
584 * Mixer volume levels for MIXER_IOCTL_SET_VOL & MIXER_IOCTL_READ_VOL
585 */
586struct sb_mixer_levels
587{
588  struct stereo_vol master;	/* Master volume */
589  struct stereo_vol voc;	/* DSP Voice volume */
590  struct stereo_vol fm;		/* FM volume */
591  struct stereo_vol line;	/* Line-in volume */
592  struct stereo_vol cd;		/* CD audio */
593  S_BYTE mic;			/* Microphone level */
594};
595
596/*
597 * Mixer parameters for MIXER_IOCTL_SET_PARAMS & MIXER_IOCTL_READ_PARAMS
598 */
599struct sb_mixer_params
600{
601  S_BYTE record_source;		/* Recording source (See SRC_xxx below) */
602  S_FLAG hifreq_filter;		/* Filter frequency (hi/low) */
603  S_FLAG filter_input;		/* ANFI input filter */
604  S_FLAG filter_output;		/* DNFI output filter */
605  S_FLAG dsp_stereo;		/* 1 if DSP is in Stereo mode */
606};
607
608#define SRC_MIC         1	/* Select Microphone recording source */
609#define SRC_CD          3	/* Select CD recording source */
610#define SRC_LINE        7	/* Use Line-in for recording source */
611
612#if !defined(KERNEL) && !defined(INKERNEL)
613/*
614 *	Some convenience macros to simplify programming of the
615 *	/dev/sequencer interface
616 *
617 *	These macros define the API which should be used when possible.
618 */
619
620void seqbuf_dump(void);	/* This function must be provided by programs */
621
622/* Sample seqbuf_dump() implementation:
623 *
624 *	SEQ_DEFINEBUF (2048);	-- Defines a buffer for 2048 bytes
625 *
626 *	int seqfd;		-- The file descriptor for /dev/sequencer.
627 *
628 *	void
629 *	seqbuf_dump ()
630 *	{
631 *	  if (_seqbufptr)
632 *	    if (write (seqfd, _seqbuf, _seqbufptr) == -1)
633 *	      {
634 *		perror ("write /dev/sequencer");
635 *		exit (-1);
636 *	      }
637 *	  _seqbufptr = 0;
638 *	}
639 */
640
641#define SEQ_DEFINEBUF(len)		unsigned char _seqbuf[len]; int _seqbuflen = len; int _seqbufptr = 0
642#define SEQ_DECLAREBUF()		extern unsigned char _seqbuf[]; extern int _seqbuflen;extern int _seqbufptr
643#define SEQ_PM_DEFINES			struct patmgr_info _pm_info
644#define _SEQ_NEEDBUF(len)		if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump()
645#define _SEQ_ADVBUF(len)		_seqbufptr += len
646#define SEQ_DUMPBUF			seqbuf_dump
647#define PM_LOAD_PATCH(dev, bank, pgm)	(SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
648					_pm_info.device=dev, _pm_info.data.data8[0]=pgm, \
649					_pm_info.parm1 = bank, _pm_info.parm2 = 1, \
650					ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
651#define PM_LOAD_PATCHES(dev, bank, pgm) (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
652					_pm_info.device=dev, memcpy(_pm_info.data.data8, pgm, 128), \
653					_pm_info.parm1 = bank, _pm_info.parm2 = 128, \
654					ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
655
656#define SEQ_VOLUME_MODE(dev, mode)	{_SEQ_NEEDBUF(8);\
657					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
658					_seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\
659					_seqbuf[_seqbufptr+2] = (dev);\
660					_seqbuf[_seqbufptr+3] = (mode);\
661					_seqbuf[_seqbufptr+4] = 0;\
662					_seqbuf[_seqbufptr+5] = 0;\
663					_seqbuf[_seqbufptr+6] = 0;\
664					_seqbuf[_seqbufptr+7] = 0;\
665					_SEQ_ADVBUF(8);}
666
667#define SEQ_START_NOTE(dev, voice, note, vol)	{_SEQ_NEEDBUF(8);\
668					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
669					_seqbuf[_seqbufptr+1] = SEQ_NOTEON;\
670					_seqbuf[_seqbufptr+2] = (dev);\
671					_seqbuf[_seqbufptr+3] = (voice);\
672					_seqbuf[_seqbufptr+4] = (note);\
673					_seqbuf[_seqbufptr+5] = (vol);\
674					_seqbuf[_seqbufptr+6] = 0;\
675					_seqbuf[_seqbufptr+7] = 0;\
676					_SEQ_ADVBUF(8);}
677
678#define SEQ_STOP_NOTE(dev, voice, note, vol)	{_SEQ_NEEDBUF(8);\
679					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
680					_seqbuf[_seqbufptr+1] = SEQ_NOTEOFF;\
681					_seqbuf[_seqbufptr+2] = (dev);\
682					_seqbuf[_seqbufptr+3] = (voice);\
683					_seqbuf[_seqbufptr+4] = (note);\
684					_seqbuf[_seqbufptr+5] = (vol);\
685					_seqbuf[_seqbufptr+6] = 0;\
686					_seqbuf[_seqbufptr+7] = 0;\
687					_SEQ_ADVBUF(8);}
688
689#define SEQ_CHN_PRESSURE(dev, voice, pressure)	{_SEQ_NEEDBUF(8);\
690					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
691					_seqbuf[_seqbufptr+1] = SEQ_AFTERTOUCH;\
692					_seqbuf[_seqbufptr+2] = (dev);\
693					_seqbuf[_seqbufptr+3] = (voice);\
694					_seqbuf[_seqbufptr+4] = (pressure);\
695					_seqbuf[_seqbufptr+5] = 0;\
696					_seqbuf[_seqbufptr+6] = 0;\
697					_seqbuf[_seqbufptr+7] = 0;\
698					_SEQ_ADVBUF(8);}
699
700#define SEQ_PANNING(dev, voice, pos)	{_SEQ_NEEDBUF(8);\
701					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
702					_seqbuf[_seqbufptr+1] = SEQ_BALANCE;\
703					_seqbuf[_seqbufptr+2] = (dev);\
704					_seqbuf[_seqbufptr+3] = (voice);\
705					(char)_seqbuf[_seqbufptr+4] = (pos);\
706					_seqbuf[_seqbufptr+5] = 0;\
707					_seqbuf[_seqbufptr+6] = 0;\
708					_seqbuf[_seqbufptr+7] = 0;\
709					_SEQ_ADVBUF(8);}
710
711#define SEQ_CONTROL(dev, voice, controller, value)	{_SEQ_NEEDBUF(8);\
712					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
713					_seqbuf[_seqbufptr+1] = SEQ_CONTROLLER;\
714					_seqbuf[_seqbufptr+2] = (dev);\
715					_seqbuf[_seqbufptr+3] = (voice);\
716					_seqbuf[_seqbufptr+4] = (controller);\
717					*(short *)&_seqbuf[_seqbufptr+5] = (value);\
718					_seqbuf[_seqbufptr+7] = 0;\
719					_SEQ_ADVBUF(8);}
720
721#define SEQ_PITCHBEND(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_PITCH_BENDER, value)
722#define SEQ_BENDER_RANGE(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value)
723#define SEQ_EXPRESSION(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_EXPRESSION, value)
724#define SEQ_MAIN_VOLUME(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_MAIN_VOLUME, value)
725
726#define SEQ_START_TIMER()		{_SEQ_NEEDBUF(4);\
727					_seqbuf[_seqbufptr] = SEQ_SYNCTIMER;\
728					_seqbuf[_seqbufptr+1] = 0;\
729					_seqbuf[_seqbufptr+2] = 0;\
730					_seqbuf[_seqbufptr+3] = 0;\
731					_SEQ_ADVBUF(4);}
732#define SEQ_SET_PATCH(dev, voice, patch)	{_SEQ_NEEDBUF(8);\
733					_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
734					_seqbuf[_seqbufptr+1] = SEQ_PGMCHANGE;\
735					_seqbuf[_seqbufptr+2] = (dev);\
736					_seqbuf[_seqbufptr+3] = (voice);\
737					_seqbuf[_seqbufptr+4] = (patch);\
738					_seqbuf[_seqbufptr+5] = 0;\
739					_seqbuf[_seqbufptr+6] = 0;\
740					_seqbuf[_seqbufptr+7] = 0;\
741					_SEQ_ADVBUF(8);}
742
743#define SEQ_WAIT_TIME(ticks)		{_SEQ_NEEDBUF(4);\
744				 	*(unsigned long *)&_seqbuf[_seqbufptr] = SEQ_WAIT | ((ticks) << 8);\
745				 	_SEQ_ADVBUF(4);}
746
747#define SEQ_ECHO_BACK(key)		{_SEQ_NEEDBUF(4);\
748				 	*(unsigned long *)&_seqbuf[_seqbufptr] = SEQ_ECHO | ((key) << 8);\
749				 	_SEQ_ADVBUF(4);}
750
751#define SEQ_MIDIOUT(device, byte)	{_SEQ_NEEDBUF(4);\
752					_seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\
753					_seqbuf[_seqbufptr+1] = (byte);\
754					_seqbuf[_seqbufptr+2] = (device);\
755					_seqbuf[_seqbufptr+3] = 0;\
756					_SEQ_ADVBUF(4);}
757#define SEQ_WRPATCH(patchx, len)	{if (_seqbufptr) seqbuf_dump();\
758					if (write(seqfd, (char*)(patchx), len)==-1) \
759					   perror("Write patch: /dev/sequencer");}
760
761#endif
762long soundcard_init(long mem_start);
763#endif /* _SOUNDCARD_H_ */
764