File: libgus.h

package info (click to toggle)
ultra 2.99a-devel2-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 3,104 kB
  • ctags: 5,438
  • sloc: ansic: 44,350; yacc: 2,036; makefile: 833; sh: 652; lex: 548
file content (1064 lines) | stat: -rw-r--r-- 39,361 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
/*
 * Application interface library for the GUS driver
 * Copyright (c) by Jaroslav Kysela (Perex soft)
 */

#ifndef __LIBGUS_H
#define __LIBGUS_H

#include <sys/types.h>
#include <fcntl.h>
#include <stdarg.h>
#if defined( __GUS_PATH_APP__ )
#include "./sys/gus.h"
#elif defined( __GUS_PATH_LIB__ )
#include "../../../include/sys/gus.h"
#else
#include <sys/gus.h>
#endif

#define LIBGUS_VERSION_MAJOR	0x0004
#define LIBGUS_VERSION_MINOR	0x0000
#define LIBGUS_VERSION		( ( LIBGUS_VERSION_MAJOR << 16 ) | LIBGUS_VERSION_MINOR )

  /*
   *
   */
   
#ifdef __cplusplus
extern "C" {
#endif

#define GUS_ACCESS_SYNTH	0x0000
#define GUS_ACCESS_INSMAN	0x0001
#define GUS_ACCESS_MIDI		0x0100	/* this is ORed with midi device */
#define GUS_ACCESS_MIDI_DEVICE	0x00ff	/* mask for midi device */

int gus_access_synth( void );
int gus_access_insman( void );
int gus_access_midi( int midi_device );

char *gus_model( int gus_version );

#ifdef __cplusplus
}
#endif

  /*
   * all functions return value -1 if error occured
   */

/***************************************************************************
 *                                                                         *
 *              Native synthesizer support functions                       *
 *                                                                         *
 ***************************************************************************/

#define GUS_OPEN_FLAG_NONE	0x0000
#define GUS_OPEN_FLAG_NONBLOCK	0x0001

#define GUS_WAVE_DELTA		0x0100

