root/drivers/sound/soundcard.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   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   * 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 
 106 struct 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[1];   /* 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 
 213 struct 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 
 367 typedef unsigned char sbi_instr_data[32];
 368 
 369 struct 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 
 378 struct 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 
 401 struct 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 
 555 typedef unsigned char S_BYTE;
 556 typedef unsigned char S_FLAG;
 557 struct 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  */
 572 struct 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  */
 585 struct 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 
 606 void seqbuf_dump(void); /* 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
 736 long soundcard_init(long mem_start);
 737 #endif
 738 #ifndef SOUNDCARD_H
 739 #define SOUNDCARD_H
 740 /*
 741  * Copyright by Hannu Savolainen 1993
 742  *
 743  * Redistribution and use in source and binary forms, with or without
 744  * modification, are permitted provided that the following conditions
 745  * are met:
 746  * 1. Redistributions of source code must retain the above copyright
 747  *    notice, this list of conditions and the following disclaimer.
 748  * 2. Redistributions in binary form must reproduce the above copyright
 749  *    notice, this list of conditions and the following disclaimer in the
 750  *    documentation and/or other materials provided with the distribution.
 751  *
 752  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 753  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 754  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 755  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 756  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 757  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 758  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 759  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 760  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 761  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 762  * SUCH DAMAGE.
 763  *
 764  * 
 765  */
 766 
 767  /* 
 768   * If you make modifications to this file, please contact me before
 769   * distributing the modified version. There is already enough 
 770   * divercity in the world.
 771   *
 772   * Regards,
 773   * Hannu Savolainen
 774   * hsavolai@cs.helsinki.fi
 775   */
 776 
 777 #define SOUND_VERSION   200
 778 
 779 #include <sys/ioctl.h>
 780 
 781 /*
 782  *      Supported card ID numbers (Should be somewhere else?)
 783  */
 784 
 785 #define SNDCARD_ADLIB   1
 786 #define SNDCARD_SB      2
 787 #define SNDCARD_PAS     3
 788 #define SNDCARD_GUS     4
 789 #define SNDCARD_MPU401  5
 790 
 791 /***********************************
 792  * IOCTL Commands for /dev/sequencer
 793  */
 794 
 795 #ifndef _IOWR
 796 /*      @(#)ioctlp.h */
 797 
 798 /* Ioctl's have the command encoded in the lower word,
 799  * and the size of any in or out parameters in the upper
 800  * word.  The high 2 bits of the upper word are used
 801  * to encode the in/out status of the parameter; for now
 802  * we restrict parameters to at most 128 bytes.
 803  */
 804 /* #define      IOCTYPE         (0xff<<8) */
 805 #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
 806 #define IOC_VOID        0x20000000      /* no parameters */
 807 #define IOC_OUT         0x40000000      /* copy out parameters */
 808 #define IOC_IN          0x80000000      /* copy in parameters */
 809 #define IOC_INOUT       (IOC_IN|IOC_OUT)
 810 /* the 0x20000000 is so we can distinguish new ioctl's from old */
 811 #define _IO(x,y)        ((int)(IOC_VOID|(x<<8)|y))
 812 #define _IOR(x,y,t)     ((int)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
 813 #define _IOW(x,y,t)     ((int)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
 814 /* this should be _IORW, but stdio got there first */
 815 #define _IOWR(x,y,t)    ((int)(IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y))
 816 #endif  /* !_IOWR */
 817 
 818 #define SNDCTL_SEQ_RESET                _IO  ('Q', 0)
 819 #define SNDCTL_SEQ_SYNC                 _IO  ('Q', 1)
 820 #define SNDCTL_SYNTH_INFO               _IOWR('Q', 2, struct synth_info)
 821 #define SNDCTL_SEQ_CTRLRATE             _IOWR('Q', 3, int)      /* Set/get timer resolution (HZ) */
 822 #define SNDCTL_SEQ_GETOUTCOUNT          _IOR ('Q', 4, int)
 823 #define SNDCTL_SEQ_GETINCOUNT           _IOR ('Q', 5, int)
 824 #define SNDCTL_SEQ_PERCMODE             _IOW ('Q', 6, int)
 825 #define SNDCTL_FM_LOAD_INSTR            _IOW ('Q', 7, struct sbi_instrument)    /* Valid for FM only */
 826 #define SNDCTL_SEQ_TESTMIDI             _IOW ('Q', 8, int)
 827 #define SNDCTL_SEQ_RESETSAMPLES         _IOW ('Q', 9, int)
 828 #define SNDCTL_SEQ_NRSYNTHS             _IOR ('Q',10, int)
 829 #define SNDCTL_SEQ_NRMIDIS              _IOR ('Q',11, int)
 830 #define SNDCTL_MIDI_INFO                _IOWR('Q',12, struct midi_info)
 831 #define SNDCTL_SEQ_TRESHOLD             _IOW ('Q',13, int)
 832 #define SNDCTL_SYNTH_MEMAVL             _IOWR('Q',14, int)      /* in=dev#, out=memsize */
 833 #define SNDCTL_FM_4OP_ENABLE            _IOW ('Q',15, int)      /* in=dev# */
 834 #define SNDCTL_PMGR_ACCESS              _IOWR('Q',16, struct patmgr_info)
 835 
 836 /*
 837  *      Sample loading mechanism for internal synthesizers (/dev/sequencer)
 838  *      The following patch_info structure has been designed to support
 839  *      Gravis UltraSound. It tries to be universal format for uploading
 840  *      sample based patches but is propably too limited.
 841  */
 842 
 843 struct patch_info {
 844                 short key;              /* Use GUS_PATCH here */
 845 #define GUS_PATCH       0x04fd
 846 #define OBSOLETE_GUS_PATCH      0x02fd
 847                 short device_no;        /* Synthesizer number */
 848                 short instr_no;         /* Midi pgm# */
 849 
 850                 unsigned long mode;
 851 /*
 852  * The least significant byte has the same format than the GUS .PAT
 853  * files
 854  */
 855 #define WAVE_16_BITS    0x01    /* bit 0 = 8 or 16 bit wave data. */
 856 #define WAVE_UNSIGNED   0x02    /* bit 1 = Signed - Unsigned data. */
 857 #define WAVE_LOOPING    0x04    /* bit 2 = looping enabled-1. */
 858 #define WAVE_BIDIR_LOOP 0x08    /* bit 3 = Set is bidirectional looping. */
 859 #define WAVE_LOOP_BACK  0x10    /* bit 4 = Set is looping backward. */
 860 #define WAVE_SUSTAIN_ON 0x20    /* bit 5 = Turn sustaining on. (Env. pts. 3)*/
 861 #define WAVE_ENVELOPES  0x40    /* bit 6 = Enable envelopes - 1 */
 862                                 /*      (use the env_rate/env_offs fields). */
 863 /* Linux specific bits */
 864 #define WAVE_VIBRATO    0x00010000      /* The vibrato info is valid */
 865 #define WAVE_TREMOLO    0x00020000      /* The tremolo info is valid */
 866 #define WAVE_SCALE      0x00040000      /* The scaling info is valid */
 867 /* Other bits must be zeroed */
 868 
 869                 long len;       /* Size of the wave data in bytes */
 870                 long loop_start, loop_end; /* Byte offsets from the beginning */
 871 
 872 /* 
 873  * The base_freq and base_note fields are used when computing the
 874  * playback speed for a note. The base_note defines the tone frequency
 875  * which is heard if the sample is played using the base_freq as the
 876  * playback speed.
 877  *
 878  * The low_note and high_note fields define the minimum and maximum note
 879  * frequencies for which this sample is valid. It is possible to define
 880  * more than one samples for a instrument number at the same time. The
 881  * low_note and high_note fields are used to select the most suitable one.
 882  *
 883  * The fields base_note, high_note and low_note should contain
 884  * the note frequency multiplied by 1000. For example value for the
 885  * middle A is 440*1000.
 886  */
 887 
 888                 unsigned int base_freq;
 889                 unsigned long base_note;
 890                 unsigned long high_note;
 891                 unsigned long low_note;
 892                 int panning;    /* -128=left, 127=right */
 893                 int detuning;
 894 
 895 /*      New fields introduced in version 1.99.5 */
 896 
 897        /* Envelope. Enabled by mode bit WAVE_ENVELOPES  */
 898                 unsigned char   env_rate[ 6 ];   /* GUS HW ramping rate */
 899                 unsigned char   env_offset[ 6 ]; /* 255 == 100% */
 900 
 901         /* 
 902          * The tremolo, vibrato and scale info are not supported yet.
 903          * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
 904          * WAVE_SCALE
 905          */
 906 
 907                 unsigned char   tremolo_sweep;
 908                 unsigned char   tremolo_rate;
 909                 unsigned char   tremolo_depth;
 910         
 911                 unsigned char   vibrato_sweep;
 912                 unsigned char   vibrato_rate;
 913                 unsigned char   vibrato_depth;
 914 
 915                 int             scale_frequency;
 916                 unsigned int    scale_factor;           /* from 0 to 2048 or 0 to 2 */
 917         
 918                 int             volume;
 919                 int             spare[4];
 920                 char data[0];   /* The waveform data starts here */
 921         };
 922 
 923 
 924 /*
 925  * Patch management interface (/dev/sequencer, /dev/patmgr#)
 926  * Don't use these calls if you want to maintain compatibility with
 927  * the future versions of the driver.
 928  */
 929 
 930 #define         PS_NO_PATCHES           0       /* No patch support on device */
 931 #define         PS_MGR_NOT_OK           1       /* Plain patch support (no mgr) */
 932 #define         PS_MGR_OK               2       /* Patch manager supported */
 933 #define         PS_MANAGED              3       /* Patch manager running */
 934 
 935 #define SNDCTL_PMGR_IFACE               _IOWR('P', 1, struct patmgr_info)
 936 
 937 /*
 938  * The patmgr_info is a fixed size structure which is used for two
 939  * different purposes. The intended use is for communication between
 940  * the application using /dev/sequencer and the patch manager daemon
 941  * associated with a synthesizer device (ioctl(SNDCTL_PMGR_ACCESS)).
 942  *
 943  * This structure is also used with ioctl(SNDCTL_PGMR_IFACE) which allows
 944  * a patch manager daemon to read and write device parameters. This
 945  * ioctl available through /dev/sequencer also. Avoid using it since it's
 946  * extremely hardware dependent. In addition access trough /dev/sequencer 
 947  * may confuse the patch manager daemon.
 948  */
 949 
 950 struct patmgr_info {    /* Note! size must be < 4k since kmalloc() is used */
 951           unsigned long key;    /* Don't worry. Reserved for communication
 952                                    between the patch manager and the driver. */
 953 #define PM_K_EVENT              1 /* Event from the /dev/sequencer driver */
 954 #define PM_K_COMMAND            2 /* Request from a application */
 955 #define PM_K_RESPONSE           3 /* From patmgr to application */
 956 #define PM_ERROR                4 /* Error returned by the patmgr */
 957           int device;
 958           int command;
 959 
 960 /* 
 961  * Commands 0x000 to 0xfff reserved for patch manager programs 
 962  */
 963 #define PM_GET_DEVTYPE  1       /* Returns type of the patch mgr interface of dev */
 964 #define         PMTYPE_FM2      1       /* 2 OP fm */
 965 #define         PMTYPE_FM4      2       /* Mixed 4 or 2 op FM (OPL-3) */
 966 #define         PMTYPE_WAVE     3       /* Wave table synthesizer (GUS) */
 967 #define PM_GET_NRPGM    2       /* Returns max # of midi programs in parm1 */
 968 #define PM_GET_PGMMAP   3       /* Returns map of loaded midi programs in data8 */
 969 #define PM_GET_PGM_PATCHES 4    /* Return list of patches of a program (parm1) */
 970 #define PM_GET_PATCH    5       /* Return patch header of patch parm1 */
 971 #define PM_SET_PATCH    6       /* Set patch header of patch parm1 */
 972 #define PM_READ_PATCH   7       /* Read patch (wave) data */
 973 #define PM_WRITE_PATCH  8       /* Write patch (wave) data */
 974 
 975 /*
 976  * Commands 0x1000 to 0xffff are for communication between the patch manager
 977  * and the client
 978  */
 979 #define _PM_LOAD_PATCH  0x100
 980 
 981 /* 
 982  * Commands above 0xffff reserved for device specific use
 983  */
 984 
 985           long parm1;
 986           long parm2;
 987           long parm3;
 988 
 989           union {
 990                 unsigned char data8[4000];
 991                 unsigned short data16[2000];
 992                 unsigned long data32[1000];
 993                 struct patch_info patch;
 994           } data;
 995         };
 996 
 997 /*
 998  * When a patch manager daemon is present, it will be informed by the
 999  * driver when something important happens. For example when the
1000  * /dev/sequencer is opened or closed. A record with key == PM_K_EVENT is
1001  * returned. The command field contains the event type:
1002  */
1003 #define PM_E_OPENED             1       /* /dev/sequencer opened */
1004 #define PM_E_CLOSED             2       /* /dev/sequencer closed */
1005 #define PM_E_PATCH_RESET        3       /* SNDCTL_RESETSAMPLES called */
1006 #define PM_E_PATCH_LOADED       4       /* A patch has been loaded by appl */
1007 
1008 /*
1009  * /dev/sequencer input events.
1010  *
1011  * The data written to the /dev/sequencer is a stream of events. Events
1012  * are records of 4 or 8 bytes. The first byte defines the size. 
1013  * Any number of events can be written with a write call. There
1014  * is a set of macros for sending these events. Use these macros if you
1015  * want to maximize portability of your program.
1016  *
1017  * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
1018  * (All input events are currently 4 bytes long. Be prepared to support
1019  * 8 byte events also. If you receive any event having first byte >= 0xf0,
1020  * it's a 8 byte event.
1021  *
1022  * The events are documented at the end of this file.
1023  *
1024  * Normal events (4 bytes)
1025  * There is also a 8 byte version of most of the 4 byte events. The
1026  * 8 byte one is recommended.
1027  */
1028 #define SEQ_NOTEOFF             0
1029 #define SEQ_FMNOTEOFF           SEQ_NOTEOFF     /* Just old name */
1030 #define SEQ_NOTEON              1
1031 #define SEQ_FMNOTEON            SEQ_NOTEON
1032 #define SEQ_WAIT                2
1033 #define SEQ_PGMCHANGE           3
1034 #define SEQ_FMPGMCHANGE         SEQ_PGMCHANGE
1035 #define SEQ_SYNCTIMER           4
1036 #define SEQ_MIDIPUTC            5
1037 #define SEQ_DRUMON              6       /*** OBSOLETE ***/
1038 #define SEQ_DRUMOFF             7       /*** OBSOLETE ***/
1039 #define SEQ_ECHO                8       /* For synching programs with output */
1040 #define SEQ_AFTERTOUCH          9
1041 #define SEQ_CONTROLLER          10
1042 #define    CTRL_PITCH_BENDER            255
1043 #define    CTRL_PITCH_BENDER_RANGE      254
1044 #define    CTRL_EXPRESSION              253
1045 #define    CTRL_MAIN_VOLUME             252
1046 #define SEQ_BALANCE             11
1047 
1048 /*
1049  * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
1050  *       input events.
1051  */
1052 
1053 /*
1054  * Event codes 0xf0 to 0xfc are reserved for future extensions.
1055  */
1056 
1057 #define SEQ_FULLSIZE            0xfd    /* Long events */
1058 /*
1059  *      SEQ_FULLSIZE events are used for loading patches/samples to the
1060  *      synthesizer devices. These events are passed directly to the driver
1061  *      of the associated synthesizer device. There is no limit to the size
1062  *      of the extended events. These events are not queued but executed
1063  *      immediately when the write() is called (execution can take several
1064  *      seconds of time). 
1065  *
1066  *      When a SEQ_FULLSIZE message is written to the device, it must
1067  *      be written using exactly one write() call. Other events cannot
1068  *      be mixed to the same write.
1069  *      
1070  *      For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the 
1071  *      /dev/sequencer. Don't write other data together with the instrument structure
1072  *      Set the key field of the structure to FM_PATCH. The device field is used to
1073  *      route the patch to the corresponding device.
1074  *
1075  *      For Gravis UltraSound use struct patch_info. Initialize the key field
1076  *      to GUS_PATCH.
1077  */
1078 #define SEQ_PRIVATE             0xfe    /* Low level HW dependent events (8 bytes) */
1079 #define SEQ_EXTENDED            0xff    /* Extended events (8 bytes) */
1080 
1081 /*
1082  *      Extended events for synthesizers (8 bytes)
1083  *
1084  *      Format:
1085  *
1086  *              b0      = SEQ_EXTENDED
1087  *              b1      = command
1088  *              b2      = device
1089  *              b3-b7   = parameters
1090  *
1091  *      Command                         b3      b4      b5      b6      b7
1092  *      ----------------------------------------------------------------------------
1093  *      SEQ_NOTEON                      voice   note    volume  0       0
1094  *      SEQ_NOTEOFF                     voice   note    volume  0       0
1095  *      SEQ_PGMCHANGE                   voice   pgm     0       0       0
1096  *      SEQ_DRUMON                      (voice) drum#   volume  0       0
1097  *      SEQ_DRUMOFF                     (voice) drum#   volume  0       0
1098  */
1099 
1100 /*
1101  * Record for FM patches
1102  */
1103 
1104 typedef unsigned char sbi_instr_data[32];
1105 
1106 struct sbi_instrument {
1107                 unsigned short  key;            /*      Initialize to FM_PATCH or OPL3_PATCH */
1108 #define FM_PATCH        0x01fd
1109 #define OPL3_PATCH      0x03fd
1110                 short           device;         /*      Synth# (0-4)    */
1111                 int             channel;        /*      Program# to be initialized      */
1112                 sbi_instr_data  operators;      /*      Register settings for operator cells (.SBI format)      */
1113         };
1114 
1115 struct synth_info {     /* Read only */
1116                 char    name[30];
1117                 int     device;         /* 0-N. INITIALIZE BEFORE CALLING */
1118                 int     synth_type;
1119 #define SYNTH_TYPE_FM                   0
1120 #define SYNTH_TYPE_SAMPLE               1
1121 
1122                 int     synth_subtype;
1123 #define FM_TYPE_ADLIB                   0x00
1124 #define FM_TYPE_OPL3                    0x01
1125 
1126 #define SAMPLE_TYPE_GUS                 0x10
1127 
1128                 int     perc_mode;      /* No longer supported */
1129                 int     nr_voices;
1130                 int     nr_drums;       /* Obsolete field */
1131                 int     instr_bank_size;
1132                 unsigned long   capabilities;   
1133 #define SYNTH_CAP_PERCMODE              0x00000001 /* No longer used */
1134 #define SYNTH_CAP_OPL3                  0x00000002 /* Set if OPL3 supported */
1135                 int     dummies[19];    /* Reserve space */
1136         };
1137 
1138 struct midi_info {
1139                 char            name[30];
1140                 int             device;         /* 0-N. INITIALIZE BEFORE CALLING */
1141                 unsigned long   capabilities;   /* To be defined later */
1142                 int             dummies[19];    /* Reserve space */
1143         };
1144 
1145 /********************************************
1146  * IOCTL commands for /dev/dsp and /dev/audio
1147  */
1148 
1149 #define SNDCTL_DSP_RESET                _IO  ('P', 0)
1150 #define SNDCTL_DSP_SYNC                 _IO  ('P', 1)
1151 #define SNDCTL_DSP_SPEED                _IOWR('P', 2, int)
1152 #define SNDCTL_DSP_STEREO               _IOWR('P', 3, int)
1153 #define SNDCTL_DSP_GETBLKSIZE           _IOWR('P', 4, int)
1154 #define SNDCTL_DSP_SAMPLESIZE           _IOWR('P', 5, int)      /* 8, 12 or 16 */
1155 #define SOUND_PCM_WRITE_CHANNELS        _IOWR('P', 6, int)
1156 #define SOUND_PCM_WRITE_FILTER          _IOWR('P', 7, int)
1157 #define SNDCTL_DSP_POST                 _IO  ('P', 8)
1158 
1159 #define SOUND_PCM_READ_RATE             _IOR ('P', 2, int)
1160 #define SOUND_PCM_READ_CHANNELS         _IOR ('P', 6, int)
1161 #define SOUND_PCM_READ_BITS             _IOR ('P', 5, int)
1162 #define SOUND_PCM_READ_FILTER           _IOR ('P', 7, int)
1163 
1164 /* Some alias names */
1165 #define SOUND_PCM_WRITE_BITS            SNDCTL_DSP_SAMPLESIZE
1166 #define SOUND_PCM_WRITE_RATE            SNDCTL_DSP_SPEED
1167 #define SOUND_PCM_POST                  SNDCTL_DSP_POST
1168 #define SOUND_PCM_RESET                 SNDCTL_DSP_RESET
1169 #define SOUND_PCM_SYNC                  SNDCTL_DSP_SYNC
1170 
1171 /*********************************************
1172  * IOCTL commands for /dev/mixer
1173  */
1174         
1175 /* 
1176  * Mixer devices
1177  *
1178  * There can be up to 20 different analog mixer channels. The
1179  * SOUND_MIXER_NRDEVICES gives the currently supported maximum. 
1180  * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells
1181  * the devices supported by the particular mixer.
1182  */
1183 
1184 #define SOUND_MIXER_NRDEVICES   12
1185 #define SOUND_MIXER_VOLUME      0
1186 #define SOUND_MIXER_BASS        1
1187 #define SOUND_MIXER_TREBLE      2
1188 #define SOUND_MIXER_SYNTH       3
1189 #define SOUND_MIXER_PCM         4
1190 #define SOUND_MIXER_SPEAKER     5
1191 #define SOUND_MIXER_LINE        6
1192 #define SOUND_MIXER_MIC         7
1193 #define SOUND_MIXER_CD          8
1194 #define SOUND_MIXER_IMIX        9       /*  Recording monitor  */
1195 #define SOUND_MIXER_ALTPCM      10
1196 #define SOUND_MIXER_RECLEV      11      /* Recording level */
1197 
1198 /* Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) */
1199 /* Not counted to SOUND_MIXER_NRDEVICES, but use the same number space */
1200 #define SOUND_ONOFF_MIN         28
1201 #define SOUND_ONOFF_MAX         30
1202 #define SOUND_MIXER_MUTE        28      /* 0 or 1 */
1203 #define SOUND_MIXER_ENHANCE     29      /* Enhanced stereo (0, 40, 60 or 80) */
1204 #define SOUND_MIXER_LOUD        30      /* 0 or 1 */
1205 
1206 /* Note!        Number 31 cannot be used since the sign bit is reserved */
1207 
1208 #define SOUND_DEVICE_LABELS     {"Vol  ", "Bass ", "Trebl", "Synth", "Pcm  ", "Spkr ", "Line ", \
1209                                  "Mic  ", "CD   ", "Mix  ", "Pcm2 ", "rec"}
1210 
1211 #define SOUND_DEVICE_NAMES      {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \
1212                                  "mic", "cd", "mix", "pcm2", "rec"}
1213 
1214 /*      Device bitmask identifiers      */
1215 
1216 #define SOUND_MIXER_RECSRC      0xff    /* Arg contains a bit for each recording source */
1217 #define SOUND_MIXER_DEVMASK     0xfe    /* Arg contains a bit for each supported device */
1218 #define SOUND_MIXER_RECMASK     0xfd    /* Arg contains a bit for each supported recording source */
1219 #define SOUND_MIXER_CAPS        0xfc
1220         #define SOUND_CAP_EXCL_INPUT    0x00000001      /* Only one recording source at a time */
1221 #define SOUND_MIXER_STEREODEVS  0xfb    /* Mixer channels supporting stereo */
1222 
1223 /*      Device mask bits        */
1224 
1225 #define SOUND_MASK_VOLUME       (1 << SOUND_MIXER_VOLUME)
1226 #define SOUND_MASK_BASS         (1 << SOUND_MIXER_BASS)
1227 #define SOUND_MASK_TREBLE       (1 << SOUND_MIXER_TREBLE)
1228 #define SOUND_MASK_SYNTH        (1 << SOUND_MIXER_SYNTH)
1229 #define SOUND_MASK_PCM          (1 << SOUND_MIXER_PCM)
1230 #define SOUND_MASK_SPEAKER      (1 << SOUND_MIXER_SPEAKER)
1231 #define SOUND_MASK_LINE         (1 << SOUND_MIXER_LINE)
1232 #define SOUND_MASK_MIC          (1 << SOUND_MIXER_MIC)
1233 #define SOUND_MASK_CD           (1 << SOUND_MIXER_CD)
1234 #define SOUND_MASK_IMIX         (1 << SOUND_MIXER_IMIX)
1235 #define SOUND_MASK_ALTPCM       (1 << SOUND_MIXER_ALTPCM)
1236 #define SOUND_MASK_RECLEV       (1 << SOUND_MIXER_RECLEV)
1237 
1238 #define SOUND_MASK_MUTE         (1 << SOUND_MIXER_MUTE)
1239 #define SOUND_MASK_ENHANCE      (1 << SOUND_MIXER_ENHANCE)
1240 #define SOUND_MASK_LOUD         (1 << SOUND_MIXER_LOUD)
1241 
1242 #define MIXER_READ(dev)         _IOR('M', dev, int)
1243 #define SOUND_MIXER_READ_VOLUME         MIXER_READ(SOUND_MIXER_VOLUME)
1244 #define SOUND_MIXER_READ_BASS           MIXER_READ(SOUND_MIXER_BASS)
1245 #define SOUND_MIXER_READ_TREBLE         MIXER_READ(SOUND_MIXER_TREBLE)
1246 #define SOUND_MIXER_READ_SYNTH          MIXER_READ(SOUND_MIXER_SYNTH)
1247 #define SOUND_MIXER_READ_PCM            MIXER_READ(SOUND_MIXER_PCM)
1248 #define SOUND_MIXER_READ_SPEAKER        MIXER_READ(SOUND_MIXER_SPEAKER)
1249 #define SOUND_MIXER_READ_LINE           MIXER_READ(SOUND_MIXER_LINE)
1250 #define SOUND_MIXER_READ_MIC            MIXER_READ(SOUND_MIXER_MIC)
1251 #define SOUND_MIXER_READ_CD             MIXER_READ(SOUND_MIXER_CD)
1252 #define SOUND_MIXER_READ_IMIX           MIXER_READ(SOUND_MIXER_IMIX)
1253 #define SOUND_MIXER_READ_ALTPCM         MIXER_READ(SOUND_MIXER_ALTPCM)
1254 #define SOUND_MIXER_READ_RECLEV         MIXER_READ(SOUND_MIXER_RECLEV)
1255 #define SOUND_MIXER_READ_MUTE           MIXER_READ(SOUND_MIXER_MUTE)
1256 #define SOUND_MIXER_READ_ENHANCE        MIXER_READ(SOUND_MIXER_ENHANCE)
1257 #define SOUND_MIXER_READ_LOUD           MIXER_READ(SOUND_MIXER_LOUD)
1258 
1259 #define SOUND_MIXER_READ_RECSRC         MIXER_READ(SOUND_MIXER_RECSRC)
1260 #define SOUND_MIXER_READ_DEVMASK        MIXER_READ(SOUND_MIXER_DEVMASK)
1261 #define SOUND_MIXER_READ_RECMASK        MIXER_READ(SOUND_MIXER_RECMASK)
1262 #define SOUND_MIXER_READ_STEREODEVS     MIXER_READ(SOUND_MIXER_STEREODEVS)
1263 #define SOUND_MIXER_READ_CAPS           MIXER_READ(SOUND_MIXER_CAPS)
1264 
1265 #define MIXER_WRITE(dev)                _IOWR('M', dev, int)
1266 #define SOUND_MIXER_WRITE_VOLUME        MIXER_WRITE(SOUND_MIXER_VOLUME)
1267 #define SOUND_MIXER_WRITE_BASS          MIXER_WRITE(SOUND_MIXER_BASS)
1268 #define SOUND_MIXER_WRITE_TREBLE        MIXER_WRITE(SOUND_MIXER_TREBLE)
1269 #define SOUND_MIXER_WRITE_SYNTH         MIXER_WRITE(SOUND_MIXER_SYNTH)
1270 #define SOUND_MIXER_WRITE_PCM           MIXER_WRITE(SOUND_MIXER_PCM)
1271 #define SOUND_MIXER_WRITE_SPEAKER       MIXER_WRITE(SOUND_MIXER_SPEAKER)
1272 #define SOUND_MIXER_WRITE_LINE          MIXER_WRITE(SOUND_MIXER_LINE)
1273 #define SOUND_MIXER_WRITE_MIC           MIXER_WRITE(SOUND_MIXER_MIC)
1274 #define SOUND_MIXER_WRITE_CD            MIXER_WRITE(SOUND_MIXER_CD)
1275 #define SOUND_MIXER_WRITE_IMIX          MIXER_WRITE(SOUND_MIXER_IMIX)
1276 #define SOUND_MIXER_WRITE_ALTPCM        MIXER_WRITE(SOUND_MIXER_ALTPCM)
1277 #define SOUND_MIXER_WRITE_RECLEV        MIXER_WRITE(SOUND_MIXER_RECLEV)
1278 #define SOUND_MIXER_WRITE_MUTE          MIXER_WRITE(SOUND_MIXER_MUTE)
1279 #define SOUND_MIXER_WRITE_ENHANCE       MIXER_WRITE(SOUND_MIXER_ENHANCE)
1280 #define SOUND_MIXER_WRITE_LOUD          MIXER_WRITE(SOUND_MIXER_LOUD)
1281 
1282 #define SOUND_MIXER_WRITE_RECSRC        MIXER_WRITE(SOUND_MIXER_RECSRC)
1283 
1284 /*
1285  *      The following mixer ioctl calls are compatible with the BSD driver by
1286  *        Steve Haehnichen <shaehnic@ucsd.edu>
1287  *
1288  * Since this interface is entirely SB specific, it will be dropped in the
1289  * near future.
1290  */
1291 
1292 typedef unsigned char S_BYTE;
1293 typedef unsigned char S_FLAG;
1294 struct stereo_vol
1295 {
1296   S_BYTE l;                     /* Left volume */
1297   S_BYTE r;                     /* Right volume */
1298 };
1299 
1300 #define MIXER_IOCTL_SET_LEVELS          _IOW ('s', 20, struct sb_mixer_levels)
1301 #define MIXER_IOCTL_SET_PARAMS          _IOW ('s', 21, struct sb_mixer_params)
1302 #define MIXER_IOCTL_READ_LEVELS         _IOR ('s', 22, struct sb_mixer_levels)
1303 #define MIXER_IOCTL_READ_PARAMS         _IOR ('s', 23, struct sb_mixer_params)
1304 #define MIXER_IOCTL_RESET               _IO  ('s', 24)
1305 
1306 /*
1307  * Mixer volume levels for MIXER_IOCTL_SET_VOL & MIXER_IOCTL_READ_VOL
1308  */
1309 struct sb_mixer_levels
1310 {
1311   struct stereo_vol master;     /* Master volume */
1312   struct stereo_vol voc;        /* DSP Voice volume */
1313   struct stereo_vol fm;         /* FM volume */
1314   struct stereo_vol line;       /* Line-in volume */
1315   struct stereo_vol cd;         /* CD audio */
1316   S_BYTE mic;                   /* Microphone level */
1317 };
1318 
1319 /*
1320  * Mixer parameters for MIXER_IOCTL_SET_PARAMS & MIXER_IOCTL_READ_PARAMS
1321  */
1322 struct sb_mixer_params
1323 {
1324   S_BYTE record_source;         /* Recording source (See SRC_xxx below) */
1325   S_FLAG hifreq_filter;         /* Filter frequency (hi/low) */
1326   S_FLAG filter_input;          /* ANFI input filter */
1327   S_FLAG filter_output;         /* DNFI output filter */
1328   S_FLAG dsp_stereo;            /* 1 if DSP is in Stereo mode */
1329 };
1330 
1331 #define SRC_MIC         1       /* Select Microphone recording source */
1332 #define SRC_CD          3       /* Select CD recording source */
1333 #define SRC_LINE        7       /* Use Line-in for recording source */
1334 
1335 #if !defined(KERNEL) && !defined(INKERNEL)
1336 /*
1337  *      Some convenience macros to simplify programming of the
1338  *      /dev/sequencer interface
1339  *
1340  *      These macros define the API which should be used when possible.
1341  */
1342 
1343 void seqbuf_dump(void); /* This function must be provided by programs */
1344 
1345 /* Sample seqbuf_dump() implementation:
1346  *
1347  *      SEQ_DEFINEBUF (2048);   -- Defines a buffer for 2048 bytes
1348  *
1349  *      int seqfd;              -- The file descriptor for /dev/sequencer.
1350  *
1351  *      void
1352  *      seqbuf_dump ()
1353  *      {
1354  *        if (_seqbufptr)
1355  *          if (write (seqfd, _seqbuf, _seqbufptr) == -1)
1356  *            {
1357  *              perror ("write /dev/sequencer");
1358  *              exit (-1);
1359  *            }
1360  *        _seqbufptr = 0;
1361  *      }
1362  */
1363 
1364 #define SEQ_DEFINEBUF(len)              unsigned char _seqbuf[len]; int _seqbuflen = len, _seqbufptr = 0
1365 #define SEQ_PM_DEFINES                  struct patmgr_info _pm_info
1366 #define _SEQ_NEEDBUF(len)               if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump()
1367 #define _SEQ_ADVBUF(len)                _seqbufptr += len
1368 #define SEQ_DUMPBUF                     seqbuf_dump
1369 #define PM_LOAD_PATCH(dev, bank, pgm)   (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
1370                                         _pm_info.device=dev, _pm_info.data.data8[0]=pgm, \
1371                                         _pm_info.parm1 = bank, _pm_info.parm2 = 1, \
1372                                         ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
1373 #define PM_LOAD_PATCHES(dev, bank, pgm) (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \
1374                                         _pm_info.device=dev, memcpy(_pm_info.data.data8, pgm, 128), \
1375                                         _pm_info.parm1 = bank, _pm_info.parm2 = 128, \
1376                                         ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
1377 
1378 #define SEQ_START_NOTE(dev, voice, note, vol)   {_SEQ_NEEDBUF(8);\
1379                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1380                                         _seqbuf[_seqbufptr+1] = SEQ_NOTEON;\
1381                                         _seqbuf[_seqbufptr+2] = (dev);\
1382                                         _seqbuf[_seqbufptr+3] = (voice);\
1383                                         _seqbuf[_seqbufptr+4] = (note);\
1384                                         _seqbuf[_seqbufptr+5] = (vol);\
1385                                         _seqbuf[_seqbufptr+6] = 0;\
1386                                         _seqbuf[_seqbufptr+7] = 0;\
1387                                         _SEQ_ADVBUF(8);}
1388 
1389 #define SEQ_STOP_NOTE(dev, voice, note, vol)    {_SEQ_NEEDBUF(8);\
1390                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1391                                         _seqbuf[_seqbufptr+1] = SEQ_NOTEOFF;\
1392                                         _seqbuf[_seqbufptr+2] = (dev);\
1393                                         _seqbuf[_seqbufptr+3] = (voice);\
1394                                         _seqbuf[_seqbufptr+4] = (note);\
1395                                         _seqbuf[_seqbufptr+5] = (vol);\
1396                                         _seqbuf[_seqbufptr+6] = 0;\
1397                                         _seqbuf[_seqbufptr+7] = 0;\
1398                                         _SEQ_ADVBUF(8);}
1399 
1400 #define SEQ_CHN_PRESSURE(dev, voice, pressure)  {_SEQ_NEEDBUF(8);\
1401                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1402                                         _seqbuf[_seqbufptr+1] = SEQ_AFTERTOUCH;\
1403                                         _seqbuf[_seqbufptr+2] = (dev);\
1404                                         _seqbuf[_seqbufptr+3] = (voice);\
1405                                         _seqbuf[_seqbufptr+4] = (pressure);\
1406                                         _seqbuf[_seqbufptr+5] = 0;\
1407                                         _seqbuf[_seqbufptr+6] = 0;\
1408                                         _seqbuf[_seqbufptr+7] = 0;\
1409                                         _SEQ_ADVBUF(8);}
1410 
1411 #define SEQ_PANNING(dev, voice, pos)    {_SEQ_NEEDBUF(8);\
1412                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1413                                         _seqbuf[_seqbufptr+1] = SEQ_BALANCE;\
1414                                         _seqbuf[_seqbufptr+2] = (dev);\
1415                                         _seqbuf[_seqbufptr+3] = (voice);\
1416                                         (char)_seqbuf[_seqbufptr+4] = (pos);\
1417                                         _seqbuf[_seqbufptr+5] = 0;\
1418                                         _seqbuf[_seqbufptr+6] = 0;\
1419                                         _seqbuf[_seqbufptr+7] = 0;\
1420                                         _SEQ_ADVBUF(8);}
1421 
1422 #define SEQ_CONTROL(dev, voice, controller, value)      {_SEQ_NEEDBUF(8);\
1423                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1424                                         _seqbuf[_seqbufptr+1] = SEQ_CONTROLLER;\
1425                                         _seqbuf[_seqbufptr+2] = (dev);\
1426                                         _seqbuf[_seqbufptr+3] = (voice);\
1427                                         _seqbuf[_seqbufptr+4] = (controller);\
1428                                         *(short *)&_seqbuf[_seqbufptr+5] = (value);\
1429                                         _seqbuf[_seqbufptr+7] = 0;\
1430                                         _SEQ_ADVBUF(8);}
1431 
1432 #define SEQ_PITCHBEND(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_PITCH_BENDER, value)
1433 #define SEQ_BENDER_RANGE(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value)
1434 #define SEQ_EXPRESSION(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_EXPRESSION, value)
1435 #define SEQ_MAIN_VOLUME(dev, voice, value) SEQ_CONTROL(dev, voice, CTRL_MAIN_VOLUME, value)
1436 
1437 #define SEQ_START_TIMER()               {_SEQ_NEEDBUF(4);\
1438                                         _seqbuf[_seqbufptr] = SEQ_SYNCTIMER;\
1439                                         _seqbuf[_seqbufptr+1] = 0;\
1440                                         _seqbuf[_seqbufptr+2] = 0;\
1441                                         _seqbuf[_seqbufptr+3] = 0;\
1442                                         _SEQ_ADVBUF(4);}
1443 #define SEQ_SET_PATCH(dev, voice, patch)        {_SEQ_NEEDBUF(8);\
1444                                         _seqbuf[_seqbufptr] = SEQ_EXTENDED;\
1445                                         _seqbuf[_seqbufptr+1] = SEQ_PGMCHANGE;\
1446                                         _seqbuf[_seqbufptr+2] = (dev);\
1447                                         _seqbuf[_seqbufptr+3] = (voice);\
1448                                         _seqbuf[_seqbufptr+4] = (patch);\
1449                                         _seqbuf[_seqbufptr+5] = 0;\
1450                                         _seqbuf[_seqbufptr+6] = 0;\
1451                                         _seqbuf[_seqbufptr+7] = 0;\
1452                                         _SEQ_ADVBUF(8);}
1453 
1454 #define SEQ_WAIT_TIME(ticks)            {_SEQ_NEEDBUF(4);\
1455                                         *(unsigned long *)&_seqbuf[_seqbufptr] = SEQ_WAIT | ((ticks) << 8);\
1456                                         _SEQ_ADVBUF(4);}
1457 
1458 #define SEQ_ECHO_BACK(key)              {_SEQ_NEEDBUF(4);\
1459                                         *(unsigned long *)&_seqbuf[_seqbufptr] = SEQ_ECHO | ((key) << 8);\
1460                                         _SEQ_ADVBUF(4);}
1461 
1462 #define SEQ_MIDIOUT(device, byte)       {_SEQ_NEEDBUF(4);\
1463                                         _seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\
1464                                         _seqbuf[_seqbufptr+1] = (byte);\
1465                                         _seqbuf[_seqbufptr+2] = (device);\
1466                                         _seqbuf[_seqbufptr+3] = 0;\
1467                                         _SEQ_ADVBUF(4);}
1468 #define SEQ_WRPATCH(patch, len)         {if (_seqbufptr) seqbuf_dump();\
1469                                         if (write(seqfd, (char*)(patch), len)==-1) \
1470                                            perror("Write patch: /dev/sequencer");}
1471 
1472 #endif
1473 long soundcard_init(long mem_start);
1474 #endif

/* [previous][next][first][last][top][bottom][index][help] */