NEWGF1.H 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /***************************************************************************
  16. * NAME: GF1.H
  17. ** COPYRIGHT:
  18. ** "Copyright (c) 1991,1992, by FORTE
  19. **
  20. ** "This software is furnished under a license and may be used,
  21. ** copied, or disclosed only in accordance with the terms of such
  22. ** license and with the inclusion of the above copyright notice.
  23. ** This software or any other copies thereof may not be provided or
  24. ** otherwise made available to any other person. No title to and
  25. ** ownership of the software is hereby transfered."
  26. ****************************************************************************
  27. * CREATION DATE: 07/01/92
  28. *--------------------------------------------------------------------------*
  29. * VERSION DATE NAME DESCRIPTION
  30. *> 1.0 07/01/92 Original
  31. ***************************************************************************/
  32. #ifndef _GF1_H /* allow header to be processed only once */
  33. #define _GF1_H
  34. /* error codes */
  35. #define OK 0
  36. #define NO_MORE_VOICES -1
  37. #define BASE_NOT_FOUND 1
  38. #define BAD_IRQ 2
  39. #define BAD_DMA 3
  40. #define OS_LOADED 4
  41. #define NOT_LOADED 5
  42. #define NO_MEMORY 6
  43. #define DMA_BUSY 7
  44. #define NO_MORE_HANDLERS 8
  45. #define DMA_HUNG 9
  46. #define CARD_NOT_FOUND 10
  47. #define CARD_BEING_USED 11
  48. #define NO_MORE_INTERRUPTS 12
  49. #define BAD_TIMER 13
  50. #define BAD_PATCH 14
  51. #define OLD_PATCH 15
  52. #define DOS_ERROR 16
  53. #define FILE_NOT_FOUND 17
  54. /* bits */
  55. #define BIT0 0x01
  56. #define BIT1 0x02
  57. #define BIT2 0x04
  58. #define BIT3 0x08
  59. #define BIT4 0x10
  60. #define BIT5 0x20
  61. #define BIT6 0x40
  62. #define BIT7 0x80
  63. /* bounds for volume enveloping functions */
  64. #define MIN_OFFSET 5U
  65. #define MAX_OFFSET 251U
  66. /* bounds for voice allocation */
  67. #define MIN_VOICES 14
  68. #define MAX_VOICES 32
  69. /* DMA control bits */
  70. #define DMA_ENABLE BIT0
  71. #define DMA_READ BIT1
  72. #define DMA_WIDTH_16 BIT2 /* width of DMA channel */
  73. #define DMA_RATE_DIV_1 BIT3
  74. #define DMA_RATE_DIV_2 BIT4
  75. #define DMA_IRQ_ENABLE BIT5
  76. #define DMA_IRQ_PRESENT BIT6
  77. #define DMA_DATA_16 BIT6 /* width of data */
  78. #define DMA_INVERT_MSB BIT7
  79. /* SAMPLE control bits */
  80. #define DMA_STEREO 2
  81. /* DMA flags */
  82. #define GF1_RECORD 0 /* use dma control or sample control */
  83. #define GF1_DMA 1
  84. /* MIDI control register */
  85. #define MIDI_RESET (BIT0|BIT1)
  86. #define MIDI_TD_INT BIT5
  87. #define MIDI_RD_INT BIT7
  88. /* MIDI_STATUS_REGISTER */
  89. #define MIDI_RD BIT0
  90. #define MIDI_TD BIT1
  91. #define MIDI_ERR_FRAMING BIT4
  92. #define MIDI_ERR_OVERRUN BIT5
  93. /* digital playback flags */
  94. #define TYPE_8BIT BIT0 /* 1 use 8 bit data */
  95. /* 0 use 16 bit data */
  96. #define TYPE_PRELOAD BIT1 /* preload data */
  97. #define TYPE_INVERT_MSB BIT2 /* invert most significant bit during dma */
  98. #define TYPE_STEREO BIT3 /* 1 for stereo data */
  99. /* sound effects and digital music types */
  100. #define SND_LOOP_MASK (BIT0|BIT1)
  101. #define SND_LOOP_NONE 0
  102. #define SND_LOOP 1
  103. #define SND_LOOP_BIDIR 2
  104. #define SND_8BIT (BIT2)
  105. #define SND_BACKWARD (BIT3)
  106. #define SOUND_PLAYING 2
  107. #define SOUND_ACTIVE 1
  108. /* patch macros */
  109. #define HEADER_SIZE 12
  110. #define ID_SIZE 10
  111. #define DESC_SIZE 60
  112. #define RESERVED_SIZE 40
  113. #define PATCH_HEADER_RESERVED_SIZE 36
  114. #define LAYER_RESERVED_SIZE 40
  115. #define PATCH_DATA_RESERVED_SIZE 36
  116. #define GF1_HEADER_TEXT "GF1PATCH110"
  117. #define INST_NAME_SIZE 16
  118. #define ENVELOPES 6
  119. #define MAX_LAYERS 4
  120. /* patch modes */
  121. #define PATCH_16 BIT0
  122. #define PATCH_UNSIGNED BIT1
  123. #define PATCH_LOOPEN BIT2
  124. #define PATCH_BIDIR BIT3
  125. #define PATCH_BACKWARD BIT4
  126. #define PATCH_SUSTAIN BIT5
  127. #define PATCH_NO_SRELEASE BIT6
  128. #define PATCH_FAST_REL BIT7
  129. /* flags for patch loading */
  130. #define PATCH_LOAD_8_BIT BIT0
  131. /* digital playback callback reasons & return values */
  132. #define DIG_DONE 0
  133. #define DIG_MORE_DATA 1
  134. #define DIG_BUFFER_DONE 2
  135. #define DIG_PAUSE 3
  136. /* log table used for vibrato and pitch bend. log table made public for
  137. ** developers use */
  138. #define LOG_TAB_SIZE 12
  139. extern long gf1_log_table[LOG_TAB_SIZE];
  140. #if defined(__BORLANDC__)
  141. #undef RFAR
  142. #define RFAR far
  143. #elif defined(_MSC_VER) && (_MSC_VER <= 600)
  144. #define RFAR far
  145. #elif defined(_MSC_VER) && (_MSC_VER > 600)
  146. #define RFAR __far
  147. #else
  148. #undef RFAR
  149. #define RFAR
  150. #endif
  151. /* structure definitions */
  152. struct load_os
  153. {
  154. unsigned short voices;
  155. unsigned short forced_base_port;
  156. unsigned char forced_gf1_irq;
  157. unsigned char forced_midi_irq;
  158. unsigned char forced_channel_in;
  159. unsigned char forced_channel_out;
  160. };
  161. struct patchheader
  162. {
  163. char header[ HEADER_SIZE ];
  164. char gravis_id[ ID_SIZE ]; /* Id = "ID#000002" */
  165. char description[ DESC_SIZE ];
  166. unsigned char instruments;
  167. char voices;
  168. char channels;
  169. unsigned short wave_forms;
  170. unsigned short master_volume;
  171. unsigned long data_size;
  172. char reserved[ PATCH_HEADER_RESERVED_SIZE ];
  173. };
  174. struct instrumentdata
  175. {
  176. unsigned short instrument;
  177. char instrument_name[ INST_NAME_SIZE ];
  178. long instrument_size;
  179. char layers;
  180. char reserved[ RESERVED_SIZE ];
  181. };
  182. struct layerdata
  183. {
  184. char layer_duplicate;
  185. char layer;
  186. long layer_size;
  187. char samples;
  188. char reserved[ LAYER_RESERVED_SIZE ];
  189. };
  190. struct patchdata
  191. {
  192. char wave_name[7];
  193. unsigned char fractions;
  194. long wave_size;
  195. long start_loop;
  196. long end_loop;
  197. unsigned short sample_rate;
  198. long low_frequency;
  199. long high_frequency;
  200. long root_frequency;
  201. short tune;
  202. unsigned char balance;
  203. unsigned char envelope_rate[ ENVELOPES ];
  204. unsigned char envelope_offset[ ENVELOPES ];
  205. unsigned char tremolo_sweep;
  206. unsigned char tremolo_rate;
  207. unsigned char tremolo_depth;
  208. unsigned char vibrato_sweep;
  209. unsigned char vibrato_rate;
  210. unsigned char vibrato_depth;
  211. char modes;
  212. short scale_frequency;
  213. unsigned short scale_factor; /* from 0 to 2048 or 0 to 2 */
  214. char reserved[ PATCH_DATA_RESERVED_SIZE ];
  215. };
  216. struct wave_struct
  217. {
  218. unsigned long start_loop;
  219. unsigned long end_loop;
  220. long low_frequency;
  221. long high_frequency;
  222. long root_frequency;
  223. unsigned long mem;
  224. unsigned short scale_frequency;
  225. unsigned short sample_rate;
  226. unsigned short scale_factor;
  227. unsigned short start_acc_low;
  228. unsigned short start_acc_high;
  229. unsigned short start_low;
  230. unsigned short start_high;
  231. unsigned short end_low;
  232. unsigned short end_high;
  233. unsigned short end_acc_low;
  234. unsigned short end_acc_high;
  235. unsigned short sample_ratio;
  236. unsigned long wave_size;
  237. unsigned char fractions;
  238. unsigned char balance;
  239. unsigned char envelope_rate[ ENVELOPES ];
  240. unsigned char envelope_offset[ ENVELOPES ];
  241. unsigned char tremolo_sweep;
  242. unsigned char tremolo_rate;
  243. unsigned char tremolo_depth;
  244. unsigned char vibrato_sweep;
  245. unsigned char vibrato_rate;
  246. unsigned char vibrato_depth;
  247. unsigned char modes;
  248. };
  249. struct patchinfo {
  250. struct patchheader header;
  251. struct instrumentdata idata;
  252. };
  253. struct patch {
  254. short nlayers;
  255. struct wave_struct RFAR *layer_waves[MAX_LAYERS];
  256. short layer_nwaves[MAX_LAYERS];
  257. unsigned short detune;
  258. };
  259. struct gf1_dma_buff {
  260. unsigned char RFAR *vptr;
  261. unsigned long paddr;
  262. };
  263. struct gf1_sound {
  264. unsigned long mem_pos;
  265. unsigned long start_loop;
  266. unsigned long end_loop;
  267. unsigned char type;
  268. };
  269. /* GLOBAL VARIABLES (flags) */
  270. extern char gf1_linear_volumes;
  271. extern char gf1_dig_use_extra_voice;
  272. /* FUNCTION PROTOTYPES */
  273. /* Initializeation routines */
  274. int gf1_init_ports(int);
  275. int gf1_load_os(struct load_os RFAR *os);
  276. int gf1_unload_os(void);
  277. void gf1_set_appname(char RFAR *);
  278. void reset_ultra(int);
  279. int gf1_asm_init(void);
  280. unsigned char gf1_peek(unsigned long address);
  281. void gf1_poke(unsigned long address, unsigned char data);
  282. void gf1_poke_block(unsigned char RFAR *data, unsigned long address, unsigned long len, unsigned char dma_control);
  283. char gf1_good_dram(unsigned long address);
  284. int GetUltraCfg(struct load_os RFAR *os);
  285. unsigned long gf1_malloc(unsigned long);
  286. void gf1_free(unsigned long);
  287. unsigned long gf1_mem_avail(void);
  288. unsigned long gf1_mem_largest_avail(void);
  289. void gf1_delay(void);
  290. int gf1_allocate_voice(int priority, void (RFAR *steal_notify)(int));
  291. void gf1_free_voice(unsigned int i);
  292. void gf1_adjust_priority(int voice, int priority);
  293. int gf1_dram_xfer(struct gf1_dma_buff RFAR *dptr, unsigned long size, unsigned long dram_address, unsigned char dma_control, unsigned short flags);
  294. void gf1_stop_dma(void);
  295. long convert_to_16bit(long address);
  296. int gf1_wait_dma(void);
  297. int gf1_dma_ready(void);
  298. unsigned long gf1_amount_xferred(void);
  299. int gf1_detect_card(unsigned short port);
  300. char *gf1_error_str(int);
  301. int gf1_play_digital(unsigned short priority, unsigned char RFAR *buffer,
  302. unsigned long size, unsigned long gf1_addr, unsigned short volume,
  303. unsigned short pan, unsigned short frequency, unsigned char type,
  304. struct gf1_dma_buff RFAR *dptr,
  305. int (RFAR *callback)(int, int, unsigned char RFAR * RFAR *, unsigned long RFAR *));
  306. void gf1_restart_digital(int voice);
  307. void gf1_start_digital(int voice);
  308. void gf1_pause_digital(int voice);
  309. void RFAR gf1_stop_digital(int voice);
  310. void gf1_dig_set_dma_rate(unsigned short rate);
  311. unsigned long gf1_digital_position(int voice);
  312. int gf1_myatoi(void);
  313. int gf1_update_waveform(struct wave_struct RFAR *wave_info);
  314. int gf1_get_patch_info(char RFAR *patch_file, struct patchinfo RFAR *patch);
  315. int gf1_load_patch(char RFAR *patch_file, struct patchinfo RFAR *patchinfo,
  316. struct patch RFAR *patch,
  317. struct gf1_dma_buff RFAR *dptr, unsigned short size,
  318. unsigned char RFAR *wavemem, int flags);
  319. void gf1_unload_patch(struct patch RFAR *patch);
  320. void gf1_detune_patch(struct patch RFAR *patch, unsigned short detune);
  321. unsigned short gf1_calc_fc(unsigned int sample_ratio,long root,long frequency);
  322. void gf1_midi_stop_voice(int voice);
  323. void gf1_midi_wait_voice(int voice);
  324. unsigned short gf1_midi_status_note(int voice);
  325. unsigned short gf1_midi_status_voice(int voice);
  326. void RFAR gf1_midi_stop_note(int note_voice);
  327. void gf1_midi_note_on(struct patch RFAR *patch, int priority, int note, int velocity, int channel);
  328. void gf1_midi_note_off(int note, int channel);
  329. void gf1_midi_silence_patch_notes(struct patch RFAR *patch);
  330. void gf1_midi_patch_removed(struct patch RFAR *patch);
  331. int gf1_enable_timer1(int (RFAR *callback)(void), int resolution);
  332. int gf1_enable_timer2(int (RFAR *callback)(void), int resolution);
  333. void gf1_disable_timer1(void);
  334. void gf1_disable_timer2(void);
  335. void gf1_channel_pitch_bend(int channel, unsigned int bend);
  336. void gf1_midi_synth_volume(unsigned short synth, int master_volume);
  337. void gf1_midi_change_program(struct patch RFAR *patch, int channel);
  338. void gf1_midi_set_vibrato(int channel, int value);
  339. void gf1_midi_change_volume(int channel, unsigned int volume);
  340. void gf1_midi_set_balance(int balance, int channel);
  341. void gf1_midi_channel_sustain(int channel, int sustain);
  342. void gf1_midi_all_notes_off(int channel);
  343. void gf1_midi_pitch_bend(int channel, int lsb, int msb);
  344. void gf1_midi_parameter(int channel, int control, int value);
  345. int gf1_midi_get_channel_notes(int channel, int notes[]);
  346. int gf1_midi_get_channel_volume(int channel);
  347. int gf1_midi_get_master_volume(void);
  348. int gf1_midi_get_volume(int voice);
  349. unsigned short gf1_read(int handle, void RFAR *io_buffer, unsigned short size);
  350. unsigned short gf1_close_file(int handle);
  351. unsigned int gf1_seek(int handle, unsigned long offset, int method);
  352. int gf1_open(char RFAR *name);
  353. #ifdef __FLAT__
  354. int gf1_atoi(char RFAR **str, int base);
  355. #else
  356. int gf1_atoi(void);
  357. #endif
  358. void gf1_leave(void);
  359. short gf1_enter(void);
  360. void gf1_enter1(void);
  361. int gf1_play_next_buffer(int voice, unsigned char RFAR *buff, unsigned long size);
  362. void gf1_dig_set_vol(unsigned short voice, unsigned short vol);
  363. void gf1_dig_set_pan(unsigned short voice, unsigned short pan);
  364. int gf1_set_external_semaphore(void RFAR *addr);
  365. int gf1_clear_external_semaphore(void RFAR *addr);
  366. void gf1_midi_reset(int c);
  367. int gf1_add_midi_recv_handler(int (RFAR *handler)());
  368. int gf1_add_dma_handler(int (*handler)());
  369. int gf1_add_voice_handler(int (*handler)(int));
  370. int gf1_add_volume_handler(int (*handler)(int));
  371. int gf1_add_timer_handler(int timer, int (RFAR *handler)(void));
  372. void gf1_set_record_rate(unsigned long rate);
  373. void gf1_create_patch(struct patch RFAR *patch);
  374. int gf1_add_layer(struct patch RFAR *patch, int layer, char RFAR *wavemem);
  375. void gf1_get_waveform_info(struct patch RFAR *patch, int layer, int waven,
  376. struct wave_struct RFAR *wave);
  377. void gf1_set_waveform_info(struct patch RFAR *patch, int layer, int waven,
  378. struct wave_struct RFAR *wave);
  379. void gf1_enable_line_in(void);
  380. void gf1_disable_line_in(void);
  381. void gf1_enable_mic_in(void);
  382. void gf1_disable_mic_in(void);
  383. void gf1_enable_output(void);
  384. void gf1_disable_output(void);
  385. void gf1_sound_volume(unsigned short voice, int volume,
  386. unsigned long period /* us*10 */);
  387. void gf1_sound_pan(unsigned short voice, unsigned short pan);
  388. void gf1_sound_frequency(unsigned short voice, unsigned long freq);
  389. void RFAR gf1_sound_stop(int voice);
  390. void gf1_sound_mode(int voice, struct gf1_sound RFAR *sound,
  391. unsigned char type);
  392. int gf1_sound_start(unsigned short priority, struct gf1_sound RFAR *sound,
  393. short volume, unsigned long period, short pan, unsigned long freq);
  394. int gf1_sound_playing(int voice);
  395. #endif