#ifdef __cplusplus
extern "C" {
#endif

int gus_cards( void );
  /* 
   * return value:	number of gus devices installed in system or
   *			zero if driver isn't installed
   */
int gus_devices( const char *id );
  /*
   * return value:	number of gus devices for specified card
   *                    (at this time is return value always 1)
   */
int gus_look_for_card( const char *card_id );
  /*
   * input value:	card number (from 1 to GUS_CARDS) or id of requested card
   * return value:	card number (from 0 to GUS_CARDS-1) if card was found
   *			-1 if card wasn't found
   */
int gus_open( void **handle, int card, int device, size_t queue_buffer_size, int flags );
  /*
   * input values:	card number,
   *			device number,
   *			size of command queue buffer (512-1MB)
   *			buffer is allocated dynamically,
   *			flags (GUS_OPEN_FLAG_XXXX)
   * return value:	zero if success and *handle is filled
   * note 1:		this function must be called as first
   * 			open file /dev/gus
   * note 2:		you can open more cards with one process
   */
int gus_close( void *handle );
  /*
   * close file (gus synthesizer) previously opened with gusOpen function
   * return value:	zero if success
   */
int gus_get_file_descriptor( void *handle );
  /*
   * return value:	file handle (descriptor) for /dev/gus
   */

int gus_info( void *handle, gus_info_t *info, int reread );
  /*
   * return value:	filled info variable with actual values
   * 			(look at gus.h header file for more informations)
   * version field:	0x0024	- GUS revision 2.4
   *			0x0035	- GUS revision 3.7 with flipped mixer channels
   *			0x0037	- GUS revision 3.7
   *			0x0090	- GUS ACE
   *			0x00a0	- GUS MAX revision 10
   *			0x00a1	- GUS MAX revision 11
   *                    0x0100  - InterWave (full version)
   * flags field:	see to GUS_STRU_INFO_F_???? constants (gus.h header file)
   * port field:	port number (for example 0x220)
   * irq field:		irq number (for example 11)
   * dma1 field:	dma1 number (for example 5)
   * dma2 field:	dma2 number (for example 6)
   * note:		dma1 and dma2 could be same in case of only one dma channel used
   */

int gus_ultraclick_get( void *handle, gus_ultraclick_t *ultraclick );
  /*
   * return value:	filled gus_ultraclick_t structure
   */
int gus_ultraclick_set( void *handle, gus_ultraclick_t *ultraclick );
  /*
   * input_value:	filled gus_ultraclick_t structure
   */
int gus_emulation_get( void *handle );	/* midi emulation - gus_do_chn_xxxx */
  /*
   * return value:	see to GUS_MIDI_EMUL_XXXX constants
   *			-1 if error
   */
int gus_emulation_set( void *handle, int emulation );	/* midi emulation - gus_do_chn_xxxx */
  /*
   * input value:	see to GUS_MIDI_EMUL_XXXX constants
   * return value:	zero if success
   */
int gus_effect_reset( void *handle );
  /*
   * remove effect(s) voices and disable effects
   */
int gus_effect_setup( void *handle, gus_effect_t *effect ); 
  /*
   * setup effect
   *	for an InterWave board can be used gus_effect_interwave() function
   *	which fills gus_effect_t structure with two of selected effects
   * note:
   *	this setup assign 8 voices to effect processing, so only
   *	24 voices can be used with gus_do_voice_xxxx() functions!!!
   */
 
int gus_memory_size( void *handle );
  /*
   * return value:	gus memory size in bytes
   */
int gus_memory_free_size( void *handle );
  /*
   * return value:	unused gus memory in bytes
   * warning:		reset function must be called before
   */
int gus_memory_free_block( void *handle, int w_16bit );
  /*
   * return value:	current largest free block for 8-bit or 16-bit wave
   */
int gus_memory_rom_size( void *handle );
  /*
   * return value:	gus memory size (ROM) in bytes
   */
int gus_memory_rom_banks( void *handle );
  /*
   * return value:	gus memory ROM banks
   */
int gus_memory_rom_present( void *handle );
  /*
   * return value:	bitmap of ROM banks which are present
   */

int gus_reset( void *handle, int voices, unsigned int channel_voices );
  /*
   * input values:	active voices and channel voices (for dynamic allocation)
   * return value:	number of active voices if reset was successfull (GF1 chip active)
   */
int gus_reset_engine_only( void *handle );
  /*
   * return value:	same as gus_reset function
   * note:		this command doesn't change number of active
   *			voices and doesn't do hardware reset
   */
   
int gus_timer_start( void *handle );
  /*
   * return value:	zero if successfull
   */
int gus_timer_stop( void *handle );
  /*
   * return value:	zero if timer was stoped
   */
int gus_timer_continue( void *handle );
  /*
   * return value:	zero if timer will be continue
   */
int gus_timer_base( void *handle, int base );
  /*
   * return value:	zero if setup was success (default timebase = 100)
   */
int gus_timer_tempo( void *handle, int ticks );
  /*
   * return value:	zero if setup was success
   */
int gus_timer_master( void *handle );
int gus_timer_slave( void *handle, int slave_card );

int gus_memory_reset( void *handle, int mode );
  /*
   * input value:	see to GUS_DOWNLOAD_MODE_XXXX constants (gus.h) 
   * return value:	zero if samples & instruments was successfully removed
   *			from GF1 memory manager
   */
int gus_memory_test( void *handle, gus_instrument_t *instrument );
  /*
   * input value:	look at gus.h for more details about gus_instrument_t structure
   * return value:	zero if sample !can be! downloaded
   * note:		sample isn't allocated in GF1 memory manager
   */
int gus_memory_get_name( void *handle, gus_instrument_name_t *instrument );
  /*
   * 			get name of instrument and instrument flags
   * input value:	look at gus.h for more details about gus_instrument_t structure
   * return value:	zero if success
   */
int gus_memory_alloc( void *handle, gus_instrument_t *instrument );
  /*
   * input value:	look at gus.h for more details about gus_instrument_t structure
   * return value:	zero if instrument was successfully allocated
   */
int gus_memory_free( void *handle, gus_instrument_t *instrument );
  /*
   * input value:	look at gus.h for more details about gus_instrument_t structure
   * return value:	zero if instrument was successfully removed
   */
int gus_memory_pack( void *handle );
  /*
   * return value:	zero if success
   */
int gus_memory_list( void *handle, gus_memory_list_t *list );
  /*
   * input value:	list -> count = maximum instruments to read
   *			list -> info.instruments = pointer to unsigned int array
   *			  which is filled by driver, -1 = no more instruments
   * return value:	zero if success
   */
int gus_memory_block_alloc( void *handle, gus_memory_block_t *block );
  /*
   * undocumented at this time - see to gus.h for more info
   */
int gus_memory_block_free( void *handle, gus_memory_block_t *block );
  /*
   * undocumented at this time - see to gus.h for more info
   */
int gus_memory_dump( void *handle, gus_memory_dump_t *dump );
  /*
   * undocumented at this time - see to gus.h for more info
   */

int gus_queue_write_set_size( void *handle, int items );
  /*
   * input value:	write queue size in items (each item have 8 bytes)
   */
int gus_queue_write_get_size( void *handle );
  /*
   * output value:	write queue size in items (each item have 8 bytes)
   */
int gus_queue_write_free( void *handle );
  /*
   * return value:	free items (ticks) in queue
   */
int gus_queue_write_threshold( void *handle, int threshold );
  /*
   * input value:	threshold in queue items (ticks)
   *			range 1 - gus_queue_write_get_size()
   *			good value = items - ( items / 3 )
   * return value:	zero if success
   */

int gus_queue_read_set_size( void *handle, int items );
  /*
   * input value:	echo buffer size in items (if 0 - erase echo buffer)
   */
int gus_queue_read_get_size( void *handle );
  /*
   * output value:	echo buffer size in items
   */
int gus_queue_read_used( void *handle );
  /*
   * output value:	used items in read queue
   */

int gus_queue_flush( void *handle );
  /*
   * return value:	zero if command queue was successfully flushed
   */
int gus_queue_abort( void *handle );
  /*
   * return value:	zero if command queue was successfully aborted and
   *			GF1 chip was stoped
   * note:		reset must be called after this command for
   *			more sound!
   */
int gus_queue_abort_to_stop( void *handle );
  /*
   * return value:	zero if command queue was successfully aborted
   *			to queue command STOP; all voices was stoped
   */
int gus_queue_stop_playback( void *handle );
  /*
   *			zero if command was successfull
   */
int gus_queue_continue_playback( void *handle );
  /*
   *			zero if command was successfull
   */
   
/*
 *  Queue commands
 *
 *  This commands are interpreted by block. Blocks are separated by command
 *  gus_do_wait or gus_do_stop (for abort_to_stop command). Queue command
 *  isn't sent to GUS driver in same time user calls it. Queue commands
 *  are stored into internal buffer dynamically allocated by gus library
 *  (look at gus_open function). Internal buffer is flushed (forwarded to
 *  GUS driver) when is full or in case user forces buffer flush with
 *  gus_do_flush function.
 */

int gus_do_flush( void *handle );
  /*
   * return value:	zero if command queue was successfully flushed
   *			in non block mode - number of written bytes
   */


void gus_do_program( void *handle, unsigned char voice, unsigned int program );
void gus_do_voice_start( void *handle, unsigned char voice, unsigned int program, unsigned int freq, unsigned short volume, unsigned short pan );
  /*
   * start voice
   *		voice	 : voice #
   *		program	 : program # or ~0 = current
   *		freq	 : frequency in Hz
   *		volume	 : volume level (0-16384) or ~0 = current
   *		pan	 : pan level (0-16384) or ~0 = current
   */
void gus_do_voice_start_position( void *handle, unsigned char voice, unsigned int program, unsigned int freq, unsigned short volume, unsigned short pan, unsigned int position );
  /*
   * start voice
   *		voice	 : voice #
   *		program	 : program # or ~0 = current
   *		freq	 : frequency in Hz
   *		volume	 : volume level (0-16384) or ~0 = current
   *		pan	 : pan level (0-16384) or ~0 = current
   *		position : offset to wave in bytes * 16 (lowest 4 bits - fraction)
   */
void gus_do_voice_stop( void *handle, unsigned char voice, unsigned char mode );
  /*
   * stop voice
   *		mode = 0 : stop voice now
   *		mode = 1 : disable wave loop and finish it
   */

void gus_do_voice_control( void *handle, unsigned char voice, unsigned char cntrl );
  /*
   * set voice control register:
   *	bit 0. - 0 = voice is running, 1 = voice is stopped
   *	bit 1. - 0 = nothing, 1 = stop voice
   *	bit 2. - 0 = 8 bit wave, 1 = 16 bit wave
   *	bit 3. - 0 = nothing, 1 = enable looping
   *	bit 4. - 0 = nothing, 1 = bidirectional looping
   *	bit 5. - 0 = nothing, 1 = enable wavetable IRQ
   *	bit 6. - 0 = increasing addresses, 1 = decreasing addresses
   *	bit 7. - 1 = copy bits 0. & 1. from actual voice control register
   * note: don't set bits 5 & 7 - this thing must be controled by driver
   */
void gus_do_voice_frequency( void *handle, unsigned char voice, unsigned int freq );
  /*
   * set voice frequency in Hz
   */
void gus_do_voice_volume( void *handle, unsigned char voice, unsigned short vol );
  /*
   * set voice volume level 0-16384 (linear)
   */
void gus_do_voice_loop_range( void *handle, unsigned char voice, unsigned int start, unsigned int end );
  /*
   * set voice loop start & end positions in sample
   * values are relative from the begining of sample
   */
void gus_do_voice_ramp( void *handle, unsigned char voice, unsigned char start, unsigned char end, unsigned char rate, unsigned char control );
  /*
   * set voice ramp start value
   *    bits 7-4: exponent
   *    bits 3-0: mantisa
   * set voice ramp end value
   *    bits 7-4: exponent
   *    bits 3-0: mantisa
   * set voice volume ramping rate
   * (look at UltraSound Lowlevel Toolkit documentation for more details)
   *    bits 7-6: rate
   *	bits 5-0: volume increment
   * set ramp control register
   *   bit 0. - 0 = volume ramping in progress, 1 = volume ramping is inactive
   *   bit 1. - 0 = nothing, 1 = stop ramp
   *   bit 2. - 0 = nothing, 1 = roll over condition
   *   bit 3. - 0 = nothing, 1 = ramp loop enable
   *   bit 4. - 0 = nothing, 1 = bidirectional ramp loop enable
   *   bit 5. - 0 = nothing, 1 = volume ramp IRQ enable
   *   bit 6. - 0 = increasing direction, 1 = decreasing direction
   *   bit 7. - 0 = nothing, 1 = volume ramp IRQ pending
   * note: don't set bits 2,5,7 - these things must be controled by driver
   */
void gus_do_voice_position( void *handle, unsigned char voice, unsigned int pos );
  /*
   * set current voice position
   * value is relative from the begining of sample
   */
void gus_do_voice_pan( void *handle, unsigned char voice, unsigned short pan );
  /*
   * set voice pan (0-16384) (full left - full right)
   */

void gus_do_voice_lfo_setup( void *handle, unsigned char voice, int type, int freq, int final_depth, int sweep, int shape );
void gus_do_voice_lfo_freq( void *handle, unsigned char voice, int type, int freq );
void gus_do_voice_lfo_depth( void *handle, unsigned char voice, int type, int depth );
void gus_do_voice_lfo_enable( void *handle, unsigned char voice, int type );
void gus_do_voice_lfo_disable( void *handle, unsigned char voice, int type );
void gus_do_voice_lfo_shutdown( void *handle, unsigned char voice, int type );

void gus_do_voice_interwave_effect( void *handle, unsigned char voice, unsigned short eff_volume, int eff1, int eff2, int eff3, int eff4 );
  /*
   * select effects for this voice and setup effect volume
   * effect_volume level 0-16384
   * if effX == -1 -> no effect
   * if this command is used with gus_effect_interwave() function,
   *   reverb effect = 0 and chorus effect = 2
   */
void gus_do_voice_frequency_mode( void *handle, unsigned int mode );
  /*
   * see to GUS_FREQ_XXXX contants in gus.h
   */
void gus_do_voice_volume_mode( void *handle, unsigned short mode );
  /*
   * see to GUS_VOLUME_XXXX contants in gus.h
   */
void gus_do_voice_pan_mode( void *handle, unsigned short mode );
  /*
   * see to GUS_PAN_XXXX contants in gus.h
   */

void gus_do_chn_program( void *handle, unsigned char channel, unsigned short program );
void gus_do_chn_note_on( void *handle, unsigned char channel, unsigned char note, unsigned char velocity, unsigned char priority );
void gus_do_chn_note_off( void *handle, unsigned char channel, unsigned char note, unsigned char velocity );
void gus_do_chn_pitchbend( void *handle, unsigned char channel, unsigned short pitchbend );
void gus_do_chn_control( void *handle, unsigned char channel, unsigned char p1, unsigned char p2 );
void gus_do_chn_note_pressure( void *handle, unsigned char channel, unsigned char p1, unsigned char p2 );
void gus_do_chn_pressure( void *handle, unsigned char channel, unsigned char p1 );

void gus_do_tempo( void *handle, unsigned int tempo );
  /*
   * set new tempo
   */
void gus_do_wait( void *handle, unsigned int ticks );
  /*
   * wait x ticks - this command is block separator
   * all commands between blocks are interpreted in the begining of one tick
   */
void gus_do_stop( void *handle );
  /*
   * this command is remark for gus_queue_abort_to_stop
   */
void gus_do_echo( void *handle, unsigned char *src, int size );
  /*
   * echo data at *src (max 7 bytes) in specified time to file (stream) input
   */

#ifdef __cplusplus
}
#endif

