"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "usr/lib/oss/include/sys/soundcard.h" of archive oss-linux-v4.0-1016-x86_64.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2  * Purpose: The C/C++ header file that defines the OSS API.
    3  * Description:
    4  * This header file contains all the declarations required to compile OSS
    5  * programs. The latest version is always installed together with OSS
    6  * use of the latest version is strongly recommended.
    7  *
    8  * {!notice This header file contains many obsolete definitions
    9  * (for compatibility with older applications that still ned them).
   10  * Do not use this file as a reference manual of OSS.
   11  * Please check the OSS Programmer's guide for descriptions
   12  * of the supported API details (http://manuals.opensound.com/developer).}
   13  */
   14 
   15 #ifndef SOUNDCARD_H
   16 #define SOUNDCARD_H
   17 
   18 #define COPYING40 Copyright (C) 4Front Technologies 2000-2006. Released under the BSD license.
   19 
   20 #if defined(__cplusplus)
   21 #define EXTERNC extern "C"
   22 #else
   23 #define EXTERNC extern
   24 #endif /* EXTERN_C_WRAPPERS */
   25 
   26 #define OSS_VERSION	0x040003
   27 
   28 #define SOUND_VERSION	OSS_VERSION
   29 #define OPEN_SOUND_SYSTEM
   30 
   31 #if defined(__hpux) && !defined(_HPUX_SOURCE)
   32 #	error "-D_HPUX_SOURCE must be used when compiling OSS applications"
   33 #endif
   34 
   35 #ifdef __hpux
   36 #include <sys/ioctl.h>
   37 #endif
   38 
   39 #ifdef linux
   40 /* In Linux we need to be prepared for cross compiling */
   41 #include <linux/ioctl.h>
   42 #else
   43 # ifdef __FreeBSD__
   44 #    include <sys/ioccom.h>
   45 # else
   46 #    include <sys/ioctl.h>
   47 # endif
   48 #endif
   49 
   50 #ifndef __SIOWR
   51 #if defined(__hpux) || (defined(_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__INCioctlh) && !defined(__Lynx__))))
   52 
   53 /*
   54  * Make sure the ioctl macros are compatible with the ones already used
   55  * by this operating system.
   56  */
   57 #define	SIOCPARM_MASK	IOCPARM_MASK
   58 #define	SIOC_VOID	IOC_VOID
   59 #define	SIOC_OUT	IOC_OUT
   60 #define	SIOC_IN		IOC_IN
   61 #define	SIOC_INOUT	IOC_INOUT
   62 #define __SIOC_SIZE	_IOC_SIZE
   63 #define __SIOC_DIR	_IOC_DIR
   64 #define __SIOC_NONE	_IOC_NONE
   65 #define __SIOC_READ	_IOC_READ
   66 #define __SIOC_WRITE	_IOC_WRITE
   67 #define	__SIO		_IO
   68 #define	__SIOR		_IOR
   69 #define	__SIOW		_IOW
   70 #define	__SIOWR		_IOWR
   71 #else
   72 
   73 /* #define	SIOCTYPE		(0xff<<8) */
   74 #define	SIOCPARM_MASK	0x1fff	/* parameters must be < 8192 bytes */
   75 #define	SIOC_VOID	0x00000000	/* no parameters */
   76 #define	SIOC_OUT	0x20000000	/* copy out parameters */
   77 #define	SIOC_IN		0x40000000	/* copy in parameters */
   78 #define	SIOC_INOUT	(SIOC_IN|SIOC_OUT)
   79 
   80 #define	__SIO(x,y)	((int)(SIOC_VOID|(x<<8)|y))
   81 #define	__SIOR(x,y,t)	((int)(SIOC_OUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
   82 #define	__SIOW(x,y,t)	((int)(SIOC_IN|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
   83 #define	__SIOWR(x,y,t)	((int)(SIOC_INOUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y))
   84 #define __SIOC_SIZE(x)	((x>>16)&SIOCPARM_MASK)
   85 #define __SIOC_DIR(x)	(x & 0xf0000000)
   86 #define __SIOC_NONE	SIOC_VOID
   87 #define __SIOC_READ	SIOC_OUT
   88 #define __SIOC_WRITE	SIOC_IN
   89 #  endif /* _IOWR */
   90 #endif /* !__SIOWR */
   91 
   92 #define OSS_LONGNAME_SIZE	64
   93 #define OSS_LABEL_SIZE		16
   94 #define OSS_DEVNODE_SIZE	32
   95 typedef char oss_longname_t[OSS_LONGNAME_SIZE];
   96 typedef char oss_label_t[OSS_LABEL_SIZE];
   97 typedef char oss_devnode_t[OSS_DEVNODE_SIZE];
   98 
   99 #ifndef DISABLE_SEQUENCER
  100 /*
  101  ****************************************************************************
  102  * IOCTL Commands for /dev/sequencer and /dev/music (AKA /dev/sequencer2)
  103  *
  104  * Note that this interface is obsolete and no longer developed. New
  105  * applications should use /dev/midi instead.
  106  ****************************************************************************/
  107 #define SNDCTL_SEQ_RESET		__SIO  ('Q', 0)
  108 #define SNDCTL_SEQ_SYNC			__SIO  ('Q', 1)
  109 #define SNDCTL_SYNTH_INFO		__SIOWR('Q', 2, struct synth_info)
  110 #define SNDCTL_SEQ_CTRLRATE		__SIOWR('Q', 3, int)	/* Set/get timer resolution (HZ) */
  111 #define SNDCTL_SEQ_GETOUTCOUNT		__SIOR ('Q', 4, int)
  112 #define SNDCTL_SEQ_GETINCOUNT		__SIOR ('Q', 5, int)
  113 #define SNDCTL_SEQ_PERCMODE		__SIOW ('Q', 6, int)
  114 #define SNDCTL_FM_LOAD_INSTR		__SIOW ('Q', 7, struct sbi_instrument)	/* Obsolete. Don't use!!!!!! */
  115 #define SNDCTL_SEQ_TESTMIDI		__SIOW ('Q', 8, int)
  116 #define SNDCTL_SEQ_RESETSAMPLES		__SIOW ('Q', 9, int)
  117 #define SNDCTL_SEQ_NRSYNTHS		__SIOR ('Q',10, int)
  118 #define SNDCTL_SEQ_NRMIDIS		__SIOR ('Q',11, int)
  119 #define SNDCTL_MIDI_INFO		__SIOWR('Q',12, struct midi_info)	/* OBSOLETE - use SNDCTL_MIDIINFO instead */
  120 #define SNDCTL_SEQ_THRESHOLD		__SIOW ('Q',13, int)
  121 #define SNDCTL_SYNTH_MEMAVL		__SIOWR('Q',14, int)	/* in=dev#, out=memsize */
  122 #define SNDCTL_FM_4OP_ENABLE		__SIOW ('Q',15, int)	/* in=dev# */
  123 #define SNDCTL_SEQ_PANIC		__SIO  ('Q',17)
  124 #define SNDCTL_SEQ_OUTOFBAND		__SIOW ('Q',18, struct seq_event_rec)
  125 #define SNDCTL_SEQ_GETTIME		__SIOR ('Q',19, int)
  126 #define SNDCTL_SYNTH_ID			__SIOWR('Q',20, struct synth_info)
  127 #define SNDCTL_SYNTH_CONTROL		__SIOWR('Q',21, struct synth_control)
  128 #define SNDCTL_SYNTH_REMOVESAMPLE	__SIOWR('Q',22, struct remove_sample)	/* Reserved for future use */
  129 #define SNDCTL_SEQ_TIMING_ENABLE	__SIO  ('Q', 23)	/* Enable incoming MIDI timing messages */
  130 #define SNDCTL_SEQ_ACTSENSE_ENABLE	__SIO  ('Q', 24)	/* Enable incoming active sensing messages */
  131 #define SNDCTL_SEQ_RT_ENABLE		__SIO  ('Q', 25)	/* Enable other incoming realtime messages */
  132 
  133 typedef struct synth_control
  134 {
  135   int devno;			/* Synthesizer # */
  136   char data[4000];		/* Device spesific command/data record */
  137 } synth_control;
  138 
  139 typedef struct remove_sample
  140 {
  141   int devno;			/* Synthesizer # */
  142   int bankno;			/* MIDI bank # (0=General MIDI) */
  143   int instrno;			/* MIDI instrument number */
  144 } remove_sample;
  145 
  146 typedef struct seq_event_rec
  147 {
  148   unsigned char arr[8];
  149 } seq_event_rec;
  150 
  151 #define SNDCTL_TMR_TIMEBASE		__SIOWR('T', 1, int)
  152 #define SNDCTL_TMR_START		__SIO  ('T', 2)
  153 #define SNDCTL_TMR_STOP			__SIO  ('T', 3)
  154 #define SNDCTL_TMR_CONTINUE		__SIO  ('T', 4)
  155 #define SNDCTL_TMR_TEMPO		__SIOWR('T', 5, int)
  156 #define SNDCTL_TMR_SOURCE		__SIOWR('T', 6, int)
  157 #	define TMR_INTERNAL		0x00000001
  158 #	define TMR_EXTERNAL		0x00000002
  159 #		define TMR_MODE_MIDI	0x00000010
  160 #		define TMR_MODE_FSK	0x00000020
  161 #		define TMR_MODE_CLS	0x00000040
  162 #		define TMR_MODE_SMPTE	0x00000080
  163 #define SNDCTL_TMR_METRONOME		__SIOW ('T', 7, int)
  164 #define SNDCTL_TMR_SELECT		__SIOW ('T', 8, int)
  165 
  166 /*
  167  * Sample loading mechanism for internal synthesizers (/dev/sequencer)
  168  * (for the .PAT format).
  169  */
  170 
  171 struct patch_info
  172 {
  173   unsigned short key;		/* Use WAVE_PATCH here */
  174 #define WAVE_PATCH	_PATCHKEY(0x04)
  175 #define GUS_PATCH	WAVE_PATCH
  176 #define WAVEFRONT_PATCH _PATCHKEY(0x06)
  177 
  178   short device_no;		/* Synthesizer number */
  179   short instr_no;		/* Midi pgm# */
  180 
  181   unsigned int mode;
  182 /*
  183  * The least significant byte has the same format than the GUS .PAT
  184  * files
  185  */
  186 #define WAVE_16_BITS	0x01	/* bit 0 = 8 or 16 bit wave data. */
  187 #define WAVE_UNSIGNED	0x02	/* bit 1 = Signed - Unsigned data. */
  188 #define WAVE_LOOPING	0x04	/* bit 2 = looping enabled-1. */
  189 #define WAVE_BIDIR_LOOP	0x08	/* bit 3 = Set is bidirectional looping. */
  190 #define WAVE_LOOP_BACK	0x10	/* bit 4 = Set is looping backward. */
  191 #define WAVE_SUSTAIN_ON	0x20	/* bit 5 = Turn sustaining on. (Env. pts. 3) */
  192 #define WAVE_ENVELOPES	0x40	/* bit 6 = Enable envelopes - 1 */
  193 #define WAVE_FAST_RELEASE 0x80	/* bit 7 = Shut off immediately after note off */
  194   /*  (use the env_rate/env_offs fields). */
  195 /* Linux specific bits */
  196 #define WAVE_VIBRATO	0x00010000	/* The vibrato info is valid */
  197 #define WAVE_TREMOLO	0x00020000	/* The tremolo info is valid */
  198 #define WAVE_SCALE	0x00040000	/* The scaling info is valid */
  199 #define WAVE_FRACTIONS	0x00080000	/* Fraction information is valid */
  200 /* Reserved bits */
  201 #define WAVE_ROM	0x40000000	/* For future use */
  202 #define WAVE_MULAW	0x20000000	/* For future use */
  203 /* Other bits must be zeroed */
  204 
  205   int len;			/* Size of the wave data in bytes */
  206   int loop_start, loop_end;	/* Byte offsets from the beginning */
  207 
  208 /*
  209  * The base_freq and base_note fields are used when computing the
  210  * playback speed for a note. The base_note defines the tone frequency
  211  * which is heard if the sample is played using the base_freq as the
  212  * playback speed.
  213  *
  214  * The low_note and high_note fields define the minimum and maximum note
  215  * frequencies for which this sample is valid. It is possible to define
  216  * more than one samples for an instrument number at the same time. The
  217  * low_note and high_note fields are used to select the most suitable one.
  218  *
  219  * The fields base_note, high_note and low_note should contain
  220  * the note frequency multiplied by 1000. For example value for the
  221  * middle A is 440*1000.
  222  */
  223 
  224   unsigned int base_freq;
  225   unsigned int base_note;
  226   unsigned int high_note;
  227   unsigned int low_note;
  228   int panning;			/* -128=left, 127=right */
  229   int detuning;
  230 
  231   /* Envelope. Enabled by mode bit WAVE_ENVELOPES  */
  232   unsigned char env_rate[6];	/* GUS HW ramping rate */
  233   unsigned char env_offset[6];	/* 255 == 100% */
  234 
  235   /*
  236    * The tremolo, vibrato and scale info are not supported yet.
  237    * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or
  238    * WAVE_SCALE
  239    */
  240 
  241   unsigned char tremolo_sweep;
  242   unsigned char tremolo_rate;
  243   unsigned char tremolo_depth;
  244 
  245   unsigned char vibrato_sweep;
  246   unsigned char vibrato_rate;
  247   unsigned char vibrato_depth;
  248 
  249   int scale_frequency;
  250   unsigned int scale_factor;	/* from 0 to 2048 or 0 to 2 */
  251 
  252   int volume;
  253   int fractions;
  254   int reserved1;
  255   int spare[2];
  256   char data[1];			/* The waveform data starts here */
  257 };
  258 
  259 struct sysex_info
  260 {
  261   short key;			/* Use SYSEX_PATCH or MAUI_PATCH here */
  262 #define SYSEX_PATCH	_PATCHKEY(0x05)
  263 #define MAUI_PATCH	_PATCHKEY(0x06)
  264   short device_no;		/* Synthesizer number */
  265   int len;			/* Size of the sysex data in bytes */
  266   unsigned char data[1];	/* Sysex data starts here */
  267 };
  268 
  269 /*
  270  * /dev/sequencer input events.
  271  *
  272  * The data written to the /dev/sequencer is a stream of events. Events
  273  * are records of 4 or 8 bytes. The first byte defines the size.
  274  * Any number of events can be written with a write call. There
  275  * is a set of macros for sending these events. Use these macros if you
  276  * want to maximize portability of your program.
  277  *
  278  * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events.
  279  * (All input events are currently 4 bytes long. Be prepared to support
  280  * 8 byte events also. If you receive any event having first byte >= 128,
  281  * it's a 8 byte event.
  282  *
  283  * The events are documented at the end of this file.
  284  *
  285  * Normal events (4 bytes)
  286  * There is also a 8 byte version of most of the 4 byte events. The
  287  * 8 byte one is recommended.
  288  *
  289  * NOTE! All 4 byte events are now obsolete. Applications should not write
  290  *       them. However 4 byte events are still used as inputs from
  291  *       /dev/sequencer (/dev/music uses only 8 byte ones).
  292  */
  293 #define SEQ_NOTEOFF		0
  294 #define SEQ_FMNOTEOFF		SEQ_NOTEOFF	/* Just old name */
  295 #define SEQ_NOTEON		1
  296 #define	SEQ_FMNOTEON		SEQ_NOTEON
  297 #define SEQ_WAIT		TMR_WAIT_ABS
  298 #define SEQ_PGMCHANGE		3
  299 #define SEQ_FMPGMCHANGE		SEQ_PGMCHANGE
  300 #define SEQ_SYNCTIMER		TMR_START
  301 #define SEQ_MIDIPUTC		5
  302 #define SEQ_DRUMON		6		/*** OBSOLETE ***/
  303 #define SEQ_DRUMOFF		7		/*** OBSOLETE ***/
  304 #define SEQ_ECHO		TMR_ECHO	/* For synching programs with output */
  305 #define SEQ_AFTERTOUCH		9
  306 #define SEQ_CONTROLLER		10
  307 #define SEQ_BALANCE		11
  308 #define SEQ_VOLMODE             12
  309 
  310 /************************************
  311  *	Midi controller numbers	    *
  312  ************************************/
  313 /*
  314  * Controllers 0 to 31 (0x00 to 0x1f) and
  315  * 32 to 63 (0x20 to 0x3f) are continuous
  316  * controllers.
  317  * In the MIDI 1.0 these controllers are sent using
  318  * two messages. Controller numbers 0 to 31 are used
  319  * to send the MSB and the controller numbers 32 to 63
  320  * are for the LSB. Note that just 7 bits are used in MIDI bytes.
  321  */
  322 
  323 #define	   CTL_BANK_SELECT		0x00
  324 #define	   CTL_MODWHEEL			0x01
  325 #define    CTL_BREATH			0x02
  326 /*		undefined		0x03 */
  327 #define    CTL_FOOT			0x04
  328 #define    CTL_PORTAMENTO_TIME		0x05
  329 #define    CTL_DATA_ENTRY		0x06
  330 #define    CTL_MAIN_VOLUME		0x07
  331 #define    CTL_BALANCE			0x08
  332 /*		undefined		0x09 */
  333 #define    CTL_PAN			0x0a
  334 #define    CTL_EXPRESSION		0x0b
  335 /*		undefined		0x0c */
  336 /*		undefined		0x0d */
  337 /*		undefined		0x0e */
  338 /*		undefined		0x0f */
  339 #define    CTL_GENERAL_PURPOSE1		0x10
  340 #define    CTL_GENERAL_PURPOSE2		0x11
  341 #define    CTL_GENERAL_PURPOSE3		0x12
  342 #define    CTL_GENERAL_PURPOSE4		0x13
  343 /*		undefined		0x14 - 0x1f */
  344 
  345 /*		undefined		0x20 */
  346 /* The controller numbers 0x21 to 0x3f are reserved for the */
  347 /* least significant bytes of the controllers 0x00 to 0x1f. */
  348 /* These controllers are not recognised by the driver. */
  349 
  350 /* Controllers 64 to 69 (0x40 to 0x45) are on/off switches. */
  351 /* 0=OFF and 127=ON (intermediate values are possible) */
  352 #define    CTL_DAMPER_PEDAL		0x40
  353 #define    CTL_SUSTAIN			0x40	/* Alias */
  354 #define    CTL_HOLD			0x40	/* Alias */
  355 #define    CTL_PORTAMENTO		0x41
  356 #define    CTL_SOSTENUTO		0x42
  357 #define    CTL_SOFT_PEDAL		0x43
  358 /*		undefined		0x44 */
  359 #define    CTL_HOLD2			0x45
  360 /*		undefined		0x46 - 0x4f */
  361 
  362 #define    CTL_GENERAL_PURPOSE5		0x50
  363 #define    CTL_GENERAL_PURPOSE6		0x51
  364 #define    CTL_GENERAL_PURPOSE7		0x52
  365 #define    CTL_GENERAL_PURPOSE8		0x53
  366 /*		undefined		0x54 - 0x5a */
  367 #define    CTL_EXT_EFF_DEPTH		0x5b
  368 #define    CTL_TREMOLO_DEPTH		0x5c
  369 #define    CTL_CHORUS_DEPTH		0x5d
  370 #define    CTL_DETUNE_DEPTH		0x5e
  371 #define    CTL_CELESTE_DEPTH		0x5e	/* Alias for the above one */
  372 #define    CTL_PHASER_DEPTH		0x5f
  373 #define    CTL_DATA_INCREMENT		0x60
  374 #define    CTL_DATA_DECREMENT		0x61
  375 #define    CTL_NONREG_PARM_NUM_LSB	0x62
  376 #define    CTL_NONREG_PARM_NUM_MSB	0x63
  377 #define    CTL_REGIST_PARM_NUM_LSB	0x64
  378 #define    CTL_REGIST_PARM_NUM_MSB	0x65
  379 /*		undefined		0x66 - 0x78 */
  380 /*		reserved		0x79 - 0x7f */
  381 
  382 /* Pseudo controllers (not midi compatible) */
  383 #define    CTRL_PITCH_BENDER		255
  384 #define    CTRL_PITCH_BENDER_RANGE	254
  385 #define    CTRL_EXPRESSION		253	/* Obsolete */
  386 #define    CTRL_MAIN_VOLUME		252	/* Obsolete */
  387 
  388 /*
  389  * Volume mode defines how volumes are used
  390  */
  391 
  392 #define VOL_METHOD_ADAGIO	1
  393 #define VOL_METHOD_LINEAR	2
  394 
  395 /*
  396  * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
  397  *	 input events.
  398  */
  399 
  400 /*
  401  * Event codes 0xf0 to 0xfc are reserved for future extensions.
  402  */
  403 
  404 #define SEQ_FULLSIZE		0xfd	/* Long events */
  405 /*
  406  * SEQ_FULLSIZE events are used for loading patches/samples to the
  407  * synthesizer devices. These events are passed directly to the driver
  408  * of the associated synthesizer device. There is no limit to the size
  409  * of the extended events. These events are not queued but executed
  410  * immediately when the write() is called (execution can take several
  411  * seconds of time).
  412  *
  413  * When a SEQ_FULLSIZE message is written to the device, it must
  414  * be written using exactly one write() call. Other events cannot
  415  * be mixed to the same write.
  416  *
  417  * For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the
  418  * /dev/sequencer. Don't write other data together with the instrument structure
  419  * Set the key field of the structure to FM_PATCH. The device field is used to
  420  * route the patch to the corresponding device.
  421  *
  422  * For wave table use struct patch_info. Initialize the key field
  423  * to WAVE_PATCH.
  424  */
  425 #define SEQ_PRIVATE		0xfe	/* Low level HW dependent events (8 bytes) */
  426 #define SEQ_EXTENDED		0xff	/* Extended events (8 bytes) OBSOLETE */
  427 
  428 /*
  429  * Record for FM patches
  430  */
  431 
  432 typedef unsigned char sbi_instr_data[32];
  433 
  434 struct sbi_instrument
  435 {
  436   unsigned short key;		/* FM_PATCH or OPL3_PATCH */
  437 #define FM_PATCH	_PATCHKEY(0x01)
  438 #define OPL3_PATCH	_PATCHKEY(0x03)
  439   short device;			/*  Synth# (0-4)    */
  440   int channel;			/*  Program# to be initialized  */
  441   sbi_instr_data operators;	/*  Register settings for operator cells (.SBI format)  */
  442 };
  443 
  444 struct synth_info
  445 {				/* Read only */
  446   char name[30];
  447   int device;			/* 0-N. INITIALIZE BEFORE CALLING */
  448   int synth_type;
  449 #define SYNTH_TYPE_FM			0
  450 #define SYNTH_TYPE_SAMPLE		1
  451 #define SYNTH_TYPE_MIDI			2	/* Midi interface */
  452 
  453   int synth_subtype;
  454 #define FM_TYPE_ADLIB			0x00
  455 #define FM_TYPE_OPL3			0x01
  456 #define MIDI_TYPE_MPU401		0x401
  457 
  458 #define SAMPLE_TYPE_BASIC		0x10
  459 #define SAMPLE_TYPE_GUS			SAMPLE_TYPE_BASIC
  460 #define SAMPLE_TYPE_WAVEFRONT   	0x11
  461 
  462   int perc_mode;		/* No longer supported */
  463   int nr_voices;
  464   int nr_drums;			/* Obsolete field */
  465   int instr_bank_size;
  466   unsigned int capabilities;
  467 #define SYNTH_CAP_PERCMODE	0x00000001	/* No longer used */
  468 #define SYNTH_CAP_OPL3		0x00000002	/* Set if OPL3 supported */
  469 #define SYNTH_CAP_INPUT		0x00000004	/* Input (MIDI) device */
  470   int dummies[19];		/* Reserve space */
  471 };
  472 
  473 struct sound_timer_info
  474 {
  475   char name[32];
  476   int caps;
  477 };
  478 
  479 struct midi_info		/* OBSOLETE */
  480 {
  481   char name[30];
  482   int device;			/* 0-N. INITIALIZE BEFORE CALLING */
  483   unsigned int capabilities;	/* To be defined later */
  484   int dev_type;
  485   int dummies[18];		/* Reserve space */
  486 };
  487 
  488 /*
  489  * Level 2 event types for /dev/sequencer
  490  */
  491 
  492 /*
  493  * The 4 most significant bits of byte 0 specify the class of
  494  * the event:
  495  *
  496  *	0x8X = system level events,
  497  *	0x9X = device/port specific events, event[1] = device/port,
  498  *		The last 4 bits give the subtype:
  499  *			0x02	= Channel event (event[3] = chn).
  500  *			0x01	= note event (event[4] = note).
  501  *			(0x01 is not used alone but always with bit 0x02).
  502  *	       event[2] = MIDI message code (0x80=note off etc.)
  503  *
  504  */
  505 
  506 #define EV_SEQ_LOCAL		0x80
  507 #define EV_TIMING		0x81
  508 #define EV_CHN_COMMON		0x92
  509 #define EV_CHN_VOICE		0x93
  510 #define EV_SYSEX		0x94
  511 #define EV_SYSTEM		0x95	/* MIDI system and real time messages (input only) */
  512 /*
  513  * Event types 200 to 220 are reserved for application use.
  514  * These numbers will not be used by the driver.
  515  */
  516 
  517 /*
  518  * Events for event type EV_CHN_VOICE
  519  */
  520 
  521 #define MIDI_NOTEOFF		0x80
  522 #define MIDI_NOTEON		0x90
  523 #define MIDI_KEY_PRESSURE	0xA0
  524 
  525 /*
  526  * Events for event type EV_CHN_COMMON
  527  */
  528 
  529 #define MIDI_CTL_CHANGE		0xB0
  530 #define MIDI_PGM_CHANGE		0xC0
  531 #define MIDI_CHN_PRESSURE	0xD0
  532 #define MIDI_PITCH_BEND		0xE0
  533 
  534 #define MIDI_SYSTEM_PREFIX	0xF0
  535 
  536 /*
  537  * Timer event types
  538  */
  539 #define TMR_WAIT_REL		1	/* Time relative to the prev time */
  540 #define TMR_WAIT_ABS		2	/* Absolute time since TMR_START */
  541 #define TMR_STOP		3
  542 #define TMR_START		4
  543 #define TMR_CONTINUE		5
  544 #define TMR_TEMPO		6
  545 #define TMR_ECHO		8
  546 #define TMR_CLOCK		9	/* MIDI clock */
  547 #define TMR_SPP			10	/* Song position pointer */
  548 #define TMR_TIMESIG		11	/* Time signature */
  549 
  550 /*
  551  *	Local event types
  552  */
  553 #define LOCL_STARTAUDIO		1
  554 #define LOCL_STARTAUDIO2	2
  555 #define LOCL_STARTAUDIO3	3
  556 #define LOCL_STARTAUDIO4	4
  557 
  558 #if (!defined(__KERNEL__) && !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL)) || defined(USE_SEQ_MACROS)
  559 /*
  560  * Some convenience macros to simplify programming of the
  561  * /dev/sequencer interface
  562  *
  563  * These macros define the API which should be used when possible.
  564  */
  565 #define SEQ_DECLAREBUF()		SEQ_USE_EXTBUF()
  566 
  567 void seqbuf_dump (void);	/* This function must be provided by programs */
  568 
  569 EXTERNC int OSS_init (int seqfd, int buflen);
  570 EXTERNC void OSS_seqbuf_dump (int fd, unsigned char *buf, int buflen);
  571 EXTERNC void OSS_seq_advbuf (int len, int fd, unsigned char *buf, int buflen);
  572 EXTERNC void OSS_seq_needbuf (int len, int fd, unsigned char *buf,
  573 			      int buflen);
  574 EXTERNC void OSS_patch_caching (int dev, int chn, int patch, int fd,
  575 				unsigned char *buf, int buflen);
  576 EXTERNC void OSS_drum_caching (int dev, int chn, int patch, int fd,
  577 			       unsigned char *buf, int buflen);
  578 EXTERNC void OSS_write_patch (int fd, unsigned char *buf, int len);
  579 EXTERNC int OSS_write_patch2 (int fd, unsigned char *buf, int len);
  580 
  581 #define SEQ_PM_DEFINES int __foo_bar___
  582 #ifdef OSSLIB
  583 #  define SEQ_USE_EXTBUF() \
  584 		EXTERNC unsigned char *_seqbuf; \
  585 		EXTERNC int _seqbuflen;EXTERNC int _seqbufptr
  586 #  define SEQ_DEFINEBUF(len) SEQ_USE_EXTBUF();static int _requested_seqbuflen=len
  587 #  define _SEQ_ADVBUF(len) OSS_seq_advbuf(len, seqfd, _seqbuf, _seqbuflen)
  588 #  define _SEQ_NEEDBUF(len) OSS_seq_needbuf(len, seqfd, _seqbuf, _seqbuflen)
  589 #  define SEQ_DUMPBUF() OSS_seqbuf_dump(seqfd, _seqbuf, _seqbuflen)
  590 
  591 #  define SEQ_LOAD_GMINSTR(dev, instr) \
  592 		OSS_patch_caching(dev, -1, instr, seqfd, _seqbuf, _seqbuflen)
  593 #  define SEQ_LOAD_GMDRUM(dev, drum) \
  594 		OSS_drum_caching(dev, -1, drum, seqfd, _seqbuf, _seqbuflen)
  595 #else /* !OSSLIB */
  596 
  597 #  define SEQ_LOAD_GMINSTR(dev, instr)
  598 #  define SEQ_LOAD_GMDRUM(dev, drum)
  599 
  600 #  define SEQ_USE_EXTBUF() \
  601 		EXTERNC unsigned char _seqbuf[]; \
  602 		EXTERNC int _seqbuflen;EXTERNC int _seqbufptr
  603 
  604 #ifndef USE_SIMPLE_MACROS
  605 /* Sample seqbuf_dump() implementation:
  606  *
  607  *	SEQ_DEFINEBUF (2048);	-- Defines a buffer for 2048 bytes
  608  *
  609  *	int seqfd;		-- The file descriptor for /dev/sequencer.
  610  *
  611  *	void
  612  *	seqbuf_dump ()
  613  *	{
  614  *	  if (_seqbufptr)
  615  *	    if (write (seqfd, _seqbuf, _seqbufptr) == -1)
  616  *	      {
  617  *		perror ("write /dev/sequencer");
  618  *		exit (-1);
  619  *	      }
  620  *	  _seqbufptr = 0;
  621  *	}
  622  */
  623 
  624 #define SEQ_DEFINEBUF(len) \
  625 	unsigned char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0
  626 #define _SEQ_NEEDBUF(len) \
  627 	if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump()
  628 #define _SEQ_ADVBUF(len) _seqbufptr += len
  629 #define SEQ_DUMPBUF seqbuf_dump
  630 #else
  631 /*
  632  * This variation of the sequencer macros is used just to format one event
  633  * using fixed buffer.
  634  *
  635  * The program using the macro library must define the following macros before
  636  * using this library.
  637  *
  638  * #define _seqbuf 		 name of the buffer (unsigned char[])
  639  * #define _SEQ_ADVBUF(len)	 If the applic needs to know the exact
  640  *				 size of the event, this macro can be used.
  641  *				 Otherwise this must be defined as empty.
  642  * #define _seqbufptr		 Define the name of index variable or 0 if
  643  *				 not required.
  644  */
  645 #define _SEQ_NEEDBUF(len)	/* empty */
  646 #endif
  647 #endif /* !OSSLIB */
  648 
  649 #define SEQ_VOLUME_MODE(dev, mode) \
  650 				{_SEQ_NEEDBUF(8);\
  651 				_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
  652 				_seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\
  653 				_seqbuf[_seqbufptr+2] = (dev);\
  654 				_seqbuf[_seqbufptr+3] = (mode);\
  655 				_seqbuf[_seqbufptr+4] = 0;\
  656 				_seqbuf[_seqbufptr+5] = 0;\
  657 				_seqbuf[_seqbufptr+6] = 0;\
  658 				_seqbuf[_seqbufptr+7] = 0;\
  659 				_SEQ_ADVBUF(8);}
  660 
  661 /*
  662  * Midi voice messages
  663  */
  664 
  665 #define _CHN_VOICE(dev, event, chn, note, parm) \
  666 				{_SEQ_NEEDBUF(8);\
  667 				_seqbuf[_seqbufptr] = EV_CHN_VOICE;\
  668 				_seqbuf[_seqbufptr+1] = (dev);\
  669 				_seqbuf[_seqbufptr+2] = (event);\
  670 				_seqbuf[_seqbufptr+3] = (chn);\
  671 				_seqbuf[_seqbufptr+4] = (note);\
  672 				_seqbuf[_seqbufptr+5] = (parm);\
  673 				_seqbuf[_seqbufptr+6] = (0);\
  674 				_seqbuf[_seqbufptr+7] = 0;\
  675 				_SEQ_ADVBUF(8);}
  676 
  677 #define SEQ_START_NOTE(dev, chn, note, vol) \
  678 			_CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol)
  679 
  680 #define SEQ_STOP_NOTE(dev, chn, note, vol) \
  681 			_CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol)
  682 
  683 #define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \
  684 			_CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure)
  685 
  686 /*
  687  * Midi channel messages
  688  */
  689 
  690 #define _CHN_COMMON(dev, event, chn, p1, p2, w14) \
  691 				{_SEQ_NEEDBUF(8);\
  692 				_seqbuf[_seqbufptr] = EV_CHN_COMMON;\
  693 				_seqbuf[_seqbufptr+1] = (dev);\
  694 				_seqbuf[_seqbufptr+2] = (event);\
  695 				_seqbuf[_seqbufptr+3] = (chn);\
  696 				_seqbuf[_seqbufptr+4] = (p1);\
  697 				_seqbuf[_seqbufptr+5] = (p2);\
  698 				*(short *)&_seqbuf[_seqbufptr+6] = (w14);\
  699 				_SEQ_ADVBUF(8);}
  700 /*
  701  * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits
  702  * sending any MIDI bytes but it's absolutely not possible. Trying to do
  703  * so _will_ cause problems with MPU401 intelligent mode).
  704  *
  705  * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be
  706  * sent by calling SEQ_SYSEX() several times (there must be no other events
  707  * between them). First sysex fragment must have 0xf0 in the first byte
  708  * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte
  709  * between these sysex start and end markers cannot be larger than 0x7f. Also
  710  * lengths of each fragments (except the last one) must be 6.
  711  *
  712  * Breaking the above rules may work with some MIDI ports but is likely to
  713  * cause fatal problems with some other devices (such as MPU401).
  714  */
  715 #define SEQ_SYSEX(dev, buf, len) \
  716 				{int ii, ll=(len); \
  717 				 unsigned char *bufp=buf;\
  718 				 if (ll>6)ll=6;\
  719 				_SEQ_NEEDBUF(8);\
  720 				_seqbuf[_seqbufptr] = EV_SYSEX;\
  721 				_seqbuf[_seqbufptr+1] = (dev);\
  722 				for(ii=0;ii<ll;ii++)\
  723 				   _seqbuf[_seqbufptr+ii+2] = bufp[ii];\
  724 				for(ii=ll;ii<6;ii++)\
  725 				   _seqbuf[_seqbufptr+ii+2] = 0xff;\
  726 				_SEQ_ADVBUF(8);}
  727 
  728 #define SEQ_CHN_PRESSURE(dev, chn, pressure) \
  729 		_CHN_COMMON(dev, MIDI_CHN_PRESSURE, chn, pressure, 0, 0)
  730 
  731 #define SEQ_SET_PATCH SEQ_PGM_CHANGE
  732 #ifdef OSSLIB
  733 #   define SEQ_PGM_CHANGE(dev, chn, patch) \
  734 		{OSS_patch_caching(dev, chn, patch, seqfd, _seqbuf, _seqbuflen); \
  735 		 _CHN_COMMON(dev, MIDI_PGM_CHANGE, chn, patch, 0, 0);}
  736 #else
  737 #   define SEQ_PGM_CHANGE(dev, chn, patch) \
  738 		_CHN_COMMON(dev, MIDI_PGM_CHANGE, chn, patch, 0, 0)
  739 #endif
  740 
  741 #define SEQ_CONTROL(dev, chn, controller, value) \
  742 		_CHN_COMMON(dev, MIDI_CTL_CHANGE, chn, controller, 0, value)
  743 
  744 #define SEQ_BENDER(dev, chn, value) \
  745 		_CHN_COMMON(dev, MIDI_PITCH_BEND, chn, 0, 0, value)
  746 
  747 #define SEQ_V2_X_CONTROL(dev, voice, controller, value)	\
  748 				{_SEQ_NEEDBUF(8);\
  749 				_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
  750 				_seqbuf[_seqbufptr+1] = SEQ_CONTROLLER;\
  751 				_seqbuf[_seqbufptr+2] = (dev);\
  752 				_seqbuf[_seqbufptr+3] = (voice);\
  753 				_seqbuf[_seqbufptr+4] = (controller);\
  754 				_seqbuf[_seqbufptr+5] = ((value)&0xff);\
  755 				_seqbuf[_seqbufptr+6] = ((value>>8)&0xff);\
  756 				_seqbuf[_seqbufptr+7] = 0;\
  757 				_SEQ_ADVBUF(8);}
  758 /*
  759  * The following 5 macros are incorrectly implemented and obsolete.
  760  * Use SEQ_BENDER and SEQ_CONTROL (with proper controller) instead.
  761  */
  762 #define SEQ_PITCHBEND(dev, voice, value) \
  763 	SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER, value)
  764 #define SEQ_BENDER_RANGE(dev, voice, value) \
  765 	SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value)
  766 #define SEQ_EXPRESSION(dev, voice, value) \
  767 	SEQ_CONTROL(dev, voice, CTL_EXPRESSION, value*128)
  768 #define SEQ_MAIN_VOLUME(dev, voice, value) \
  769 	SEQ_CONTROL(dev, voice, CTL_MAIN_VOLUME, (value*16383)/100)
  770 #define SEQ_PANNING(dev, voice, pos) \
  771 	SEQ_CONTROL(dev, voice, CTL_PAN, (pos+128) / 2)
  772 
  773 /*
  774  * Timing and syncronization macros
  775  */
  776 
  777 #define _TIMER_EVENT(ev, parm)	{_SEQ_NEEDBUF(8);\
  778 			 	_seqbuf[_seqbufptr+0] = EV_TIMING; \
  779 			 	_seqbuf[_seqbufptr+1] = (ev); \
  780 				_seqbuf[_seqbufptr+2] = 0;\
  781 				_seqbuf[_seqbufptr+3] = 0;\
  782 			 	*(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \
  783 				_SEQ_ADVBUF(8);}
  784 
  785 #define SEQ_START_TIMER()		_TIMER_EVENT(TMR_START, 0)
  786 #define SEQ_STOP_TIMER()		_TIMER_EVENT(TMR_STOP, 0)
  787 #define SEQ_CONTINUE_TIMER()		_TIMER_EVENT(TMR_CONTINUE, 0)
  788 #define SEQ_WAIT_TIME(ticks)		_TIMER_EVENT(TMR_WAIT_ABS, ticks)
  789 #define SEQ_DELTA_TIME(ticks)		_TIMER_EVENT(TMR_WAIT_REL, ticks)
  790 #define SEQ_ECHO_BACK(key)		_TIMER_EVENT(TMR_ECHO, key)
  791 #define SEQ_SET_TEMPO(value)		_TIMER_EVENT(TMR_TEMPO, value)
  792 #define SEQ_SONGPOS(pos)		_TIMER_EVENT(TMR_SPP, pos)
  793 #define SEQ_TIME_SIGNATURE(sig)		_TIMER_EVENT(TMR_TIMESIG, sig)
  794 
  795 /*
  796  * Local control events
  797  */
  798 
  799 #define _LOCAL_EVENT(ev, parm)		{_SEQ_NEEDBUF(8);\
  800 				 	_seqbuf[_seqbufptr+0] = EV_SEQ_LOCAL; \
  801 				 	_seqbuf[_seqbufptr+1] = (ev); \
  802 					_seqbuf[_seqbufptr+2] = 0;\
  803 					_seqbuf[_seqbufptr+3] = 0;\
  804 				 	*(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \
  805 					_SEQ_ADVBUF(8);}
  806 
  807 #define SEQ_PLAYAUDIO(devmask)		_LOCAL_EVENT(LOCL_STARTAUDIO, devmask)
  808 #define SEQ_PLAYAUDIO2(devmask)		_LOCAL_EVENT(LOCL_STARTAUDIO2, devmask)
  809 #define SEQ_PLAYAUDIO3(devmask)		_LOCAL_EVENT(LOCL_STARTAUDIO3, devmask)
  810 #define SEQ_PLAYAUDIO4(devmask)		_LOCAL_EVENT(LOCL_STARTAUDIO4, devmask)
  811 /*
  812  * Events for the level 1 interface only
  813  */
  814 
  815 #define SEQ_MIDIOUT(device, byte)	{_SEQ_NEEDBUF(4);\
  816 					_seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\
  817 					_seqbuf[_seqbufptr+1] = (byte);\
  818 					_seqbuf[_seqbufptr+2] = (device);\
  819 					_seqbuf[_seqbufptr+3] = 0;\
  820 					_SEQ_ADVBUF(4);}
  821 
  822 /*
  823  * Patch loading.
  824  */
  825 #ifdef OSSLIB
  826 #   define SEQ_WRPATCH(patchx, len) \
  827 		OSS_write_patch(seqfd, (char*)(patchx), len)
  828 #   define SEQ_WRPATCH2(patchx, len) \
  829 		OSS_write_patch2(seqfd, (char*)(patchx), len)
  830 #else
  831 #   define SEQ_WRPATCH(patchx, len) \
  832 		{if (_seqbufptr) SEQ_DUMPBUF();\
  833 		 if (write(seqfd, (char*)(patchx), len)==-1) \
  834 		    perror("Write patch: /dev/sequencer");}
  835 #   define SEQ_WRPATCH2(patchx, len) \
  836 		(SEQ_DUMPBUF(), write(seqfd, (char*)(patchx), len))
  837 #endif
  838 
  839 #endif
  840 #endif /* ifndef DISABLE_SEQUENCER */
  841 
  842 /*
  843  ****************************************************************************
  844  * ioctl commands for the /dev/midi##
  845  ****************************************************************************/
  846 #define SNDCTL_MIDI_PRETIME	__SIOWR('m', 0, int)
  847 
  848 #if 0
  849 /*
  850  * The SNDCTL_MIDI_MPUMODE and SNDCTL_MIDI_MPUCMD calls
  851  * are completely obsolete. The hardware device (MPU-401 "intelligent mode"
  852  * and compatibles) has disappeared from the market 10 years ago so there
  853  * is no need for this stuff. The MPU-401 "UART" mode devices don't support
  854  * this stuff.
  855  */
  856 typedef struct
  857 {
  858   unsigned char cmd;
  859   char nr_args, nr_returns;
  860   unsigned char data[30];
  861 } mpu_command_rec;
  862 
  863 #define SNDCTL_MIDI_MPUMODE	__SIOWR('m', 1, int)
  864 #define SNDCTL_MIDI_MPUCMD	__SIOWR('m', 2, mpu_command_rec)
  865 #endif
  866 
  867 /*
  868  * SNDCTL_MIDI_MTCINPUT turns on a mode where OSS automatically inserts
  869  * MTC quarter frame messages (F1 xx) to the input.
  870  * The argument is the MTC mode:
  871  *
  872  * 	-1 = Turn MTC messages OFF (default)
  873  *	24 = 24 FPS
  874  *	25 = 25 FPS
  875  *	29 = 30 FPS drop frame
  876  *	30 = 30 FPS
  877  *
  878  * Note that 25 FPS mode is probably the only mode that is supported. Other
  879  * modes may be supported in the future versions of OSS, 25 FPS is handy
  880  * because it generates 25*4=100 quarter frame messages per second which
  881  * matches the usual 100 HZ system timer rate).
  882  *
  883  * The quarter frame timer will be reset to 0:00:00:00.0 at the moment this
  884  * ioctl is made.
  885  */
  886 #define SNDCTL_MIDI_MTCINPUT	__SIOWR('m', 3, int)
  887 
  888 /*
  889  * MTC/SMPTE time code record (for future use)
  890  */
  891 typedef struct
  892 {
  893   unsigned char hours, minutes, seconds, frames, qframes;
  894   char direction;
  895 #define MTC_DIR_STOPPED		 0
  896 #define MTC_DIR_FORWARD		 1
  897 #define MTC_DIR_BACKWARD	-1
  898   unsigned char time_code_type;
  899   unsigned int flags;
  900 } oss_mtc_data_t;
  901 
  902 #define SNDCTL_MIDI_SETMODE	__SIOWR('m', 6, int)
  903 #	define MIDI_MODE_TRADITIONAL	0
  904 #	define MIDI_MODE_TIMED		1	/* Input times are in MIDI ticks */
  905 #	define MIDI_MODE_TIMED_ABS  	2	/* Input times are absolute (usecs) */
  906 
  907 /*
  908  * Packet header for MIDI_MODE_TIMED and MIDI_MODE_TIMED_ABS
  909  */
  910 typedef unsigned long long oss_midi_time_t;	/* Variable type for MIDI time (clock ticks) */
  911 
  912 typedef struct
  913 {
  914   int magic;			/* Initialize to MIDI_HDR_MAGIC */
  915 #define MIDI_HDR_MAGIC	-1
  916   unsigned short event_type;
  917 #define MIDI_EV_WRITE			0	/* Write or read (with payload) */
  918 #define MIDI_EV_TEMPO			1
  919 #define MIDI_EV_ECHO			2
  920 #define MIDI_EV_START			3
  921 #define MIDI_EV_STOP			4
  922 #define MIDI_EV_CONTINUE		5
  923 #define MIDI_EV_XPRESSWRITE		6
  924 #define MIDI_EV_TIMEBASE		7
  925 #define MIDI_EV_DEVCTL			8	/* Device control read/write */
  926   unsigned short options;
  927 #define MIDI_OPT_NONE			0x0000
  928 #define MIDI_OPT_TIMED			0x0001
  929 #define MIDI_OPT_CONTINUATION		0x0002
  930 #define MIDI_OPT_USECTIME		0x0004	/* Time is absolute (in usecs) */
  931 #define MIDI_OPT_BUSY			0x0008	/* Reserved for internal use */
  932   oss_midi_time_t time;
  933   int parm;
  934   int filler[3];		/* Fur future expansion - init to zeros */
  935 } midi_packet_header_t;
  936 /*
  937  * MIDI_PAYLOAD_SIZE is the maximum size of one MIDI input chunk. It must be
  938  * less (or equal) than 1024 which is the read size recommended in the
  939  * documentation. TODO: Explain this better.
  940  */
  941 #define MIDI_PAYLOAD_SIZE		1000
  942 
  943 typedef struct
  944 {
  945   midi_packet_header_t hdr;
  946   unsigned char payload[MIDI_PAYLOAD_SIZE];
  947 } midi_packet_t;
  948 
  949 #define SNDCTL_MIDI_TIMEBASE		__SIOWR('m', 7, int)
  950 #define SNDCTL_MIDI_TEMPO		__SIOWR('m', 8, int)
  951 /*
  952  * User land MIDI servers (synths) can use SNDCTL_MIDI_SET_LATENCY
  953  * to request MIDI events to be sent to them in advance. The parameter
  954  * (in microseconds) tells how much before the events are submitted.
  955  *
  956  * This feature is only valid for loopback devices and possibly some other
  957  * types of virtual devices.
  958  */
  959 #define SNDCTL_MIDI_SET_LATENCY		__SIOW ('m', 9, int)
  960 /*
  961  ****************************************************************************
  962  * IOCTL commands for /dev/dsp
  963  ****************************************************************************/
  964 
  965 #define SNDCTL_DSP_HALT			__SIO  ('P', 0)
  966 #define SNDCTL_DSP_RESET		SNDCTL_DSP_HALT	/* Old name */
  967 #define SNDCTL_DSP_SYNC			__SIO  ('P', 1)
  968 #define SNDCTL_DSP_SPEED		__SIOWR('P', 2, int)
  969 
  970 /* SNDCTL_DSP_STEREO is obsolete - use SNDCTL_DSP_CHANNELS instead */
  971 #define SNDCTL_DSP_STEREO		__SIOWR('P', 3, int)
  972 /* SNDCTL_DSP_STEREO is obsolete - use SNDCTL_DSP_CHANNELS instead */
  973 
  974 #define SNDCTL_DSP_GETBLKSIZE		__SIOWR('P', 4, int)
  975 #define SNDCTL_DSP_SAMPLESIZE		SNDCTL_DSP_SETFMT
  976 #define SNDCTL_DSP_CHANNELS		__SIOWR('P', 6, int)
  977 #define SNDCTL_DSP_POST			__SIO  ('P', 8)
  978 #define SNDCTL_DSP_SUBDIVIDE		__SIOWR('P', 9, int)
  979 #define SNDCTL_DSP_SETFRAGMENT		__SIOWR('P',10, int)
  980 
  981 /* Audio data formats (Note! U8=8 and S16_LE=16 for compatibility) */
  982 #define SNDCTL_DSP_GETFMTS		__SIOR ('P',11, int)	/* Returns a mask */
  983 #define SNDCTL_DSP_SETFMT		__SIOWR('P',5, int)	/* Selects ONE fmt */
  984 #	define AFMT_QUERY	0x00000000	/* Return current fmt */
  985 #	define AFMT_MU_LAW	0x00000001
  986 #	define AFMT_A_LAW	0x00000002
  987 #	define AFMT_IMA_ADPCM	0x00000004
  988 #	define AFMT_U8		0x00000008
  989 #	define AFMT_S16_LE	0x00000010	/* Little endian signed 16 */
  990 #	define AFMT_S16_BE	0x00000020	/* Big endian signed 16 */
  991 #	define AFMT_S8		0x00000040
  992 #	define AFMT_U16_LE	0x00000080	/* Little endian U16 */
  993 #	define AFMT_U16_BE	0x00000100	/* Big endian U16 */
  994 #	define AFMT_MPEG	0x00000200	/* MPEG (2) audio */
  995 
  996 /* AC3 _compressed_ bitstreams (See Programmer's Guide for details). */
  997 #	define AFMT_AC3		0x00000400
  998 /* Ogg Vorbis _compressed_ bit streams */
  999 #	define AFMT_VORBIS	0x00000800
 1000 
 1001 /* 32 bit formats (MSB aligned) formats */
 1002 #	define AFMT_S32_LE	0x00001000
 1003 #	define AFMT_S32_BE	0x00002000
 1004 
 1005 /* Reserved for _native_ endian double precision IEEE floating point */
 1006 #	define AFMT_FLOAT	0x00004000
 1007 
 1008 /* 24 bit formats (LSB aligned in 32 bit word) formats */
 1009 #	define AFMT_S24_LE	0x00008000
 1010 #	define AFMT_S24_BE	0x00010000
 1011 
 1012 /*
 1013  * S/PDIF raw format. In this format the S/PDIF frames (including all
 1014  * control and user bits) are included in the data stream. Each sample
 1015  * is stored in a 32 bit frame (see IEC-958 for more info). This format
 1016  * is supported by very few devices and it's only usable for purposes
 1017  * where full access to the control/user bits is required (real time control).
 1018  */
 1019 #	define AFMT_SPDIF_RAW	0x00020000
 1020 
 1021 /* 24 bit packed (3 byte) little endian format (USB compatibility) */
 1022 #	define AFMT_S24_PACKED	0x00040000
 1023 
 1024 
 1025 /*
 1026  * Some big endian/little endian handling macros (native endian and opposite
 1027  * endian formats). The usage of these macros is described in the OSS
 1028  * Programmer's Manual.
 1029  */
 1030 
 1031 #if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__hppa) || defined(PPC) || defined(__powerpc__) && !defined(i386) && !defined(__i386) && !defined(__i386__)
 1032 
 1033 /* Big endian machines */
 1034 #  define _PATCHKEY(id) (0xfd00|id)
 1035 #  define AFMT_S16_NE AFMT_S16_BE
 1036 #  define AFMT_U16_NE AFMT_U16_BE
 1037 #  define AFMT_S32_NE AFMT_S32_BE
 1038 #  define AFMT_S24_NE AFMT_S24_BE
 1039 #  define AFMT_S16_OE AFMT_S16_LE
 1040 #  define AFMT_S32_OE AFMT_S32_LE
 1041 #  define AFMT_S24_OE AFMT_S24_LE
 1042 #else
 1043 #  define _PATCHKEY(id) ((id<<8)|0xfd)
 1044 #  define AFMT_S16_NE AFMT_S16_LE
 1045 #  define AFMT_U16_NE AFMT_U16_LE
 1046 #  define AFMT_S32_NE AFMT_S32_LE
 1047 #  define AFMT_S24_NE AFMT_S24_LE
 1048 #  define AFMT_S16_OE AFMT_S16_BE
 1049 #  define AFMT_S32_OE AFMT_S32_BE
 1050 #  define AFMT_S24_OE AFMT_S24_BE
 1051 #endif
 1052 /*
 1053  * Buffer status queries.
 1054  */
 1055 typedef struct audio_buf_info
 1056 {
 1057   int fragments;		/* # of available fragments (partially usend ones not counted) */
 1058   int fragstotal;		/* Total # of fragments allocated */
 1059   int fragsize;			/* Size of a fragment in bytes */
 1060   int bytes;			/* Available space in bytes (includes partially used fragments) */
 1061   /* Note! 'bytes' could be more than fragments*fragsize */
 1062 } audio_buf_info;
 1063 
 1064 #define SNDCTL_DSP_GETOSPACE		__SIOR ('P',12, audio_buf_info)
 1065 #define SNDCTL_DSP_GETISPACE		__SIOR ('P',13, audio_buf_info)
 1066 #define SNDCTL_DSP_GETCAPS		__SIOR ('P',15, int)
 1067 #	define PCM_CAP_REVISION		0x000000ff	/* Bits for revision level (0 to 255) */
 1068 #	define PCM_CAP_DUPLEX		0x00000100	/* Full duplex record/playback */
 1069 #	define PCM_CAP_REALTIME		0x00000200	/* Not in use */
 1070 #	define PCM_CAP_BATCH		0x00000400	/* Device has some kind of */
 1071 							/* internal buffers which may */
 1072 							/* cause some delays and */
 1073 							/* decrease precision of timing */
 1074 #	define PCM_CAP_COPROC		0x00000800	/* Has a coprocessor */
 1075 							/* Sometimes it's a DSP */
 1076 							/* but usually not */
 1077 #	define PCM_CAP_TRIGGER		0x00001000	/* Supports SETTRIGGER */
 1078 #	define PCM_CAP_MMAP		0x00002000	/* Supports mmap() */
 1079 #	define PCM_CAP_MULTI		0x00004000	/* Supports multiple open */
 1080 #	define PCM_CAP_BIND		0x00008000	/* Supports binding to front/rear/center/lfe */
 1081 #   	define PCM_CAP_INPUT		0x00010000	/* Supports recording */
 1082 #   	define PCM_CAP_OUTPUT		0x00020000	/* Supports playback */
 1083 #	define PCM_CAP_VIRTUAL		0x00040000	/* Virtual device */
 1084 /* 0x00040000 and 0x00080000 reserved for future use */
 1085 
 1086 /* Analog/digital control capabilities */
 1087 #	define PCM_CAP_ANALOGOUT	0x00100000
 1088 #	define PCM_CAP_ANALOGIN		0x00200000
 1089 #	define PCM_CAP_DIGITALOUT	0x00400000
 1090 #	define PCM_CAP_DIGITALIN	0x00800000
 1091 #	define PCM_CAP_ADMASK		0x00f00000
 1092 /*
 1093  * NOTE! (capabilities & PCM_CAP_ADMASK)==0 means just that the
 1094  * digital/analog interface control features are not supported by the
 1095  * device/driver. However the device still supports analog, digital or
 1096  * both inputs/outputs (depending on the device). See the OSS Programmer's
 1097  * Guide for full details.
 1098  */
 1099 #	define PCM_CAP_SHADOW		0x01000000	/* "Shadow" device */
 1100 
 1101 /*
 1102  * Preferred channel usage. These bits can be used to
 1103  * give recommendations to the application. Used by few drivers.
 1104  * For example if ((caps & DSP_CH_MASK) == DSP_CH_MONO) means that
 1105  * the device works best in mono mode. However it doesn't necessarily mean
 1106  * that the device cannot be used in stereo. These bits should only be used
 1107  * by special applications such as multi track hard disk recorders to find
 1108  * out the initial setup. However the user should be able to override this
 1109  * selection.
 1110  *
 1111  * To find out which modes are actually supported the application should
 1112  * try to select them using SNDCTL_DSP_CHANNELS.
 1113  */
 1114 #	define DSP_CH_MASK		0x06000000	/* Mask */
 1115 #	define DSP_CH_ANY		0x00000000	/* No preferred mode */
 1116 #	define DSP_CH_MONO		0x02000000
 1117 #	define DSP_CH_STEREO		0x04000000
 1118 #	define DSP_CH_MULTI		0x06000000	/* More than two channels */
 1119 
 1120 #	define PCM_CAP_HIDDEN		0x08000000	/* Hidden device */
 1121 #	define PCM_CAP_FREERATE		0x10000000
 1122 #	define PCM_CAP_MODEM		0x20000000	/* Modem device */
 1123 #	define PCM_CAP_DEFAULT		0x40000000	/* "Default" device */
 1124 
 1125 /*
 1126  * The PCM_CAP_* capability names were known as DSP_CAP_* prior OSS 4.0
 1127  * so it's necessary to define the older names too.
 1128  */
 1129 #define DSP_CAP_ADMASK		PCM_CAP_ADMASK
 1130 #define DSP_CAP_ANALOGIN	PCM_CAP_ANALOGIN
 1131 #define DSP_CAP_ANALOGOUT	PCM_CAP_ANALOGOUT
 1132 #define DSP_CAP_BATCH		PCM_CAP_BATCH
 1133 #define DSP_CAP_BIND		PCM_CAP_BIND
 1134 #define DSP_CAP_COPROC		PCM_CAP_COPROC
 1135 #define DSP_CAP_DEFAULT		PCM_CAP_DEFAULT
 1136 #define DSP_CAP_DIGITALIN	PCM_CAP_DIGITALIN
 1137 #define DSP_CAP_DIGITALOUT	PCM_CAP_DIGITALOUT
 1138 #define DSP_CAP_DUPLEX		PCM_CAP_DUPLEX
 1139 #define DSP_CAP_FREERATE	PCM_CAP_FREERATE
 1140 #define DSP_CAP_HIDDEN		PCM_CAP_HIDDEN
 1141 #define DSP_CAP_INPUT		PCM_CAP_INPUT
 1142 #define DSP_CAP_MMAP		PCM_CAP_MMAP
 1143 #define DSP_CAP_MODEM		PCM_CAP_MODEM
 1144 #define DSP_CAP_MULTI		PCM_CAP_MULTI
 1145 #define DSP_CAP_OUTPUT		PCM_CAP_OUTPUT
 1146 #define DSP_CAP_REALTIME	PCM_CAP_REALTIME
 1147 #define DSP_CAP_REVISION	PCM_CAP_REVISION
 1148 #define DSP_CAP_SHADOW		PCM_CAP_SHADOW
 1149 #define DSP_CAP_TRIGGER		PCM_CAP_TRIGGER
 1150 #define DSP_CAP_VIRTUAL		PCM_CAP_VIRTUAL
 1151 
 1152 #define SNDCTL_DSP_GETTRIGGER		__SIOR ('P',16, int)
 1153 #define SNDCTL_DSP_SETTRIGGER		__SIOW ('P',16, int)
 1154 #	define PCM_ENABLE_INPUT		0x00000001
 1155 #	define PCM_ENABLE_OUTPUT	0x00000002
 1156 
 1157 typedef struct count_info
 1158 {
 1159   unsigned int bytes;		/* Total # of bytes processed */
 1160   int blocks;			/* # of fragment transitions since last time */
 1161   int ptr;			/* Current DMA pointer value */
 1162 } count_info;
 1163 
 1164 #define SNDCTL_DSP_GETIPTR		__SIOR ('P',17, count_info)
 1165 #define SNDCTL_DSP_GETOPTR		__SIOR ('P',18, count_info)
 1166 
 1167 typedef struct buffmem_desc
 1168 {
 1169   unsigned *buffer;
 1170   int size;
 1171 } buffmem_desc;
 1172 #define SNDCTL_DSP_SETSYNCRO		__SIO  ('P', 21)
 1173 #define SNDCTL_DSP_SETDUPLEX		__SIO  ('P', 22)
 1174 
 1175 #define SNDCTL_DSP_PROFILE		__SIOW ('P', 23, int)	/* OBSOLETE */
 1176 #define	  APF_NORMAL	0	/* Normal applications */
 1177 #define	  APF_NETWORK	1	/* Underruns probably caused by an "external" delay */
 1178 #define   APF_CPUINTENS 2	/* Underruns probably caused by "overheating" the CPU */
 1179 
 1180 #define SNDCTL_DSP_GETODELAY		__SIOR ('P', 23, int)
 1181 
 1182 typedef struct audio_errinfo
 1183 {
 1184   int play_underruns;
 1185   int rec_overruns;
 1186   unsigned int play_ptradjust;
 1187   unsigned int rec_ptradjust;
 1188   int play_errorcount;
 1189   int rec_errorcount;
 1190   int</