Branch annhell-branch-paged MERGED.
[ahxm.git] / annhell.h
blob6882e20f3b058df088b6e842df049f55bdb1fde1
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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_NOTE_OFF,
164 SONG_EV_NOTE_ON,
166 SONG_EV_END
168 } song_ev_type;
170 struct song_ev_generic
172 song_ev_type type; /* event type */
173 double time; /* event time (1: whole note) */
174 int trk_id; /* track id */
175 int event_id; /* event id */
178 struct song_ev_note
180 song_ev_type type; /* SONG_EV_NOTE */
181 double time;
182 int trk_id;
183 int event_id;
184 int note; /* MIDI-like note */
185 double len; /* note length (1: whole note) */
186 sample_t vol; /* note volume (1: full volume) */
189 struct song_ev_back
191 song_ev_type type; /* SONG_EV_BACK */
192 double time;
193 int trk_id;
194 int event_id;
195 double len; /* note length (1: whole note) */
198 struct song_ev_tempo
200 song_ev_type type; /* SONG_EV_TEMPO */
201 double time;
202 int trk_id; /* always < 0 */
203 int event_id;
204 double tempo; /* tempo in bpm */
207 struct song_ev_meter
209 song_ev_type type; /* SONG_EV_METER */
210 double time;
211 int trk_id; /* always < 0 */
212 int event_id;
213 int num; /* meter numerator */
214 int den; /* meter denominator */
217 struct song_ev_measure
219 song_ev_type type; /* SONG_EV_MEASURE */
220 double time;
221 int trk_id;
222 int event_id;
223 int line; /* line number */
226 struct song_ev_ss_pitch_stretch
228 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
229 double time;
230 int trk_id;
231 int event_id;
232 int note; /* MIDI-like note (to find the wave) */
233 double len; /* note length (1: whole note) */
234 sample_t vol; /* note volume (1: full volume) */
237 struct song_ev_ss_print_wave_tempo
239 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
240 double time;
241 int trk_id;
242 int event_id;
243 int note; /* MIDI-like note (to find the wave) */
244 double len; /* note length (1: whole note) */
247 struct song_ev_ss_sustain
249 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
250 double time;
251 int trk_id;
252 int event_id;
253 double sustain; /* sustain time (in msecs) */
256 struct song_ev_ss_vibrato
258 song_ev_type type; /* SONG_EV_SS_VIBRATO */
259 double time;
260 int trk_id;
261 int event_id;
262 double vib_depth; /* vibrato depth (in msecs) */
263 double vib_freq; /* vibrato frequency (in Hzs) */
266 struct song_ev_ss_channel
268 song_ev_type type; /* SONG_EV_SS_CHANNEL */
269 double time;
270 int trk_id;
271 int event_id;
272 int channel; /* channel */
273 sample_t vol; /* volume */
276 struct song_ev_ss_wav
278 song_ev_type type; /* SONG_EV_SS_WAV */
279 double time;
280 int trk_id;
281 int event_id;
282 char * file; /* path to .wav file */
283 int base; /* MIDI-like base note */
284 int min; /* MIDI-like minimum note */
285 int max; /* MIDI-like maximum note */
286 double loop_start; /* start of loop */
287 double loop_end; /* end of loop */
290 struct song_ev_ss_pat
292 song_ev_type type; /* SONG_EV_SS_PAT */
293 double time;
294 int trk_id;
295 int event_id;
296 char * file; /* path to .pat file */
299 struct song_ev_ss_eff
301 song_ev_type type; /* effect type */
302 double time;
303 int trk_id;
304 int event_id;
305 int channel; /* channel */
306 double size; /* size of effect */
307 sample_t gain; /* gain */
308 double depth; /* depth */
309 double freq; /* freq */
310 double phase; /* phase */
311 sample_t initial; /* initial vol */
312 sample_t final; /* final vol */
315 struct song_ev_midi_channel
317 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
318 double time;
319 int trk_id;
320 int event_id;
321 int channel; /* midi channel (1-16) */
324 struct song_ev_midi_program
326 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
327 double time;
328 int trk_id;
329 int event_id;
330 int program; /* midi program (0-127) */
333 union song_ev
335 struct song_ev_generic generic;
337 struct song_ev_tempo tempo;
338 struct song_ev_meter meter;
339 struct song_ev_measure measure;
341 struct song_ev_note note;
342 struct song_ev_back back;
344 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
345 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
347 struct song_ev_ss_sustain ss_sustain;
348 struct song_ev_ss_vibrato ss_vibrato;
349 struct song_ev_ss_channel ss_channel;
351 struct song_ev_ss_wav ss_wav;
352 struct song_ev_ss_pat ss_pat;
354 struct song_ev_ss_eff ss_eff;
356 struct song_ev_midi_channel midi_channel;
357 struct song_ev_midi_program midi_program;
361 /* GLOBALS */
363 /* in ss_core.c */
365 extern int ss_frequency;
366 extern int ss_interpolation;
367 extern int ss_nchannels;
369 /* in ss_input.c */
371 extern int ss_page_size;
373 /* in ss_output.c */
375 extern sample_t ss_master_volume;
376 extern int ss_output_clipped;
377 extern sample_t ss_optimal_volume;
379 /* in song.c */
381 extern union song_ev * song;
382 extern int n_song_ev;
383 extern int solo_track;
385 /* in support.c */
387 extern int debug;
388 extern int trace;
389 extern int show_progress;
391 /* MACROS */
393 /* milliseconds to frames conversion */
394 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
397 /* PROTOTYPES */
399 /* in ss_core.c */
401 double ss_note_frequency(int note);
402 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
403 void ss_free_wave(struct ss_wave * w);
404 void ss_prepare_wave(struct ss_wave * w);
405 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
406 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
407 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
409 /* in ss_gen.c */
411 void ss_gen_init(void);
412 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
413 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
414 void ss_gen_sustain(struct ss_gen * g, double sustain);
415 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
416 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
417 struct ss_wave * w);
418 void ss_gen_release(struct ss_gen * g);
419 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
421 /* in ss_ins.c */
423 void ss_ins_init(struct ss_ins * i);
424 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
425 void ss_ins_copy_layers(struct ss_ins * i, struct ss_ins * o);
426 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
427 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
428 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
429 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
430 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
431 struct ss_wave * w);
432 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
433 void ss_ins_note_off(struct ss_ins * i, int note_id);
434 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
436 /* in ss_output.c */
438 int ss_output_open(char * drvname, char * filename);
439 void ss_output_init_frame(sample_t frame[]);
440 int ss_output_write(sample_t frame[]);
441 void ss_output_close(void);
443 /* in ss_input.c */
445 void load_pcm_wave(FILE * f, struct ss_wave * w);
446 struct ss_wave * ss_load_wave_file(char * file,
447 double base_freq, double min_freq, double max_freq,
448 double loop_start, double loop_end);
449 int ss_load_pat_file(struct ss_ins * i, char * file);
451 /* in ss_eff.c */
453 void ss_eff_delay(struct ss_eff ** ec, double size);
454 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
455 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
456 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
457 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
458 double depth, double freq, double phase);
459 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
460 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
461 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
462 void ss_eff_reverb(struct ss_eff ** ec);
464 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
465 void ss_eff_off(struct ss_eff ** ec);
467 /* in song.c */
469 void song_clear(void);
470 void add_song_ev(union song_ev * ev);
471 void song_sort(void);
472 int song_test_measure_boundary(double ev_time, int num, int den, int line);
474 /* in ss_song.c */
476 int ss_song_render(int skip_secs);
478 /* in midi_song.c */
480 int midi_song_play(int skip_secs);
481 int midi_device_open(char * devfile);
482 void midi_device_close(void);
484 /* in compiler.y */
486 int compile_ahs_string(char * code);
487 int compile_ahs(char * file);
489 /* in support.c */
491 void add_to_library_path(char * path, int strip);
492 FILE * path_fopen(char * filename, char * mode);
493 char * locate_file(char * filename);