struct GUS_STRU_CALLBACKS {
  unsigned int version;			/* version of this structure - 2 */
  void *privatedata;			/* user data */
  void (*call_echo)( void *handle, void *privatedata, unsigned char *data );
  void (*call_voices_change)( void *handle, void *privatedata, int voices );
};

typedef struct GUS_STRU_CALLBACKS gus_callbacks_t;

#ifdef __cplusplus
extern "C" {
#endif
   
int gus_do_input( void *handle, gus_callbacks_t *callbacks );
  /*
   * return value:	zero if success, -1 if error
   */

#ifdef __cplusplus
}
#endif

/***************************************************************************
 *                                                                         *
 *             Support for various instrument formats                      *
 *                                                                         *
 ***************************************************************************/

typedef struct __gus_rom_interwave_header {
  char iwave[ 8 ];
  unsigned char rom_hdr_revision;
  unsigned char series_number;
  char series_name[ 16 ];
  char date[ 10 ];
  unsigned short vendor_revision_major;
  unsigned short vendor_revision_minor;
  unsigned int rom_size;
  char copyright[ 128 ];
  char vendor_name[ 64 ];
  char rom_description[ 128 ];
} gus_rom_interwave_header_t;

#ifdef __cplusplus
extern "C" {
#endif

gus_instrument_t *gus_instr_alloc( void );
int gus_instr_free( gus_instrument_t *instrument );
int gus_instr_patch_load( gus_instrument_t *instr, char *filename, int s8bit );
int gus_instr_ffff_access_synth( void );
int gus_instr_ffff_access_daemon( void );
int gus_instr_ffff_access_midi( int midi_device );
int gus_instr_ffff_get_rom_header( int fd, int access, int bank, gus_rom_interwave_header_t *header );
int gus_instr_ffff_open( char *fff_filename, char *dat_filename );
int gus_instr_ffff_open_rom( int fd, int access, int bank, int file );
int gus_instr_ffff_close( int handle );
int gus_instr_ffff_download( int handle, int fd, int access, int temporary );
int gus_instr_ffff_download_free( int handle, int fd, int access, int temporary );
int gus_instr_ffff_load( gus_instrument_t *instr, int handle, int bank, int prog );

#ifdef __cplusplus
}
#endif

