home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK6 / OS_09 / TRACK061.ZIP / DEFS.H < prev    next >
C/C++ Source or Header  |  1992-10-30  |  8KB  |  319 lines

  1. /* defs.h */
  2.  
  3. /* $Author: espie $
  4.  * $Id: extern.h,v 2.9 1991/12/04 08:28:53 espie Exp espie $
  5.  * $Revision: 2.9 $
  6.  * $Log: extern.h,v $
  7.  * Revision 2.9  1991/12/04  08:28:53  espie
  8.  * Separated mix/stereo stuff.
  9.  */
  10.  
  11. #include <stdio.h>
  12.  
  13. /*
  14.  * This is the precise type for storing the samples:
  15.  * should be signed char.
  16.  *
  17.  * Don't change this to 'int' or anything else; I found out the hard way.
  18.  * Apparently, this is used everywhere other than the output drivers,
  19.  * so I don't see any reason to have it be device-dependent.
  20.  * "machine.h" doesn't contain anything else, and things would be simpler
  21.  * for the make if we didn't have it at all.
  22.  * -SH 6/92
  23.  */
  24. typedef signed char SAMPLE;
  25.  
  26. /* How many audio channels by default (1 = Mono, 2 = Stereo) */
  27. #define DEFAULT_CHANNELS    2
  28.  
  29. /*
  30.  * What percent of the left/right channel should leak to the other side (-mix)
  31.  */
  32. #define DEFAULT_MIX    0
  33.  
  34. /* error types. Everything is centralized,
  35.  * and we check in some places (see read, player and str32)
  36.  * that there was no error. Additionnally signal traps work
  37.  * that way too.
  38.  */
  39.  
  40. #define NONE 0            /* normal state */
  41. #define FILE_TOO_SHORT 1    /* read error */
  42. #define CORRUPT_FILE 2
  43. #define NEXT_SONG 3        /* trap error: goto next song right now */
  44. #define FAULT 4            /* run time problem */
  45. #define ENDED 5            /* the song has ended */
  46. /* unrecoverable problem: typically, trying to jump to nowhere land. */
  47. #define UNRECOVERABLE 6
  48. /* Missing sample. Very common error, not too serious. */
  49. #define SAMPLE_FAULT 7
  50.  
  51. #define ACCURACY 16
  52. #define fix_to_int(x) ((x) >> ACCURACY)
  53. #define int_to_fix(x) ((x) << ACCURACY)
  54.  
  55. #define OLD 0
  56. #define NEW 1 
  57. #define BOTH 2           /* for when we try to read it as both types.*/
  58. #define NEW_NO_CHECK 3 /* special type: does not check the signature */
  59. #define NUMBER_NOTES 120
  60.  
  61. /* DO_NOTHING is also used for the automaton */
  62. #define DO_NOTHING 0
  63. #define PLAY 1
  64. #define REPLAY 2
  65.  
  66. #define MAX_ARP 3
  67.  
  68. /* 
  69.  * there is no note in each channel initially.  This is defensive
  70.  * programming, because some commands rely on the previous note.
  71.  * Checking that there was no previous note is a way to detect faulty
  72.  * modules.
  73.  */
  74. #define NO_NOTE 255
  75.   
  76. #define SET_SPEED 1
  77. #define SET_SKIP 2
  78. #define SET_FASTSKIP 4
  79.  
  80. #define NORMAL_SPEED 6
  81. #define NORMAL_FINESPEED 100
  82.  
  83. #define NUMBER_SAMPLES 32
  84.  
  85. #define BLOCK_LENGTH 64
  86. #define NUMBER_TRACKS 4
  87. #define NUMBER_PATTERNS 128
  88.  
  89. #define NUMBER_EFFECTS 16
  90.  
  91. #define MIN_PITCH 113
  92. #define MAX_PITCH 1023
  93.  
  94. #define MIN_VOLUME 0
  95. #define MAX_VOLUME 64
  96.  
  97. #define FUZZ 2            /* the fuzz in note pitch */
  98.  
  99. /* we refuse to allocate more than 500000 bytes for one sample */
  100. #define MAX_SAMPLE_LENGTH 500000
  101.  
  102. /* the actual parameters may be split in two halves occasionnally */
  103. #define LOW(para) ((para) & 15)
  104. #define HI(para) ((para) >> 4)
  105.  
  106. #define MIN(A,B) ((A)<(B) ? (A) : (B))
  107. #define MAX(A,B) ((A)>(B) ? (A) : (B))
  108.  
  109. #define FATAL_ERROR 1
  110. #define NONFATAL_ERROR 2
  111.  
  112. #define MAXSONGS 200
  113.  
  114. struct channel
  115. {
  116.   struct sample_info *samp;
  117.   int mode;            /* automaton state for the sound generatio */
  118.   unsigned int pointer;        /* current sample position (fixed pos) */
  119.   unsigned int step;        /* sample position increment (gives pitch) */
  120.   int volume;            /* current volume of the sample (0-64) */
  121.   int pitch;            /* current pitch of the sample */
  122.   int note;            /* we have to save the note cause */
  123.                 /* we can do an arpeggio without a new note */
  124.  
  125.   int arp[MAX_ARP];        /* the three pitch values for an arpeggio */
  126.   int arpindex;            /* an index to know which note
  127.                    the arpeggio is doing */
  128.  
  129.   int viboffset;        /* current offset for vibrato (if any) */
  130.   int vibdepth;            /* depth of vibrato (if any) */
  131.  
  132.   int slide;            /* step size of pitch slide */
  133.  
  134.   int pitchgoal;        /* pitch to slide to */
  135.   int pitchrate;        /* step rate for portamento */
  136.  
  137.   int volumerate;        /* step rate for volume slide */
  138.  
  139.   int vibrate;            /* step rate for vibrato */
  140.   void (*adjust) ();        /* current command to adjust parameters */
  141. };
  142.  
  143. struct automaton
  144. {
  145.   int pattern_num;        /* the pattern in the song */
  146.   int note_num;            /* the note in the pattern */
  147.   struct block *pattern;    /* the physical pattern */
  148.   struct song_info *info;    /* we need the song_info */
  149.  
  150.   int counter;            /* the fine position inside the effect */
  151.   int speed;            /* the `speed', number of effect repeats */
  152.   int finespeed;        /* the finespeed, base is 100 */
  153.  
  154.   int do_stuff;            /* keeping some stuff to do */
  155.   /* ... and parameters for it: */
  156.   int new_speed, new_note, new_pattern, new_fastspeed;
  157.  
  158.   int pitch, note, para;    /* some extra parameters effects need */
  159. };
  160.  
  161. struct pref            /* User preference settings */
  162. {
  163.   int type, speed, tolerate, repeats, stereo, verbose;
  164. };
  165.  
  166. struct sample_info
  167. {
  168.   char *name;
  169.   int length, rp_offset, rp_length;
  170.   int volume;
  171.   int finetune;
  172.   SAMPLE *start, *rp_start;
  173. };
  174.  
  175. struct event
  176. {
  177.   unsigned char sample_number;
  178.   unsigned char effect;
  179.   unsigned char parameters;
  180.   unsigned char note;
  181.   int pitch;
  182. };
  183.  
  184. struct block
  185. {
  186.   struct event e[NUMBER_TRACKS][BLOCK_LENGTH];
  187. };
  188.  
  189.  
  190. struct song_info
  191. {
  192.   int length;
  193.   int maxpat;
  194.   char patnumber[NUMBER_PATTERNS];
  195.   struct block *pblocks;
  196. };
  197.  
  198. struct song
  199. {
  200.   char *title;
  201.   /* sample 0 is always a dummy sample */
  202.   struct sample_info *samples[NUMBER_SAMPLES];
  203.   struct song_info *info;
  204. };
  205.  
  206. struct compression
  207. {
  208.   char *extension;        /* The last part of the filename */
  209.   char *decomp_cmd;        /* The command to decompress to stdout */
  210. };
  211.  
  212. extern int error;
  213. extern int quiet;
  214. extern int pitch_table[];    /* pitch of each and every note */
  215. extern struct pref pref;    /* user preferences */
  216.  
  217. /* xxx_audio.c */
  218.  
  219. /* close_audio():
  220.  * returns the audio to the system control, doing necessary
  221.  * cleanup
  222.  */
  223. void close_audio (void);
  224.  
  225. /* set_mix(percent): set mix channels level.
  226.  * 0: spatial stereo. 100: mono.
  227.  */
  228. void set_mix (int percent);
  229.  
  230. /* output_samples(l, r): outputs a pair of stereo samples.
  231.  * Samples are 15 bits signed.
  232.  */
  233. void output_samples (int left, int right);
  234.  
  235. /* flush_buffer(): call from time to time, because buffering
  236.  * is done by the program to get better (?) performance.
  237.  */
  238. void flush_buffer (void);
  239.  
  240. void flush_DMA_buffers(void);
  241.  
  242. /* automaton.c */
  243.  
  244. /* init_automaton(a, song):
  245.  * put the automaton a in the right state to play song.
  246.  */
  247. void init_automaton (struct automaton *a, struct song *song);
  248.  
  249. /* next_tick(a):
  250.  * set up everything for the next tick.
  251.  */
  252. void next_tick (struct automaton *a);
  253.  
  254. /* read.c */
  255.  
  256. /* s = read_song(f, type):
  257.  * tries to read f as a song of type NEW/OLD.
  258.  * returns NULL (and an error) if it doesn't work.
  259.  * Returns a dynamic song structure if successful.
  260.  */
  261. struct song *read_song (FILE *f, int type, int tr);
  262.  
  263. /* release_song(s):
  264.  * release all the memory song occupies.
  265.  */
  266. void release_song (struct song *song);
  267.  
  268. /* commands.c */
  269.  
  270. /* init_effects(): sets up all data for the effects */
  271. void init_effects (void (**table) (/* ??? */));
  272.  
  273. /* do_nothing: this is the default behavior for an effect.
  274.  */
  275. void do_nothing (struct channel *ch);
  276.  
  277. /* audio.c */
  278.  
  279. /* init_tables(oversample, frequency):
  280.  * precomputes the step_table and the pitch_table
  281.  * according to the desired oversample and frequency.
  282.  * This is static, you can call it again whenever you want.
  283.  */
  284. void init_tables (int oversample, int frequency);
  285.  
  286. /* resample(chan, oversample, number):
  287.  * send number samples out computed according
  288.  * to the current state of chan[0:NUMBER_CHANNELS],
  289.  * and oversample.
  290.  */
  291. void resample (struct channel *chan, int oversample, int number);
  292.  
  293. /* reset_note(ch, note, pitch):
  294.  * set channel ch to play note at pitch pitch
  295.  */
  296. void reset_note (struct channel *ch, int note, int pitch);
  297.  
  298. /* set_current_pitch(ch, pitch):
  299.  * set channel ch to play at pitch pitch
  300.  */
  301. void set_current_pitch (struct channel *ch, int pitch);
  302.  
  303. /* player.c */
  304.  
  305. /* init_player(oversample, frequency):
  306.  * sets up the player for a given oversample and
  307.  * output frequency.
  308.  */
  309. void init_player (int o, int f);
  310.  
  311. /* prints error messages */
  312. void trackerror(int err, char *txt, int errtype);
  313.  
  314. /* exits programs and restores sbpro mixer params if needed */
  315. void quit(int rv);
  316.  
  317. /* restores SBPro parameters */
  318. void restoreparams();
  319.