* Copyright by Hannu Savolainen 1993-1997
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. 2.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* OSS interface version. With versions earlier than 3.6 this value is
* an integer with value less than 361. In versions 3.6 and later
* it's a six digit hexadecimal value. For example value
* of 0x030600 represents OSS version 3.6.0.
* Use ioctl(fd, OSS_GETVERSION, &int) to get the version number of
* the currently active driver.
#define SOUND_VERSION 0x030802
#define OPEN_SOUND_SYSTEM
/* In Linux we need to be prepared for cross compiling */
* Supported card ID numbers (Should be somewhere else?)
#define SNDCARD_SB16MIDI 7
#define SNDCARD_UART6850 8
#define SNDCARD_SSCAPE 12
#define SNDCARD_PSS_MPU 13
#define SNDCARD_PSS_MSS 14
#define SNDCARD_SSCAPE_MSS 15
#define SNDCARD_TRXPRO 16
#define SNDCARD_TRXPRO_SB 17
#define SNDCARD_TRXPRO_MPU 18
#define SNDCARD_MAD16_MPU 20
#define SNDCARD_CS4232 21
#define SNDCARD_CS4232_MPU 22
#define SNDCARD_PSEUDO_MSS 24
#define SNDCARD_GUSPNP 25
#define SNDCARD_UART401 26
/* Sound card numbers 27 to N are reserved. Don't add more numbers here. */
/***********************************
* IOCTL Commands for /dev/sequencer
#if defined(_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__sparc__) && !defined(__INCioctlh) && !defined(__Lynx__)))
/* Use already defined ioctl defines if they exist (except with Sun or Sparc) */
#define SIOCPARM_MASK IOCPARM_MASK
#define SIOC_VOID IOC_VOID
#define SIOC_INOUT IOC_INOUT
#define _SIOC_SIZE _IOC_SIZE
#define _SIOC_DIR _IOC_DIR
#define _SIOC_NONE _IOC_NONE
#define _SIOC_READ _IOC_READ
#define _SIOC_WRITE _IOC_WRITE
/* Ioctl's have the command encoded in the lower word,
* and the size of any in or out parameters in the upper
* word. The high 2 bits of the upper word are used
* to encode the in/out status of the parameter; for now
* we restrict parameters to at most 8191 bytes.
/* #define SIOCTYPE (0xff<<8) */
#define SIOCPARM_MASK 0x1fff /* parameters must be < 8192 bytes */
#define SIOC_VOID 0x00000000 /* no parameters */
#define SIOC_OUT 0x20000000 /* copy out parameters */
#define SIOC_IN 0x40000000 /* copy in parameters */
#define SIOC_INOUT (SIOC_IN|SIOC_OUT)
/* the 0x20000000 is so we can distinguish new ioctl's from old */
#define _SIO(x,y) ((int)(SIOC_VOID|(x<<8)|y))
#define _SIOR(x,y,t) ((int)(SIOC_OUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
#define _SIOW(x,y,t) ((int)(SIOC_IN|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
/* this should be _SIORW, but stdio got there first */
#define _SIOWR(x,y,t) ((int)(SIOC_INOUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
#define _SIOC_SIZE(x) ((x>>16)&SIOCPARM_MASK)
#define _SIOC_DIR(x) (x & 0xf0000000)
#define _SIOC_NONE SIOC_VOID
#define _SIOC_READ SIOC_OUT
#define _SIOC_WRITE SIOC_IN
#define SNDCTL_SEQ_RESET _SIO ('Q', 0)
#define SNDCTL_SEQ_SYNC _SIO ('Q', 1)
#define SNDCTL_SYNTH_INFO _SIOWR('Q', 2, struct synth_info)
#define SNDCTL_SEQ_CTRLRATE _SIOWR('Q', 3, int) /* Set/get timer resolution (HZ) */
#define SNDCTL_SEQ_GETOUTCOUNT _SIOR ('Q', 4, int)
#define SNDCTL_SEQ_GETINCOUNT _SIOR ('Q', 5, int)
#define SNDCTL_SEQ_PERCMODE _SIOW ('Q', 6, int)
#define SNDCTL_FM_LOAD_INSTR _SIOW ('Q', 7, struct sbi_instrument) /* Obsolete. Don't use!!!!!! */
#define SNDCTL_SEQ_TESTMIDI _SIOW ('Q', 8, int)
#define SNDCTL_SEQ_RESETSAMPLES _SIOW ('Q', 9, int)
#define SNDCTL_SEQ_NRSYNTHS _SIOR ('Q',10, int)
#define SNDCTL_SEQ_NRMIDIS _SIOR ('Q',11, int)
#define SNDCTL_MIDI_INFO _SIOWR('Q',12, struct midi_info)
#define SNDCTL_SEQ_THRESHOLD _SIOW ('Q',13, int)
#define SNDCTL_SYNTH_MEMAVL _SIOWR('Q',14, int) /* in=dev#, out=memsize */
#define SNDCTL_FM_4OP_ENABLE _SIOW ('Q',15, int) /* in=dev# */
#define SNDCTL_SEQ_PANIC _SIO ('Q',17)
#define SNDCTL_SEQ_OUTOFBAND _SIOW ('Q',18, struct seq_event_rec)
#define SNDCTL_SEQ_GETTIME _SIOR ('Q',19, int)
#define SNDCTL_SYNTH_ID _SIOWR('Q',20, struct synth_info)
#define SNDCTL_SYNTH_CONTROL _SIOWR('Q',21, struct synth_control)
#define SNDCTL_SYNTH_REMOVESAMPLE _SIOWR('Q',22, struct remove_sample)
typedef struct synth_control
int devno; /* Synthesizer # */
char data[4000]; /* Device spesific command/data record */
typedef struct remove_sample
int devno; /* Synthesizer # */
int bankno; /* MIDI bank # (0=General MIDI) */
int instrno; /* MIDI instrument number */
typedef struct seq_event_rec {
#define SNDCTL_TMR_TIMEBASE _SIOWR('T', 1, int)
#define SNDCTL_TMR_START _SIO ('T', 2)
#define SNDCTL_TMR_STOP _SIO ('T', 3)
#define SNDCTL_TMR_CONTINUE _SIO ('T', 4)
#define SNDCTL_TMR_TEMPO _SIOWR('T', 5, int)
#define SNDCTL_TMR_SOURCE _SIOWR('T', 6, int)
# define TMR_INTERNAL 0x00000001
# define TMR_EXTERNAL 0x00000002
# define TMR_MODE_MIDI 0x00000010
# define TMR_MODE_FSK 0x00000020
# define TMR_MODE_CLS 0x00000040
# define TMR_MODE_SMPTE 0x00000080
#define SNDCTL_TMR_METRONOME _SIOW ('T', 7, int)
#define SNDCTL_TMR_SELECT _SIOW ('T', 8, int)
* Some big endian/little endian handling macros
#define _LINUX_PATCHKEY_H_INDIRECT
#include <linux/patchkey.h>
#undef _LINUX_PATCHKEY_H_INDIRECT
# if defined(__BYTE_ORDER)
# if __BYTE_ORDER == __BIG_ENDIAN
# define AFMT_S16_NE AFMT_S16_BE
# elif __BYTE_ORDER == __LITTLE_ENDIAN
# define AFMT_S16_NE AFMT_S16_LE
# error "could not determine byte order"
* Sample loading mechanism for internal synthesizers (/dev/sequencer)
* The following patch_info structure has been designed to support
* Gravis UltraSound. It tries to be universal format for uploading
* sample based patches but is probably too limited.
* (PBD) As Hannu guessed, the GUS structure is too limited for
* the WaveFront, but this is the right place for a constant definition.
unsigned short key; /* Use WAVE_PATCH here */
#define WAVE_PATCH _PATCHKEY(0x04)
#define GUS_PATCH WAVE_PATCH
#define WAVEFRONT_PATCH _PATCHKEY(0x06)
short device_no; /* Synthesizer number */
short instr_no; /* Midi pgm# */
* The least significant byte has the same format than the GUS .PAT
#define WAVE_16_BITS 0x01 /* bit 0 = 8 or 16 bit wave data. */
#define WAVE_UNSIGNED 0x02 /* bit 1 = Signed - Unsigned data. */
#define WAVE_LOOPING 0x04 /* bit 2 = looping enabled-1. */
#define WAVE_BIDIR_LOOP 0x08 /* bit 3 = Set is bidirectional looping. */
#define WAVE_LOOP_BACK 0x10 /* bit 4 = Set is looping backward. */
#define WAVE_SUSTAIN_ON 0x20 /* bit 5 = Turn sustaining on. (Env. pts. 3)*/
#define WAVE_ENVELOPES 0x40 /* bit 6 = Enable envelopes - 1 */
#define WAVE_FAST_RELEASE 0x80 /* bit 7 = Shut off immediately after note off */
/* (use the env_rate/env_offs fields). */
/* Linux specific bits */
#define WAVE_VIBRATO 0x00010000 /* The vibrato info is valid */
#define WAVE_TREMOLO 0x00020000 /* The tremolo info is valid */
#define WAVE_SCALE 0x00040000 /* The scaling info is valid */
#define WAVE_FRACTIONS 0x00080000 /* Fraction information is valid */
#define WAVE_ROM 0x40000000 /* For future use */
#define WAVE_MULAW 0x20000000 /* For future use */
/* Other bits must be zeroed */
int len; /* Size of the wave data in bytes */
int loop_start, loop_end; /* Byte offsets from the beginning */
* The base_freq and base_note fields are used when computing the
* playback speed for a note. The base_note defines the tone frequency
* which is heard if the sample is played using the base_freq as the
* The low_note and high_note fields define the minimum and maximum note
* frequencies for which this sample is valid. It is possible to define
* more than one samples for an instrument number at the same time. The
* low_note and high_note fields are used to select the most suitable one.
* The fields base_note, high_note and low_note should contain
* the note frequency multiplied by 1000. For example value for the
int panning; /* -128=left, 127=right */
/* New fields introduced in version 1.99.5 */
/* Envelope. Enabled by mode bit WAVE_ENVELOPES */
unsigned char env_rate[ 6 ]; /* GUS HW ramping rate */
unsigned char env_offset[ 6 ]; /* 255 == 100% */
* The tremolo, vibrato and scale info are not supported yet.
* Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
unsigned char tremolo_sweep;
unsigned char tremolo_rate;
unsigned char tremolo_depth;
unsigned char vibrato_sweep;
unsigned char vibrato_rate;
unsigned char vibrato_depth;
unsigned int scale_factor; /* from 0 to 2048 or 0 to 2 */
char data[1]; /* The waveform data starts here */
short key; /* Use SYSEX_PATCH or MAUI_PATCH here */
#define SYSEX_PATCH _PATCHKEY(0x05)
#define MAUI_PATCH _PATCHKEY(0x06)
short device_no; /* Synthesizer number */
int len; /* Size of the sysex data in bytes */
unsigned char data[1]; /* Sysex data starts here */
* /dev/sequencer input events.
* The data written to the /dev/sequencer is a stream of events. Events
* are records of 4 or 8 bytes. The first byte defines the size.
* Any number of events can be written with a write call. There
* is a set of macros for sending these events. Use these macros if you
* want to maximize portability of your program.
* Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
* (All input events are currently 4 bytes long. Be prepared to support
* 8 byte events also. If you receive any event having first byte >= 128,
* The events are documented at the end of this file.
* Normal events (4 bytes)
* There is also a 8 byte version of most of the 4 byte events. The
* 8 byte one is recommended.
#define SEQ_FMNOTEOFF SEQ_NOTEOFF /* Just old name */
#define SEQ_FMNOTEON SEQ_NOTEON
#define SEQ_WAIT TMR_WAIT_ABS
#define SEQ_FMPGMCHANGE SEQ_PGMCHANGE
#define SEQ_SYNCTIMER TMR_START
#define SEQ_DRUMON 6 /*** OBSOLETE ***/
#define SEQ_DRUMOFF 7 /*** OBSOLETE ***/
#define SEQ_ECHO TMR_ECHO /* For synching programs with output */
#define SEQ_CONTROLLER 10
/*******************************************
* Midi controller numbers
*******************************************
* Controllers 0 to 31 (0x00 to 0x1f) and
* 32 to 63 (0x20 to 0x3f) are continuous
* In the MIDI 1.0 these controllers are sent using
* two messages. Controller numbers 0 to 31 are used
* to send the MSB and the controller numbers 32 to 63
* are for the LSB. Note that just 7 bits are used in MIDI bytes.
#define CTL_BANK_SELECT 0x00
#define CTL_MODWHEEL 0x01
#define CTL_PORTAMENTO_TIME 0x05
#define CTL_DATA_ENTRY 0x06
#define CTL_MAIN_VOLUME 0x07
#define CTL_EXPRESSION 0x0b
#define CTL_GENERAL_PURPOSE1 0x10
#define CTL_GENERAL_PURPOSE2 0x11
#define CTL_GENERAL_PURPOSE3 0x12
#define CTL_GENERAL_PURPOSE4 0x13
/* undefined 0x14 - 0x1f */
/* The controller numbers 0x21 to 0x3f are reserved for the */
/* least significant bytes of the controllers 0x00 to 0x1f. */
/* These controllers are not recognised by the driver. */
/* Controllers 64 to 69 (0x40 to 0x45) are on/off switches. */
/* 0=OFF and 127=ON (intermediate values are possible) */
#define CTL_DAMPER_PEDAL 0x40
#define CTL_SUSTAIN 0x40 /* Alias */
#define CTL_HOLD 0x40 /* Alias */
#define CTL_PORTAMENTO 0x41
#define CTL_SOSTENUTO 0x42
#define CTL_SOFT_PEDAL 0x43
/* undefined 0x46 - 0x4f */
#define CTL_GENERAL_PURPOSE5 0x50
#define CTL_GENERAL_PURPOSE6 0x51
#define CTL_GENERAL_PURPOSE7 0x52
#define CTL_GENERAL_PURPOSE8 0x53
/* undefined 0x54 - 0x5a */
#define CTL_EXT_EFF_DEPTH 0x5b
#define CTL_TREMOLO_DEPTH 0x5c
#define CTL_CHORUS_DEPTH 0x5d
#define CTL_DETUNE_DEPTH 0x5e
#define CTL_CELESTE_DEPTH 0x5e /* Alias for the above one */
#define CTL_PHASER_DEPTH 0x5f
#define CTL_DATA_INCREMENT 0x60
#define CTL_DATA_DECREMENT 0x61
#define CTL_NONREG_PARM_NUM_LSB 0x62
#define CTL_NONREG_PARM_NUM_MSB 0x63
#define CTL_REGIST_PARM_NUM_LSB 0x64
#define CTL_REGIST_PARM_NUM_MSB 0x65
/* undefined 0x66 - 0x78 */
/* reserved 0x79 - 0x7f */
/* Pseudo controllers (not midi compatible) */
#define CTRL_PITCH_BENDER 255
#define CTRL_PITCH_BENDER_RANGE 254
#define CTRL_EXPRESSION 253 /* Obsolete */
#define CTRL_MAIN_VOLUME 252 /* Obsolete */
* Volume mode decides how volumes are used
#define VOL_METHOD_ADAGIO 1
#define VOL_METHOD_LINEAR 2
* Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
* Event codes 0xf0 to 0xfc are reserved for future extensions.
#define SEQ_FULLSIZE 0xfd /* Long events */
* SEQ_FULLSIZE events are used for loading patches/samples to the
* synthesizer devices. These events are passed directly to the driver
* of the associated synthesizer device. There is no limit to the size
* of the extended events. These events are not queued but executed
* immediately when the write() is called (execution can take several
* When a SEQ_FULLSIZE message is written to the device, it must
* be written using exactly one write() call. Other events cannot
* be mixed to the same write.
* For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the
* /dev/sequencer. Don't write other data together with the instrument structure
* Set the key field of the structure to FM_PATCH. The device field is used to
* route the patch to the corresponding device.
* For wave table use struct patch_info. Initialize the key field
#define SEQ_PRIVATE 0xfe /* Low level HW dependent events (8 bytes) */
#define SEQ_EXTENDED 0xff /* Extended events (8 bytes) OBSOLETE */
typedef unsigned char sbi_instr_data[32];
unsigned short key; /* FM_PATCH or OPL3_PATCH */
#define FM_PATCH _PATCHKEY(0x01)
#define OPL3_PATCH _PATCHKEY(0x03)
short device; /* Synth# (0-4) */
int channel; /* Program# to be initialized */
sbi_instr_data operators; /* Register settings for operator cells (.SBI format) */
struct synth_info { /* Read only */
int device; /* 0-N. INITIALIZE BEFORE CALLING */
#define SYNTH_TYPE_SAMPLE 1
#define SYNTH_TYPE_MIDI 2 /* Midi interface */
#define FM_TYPE_ADLIB 0x00
#define FM_TYPE_OPL3 0x01
#define MIDI_TYPE_MPU401 0x401
#define SAMPLE_TYPE_BASIC 0x10
#define SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC
#define SAMPLE_TYPE_WAVEFRONT 0x11
int perc_mode; /* No longer supported */
int nr_drums; /* Obsolete field */
unsigned int capabilities;
#define SYNTH_CAP_PERCMODE 0x00000001 /* No longer used */
#define SYNTH_CAP_OPL3 0x00000002 /* Set if OPL3 supported */
#define SYNTH_CAP_INPUT 0x00000004 /* Input (MIDI) device */