/***************************************************************************
 *                                                                         *
 *                            Effects support                              *
 *                                                                         *
 ***************************************************************************/

/* effect1 - known as reverb */
#define GUS_EFFECT_INTERWAVE_1_ROOM1		0
#define GUS_EFFECT_INTERWAVE_1_ROOM2		1
#define GUS_EFFECT_INTERWAVE_1_ROOM3		2
#define GUS_EFFECT_INTERWAVE_1_HALL1		3
#define GUS_EFFECT_INTERWAVE_1_HALL2		4	/* default in DOS */
#define GUS_EFFECT_INTERWAVE_1_PLATE		5
#define GUS_EFFECT_INTERWAVE_1_DELAY		6
#define GUS_EFFECT_INTERWAVE_1_PANNING_DELAY	7
/* effect3 - known as chorus */
#define GUS_EFFECT_INTERWAVE_3_CHORUS1		0
#define GUS_EFFECT_INTERWAVE_3_CHORUS2		1
#define GUS_EFFECT_INTERWAVE_3_CHORUS3		2	/* default in DOS */
#define GUS_EFFECT_INTERWAVE_3_CHORUS4		3
#define GUS_EFFECT_INTERWAVE_3_FEEDBACK_CHORUS	4
#define GUS_EFFECT_INTERWAVE_3_FLANGER		5
#define GUS_EFFECT_INTERWAVE_3_SHORT_DELAY	6
#define GUS_EFFECT_INTERWAVE_3_SHORT_DELAY_FB	7	/* feed back? */

