Fixed typo in RELEASE_NOTES.
[ahxm.git] / ahxm.h
blob88aa2d33268f3b08744b7cafd5190cdb8c6dbd0e
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2007 Angel Ortega <angel@triptico.com>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 http://www.triptico.com
24 /* HARD LIMITS */
26 #ifndef SS_MAX_CHANNELS
27 #define SS_MAX_CHANNELS 16
28 #endif
30 #ifndef SS_MAX_GENERATORS
31 #define SS_MAX_GENERATORS 256
32 #endif
34 #ifndef SS_MAX_INSTRUMENTS
35 #define SS_MAX_INSTRUMENTS 256
36 #endif
38 /* STRUCTURES AND TYPES */
40 /* samples */
42 typedef double sample_t;
44 /* waves */
46 struct ss_wave
48 double size; /* size in frames of full wave */
49 int p_size; /* size in frames of the page */
50 int n_channels; /* # of channels */
51 sample_t ** wave; /* the PCM waves */
52 int s_rate; /* original sample rate */
54 double loop_start; /* start of loop (-1, no loop) */
55 double loop_end; /* end of loop */
57 double base_freq; /* base frequency */
58 double min_freq; /* minimum frequency */
59 double max_freq; /* maximum frequency */
61 int first_channel; /* first channel to spread into */
62 int skip_channels; /* channels to skip when spreading */
64 char * filename; /* filename (for paged files) */
65 long f_pos; /* file position where the PCM files */
66 int p_offset; /* offset in frames of the page */
67 int bits; /* bits of the PCM wave (8, 16) */
68 int sign; /* sign of the PCM wave (1, -1) */
70 int page_faults; /* number of times ss_load_page() was called */
73 /* generators */
75 struct ss_gen
77 int note_id; /* note ID */
78 sample_t vol; /* volume */
79 struct ss_wave * w; /* the wave data */
81 double cursor; /* offset to next sample */
82 double inc; /* increment (frequency) */
84 int sustain; /* number of frames to play after release */
85 sample_t dsvol; /* volume decrement in sustain */
87 int attack; /* number of frames of fade-in attack */
88 sample_t davol; /* volume increment in attack */
90 double vibrato; /* vibrato oscillator */
91 double vib_depth; /* vibrato depth */
92 double vib_inc; /* increment for vibrato oscillator */
94 double portamento; /* portamento sum to inc */
96 struct ss_gen * next;
97 struct ss_gen * prev;
100 /* software syntesizer instruments */
102 struct ss_ins
104 int n_layers; /* # of layers */
105 struct ss_wave ** layers; /* layers */
107 struct ss_gen * gens; /* generator queue */
109 int n_channels; /* number of channels */
110 sample_t * vols; /* volumes (1 per channel) */
111 struct ss_eff ** effs; /* effect chains (1 per channel) */
113 double sustain; /* sustain in msecs */
114 double attack; /* attack in msecs */
115 double vib_depth; /* vibrato depth */
116 double vib_freq; /* vibrato frequency */
118 int disabled; /* if set, no processing is done */
120 double portamento; /* portamento */
123 /* digital effects */
125 struct ss_eff
127 struct ss_wave * wave; /* wave buffer */
128 sample_t gain; /* effect gain */
129 sample_t igain; /* gain increment */
131 double lfo; /* lfo value */
132 double lfo_depth; /* lfo depth */
133 double lfo_inc; /* lfo increment */
135 double cursor; /* current buffer position */
137 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
139 struct ss_eff * next; /* next in chain */
142 /* song events */
144 typedef enum
146 SONG_EV_TEMPO,
147 SONG_EV_METER,
148 SONG_EV_MEASURE,
150 SONG_EV_SS_SUSTAIN,
151 SONG_EV_SS_ATTACK,
152 SONG_EV_SS_VIBRATO,
153 SONG_EV_SS_PORTAMENTO,
154 SONG_EV_SS_CHANNEL,
156 SONG_EV_SS_WAV,
157 SONG_EV_SS_PAT,
159 SONG_EV_SS_EFF_OFF,
160 SONG_EV_SS_EFF_DELAY,
161 SONG_EV_SS_EFF_ECHO,
162 SONG_EV_SS_EFF_COMB,
163 SONG_EV_SS_EFF_ALLPASS,
164 SONG_EV_SS_EFF_FLANGER,
165 SONG_EV_SS_EFF_WOBBLE,
166 SONG_EV_SS_EFF_SQWOBBLE,
167 SONG_EV_SS_EFF_HFWOBBLE,
168 SONG_EV_SS_EFF_FADER,
169 SONG_EV_SS_EFF_REVERB,
171 SONG_EV_SS_EFF_FOLDBACK,
172 SONG_EV_SS_EFF_ATAN,
173 SONG_EV_SS_EFF_DISTORT,
174 SONG_EV_SS_EFF_OVERDRIVE,
176 SONG_EV_MIDI_CHANNEL,
177 SONG_EV_MIDI_PROGRAM,
179 SONG_EV_BACK,
180 SONG_EV_NOTE,
181 SONG_EV_SS_PITCH_STRETCH,
182 SONG_EV_SS_PRINT_WAVE_TEMPO,
184 SONG_EV_SONG_INFO,
186 SONG_EV_NOTE_OFF,
187 SONG_EV_NOTE_ON,
189 SONG_EV_EOT,
190 SONG_EV_END
192 } song_ev_type;
194 struct song_ev_generic
196 song_ev_type type; /* event type */
197 double time; /* event time (1: whole note) */
198 int trk_id; /* track id */
199 int event_id; /* event id */
202 struct song_ev_note
204 song_ev_type type; /* SONG_EV_NOTE */
205 double time;
206 int trk_id;
207 int event_id;
208 int note; /* MIDI-like note */
209 double len; /* note length (1: whole note) */
210 sample_t vol; /* note volume (1: full volume) */
213 struct song_ev_back
215 song_ev_type type; /* SONG_EV_BACK */
216 double time;
217 int trk_id;
218 int event_id;
219 double len; /* note length (1: whole note) */
222 struct song_ev_tempo
224 song_ev_type type; /* SONG_EV_TEMPO */
225 double time;
226 int trk_id; /* always < 0 */
227 int event_id;
228 double tempo; /* tempo in bpm */
231 struct song_ev_meter
233 song_ev_type type; /* SONG_EV_METER */
234 double time;
235 int trk_id; /* always < 0 */
236 int event_id;
237 int num; /* meter numerator */
238 int den; /* meter denominator */
241 struct song_ev_measure
243 song_ev_type type; /* SONG_EV_MEASURE */
244 double time;
245 int trk_id;
246 int event_id;
247 int line; /* line number */
250 struct song_ev_ss_pitch_stretch
252 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
253 double time;
254 int trk_id;
255 int event_id;
256 int note; /* MIDI-like note (to find the wave) */
257 double len; /* note length (1: whole note) */
258 sample_t vol; /* note volume (1: full volume) */
261 struct song_ev_ss_print_wave_tempo
263 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
264 double time;
265 int trk_id;
266 int event_id;
267 int note; /* MIDI-like note (to find the wave) */
268 double len; /* note length (1: whole note) */
271 struct song_ev_ss_sustain
273 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
274 double time;
275 int trk_id;
276 int event_id;
277 double sustain; /* sustain time (in msecs) */
280 struct song_ev_ss_attack
282 song_ev_type type; /* SONG_EV_SS_ATTACK */
283 double time;
284 int trk_id;
285 int event_id;
286 double attack; /* attack time (in msecs) */
289 struct song_ev_ss_vibrato
291 song_ev_type type; /* SONG_EV_SS_VIBRATO */
292 double time;
293 int trk_id;
294 int event_id;
295 double vib_depth; /* vibrato depth (in msecs) */
296 double vib_freq; /* vibrato frequency (in Hzs) */
299 struct song_ev_ss_portamento
301 song_ev_type type; /* SONG_EV_SS_PORTAMENTO */
302 double time;
303 int trk_id;
304 int event_id;
305 double portamento; /* portamento */
308 struct song_ev_ss_channel
310 song_ev_type type; /* SONG_EV_SS_CHANNEL */
311 double time;
312 int trk_id;
313 int event_id;
314 int channel; /* channel */
315 sample_t vol; /* volume */
318 struct song_ev_ss_wav
320 song_ev_type type; /* SONG_EV_SS_WAV */
321 double time;
322 int trk_id;
323 int event_id;
324 char * file; /* path to .wav file */
325 int base; /* MIDI-like base note */
326 int min; /* MIDI-like minimum note */
327 int max; /* MIDI-like maximum note */
328 double loop_start; /* start of loop */
329 double loop_end; /* end of loop */
330 int first_channel; /* first channel to start spreading */
331 int skip_channels; /* channels to skip when spreading */
334 struct song_ev_ss_pat
336 song_ev_type type; /* SONG_EV_SS_PAT */
337 double time;
338 int trk_id;
339 int event_id;
340 char * file; /* path to .pat file */
343 struct song_ev_ss_eff
345 song_ev_type type; /* effect type */
346 double time;
347 int trk_id;
348 int event_id;
349 int channel; /* channel */
350 double size; /* size of effect */
351 sample_t gain; /* gain */
352 double depth; /* depth */
353 double freq; /* freq */
354 double phase; /* phase */
355 sample_t initial; /* initial vol */
356 sample_t final; /* final vol */
359 struct song_ev_midi_channel
361 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
362 double time;
363 int trk_id;
364 int event_id;
365 int channel; /* midi channel (1-16) */
368 struct song_ev_midi_program
370 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
371 double time;
372 int trk_id;
373 int event_id;
374 int program; /* midi program (0-127) */
377 struct song_ev_song_info
379 song_ev_type type; /* SONG_EV_SONG_INFO */
380 double time;
381 int trk_id;
382 int event_id;
383 char * author; /* track author */
384 char * name; /* track name */
387 union song_ev
389 struct song_ev_generic generic;
391 struct song_ev_tempo tempo;
392 struct song_ev_meter meter;
393 struct song_ev_measure measure;
395 struct song_ev_note note;
396 struct song_ev_back back;
398 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
399 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
401 struct song_ev_ss_sustain ss_sustain;
402 struct song_ev_ss_attack ss_attack;
403 struct song_ev_ss_vibrato ss_vibrato;
404 struct song_ev_ss_portamento ss_portamento;
405 struct song_ev_ss_channel ss_channel;
407 struct song_ev_ss_wav ss_wav;
408 struct song_ev_ss_pat ss_pat;
410 struct song_ev_ss_eff ss_eff;
412 struct song_ev_midi_channel midi_channel;
413 struct song_ev_midi_program midi_program;
415 struct song_ev_song_info song_info;
419 /* GLOBALS */
421 /* in ss_core.c */
423 extern int ss_frequency;
424 extern int ss_interpolation;
425 extern int ss_nchannels;
427 /* in ss_input.c */
429 extern int ss_page_size;
431 /* in ss_output.c */
433 extern sample_t ss_master_volume;
434 extern int ss_output_clipped;
435 extern sample_t ss_optimal_volume;
436 extern char * ss_cue_file_name;
438 /* in song.c */
440 extern union song_ev * song;
441 extern int n_song_ev;
442 extern int solo_track;
443 extern int n_song_tracks;
445 /* in support.c */
447 extern int verbose;
448 extern int trace;
450 /* MACROS */
452 /* milliseconds to frames conversion */
453 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
455 /* grows a dynamic array */
456 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
458 /* PROTOTYPES */
460 /* in ss_core.c */
462 double ss_note_frequency(int note);
463 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
464 void ss_free_wave(struct ss_wave * w);
465 void ss_prepare_wave(struct ss_wave * w);
466 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
467 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
468 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
470 /* in ss_gen.c */
472 void ss_gen_init(void);
473 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
474 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
475 void ss_gen_sustain(struct ss_gen * g, double sustain);
476 void ss_gen_attack(struct ss_gen * g, double attack);
477 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
478 void ss_gen_portamento(struct ss_gen * g, double portamento);
479 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
480 struct ss_wave * w);
481 void ss_gen_release(struct ss_gen * g);
482 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
484 /* in ss_ins.c */
486 void ss_ins_init(struct ss_ins * i);
487 void ss_ins_disable(struct ss_ins * i);
488 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
489 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
490 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
491 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
492 void ss_ins_set_attack(struct ss_ins * i, double attack);
493 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
494 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
495 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
496 struct ss_wave * w);
497 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
498 void ss_ins_note_off(struct ss_ins * i, int note_id);
499 int ss_ins_frame(struct ss_ins * i, sample_t frame[]);
501 /* in ss_output.c */
503 int ss_output_open(char * drvname, char * filename);
504 void ss_output_init_frame(sample_t frame[]);
505 int ss_output_write(sample_t frame[]);
506 void ss_output_close(void);
507 int cue_file_song_info(int frame, char * author, char * name);
509 /* in ss_input.c */
511 void load_pcm_wave(FILE * f, struct ss_wave * w);
512 struct ss_wave * ss_load_wav_file(char * file,
513 double base_freq, double min_freq, double max_freq,
514 double loop_start, double loop_end,
515 int first_channel, int skip_channels);
516 int ss_load_pat_file(struct ss_ins * i, char * file);
518 /* in ss_eff.c */
520 void ss_eff_delay(struct ss_eff ** ec, double size);
521 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
522 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
523 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
524 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
525 double depth, double freq, double phase);
526 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase, sample_t gain);
527 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
528 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
529 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
530 void ss_eff_reverb(struct ss_eff ** ec);
531 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
532 void ss_eff_atan(struct ss_eff ** ec, sample_t gain);
533 void ss_eff_distort(struct ss_eff ** ec, sample_t gain);
534 void ss_eff_overdrive(struct ss_eff ** ec, sample_t gain);
536 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
537 void ss_eff_off(struct ss_eff ** ec);
539 /* in song.c */
541 void song_clear(void);
542 void add_song_ev(song_ev_type type, double time, union song_ev * ev);
543 void song_sort(void);
544 int song_test_measure_boundary(double ev_time, int num, int den, int line);
546 /* in ss_song.c */
548 int ss_song_render(int skip_secs, char * driver, char * devfile);
550 /* in midi_song.c */
552 int midi_song_play(int skip_secs);
553 int midi_device_open(char * devfile);
554 void midi_device_close(void);
556 /* in compiler.y */
558 int compile_ahs_string(char * code);
559 int compile_ahs(char * file);
561 /* in support.c */
563 void libpath_add(char * path, int strip);
564 FILE * libpath_fopen(char * filename, char * mode);
565 char * libpath_locate(char * filename);
566 void transconv_add(char * from, char * to, char * convcmd);
567 char * transconv_pipe(char * cmd, char * ext, char * dir);
568 char * transconv(char * file, char * ext, char * dir);