#ifndef GUS_PATCH_H
#define GUS_PATCH_H


/******************************************************************************

{                     ** FORTE's patch format, v1.10 **                      }
{   (compiled from various sources, most notably Francois Dion's PATCHKIT)   }


{  Patch file structure:

_________________________________
|  PatchHeader                  |
_________________________________
|  instruments *                |
|  _________________________________
|  |  InstrumentHeader             |
|  _________________________________
|  |  layers *                     |
|  |  _________________________________
|  |  |  LayerHeader                  |
|  |  _________________________________
|  |  |  samples *                    |
|  |  |  _________________________________
____  |  |  WaveHeader                   |
   ____  _________________________________
      ____  The actual sample data       |
         _________________________________ }


******************************************************************************/


/* GUS PatchHeader */
#define	GPH_header				0	/* array[0..11] of Char; { asciz, Currently 'GF1PATCH110'#0  } */
#define	GPH_gravis_id			12	/* array[0..9] of Char;  { asciz, Always 'ID#000002'         } */
#define	GPH_description		22	/* array[0..59] of Char; { asciz, Whatever you want, (Gravis } */
											/*                       { uses it for a copyright notice)   } */
#define	GPH_instruments		82	/* Byte;                 { 1, number of instruments in patch } */
											/*                       { Could be > 1 but why such a thing?} */
#define	GPH_voices				83	/* Byte;                 { 14, Playback voices, ignored      } */
#define	GPH_channels			84	/* Byte;                 { 0, ignored, Wav channels that can } */
											/*                       { be played beside the patch        } */
#define	GPH_wave_forms			85	/* Word;                 { Total number of waveforms in file } */
#define	GPH_master_volume		87	/* Word;                 { Master Volume, 00..7F             } */
#define	GPH_data_size			89	/* DWord;                { Memory patch takes in gusram?     } */
#define	GPH_reserved			93	/* array[0..35] of Byte; { For future extensions             } */
#define	GPH_sizeof				129

#define GF1_HEADER_TEXT	"GF1PATCH110"
#define GRAVIS_ID_TEXT	"ID#000002"


/* GUS InstrHeader */
#define	GIH_instrument			0	/* Word;                { Instrument id: 0..FFFF            } */
#define	GIH_instrument_name	2	/* array[0..15] of Char;{ Name of instrument                } */
											/*                      { Not used in patches of 2.06 disks } */
											/*                      { but you SHOULD use it, This is    } */
											/*                      { what's seen when you choose  'Use } */
											/*                      { Names from Patch files' in the Win} */
											/*                      { Patch Manager, and it will become } */
											/*                      { essential once we have bank-switch} */
											/*                      { and not only GM-sounds            } */
#define	GIH_instrument_size	18	/* DWord;               { Number of bytes for the instrument} */
											/*                      { excl. header.To skip to next instr} */
#define	GIH_layers				22	/* Byte;                { 1, Number of layers in instr: 1-4 } */
											/*                      { Current drivers only support 1    } */
#define	GIH_reserved			23	/* array[0..39] of Byte;{ For future extensions             } */
#define	GIH_sizeof				63


/* GUS LayerHeader */
#define	GLH_layer_duplicate	0	/* Byte;             { If not 0 the wavesample to use is from the } */
											/*                   { previous layer. Waveheader is still needed } */
#define	GLH_layer				1	/* Byte;             { 0, Layer id: 0..3                          } */
#define	GLH_layer_size			2	/* DWord;            { Data size in bytes in the layer, excluding } */
											/*                   { the header. To skip to next layer          } */
#define	GLH_samples				6	/* Byte;             { number of wavesamples                      } */
#define	GLH_reserved			7	/* array[0..39] of Byte; { For future extensions                  } */
#define	GLH_sizeof				47


/* GUSWaveHeader */
#define	GWH_wave_name			0	/* array[0..6] of Char; { asciz. name of the wave. 'NoName'#0 } */
											/*              { if none, use 'C3', 'High' and such names    } */
#define	GWH_fractions			7	/* Byte;        { Start loop point fraction in 4 bits + End } */
											/*              { loop point fraction in the 4 other bits;  } */
											/*              { used when looppoint is between two samples} */
#define	GWH_wave_size			8	/* DWord;       { Total size of wavesample. Limited to 64KB } */
											/*              { now by the drivers,card can do up to 256KB} */