int gus_effect_interwave( gus_effect_t *effect, int effect1, int effect3 );

/***************************************************************************
 *                                                                         *
 *                    GUS instrument configuration                         *
 *                                                                         *
 ***************************************************************************/

#if defined( __GUS_PATH_APP__ )
#include "./libgus_icfg.h"
#elif defined( __GUS_PATH_LIB__ )
#include "../../../include/libgus_icfg.h"
#else
#include <libgus_icfg.h>
#endif

/***************************************************************************
 *                                                                         *
 *                    GUS mixer support functions                          *
 *                                                                         *
 ***************************************************************************/

#define GUS_MIXER_ID_MASTER	SOUND_MIXER_VOLUME
#define GUS_MIXER_ID_SYNTH	SOUND_MIXER_SYNTH
#define GUS_MIXER_ID_PCM	SOUND_MIXER_PCM
#define GUS_MIXER_ID_PCM1	SOUND_MIXER_SPEAKER
#define GUS_MIXER_ID_LINE	SOUND_MIXER_LINE
#define GUS_MIXER_ID_MIC	SOUND_MIXER_MIC
#define GUS_MIXER_ID_CD		SOUND_MIXER_CD
#define GUS_MIXER_ID_SOFT	SOUND_MIXER_IMIX
#define GUS_MIXER_ID_GAIN	SOUND_MIXER_RECLEV
#define GUS_MIXER_ID_LOOP	SOUND_MIXER_LINE1
#define GUS_MIXER_ID_EFFECT	SOUND_MIXER_LINE2

#define GUS_MIXER_MASK_MASTER	SOUND_MASK_VOLUME
#define GUS_MIXER_MASK_SYNTH	SOUND_MASK_SYNTH
#define GUS_MIXER_MASK_PCM	SOUND_MASK_PCM
#define GUS_MIXER_MASK_PCM1	SOUND_MASK_SPEAKER
#define GUS_MIXER_MASK_LINE	SOUND_MASK_LINE
#define GUS_MIXER_MASK_MIC	SOUND_MASK_MIC
#define GUS_MIXER_MASK_CD	SOUND_MASK_CD
#define GUS_MIXER_MASK_SOFT	SOUND_MASK_IMIX
#define GUS_MIXER_MASK_GAIN	SOUND_MASK_RECLEV
#define GUS_MIXER_MASK_LOOP	SOUND_MASK_LINE1
#define GUS_MIXER_MASK_EFFECT	SOUND_MASK_LINE2

