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