Updated RELEASE_NOTES.
[ahxm.git] / annhell.h
blob85f44f52e91aa610de5dd95aca44f322daf7eecd
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 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 char * filename; /* filename (for paged files) */
62 long f_pos; /* file position where the PCM files */
63 int p_offset; /* offset in frames of the page */
64 int bits; /* bits of the PCM wave (8, 16) */
65 int sign; /* sign of the PCM wave (1, -1) */
68 /* generators */
70 struct ss_gen
72 int note_id; /* note ID */
73 sample_t vol; /* volume */
74 struct ss_wave * w; /* the wave data */
76 double cursor; /* offset to next sample */
77 double inc; /* increment (frequency) */
79 int sustain; /* number of frames to play after release */
80 sample_t dvol; /* volume decrement in sustain */
82 double vibrato; /* vibrato oscillator */
83 double vib_depth; /* vibrato depth */
84 double vib_inc; /* increment for vibrato oscillator */
86 double portamento; /* portamento sum to inc */
88 struct ss_gen * next;
89 struct ss_gen * prev;
92 /* software syntesizer instruments */
94 struct ss_ins
96 int n_layers; /* # of layers */
97 struct ss_wave ** layers; /* layers */
99 struct ss_gen * gens; /* generator queue */
101 int n_channels; /* number of channels */
102 sample_t * vols; /* volumes (1 per channel) */
103 struct ss_eff ** effs; /* effect chains (1 per channel) */
105 double sustain; /* sustain in msecs */
106 double vib_depth; /* vibrato depth */
107 double vib_freq; /* vibrato frequency */
110 /* digital effects */
112 struct ss_eff
114 struct ss_wave * wave; /* wave buffer */
115 sample_t gain; /* effect gain */
116 sample_t igain; /* gain increment */
118 double lfo; /* lfo value */
119 double lfo_depth; /* lfo depth */
120 double lfo_inc; /* lfo increment */
122 double cursor; /* current buffer position */
124 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
126 struct ss_eff * next; /* next in chain */
129 /* song events */
131 typedef enum
133 SONG_EV_TEMPO,
134 SONG_EV_METER,
135 SONG_EV_MEASURE,
137 SONG_EV_SS_SUSTAIN,
138 SONG_EV_SS_VIBRATO,
139 SONG_EV_SS_CHANNEL,
141 SONG_EV_SS_WAV,
142 SONG_EV_SS_PAT,
144 SONG_EV_SS_EFF_DELAY,
145 SONG_EV_SS_EFF_ECHO,
146 SONG_EV_SS_EFF_COMB,
147 SONG_EV_SS_EFF_ALLPASS,
148 SONG_EV_SS_EFF_FLANGER,
149 SONG_EV_SS_EFF_WOBBLE,
150 SONG_EV_SS_EFF_SQWOBBLE,
151 SONG_EV_SS_EFF_FADER,
152 SONG_EV_SS_EFF_REVERB,
153 SONG_EV_SS_EFF_OFF,
155 SONG_EV_MIDI_CHANNEL,
156 SONG_EV_MIDI_PROGRAM,
158 SONG_EV_BACK,
159 SONG_EV_NOTE,
160 SONG_EV_SS_PITCH_STRETCH,
161 SONG_EV_SS_PRINT_WAVE_TEMPO,
163 SONG_EV_SONG_INFO,
165 SONG_EV_NOTE_OFF,
166 SONG_EV_NOTE_ON,
168 SONG_EV_END
170 } song_ev_type;
172 struct song_ev_generic
174 song_ev_type type; /* event type */
175 double time; /* event time (1: whole note) */
176 int trk_id; /* track id */
177 int event_id; /* event id */
180 struct song_ev_note
182 song_ev_type type; /* SONG_EV_NOTE */
183 double time;
184 int trk_id;
185 int event_id;
186 int note; /* MIDI-like note */
187 double len; /* note length (1: whole note) */
188 sample_t vol; /* note volume (1: full volume) */
191 struct song_ev_back
193 song_ev_type type; /* SONG_EV_BACK */
194 double time;
195 int trk_id;
196 int event_id;
197 double len; /* note length (1: whole note) */
200 struct song_ev_tempo
202 song_ev_type type; /* SONG_EV_TEMPO */
203 double time;
204 int trk_id; /* always < 0 */
205 int event_id;
206 double tempo; /* tempo in bpm */
209 struct song_ev_meter
211 song_ev_type type; /* SONG_EV_METER */
212 double time;
213 int trk_id; /* always < 0 */
214 int event_id;
215 int num; /* meter numerator */
216 int den; /* meter denominator */
219 struct song_ev_measure
221 song_ev_type type; /* SONG_EV_MEASURE */
222 double time;
223 int trk_id;
224 int event_id;
225 int line; /* line number */
228 struct song_ev_ss_pitch_stretch
230 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
231 double time;
232 int trk_id;
233 int event_id;
234 int note; /* MIDI-like note (to find the wave) */
235 double len; /* note length (1: whole note) */
236 sample_t vol; /* note volume (1: full volume) */
239 struct song_ev_ss_print_wave_tempo
241 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
242 double time;
243 int trk_id;
244 int event_id;
245 int note; /* MIDI-like note (to find the wave) */
246 double len; /* note length (1: whole note) */
249 struct song_ev_ss_sustain
251 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
252 double time;
253 int trk_id;
254 int event_id;
255 double sustain; /* sustain time (in msecs) */
258 struct song_ev_ss_vibrato
260 song_ev_type type; /* SONG_EV_SS_VIBRATO */
261 double time;
262 int trk_id;
263 int event_id;
264 double vib_depth; /* vibrato depth (in msecs) */
265 double vib_freq; /* vibrato frequency (in Hzs) */
268 struct song_ev_ss_channel
270 song_ev_type type; /* SONG_EV_SS_CHANNEL */
271 double time;
272 int trk_id;
273 int event_id;
274 int channel; /* channel */
275 sample_t vol; /* volume */
278 struct song_ev_ss_wav
280 song_ev_type type; /* SONG_EV_SS_WAV */
281 double time;
282 int trk_id;
283 int event_id;
284 char * file; /* path to .wav file */
285 int base; /* MIDI-like base note */
286 int min; /* MIDI-like minimum note */
287 int max; /* MIDI-like maximum note */
288 double loop_start; /* start of loop */
289 double loop_end; /* end of loop */
292 struct song_ev_ss_pat
294 song_ev_type type; /* SONG_EV_SS_PAT */
295 double time;
296 int trk_id;
297 int event_id;
298 char * file; /* path to .pat file */
301 struct song_ev_ss_eff
303 song_ev_type type; /* effect type */
304 double time;
305 int trk_id;
306 int event_id;
307 int channel; /* channel */
308 double size; /* size of effect */
309 sample_t gain; /* gain */
310 double depth; /* depth */
311 double freq; /* freq */
312 double phase; /* phase */
313 sample_t initial; /* initial vol */
314 sample_t final; /* final vol */
317 struct song_ev_midi_channel
319 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
320 double time;
321 int trk_id;
322 int event_id;
323 int channel; /* midi channel (1-16) */
326 struct song_ev_midi_program
328 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
329 double time;
330 int trk_id;
331 int event_id;
332 int program; /* midi program (0-127) */
335 struct song_ev_song_info
337 song_ev_type type; /* SONG_EV_SONG_INFO */
338 double time;
339 int trk_id;
340 int event_id;
341 char * author; /* track author */
342 char * name; /* track name */
345 union song_ev
347 struct song_ev_generic generic;
349 struct song_ev_tempo tempo;
350 struct song_ev_meter meter;
351 struct song_ev_measure measure;
353 struct song_ev_note note;
354 struct song_ev_back back;
356 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
357 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
359 struct song_ev_ss_sustain ss_sustain;
360 struct song_ev_ss_vibrato ss_vibrato;
361 struct song_ev_ss_channel ss_channel;
363 struct song_ev_ss_wav ss_wav;
364 struct song_ev_ss_pat ss_pat;
366 struct song_ev_ss_eff ss_eff;
368 struct song_ev_midi_channel midi_channel;
369 struct song_ev_midi_program midi_program;
371 struct song_ev_song_info song_info;
375 /* GLOBALS */
377 /* in ss_core.c */
379 extern int ss_frequency;
380 extern int ss_interpolation;
381 extern int ss_nchannels;
383 /* in ss_input.c */
385 extern int ss_page_size;
387 /* in ss_output.c */
389 extern sample_t ss_master_volume;
390 extern int ss_output_clipped;
391 extern sample_t ss_optimal_volume;
392 extern char * ss_cue_file_name;
394 /* in song.c */
396 extern union song_ev * song;
397 extern int n_song_ev;
398 extern int solo_track;
400 /* in support.c */
402 extern int verbose;
403 extern int trace;
405 /* MACROS */
407 /* milliseconds to frames conversion */
408 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
411 /* PROTOTYPES */
413 /* in ss_core.c */
415 double ss_note_frequency(int note);
416 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
417 void ss_free_wave(struct ss_wave * w);
418 void ss_prepare_wave(struct ss_wave * w);
419 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
420 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
421 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
423 /* in ss_gen.c */
425 void ss_gen_init(void);
426 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
427 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
428 void ss_gen_sustain(struct ss_gen * g, double sustain);
429 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
430 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
431 struct ss_wave * w);
432 void ss_gen_release(struct ss_gen * g);
433 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
435 /* in ss_ins.c */
437 void ss_ins_init(struct ss_ins * i);
438 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
439 void ss_ins_copy_layers(struct ss_ins * i, struct ss_ins * o);
440 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
441 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
442 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
443 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
444 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
445 struct ss_wave * w);
446 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
447 void ss_ins_note_off(struct ss_ins * i, int note_id);
448 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
450 /* in ss_output.c */
452 int ss_output_open(char * drvname, char * filename);
453 void ss_output_init_frame(sample_t frame[]);
454 int ss_output_write(sample_t frame[]);
455 void ss_output_close(void);
456 int cue_file_song_info(int frame, char * author, char * name);
458 /* in ss_input.c */
460 void load_pcm_wave(FILE * f, struct ss_wave * w);
461 struct ss_wave * ss_load_wave_file(char * file,
462 double base_freq, double min_freq, double max_freq,
463 double loop_start, double loop_end);
464 int ss_load_pat_file(struct ss_ins * i, char * file);
466 /* in ss_eff.c */
468 void ss_eff_delay(struct ss_eff ** ec, double size);
469 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
470 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
471 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
472 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
473 double depth, double freq, double phase);
474 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
475 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
476 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
477 void ss_eff_reverb(struct ss_eff ** ec);
479 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
480 void ss_eff_off(struct ss_eff ** ec);
482 /* in song.c */
484 void song_clear(void);
485 void add_song_ev(union song_ev * ev);
486 void song_sort(void);
487 int song_test_measure_boundary(double ev_time, int num, int den, int line);
489 /* in ss_song.c */
491 int ss_song_render(int skip_secs);
493 /* in midi_song.c */
495 int midi_song_play(int skip_secs);
496 int midi_device_open(char * devfile);
497 void midi_device_close(void);
499 /* in compiler.y */
501 int compile_ahs_string(char * code);
502 int compile_ahs(char * file);
504 /* in support.c */
506 void add_to_library_path(char * path, int strip);
507 FILE * path_fopen(char * filename, char * mode);
508 char * locate_file(char * filename);