#ifdef __cplusplus
extern "C" {
#endif

int gus_mixer_cards( void );
  /*
   * return value:	cards installed in the system
   */
int gus_mixer_devices( const char *id );
  /*
   * return value:	devices installed in the system for specified card
   */
int gus_mixer_look_for_card( const char *id );
  /*
   * see to gus_look_for_card()
   */
int gus_mixer_open( void **handle, int card, int device );
  /*
   * input value:	selected card & device
   * return value:	selected card if successfull
   */
int gus_mixer_close( void *handle );
  /*
   * input value:	handle of device to close
   * return value:	zero if successfull
   */

int gus_mixer_version( void *handle );
  /*
   * return value:	see to GUS_CARD_VERSION_XXXX constants
   */
char *gus_mixer_model( void *handle );
  /*
   * return value:	string (allocated over strdup)
   */
int gus_mixer_read_devmask( void *handle );
  /*
   * return value:	available devices mask
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_read_stereodevs( void *handle );
  /*
   * return value:	available stereo devices mask
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_read_recmask( void *handle );
  /*
   * return value:	available record devices mask
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_read_recsrc( void *handle );
  /*
   * return value:	current record source
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_write_recsrc( void *handle, int value );
  /*
   * input value:	new record source
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_read_devs_lmute( void *handle );
  /*
   * return value:	bitmask with muted devices (left channel)
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_read_devs_rmute( void *handle );
  /*
   * return value:	bitmask with muted devices (right channel)
   *			(look at GUS_MIXER_MASK_XXXX)
   */
int gus_mixer_write_devs_lmute( void *handle, int dev, int mute );
  /*
   * input value:	device and mute flag ( 0 - unmute, != 0 - mute)
   *			left channel
   *			(look at GUS_MIXER_MASK_XXXX - soundcard.h)
   * return value:	zero if successfull
   */
int gus_mixer_write_devs_rmute( void *handle, int dev, int mute );
  /*
   * input value:	device and mute flag ( 0 - unmute, != 0 - mute)
   *			right channel
   *			(look at GUS_MIXER_MASK_XXXX - soundcard.h)
   * return value:	zero if successfull
   */

  /*
   * functions bellow use following form of the input/output values:
   *	bits 0-7 (low byte): left channel volume level (0-100)
   *	bits 8-15 (high byte): right channel volume level (0-100)
   */

int gus_mixer_read_mic( void *handle );	/* all (NONE & CODEC - mono) */
int gus_mixer_read_cd( void *handle );	/* ICS, CODEC, ENH_CODEC */
int gus_mixer_read_line( void *handle ); /* all (NONE - mono) */
int gus_mixer_read_synth( void *handle ); /* all (NONE - mono) */
int gus_mixer_read_pcm( void *handle );	/* all */
int gus_mixer_read_pcm1( void *handle ); /* only cards with CODEC (DSP) */
int gus_mixer_read_reclev( void *handle ); /* CODEC, ENH_CODEC - mono */
int gus_mixer_read_volume( void *handle ); /* ICS, ENH_CODEC */
int gus_mixer_read_imix( void *handle ); /* ICS, CODEC, ENH_CODEC - all mono */
int gus_mixer_read_loopback( void *handle ); /* CODEC, ENH_CODEC - mono */
int gus_mixer_read_effect( void *handle ); /* InterWave only - mono */

int gus_mixer_write_mic( void *handle, int value );
int gus_mixer_write_cd( void *handle, int value );
int gus_mixer_write_line( void *handle, int value );
int gus_mixer_write_synth( void *handle, int value );
int gus_mixer_write_pcm( void *handle, int value );
int gus_mixer_write_pcm1( void *handle, int value );
int gus_mixer_write_reclev( void *handle, int value );
int gus_mixer_write_volume( void *handle, int value );
int gus_mixer_write_imix( void *handle, int value );
int gus_mixer_write_loopback( void *handle, int value );
int gus_mixer_write_effect( void *handle, int value );

int gus_mixer_read_interwave_serial( void *handle );
int gus_mixer_write_interwave_serial( void *handle, int serial );

#ifdef __cplusplus
}
#endif

/***************************************************************************
 *                                                                         *
 *                      Conversion routines                                *
 *                                                                         *
 ***************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

void gus_convert_delta( unsigned int type, unsigned char *dest,
			unsigned char *src, size_t size );
  /*
   * note: dest and src pointers can be equal
   */
void gus_convert_8bit_to_16bit( unsigned short *dest, unsigned char *src,
				size_t size );
  /*
   * note: dest and src pointers can be equal
   */
void gus_convert_spline_oversampling_8bit(
			signed char *dest, signed char *src,
			size_t size, float factor, int unsigned_ );
  /*
   * note: output array is always signed
   */
void gus_convert_spline_oversampling_16bit(
			signed short *dest, signed short *src,
			size_t size, float factor, int unsigned_ );
  /*
   * note: output array is always signed
   */
void gus_convert_spline_oversampling_8bit_to_16bit(
			signed short *dest, signed char *src,
			size_t size, float factor, int unsigned_ );
  /*
   * note: output array is always signed
   */

#ifdef __cplusplus
}
#endif

/***************************************************************************
 *                                                                         *
 *                             PCM routines                                *
 *                                                                         *
 ***************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

int gus_pcm_cards( void );
  /*
   * return value:	cards installed in the system
   */
int gus_pcm_devices( const char *id );
  /*
   * return value:	devices installed in the system
   */
int gus_pcm_look_for_card( const char *id );
  /*
   * see to gus_look_for_card()
   */

#define GUS_PCM_DIRECTION_PLAYBACK	O_WRONLY
#define GUS_PCM_DIRECTION_RECORD	O_RDONLY
#define GUS_PCM_DIRECTION_DUPLEX	O_RDWR
#define GUS_PCM_DIRECTION_BOTH		GUS_PCM_DIRECTION_DUPLEX

#define GUS_PCM_OF_NONE			0x00000000
#define GUS_PCM_OF_NONBLOCK		0x00000001

int gus_pcm_open( void **handle, int card, int device, int direction, int flags );
int gus_pcm_close( void *handle );
int gus_pcm_get_file_descriptor( void *handle );

#define GUS_PCM_MODE_NONE		AFMT_QUERY
#define GUS_PCM_MODE_S8			AFMT_S8
#define GUS_PCM_MODE_U8			AFMT_U8
#define GUS_PCM_MODE_S16_LE		AFMT_S16_LE	/* little endian */
#define GUS_PCM_MODE_U16_LE		AFMT_U16_LE	/* little endian */
#define GUS_PCM_MODE_S16_BE		AFMT_S16_BE	/* big endian */
#define GUS_PCM_MODE_U16_BE		AFMT_U16_BE	/* big endian */
#define GUS_PCM_MODE_MU_LAW		AFMT_MU_LAW
#define GUS_PCM_MODE_A_LAW		AFMT_A_LAW
#define GUS_PCM_MODE_IMA_ADPCM		AFMT_IMA_ADPCM

int gus_pcm_mode_set( void *handle, int direction, unsigned int mode );
unsigned int gus_pcm_mode_get( void *handle, int direction );
unsigned int gus_pcm_mode_supported( void *handle, int direction );

