libgus.h
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:14k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* MikMod sound library
  2. (c) 1998, 1999 Miodrag Vallat and others - see file AUTHORS for
  3. complete list.
  4. This library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of
  7. the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA.
  16. */
  17. /*==============================================================================
  18.   $Id: libgus.h,v 1.1 2004/02/01 02:01:17 raph Exp $
  19.   Linux libGUS-alike library for DOS, used by drv_ultra.c under DOS.
  20. ==============================================================================*/
  21. /*
  22. Current limitations:
  23. - Only a subset of libgus is supported
  24. - Only one GUS card is supported (due to the fact that ULTRASND environment
  25.   variable is used)
  26. - No Interwawe support (if IW works the old way, it's ok).
  27. */
  28. #ifndef __LIBGUS_H__
  29. #define __LIBGUS_H__
  30. #include <stddef.h>
  31. #define __LITTLE_ENDIAN
  32. typedef struct _gus_info_t gus_info_t;
  33. typedef struct _gus_instrument_t gus_instrument_t;
  34. typedef struct _gus_wave_t gus_wave_t;
  35. typedef struct _gus_layer_t gus_layer_t;
  36. #define GUS_CARD_VERSION_CLASSIC 0x0024 /* revision 2.4 */
  37. #define GUS_CARD_VERSION_CLASSIC1 0x0034 /* revision 3.4? */
  38. #define GUS_CARD_VERSION_CLASSIC_ICS 0x0037 /* revision 3.7 (ICS mixer) */
  39. #define GUS_CARD_VERSION_EXTREME 0x0050 /* GUS Extreme */
  40. #define GUS_CARD_VERSION_ACE 0x0090 /* GUS ACE */
  41. #define GUS_CARD_VERSION_MAX 0x00a0 /* GUS MAX - revision 10 */
  42. #define GUS_CARD_VERSION_MAX1 0x00a1 /* GUS MAX - revision 11 */
  43. #define GUS_CARD_VERSION_PNP 0x0100 /* GUS Plug & Play */
  44. #define GUS_STRU_INFO_F_DB16 0x00000001 /* 16-bit daughter board present */
  45. #define GUS_STRU_INFO_F_PCM 0x00000004 /* GF1 PCM during SYNTH enabled */
  46. #define GUS_STRU_INFO_F_ENHANCED 0x00000008 /* InterWave - enhanced mode */
  47. #define GUS_STRU_INFO_F_DAEMON 0x00000010 /* instrument daemon is present */
  48. struct _gus_info_t {
  49. unsigned char id[8]; /* id of this card (warning! maybe unterminated!!!) */
  50. unsigned int flags; /* some info flags - see to GUS_STRU_INFO_F_XXXX */
  51. unsigned int version; /* see to GUS_CARD_VERSION_XXXX constants */
  52. unsigned short port;
  53. unsigned short irq;
  54. unsigned short dma1; /* DMA1 - GF1 download & codec record */
  55. unsigned short dma2; /* DMA2 - GF1 record & codec playback */
  56. unsigned int mixing_freq; /* mixing frequency in Hz */
  57. unsigned int memory_size; /* in bytes */
  58. unsigned int memory_free; /* in bytes */
  59. unsigned int memory_block_8; /* largest free 8-bit block in memory */
  60. unsigned int memory_block_16; /* largest free 16-bit block in memory */
  61. };
  62. /* struct gus_instrument_t - mode */
  63. #define GUS_INSTR_SIMPLE 0x00 /* simple format - for MOD players */
  64. #define GUS_INSTR_PATCH 0x01 /* old GF1 patch format */
  65. #define GUS_INSTR_COUNT 2
  66. #define GUS_INSTR_F_NORMAL 0x0000 /* normal mode */
  67. #define GUS_INSTR_F_NOT_FOUND 0x0001 /* instrument can't be loaded */
  68. #define GUS_INSTR_F_ALIAS 0x0002 /* alias */
  69. #define GUS_INSTR_F_NOT_LOADED 0x00ff /* instrument not loaded (not found) */
  70. #define GUS_INSTR_E_NONE 0x0000 /* exclusion mode - none */
  71. #define GUS_INSTR_E_SINGLE 0x0001 /* exclude single - single note from this instrument */
  72. #define GUS_INSTR_E_MULTIPLE 0x0002 /* exclude multiple - stop only same note from this instrument */
  73. #define GUS_INSTR_L_NONE 0x0000 /* not layered */
  74. #define GUS_INSTR_L_ON 0x0001 /* layered */
  75. #define GUS_INSTR_L_VELOCITY 0x0002 /* layered by velocity */
  76. #define GUS_INSTR_L_FREQUENCY 0x0003 /* layered by frequency */
  77. struct _gus_instrument_t {
  78. union {
  79. unsigned int instrument;/* instrument number */
  80. } number;
  81. char *name; /* name of this instrument or NULL */
  82. unsigned int mode:8, /* see to GUS_INSTR_XXXX */
  83.     flags:8, /* see to GUS_INSTR_F_XXXX */
  84.     exclusion:4, /* see to GUS_INSTR_E_XXXX */
  85.     layer:4; /* see to GUS_INSTR_L_XXXX */
  86. unsigned short exclusion_group; /* 0 - none, 1-65535 */
  87. struct {
  88. unsigned char effect1:4,/* use global effect if available */
  89.     effect2:4; /* use global effect if available */
  90. unsigned char effect1_depth;/* 0-127 */
  91. unsigned char effect2_depth;/* 0-127 */
  92. } patch;
  93. union {
  94. gus_layer_t *layer; /* first layer */
  95. unsigned int alias; /* pointer to instrument */
  96. } info;
  97. gus_instrument_t *next; /* next instrument */
  98. };
  99. struct _gus_layer_t {
  100. unsigned char mode; /* see to GUS_INSTR_XXXX constants */
  101. gus_wave_t *wave;
  102. gus_layer_t *next;
  103. };
  104. /* bits for format variable in gus_wave_t */
  105. #define GUS_WAVE_16BIT          0x0001 /* 16-bit wave */
  106. #define GUS_WAVE_UNSIGNED       0x0002 /* unsigned wave */
  107. #define GUS_WAVE_INVERT         0x0002 /* same as unsigned wave */
  108. #define GUS_WAVE_BACKWARD       0x0004 /* forward mode */
  109. #define GUS_WAVE_LOOP           0x0008 /* loop mode */
  110. #define GUS_WAVE_BIDIR          0x0010 /* bidirectional mode */
  111. #define GUS_WAVE_ULAW           0x0020 /* uLaw compressed wave */
  112. #define GUS_WAVE_RAM            0x0040 /* wave is _preloaded_ in RAM (it is used for ROM simulation) */
  113. #define GUS_WAVE_ROM            0x0080 /* wave is in ROM */
  114. #define GUS_WAVE_DELTA          0x0100
  115. #define GUS_WAVE_PATCH_ENVELOPE 0x01 /* envelopes on */
  116. #define GUS_WAVE_PATCH_SUSTAIN  0x02 /* sustain mode */
  117. struct _gus_wave_t {
  118. unsigned char mode; /* see to GUS_INSTR_XXXX constants */
  119. unsigned char format; /* see to GUS_WAVE_XXXX constants */
  120. unsigned int size; /* size of waveform in bytes */
  121. unsigned int start; /* start offset in bytes * 16 (lowest 4 bits - fraction) */
  122. unsigned int loop_start; /* bits loop start offset in bytes * 16 (lowest 4 bits - fraction) */
  123. unsigned int loop_end; /* loop start offset in bytes * 16 (lowest 4 bits - fraction) */
  124. unsigned short loop_repeat; /* loop repeat - 0 = forever */
  125. struct {
  126. unsigned int memory; /* begin of waveform in GUS's memory */
  127. unsigned char *ptr; /* pointer to waveform in system memory */
  128. } begin;
  129. struct {
  130. unsigned char flags;
  131. unsigned int sample_rate;
  132. unsigned int low_frequency;/* low frequency range for this waveform */
  133. unsigned int high_frequency;/* high frequency range for this waveform */
  134. unsigned int root_frequency;/* root frequency for this waveform */
  135. signed short tune;
  136. unsigned char balance;
  137. unsigned char envelope_rate[6];
  138. unsigned char envelope_offset[6];
  139. unsigned char tremolo_sweep;
  140. unsigned char tremolo_rate;
  141. unsigned char tremolo_depth;
  142. unsigned char vibrato_sweep;
  143. unsigned char vibrato_rate;
  144. unsigned char vibrato_depth;
  145. unsigned short scale_frequency;
  146. unsigned short scale_factor;/* 0-2048 or 0-2 */
  147. } patch;
  148. gus_wave_t *next;
  149. };
  150. /* defines for gus_memory_reset () */
  151. #define GUS_DOWNLOAD_MODE_NORMAL 0x0000
  152. #define GUS_DOWNLOAD_MODE_TEST  0x0001
  153. /*
  154.     A subset of libgus functions (used by MikMod Ultrasound driver)
  155. */
  156. int gus_cards(void);
  157.   /*
  158.    * return value:      number of GUS cards installed in system or
  159.    *                    zero if driver isn't installed
  160.    */
  161. int gus_close(int card);
  162.   /*
  163.    * close file (gus synthesizer) previously opened with gusOpen function
  164.    * return value:      zero if success
  165.    */
  166. int gus_do_flush(void);
  167.   /*
  168.    * return value:      zero if command queue was successfully flushed
  169.    *                    in non block mode - number of written bytes
  170.    */
  171. void gus_do_tempo(unsigned int tempo);
  172.   /*
  173.    * set new tempo
  174.    */
  175. void gus_do_voice_frequency(unsigned char voice, unsigned int freq);
  176.   /*
  177.    * set voice frequency in Hz
  178.    */
  179. void gus_do_voice_pan(unsigned char voice, unsigned short pan);
  180.   /*
  181.    * set voice pan (0-16384) (full left - full right)
  182.    */
  183. void gus_do_voice_start(unsigned char voice, unsigned int program,
  184.                         unsigned int freq, unsigned short volume,
  185.                         unsigned short pan);
  186.   /*
  187.    * start voice
  188.    *            voice    : voice #
  189.    *            program  : program # or ~0 = current
  190.    *            freq     : frequency in Hz
  191.    *            volume   : volume level (0-16384) or ~0 = current
  192.    *            pan      : pan level (0-16384) or ~0 = current
  193.    */
  194. void gus_do_voice_start_position(unsigned char voice, unsigned int program,
  195.                                  unsigned int freq, unsigned short volume,
  196.                                  unsigned short pan, unsigned int position);
  197.   /*
  198.    * start voice
  199.    *            voice    : voice #
  200.    *            program  : program # or ~0 = current
  201.    *            freq     : frequency in Hz
  202.    *            volume   : volume level (0-16384) or ~0 = current
  203.    *            pan      : pan level (0-16384) or ~0 = current
  204.    *            position : offset to wave in bytes * 16 (lowest 4 bits - fraction)
  205.    */
  206. void gus_do_voice_stop(unsigned char voice, unsigned char mode);
  207.   /*
  208.    * stop voice
  209.    *            mode = 0 : stop voice now
  210.    *            mode = 1 : disable wave loop and finish it
  211.    */
  212. void gus_do_voice_volume(unsigned char voice, unsigned short vol);
  213.   /*
  214.    * set voice volume level 0-16384 (linear)
  215.    */
  216. void gus_do_wait(unsigned int ticks);
  217.   /*
  218.    * wait x ticks - this command is block separator
  219.    * all commands between blocks are interpreted in the begining of one tick
  220.    */
  221. int gus_get_voice_status(int voice);
  222.   /*
  223.    * THIS IS NOT A FUNCTION OF ORIGINAL libGUS!
  224.    * Return voice status: -1 on error, 0 if voice stopped, 1 if playing
  225.    */
  226. int gus_get_handle(void);
  227.   /*
  228.    * return value:      file handle (descriptor) for /dev/gus
  229.    */
  230. int gus_info(gus_info_t * info, int reread);
  231.   /*
  232.    * return value:      filled info variable with actual values
  233.    *                    (look at gus.h header file for more informations)
  234.    * version field:     0x0024  - GUS revision 2.4
  235.    *                    0x0035  - GUS revision 3.7 with flipped mixer channels
  236.    *                    0x0037  - GUS revision 3.7
  237.    *                    0x0090  - GUS ACE
  238.    *                    0x00a0  - GUS MAX revision 10
  239.    *                    0x00a1  - GUS MAX revision 11
  240.    *                    0x0100  - InterWave (full version)
  241.    * flags field:       see to GUS_STRU_INFO_F_???? constants (gus.h header file)
  242.    * port field:        port number (for example 0x220)
  243.    * irq field:         irq number (for example 11)
  244.    * dma1 field:        dma1 number (for example 5)
  245.    * dma2 field:        dma2 number (for example 6)
  246.    * note:              dma1 and dma2 could be same in case of only one dma channel used
  247.    */
  248. int gus_memory_alloc(gus_instrument_t * instrument);
  249.   /*
  250.    * input value:       look at gus.h for more details about gus_instrument_t structure
  251.    * return value:      zero if instrument was successfully allocated
  252.    */
  253. int gus_memory_free(gus_instrument_t * instrument);
  254.   /*
  255.    * input value:       look at gus.h for more details about gus_instrument_t structure
  256.    * return value:      zero if instrument was successfully removed
  257.    */
  258. int gus_memory_size(void);
  259.   /*
  260.    * return value:  gus memory size in bytes
  261.    */
  262. int gus_memory_free_size(void);
  263.   /*
  264.    * return value:      unused gus memory in bytes
  265.    * warning:           reset function must be called before
  266.    */
  267. int gus_memory_free_block(int w_16bit);
  268.   /*
  269.    * return value:  current largest free block for 8-bit or 16-bit wave
  270.    */
  271. int gus_memory_pack(void);
  272.   /*
  273.    * return value:      zero if success
  274.    */
  275. int gus_memory_reset(int mode);
  276.   /*
  277.    * input value:   see to GUS_DOWNLOAD_MODE_XXXX constants (gus.h) 
  278.    * return value:  zero if samples & instruments was successfully removed
  279.    *            from GF1 memory manager
  280.    */
  281. int gus_open(int card, size_t queue_buffer_size, int non_block);
  282.   /*
  283.    * input values:      card number,
  284.    *                    size of command queue buffer (512-1MB)
  285.    *                    buffer is allocated dynamically,
  286.    *                    non block mode
  287.    * return value:      zero if success
  288.    * note 1:            this function must be called as first
  289.    *                    open file /dev/gus
  290.    * note 2:            you can open more cards with one process
  291.    */
  292. int gus_queue_flush(void);
  293.   /*
  294.    * return value:      zero if command queue was successfully flushed
  295.    */
  296. int gus_queue_read_set_size(int items);
  297.   /*
  298.    * input value:       echo buffer size in items (if 0 - erase echo buffer)
  299.    */
  300. int gus_queue_write_set_size(int items);
  301.   /*
  302.    * input value:       write queue size in items (each item have 8 bytes)
  303.    */
  304. int gus_reset(int voices, unsigned int channel_voices);
  305.   /*
  306.    * input values:      active voices and channel voices (for dynamic allocation)
  307.    * return value:      number of active voices if reset was successfull (GF1 chip active)
  308.    */
  309. int gus_reset_engine_only(void);
  310.   /*
  311.    * return value:  same as gus_reset function
  312.    * note:      this command doesn't change number of active
  313.    *            voices and doesn't do hardware reset
  314.    */
  315. int gus_select(int card);
  316.   /*
  317.    * select specified card
  318.    * return value:      zero if success
  319.    */
  320. int gus_timer_start(void);
  321.   /*
  322.    * return value:      zero if successfull
  323.    */
  324. int gus_timer_stop(void);
  325.   /*
  326.    * return value:      zero if timer was stoped
  327.    */
  328. int gus_timer_continue(void);
  329.   /*
  330.    * return value:  zero if timer will be continue
  331.    */
  332. int gus_timer_tempo(int ticks);
  333.   /*
  334.    * return value:      zero if setup was success
  335.    */
  336. int gus_timer_base(int base);
  337.   /*
  338.    * return value:  zero if setup was success (default timebase = 100)
  339.    */
  340. void gus_convert_delta(unsigned int type, unsigned char *dest,
  341.                        unsigned char *src, size_t size);
  342.   /*
  343.    * note: dest and src pointers can be equal
  344.    */
  345. void gus_timer_callback(void (*timer_callback) ());
  346.   /*
  347.    * Set a callback to be called once per tempo tick
  348.    */
  349. int gus_dma_usage (int use);
  350.   /*
  351.    * Tell GUS library to use/to not use DMA for sample transfer.
  352.    * In some environments/on some hardware platforms you will need
  353.    * to disable DMA in order to function properly. You should call
  354.    * this function before opening the card.
  355.    */
  356. #endif /* __LIBGUS_H__ */
  357. /* ex:set ts=4: */