#define	GWH_start_loop			12	/* DWord;       { Start loop position                       } */
#define	GWH_end_loop			16	/* DWord;       { End loop position                         } */
#define	GWH_sample_rate		20	/* Word;        { Sample frequency, in Hz                   } */
#define	GWH_low_frequency		22	/* DWord;       { Lowest frequency to play, see scale_table } */
#define	GWH_high_frequency	26	/* DWord;       { Highest frequency to play, see scale_table} */
#define	GWH_root_frequency	30	/* DWord;       { Root frequency to play, see scale_table   } */
											/*              { The 'frequency' wich correspond to the    } */
											/*              { sample_rate.(this is the freq that sounds } */
											/*              { in the drum bank are played at)           } */
#define	GWH_tune					34	/* Integer;     { Always 1, not used anymore                } */
#define	GWH_balance				36	/* Byte;        { Pan, 0..15, (0-full left, 15-full right)  } */
#define	GWH_envelope_rate		37	/* array[0..5] of Byte; { attack rates                      } */
#define	GWH_envelope_offset	43	/* array[0..5] of Byte; { attack offsets                    } */
											/*     { 6 point Envelope                                  }
											/*     { The rates are coded rather tricky. The least      }
											/*     { significant 6 bits (5..0) are used as the         }
											/*     { divisor D of a time T given by the 2 most         }
											/*     { significant bits (7..6) where T approx equals     }
											/*     { (in secs):   T*20        Bit7     Bit6            }
											/*     {              1           0        0               }
											/*     {              8           0        1               }
											/*     {              64          1        0               }
											/*     {              512         1        1               }
											/*     { The time it takes to get to the associated level  }
											/*     { now equals T/D	(D=1..63) YES: D <> 0(!)           }
											/*     { Indeed, there are overlaps in the total time.     }
											/*     { So for example:                                   }
											/*     { Fastest -> Rate = 63                              }
											/*     { Slowest -> Rate = 193                             }
#define	GWH_tremolo_sweep		49	/* Byte;        { tremolo sweep (sensitivity? amplitude?) } */
#define	GWH_tremolo_rate		50	/* Byte;        { tremolo rate                            } */
#define	GWH_tremolo_depth		51	/* Byte;        { tremolo depth                           } */
#define	GWH_vibrato_sweep		52	/* Byte;        { vibrato sweep                           } */
#define	GWH_vibrato_rate		53	/* Byte;        { vibrato rate (lfo - sine)               } */
#define	GWH_vibrato_depth		54	/* Byte;        { vibrato depth                           } */
#define	GWH_modes				55	/* Byte;        { A set of flags:                         } */
											/*     { bit 0 = 0=8 bit, 1=16 bit wave data.                                 } */
											/*     { bit 1 = 0=Signed data, 1=Unsigned data.                              } */
											/*     { bit 2 = 1=Enable looping                                             } */
											/*     { bit 3 = 1=Enable bidirectional looping                               } */
											/*     { bit 4 = 1=Enable looping backward                                    } */
											/*     { bit 5 = 1=Enable sustain (3rd point of envelope)                     } */
											/*     { bit 6 = 1=Enable envelopes, must be set if you want to hear anything } */
											/*     { bit 7 = 1=Enable clamped release (6th point of envelope)             } */
#define	GWH_scale_frequency	56	/* Integer;     { 60, offset in scale table?                } */
#define	GWH_scale_factor		58	/* Word;        { from 0 to 2048 or 0 to 2                  } */
											/*              { freq := (freq*scale_factor) shr 10        } */
#define	GWH_reserved			60	/* array[0..35] of Byte; { For future extensions            } */
#define	GWH_sizeof				96

#define ENVELOPES	6					/* number of envelope points */

#define RATE_RANGE		0xC0
#define RATE_MANTISSA	0x3F

#define WAVE_16_BITS		0x01		/* bit 0 = 8 or 16 bit wave data.              */
#define WAVE_UNSIGNED	0x02		/* bit 1 = Signed - Unsigned data.             */
#define WAVE_LOOPING		0x04		/* bit 2 = Looping enabled - 1.                */
#define WAVE_BIDIR_LOOP	0x08		/* bit 3 = Set is bidirectional looping.       */
#define WAVE_LOOP_BACK	0x10		/* bit 4 = Set is looping backward.            */
#define WAVE_SUSTAIN_ON	0x20		/* bit 5 = Turn sustaining on. (Env. pts. 3)   */
#define WAVE_ENVELOPES	0x40		/* bit 6 = Enable envelopes - 1                */
											/*         (use the env_rate/env_offs fields). */
#define WAVE_CLAMPED_ON	0x80		/* bit 7 = Enable clamped release - 1          */


#endif /* GUS_PATCH_H */