int gus_pcm_channels_set( void *handle, int direction, int channels );
int gus_pcm_channels_get( void *handle, int direction );
int gus_pcm_channels_supported( void *handle, int direction );

int gus_pcm_rate_set( void *handle, int direction, int rate );
int gus_pcm_rate_get( void *handle, int direction );
int gus_pcm_rate_supported( void *handle, int direction );

int gus_pcm_dma_size_set( void *handle, int direction, int fragments, int fragment_size );
int gus_pcm_dma_size_get( void *handle, int direction, int current );

int gus_pcm_sync( void *handle, int direction );

int gus_pcm_read( void *handle, unsigned char *buffer, int count );
int gus_pcm_write( void *handle, unsigned char *buffer, int count );

#ifdef __cplusplus
}
#endif

/***************************************************************************
 *                                                                         *
 *                             MIDI routines                               *
 *                                                                         *
 ***************************************************************************/

#define GUS_MIDI_CHANNELS		16
#define GUS_MIDI_PROGRAM( bank, prog )	(((unsigned int)bank<<16)|prog)
#define GUS_MIDI_PROGRAM_BANK( prog )	(prog >> 16)
#define GUS_MIDI_PROGRAM_PROG( prog )	(prog & 0xffff)

typedef struct __gus_midi_device {
  unsigned char mode;		/* mode.. GUS_MIDI_OPEN_MODE_XXXX */
  unsigned char device;		/* input/output device number */
  unsigned short channels;	/* midi channels processed by this device */
  unsigned char midi_device;	/* midi device # */
  unsigned char emulation;	/* emulation - GUS_MIDI_EMUL_XXXX */
  unsigned int cap;		/* device capabilities - GUS_MIDI_CAP_XXXX */
  unsigned short midi_id_number;
  unsigned short midi_family_code;
  unsigned short midi_family_number_code;
  unsigned int midi_software_revision;
  unsigned int reserved[ 4 ];	/* reserved for future use */
  struct __gus_midi_device *next; /* next device */
} gus_midi_device_t;

#ifdef __cplusplus
extern "C" {
#endif

char *gus_midi_error( void );
char *gus_midi_error_set( char *error );

int gus_midi_cards( void );
int gus_midi_devices( gus_midi_devices_t *devices );
int gus_midi_device_info( gus_midi_device_info_t *info );
char *gus_midi_device_info_manufacture( gus_midi_device_t *device );
char *gus_midi_device_info_family( gus_midi_device_t *device );
char *gus_midi_device_info_product( gus_midi_device_t *device );
int gus_midi_autodetection( int device );
gus_midi_device_t *gus_midi_output_device( int device );
gus_midi_device_t *gus_midi_input_device( int device );
gus_midi_device_t *gus_midi_output_devices( void );
gus_midi_device_t *gus_midi_input_devices( void );

#define GUS_MIDI_IN		O_RDONLY
#define GUS_MIDI_OUT		O_WRONLY
#define GUS_MIDI_BOTH		O_RDWR

#define GUS_MIDI_OF_NONE	0x00000000
#define GUS_MIDI_OF_NONBLOCK	0x00000001
#define GUS_MIDI_OF_ECHO_ENABLE	0x00000002

int gus_midi_fill_device_structure( gus_midi_device_t *device, int mode, int device_number, unsigned short channels );
int gus_midi_open( int file_flags, gus_midi_device_t *cards, size_t buffer_size, int flags );
int gus_midi_open_intelligent( int file_flags, char *cfg_file, size_t buffer_size, int flags );
int gus_midi_close( void );
int gus_midi_get_file_descriptor( void );

int gus_midi_realtime( int enable );

int gus_midi_gs_sysex_checksum( unsigned char *data, int size );

int gus_midi_reset( void );
int gus_midi_detach( void );
int gus_midi_emulation_set( int device, int emulation );	/* see to GUS_MIDI_EMUL_XXXX */
int gus_midi_emulation_get( int device );			/* see to GUS_MIDI_EMUL_XXXX */

int gus_midi_note_on( int device, int chn, int note, int vel );
int gus_midi_note_off( int device, int chn, int note, int vel );
int gus_midi_note_pressure( int device, int chn, int note, int vel );
int gus_midi_channel_pressure( int device, int chn, int vel );
int gus_midi_bender( int device, int chn, int pitch );	/* range: 0-16383 */
int gus_midi_program_change( int device, int chn, int program );
int gus_midi_control( int device, int chn, int p1, int p2 );
int gus_midi_sysex( int device, unsigned char *data, int len );
int gus_midi_master_volume( int device, int volume );

int gus_midi_raw_data( int device, unsigned char *data, int len );
int gus_midi_echo( unsigned char *data, int len );

int gus_midi_timer_base( int base );
int gus_midi_timer_tempo( int tempo );
int gus_midi_timer_start( void );
int gus_midi_timer_stop( void );
int gus_midi_timer_continue( void );
int gus_midi_wait( int ticks );
int gus_midi_write( void );
int gus_midi_flush( void );
int gus_midi_abort( void );
int gus_midi_threshold( int threshold );

#ifdef __cplusplus
}
#endif

typedef struct __gus_midi_callbacks {
  unsigned int version;			/* version of this structure - 17 */
  void *privatedata;			/* user data */
  void (*call_note_on)( void *privatedata, int device, int chn, int note, int vel );
  void (*call_note_off)( void *privatedata, int device, int chn, int note, int vel );
  void (*call_note_pressure)( void *privatedata, int device, int chn, int note, int vel );
  void (*call_channel_pressure)( void *privatedata, int device, int chn, int vel );
  void (*call_bender)( void *privatedata, int device, int chn, int pitch );
  void (*call_program_change)( void *privatedata, int device, int chn, int program );
  void (*call_control)( void *privatedata, int device, int chn, int p1, int p2 );
  void (*call_sysex)( void *privatedata, int device, unsigned char *data, int len );
  void (*call_echo)( void *privatedata, unsigned char *data, int len );
  void (*call_wait)( void *privatedata, unsigned int tick );
  void (*call_mtc_quarter)( void *privatedata, int device, int quarter );
  void (*call_song_select)( void *privatedata, int device, int song );
  void (*call_song_position)( void *privatedata, int device, int position );
  void (*call_tune_request)( void *privatedata, int device );
  void (*call_start)( void *privatedata, int device );
  void (*call_continue)( void *privatedata, int device );
  void (*call_stop)( void *privatedata, int device );
} gus_midi_callbacks_t;

#ifdef __cplusplus
extern "C" {
#endif

int gus_midi_input( gus_midi_callbacks_t *callbacks );

int gus_midi_thru_set( gus_midi_thru_t *thru );
int gus_midi_thru_get( gus_midi_thru_t *thru );
int gus_mdii_thru_clear( int i_dev );
int gus_midi_thru_channel_set( int i_dev, int i_chn, int o_dev, int o_chn, int o_vel );
int gus_midi_thru_channel_clear( int i_dev, int i_chn, int o_dev );

int gus_midi_preload_bank( int device, char *bank_name );
int gus_midi_preload_program( int device, int *instruments, int count );

int gus_midi_icfg_open( int device, char *filename, char *source, char *options );
int gus_midi_icfg_close( int device );
int gus_midi_icfg_emulation_sync( int device );
void gus_midi_icfg_error_handler( int device,
	void (*error)( int device, char *filename, int line, char *format, va_list va ),
	void (*warning)( int device, char *filename, int line, char *format, va_list va ) );
int gus_midi_icfg_preload( int device, char *source, char *options );
int gus_midi_icfg_download_program( int device, int *instruments, int count );
int gus_midi_icfg_info( int device, char *filename, struct gus_icfg_info **info );

int gus_midi_memory_reset_all( void );
int gus_midi_memory_reset( int device );
int gus_midi_memory_test( int device, gus_instrument_t *instr );
int gus_midi_memory_alloc( int device, gus_instrument_t *instr );
int gus_midi_memory_free( int device, gus_instrument_t *instr );
int gus_midi_memory_pack( int device );
int gus_midi_memory_list( int device, gus_memory_list_t *list );
int gus_midi_memory_block_alloc( int device, gus_memory_block_t *block );
int gus_midi_memory_block_free( int device, gus_memory_block_t *block );
int gus_midi_memory_get_name( int device, gus_instrument_name_t *name );
int gus_midi_memory_dump( int device, gus_memory_dump_t *dump );

int gus_midi_synth_info( int device, gus_info_t *info );

int gus_midi_effect_reset( int device );
int gus_midi_effect_setup( int device, gus_effect_t *effect );

#ifdef __cplusplus
}
#endif

typedef struct __gus_midiplay_callbacks {
  unsigned int version;			/* version of this structure - 15 */
  void *privatedata;			/* user data */
  int last_fd;				/* last file descriptor - for select() */
  fd_set read_fds;
  fd_set write_fds;
  void (*call_select)( void *privatedata, fd_set *read_fds, fd_set *write_fds );
  void (*call_info)( void *privatedata, int format, char *format_name, int tracks );
  void (*call_download_program)( void *privatedata, gus_midi_device_t *device, unsigned int program );
  void (*call_totaltime)( void *privatedata, unsigned int time );	/* in 1/10 of sec */
  void (*call_time)( void *privatedata, unsigned int time );	/* in 1/10 of sec */
  void (*call_text)( void *privatedata, int track, char *text );
  void (*call_copyright)( void *privatedata, int track, char *text );
  void (*call_sequence)( void *privatedata, int track, char *text );
  void (*call_instrument)( void *privatedata, int track, char *text );
  void (*call_lyric)( void *privatedata, int track, char *text );
  void (*call_marker)( void *privatedata, int track, char *text );
  void (*call_cuepoint)( void *privatedata, int track, char *text );
} gus_midiplay_callbacks_t;

#ifdef __cplusplus
extern "C" {
#endif

int gus_midiplay_songs( unsigned char *song_data, unsigned int song_size );
int gus_midiplay_song( int device, unsigned char *song_data, unsigned int song_size, int song_number, gus_midiplay_callbacks_t *callbacks );
int gus_midiplay_stop( int pause );
  /*
   * pause == 1 -> abort
   * pause == 2 -> pause
   * pause == 0 -> continue
   */

#ifdef __cplusplus
}
#endif

/*
 *
 */
 
#endif /* __LIBGUS_H */