Version 1.0.2b RELEASED.
[ahxm.git] / annhell.h
blob9b9ad54fcfdb494ed2ae66253877463c3d1c557c
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 */
49 int n_channels; /* # of channels */
50 sample_t ** wave; /* the PCM waves */
51 int s_rate; /* original sample rate */
53 double loop_start; /* start of loop (-1, no loop) */
54 double loop_end; /* end of loop */
56 double base_freq; /* base frequency */
57 double min_freq; /* minimum frequency */
58 double max_freq; /* maximum frequency */
61 /* generators */
63 struct ss_gen
65 int note_id; /* note ID */
66 sample_t vol; /* volume */
67 struct ss_wave * w; /* the wave data */
69 double cursor; /* offset to next sample */
70 double inc; /* increment (frequency) */
72 int sustain; /* number of frames to play after release */
73 sample_t dvol; /* volume decrement in sustain */
75 double vibrato; /* vibrato oscillator */
76 double vib_depth; /* vibrato depth */
77 double vib_inc; /* increment for vibrato oscillator */
79 double portamento; /* portamento sum to inc */
81 struct ss_gen * next;
82 struct ss_gen * prev;
85 /* software syntesizer instruments */
87 struct ss_ins
89 int n_layers; /* # of layers */
90 struct ss_wave ** layers; /* layers */
92 struct ss_gen * gens; /* generator queue */
94 int n_channels; /* number of channels */
95 sample_t * vols; /* volumes (1 per channel) */
96 struct ss_eff ** effs; /* effect chains (1 per channel) */
98 double sustain; /* sustain in msecs */
99 double vib_depth; /* vibrato depth */
100 double vib_freq; /* vibrato frequency */
103 /* digital effects */
105 struct ss_eff
107 struct ss_wave * wave; /* wave buffer */
108 sample_t gain; /* effect gain */
109 sample_t igain; /* gain increment */
111 double lfo; /* lfo value */
112 double lfo_depth; /* lfo depth */
113 double lfo_inc; /* lfo increment */
115 double cursor; /* current buffer position */
117 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
119 struct ss_eff * next; /* next in chain */
122 /* song events */
124 typedef enum
126 SONG_EV_TEMPO,
127 SONG_EV_METER,
128 SONG_EV_MEASURE,
130 SONG_EV_SS_SUSTAIN,
131 SONG_EV_SS_VIBRATO,
132 SONG_EV_SS_CHANNEL,
134 SONG_EV_SS_WAV,
135 SONG_EV_SS_PAT,
137 SONG_EV_SS_EFF_DELAY,
138 SONG_EV_SS_EFF_ECHO,
139 SONG_EV_SS_EFF_COMB,
140 SONG_EV_SS_EFF_ALLPASS,
141 SONG_EV_SS_EFF_FLANGER,
142 SONG_EV_SS_EFF_WOBBLE,
143 SONG_EV_SS_EFF_SQWOBBLE,
144 SONG_EV_SS_EFF_FADER,
145 SONG_EV_SS_EFF_REVERB,
146 SONG_EV_SS_EFF_OFF,
148 SONG_EV_MIDI_CHANNEL,
149 SONG_EV_MIDI_PROGRAM,
151 SONG_EV_BACK,
152 SONG_EV_NOTE,
153 SONG_EV_SS_PITCH_STRETCH,
154 SONG_EV_SS_PRINT_WAVE_TEMPO,
156 SONG_EV_NOTE_OFF,
157 SONG_EV_NOTE_ON,
159 SONG_EV_END
161 } song_ev_type;
163 struct song_ev_generic
165 song_ev_type type; /* event type */
166 double time; /* event time (1: whole note) */
167 int trk_id; /* track id */
168 int event_id; /* event id */
171 struct song_ev_note
173 song_ev_type type; /* SONG_EV_NOTE */
174 double time;
175 int trk_id;
176 int event_id;
177 int note; /* MIDI-like note */
178 double len; /* note length (1: whole note) */
179 sample_t vol; /* note volume (1: full volume) */
182 struct song_ev_back
184 song_ev_type type; /* SONG_EV_BACK */
185 double time;
186 int trk_id;
187 int event_id;
188 double len; /* note length (1: whole note) */
191 struct song_ev_tempo
193 song_ev_type type; /* SONG_EV_TEMPO */
194 double time;
195 int trk_id; /* always < 0 */
196 int event_id;
197 double tempo; /* tempo in bpm */
200 struct song_ev_meter
202 song_ev_type type; /* SONG_EV_METER */
203 double time;
204 int trk_id; /* always < 0 */
205 int event_id;
206 int num; /* meter numerator */
207 int den; /* meter denominator */
210 struct song_ev_measure
212 song_ev_type type; /* SONG_EV_MEASURE */
213 double time;
214 int trk_id;
215 int event_id;
216 int line; /* line number */
219 struct song_ev_ss_pitch_stretch
221 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
222 double time;
223 int trk_id;
224 int event_id;
225 int note; /* MIDI-like note (to find the wave) */
226 double len; /* note length (1: whole note) */
227 sample_t vol; /* note volume (1: full volume) */
230 struct song_ev_ss_print_wave_tempo
232 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
233 double time;
234 int trk_id;
235 int event_id;
236 int note; /* MIDI-like note (to find the wave) */
237 double len; /* note length (1: whole note) */
240 struct song_ev_ss_sustain
242 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
243 double time;
244 int trk_id;
245 int event_id;
246 double sustain; /* sustain time (in msecs) */
249 struct song_ev_ss_vibrato
251 song_ev_type type; /* SONG_EV_SS_VIBRATO */
252 double time;
253 int trk_id;
254 int event_id;
255 double vib_depth; /* vibrato depth (in msecs) */
256 double vib_freq; /* vibrato frequency (in Hzs) */
259 struct song_ev_ss_channel
261 song_ev_type type; /* SONG_EV_SS_CHANNEL */
262 double time;
263 int trk_id;
264 int event_id;
265 int channel; /* channel */
266 sample_t vol; /* volume */
269 struct song_ev_ss_wav
271 song_ev_type type; /* SONG_EV_SS_WAV */
272 double time;
273 int trk_id;
274 int event_id;
275 char * file; /* path to .wav file */
276 int base; /* MIDI-like base note */
277 int min; /* MIDI-like minimum note */
278 int max; /* MIDI-like maximum note */
279 double loop_start; /* start of loop */
280 double loop_end; /* end of loop */
283 struct song_ev_ss_pat
285 song_ev_type type; /* SONG_EV_SS_PAT */
286 double time;
287 int trk_id;
288 int event_id;
289 char * file; /* path to .pat file */
292 struct song_ev_ss_eff
294 song_ev_type type; /* effect type */
295 double time;
296 int trk_id;
297 int event_id;
298 int channel; /* channel */
299 double size; /* size of effect */
300 sample_t gain; /* gain */
301 double depth; /* depth */
302 double freq; /* freq */
303 double phase; /* phase */
304 sample_t initial; /* initial vol */
305 sample_t final; /* final vol */
308 struct song_ev_midi_channel
310 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
311 double time;
312 int trk_id;
313 int event_id;
314 int channel; /* midi channel (1-16) */
317 struct song_ev_midi_program
319 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
320 double time;
321 int trk_id;
322 int event_id;
323 int program; /* midi program (0-127) */
326 union song_ev
328 struct song_ev_generic generic;
330 struct song_ev_tempo tempo;
331 struct song_ev_meter meter;
332 struct song_ev_measure measure;
334 struct song_ev_note note;
335 struct song_ev_back back;
337 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
338 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
340 struct song_ev_ss_sustain ss_sustain;
341 struct song_ev_ss_vibrato ss_vibrato;
342 struct song_ev_ss_channel ss_channel;
344 struct song_ev_ss_wav ss_wav;
345 struct song_ev_ss_pat ss_pat;
347 struct song_ev_ss_eff ss_eff;
349 struct song_ev_midi_channel midi_channel;
350 struct song_ev_midi_program midi_program;
354 /* GLOBALS */
356 /* in ss_core.c */
358 extern int ss_frequency;
359 extern int ss_interpolation;
360 extern int ss_nchannels;
362 /* in ss_output.c */
364 extern sample_t ss_master_volume;
365 extern int ss_output_clipped;
366 extern sample_t ss_optimal_volume;
368 /* in song.c */
370 extern union song_ev * song;
371 extern int n_song_ev;
372 extern int solo_track;
374 /* MACROS */
376 /* milliseconds to frames conversion */
377 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
380 /* PROTOTYPES */
382 /* in ss_core.c */
384 double ss_note_frequency(int note);
385 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate);
386 void ss_free_wave(struct ss_wave * w);
387 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
388 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
389 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
391 /* in ss_gen.c */
393 void ss_gen_init(void);
394 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
395 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
396 void ss_gen_sustain(struct ss_gen * g, double sustain);
397 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
398 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
399 struct ss_wave * w);
400 void ss_gen_release(struct ss_gen * g);
401 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
403 /* in ss_ins.c */
405 void ss_ins_init(struct ss_ins * i);
406 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
407 void ss_ins_copy_layers(struct ss_ins * i, struct ss_ins * o);
408 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
409 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
410 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
411 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
412 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
413 struct ss_wave * w);
414 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
415 void ss_ins_note_off(struct ss_ins * i, int note_id);
416 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
418 /* in ss_output.c */
420 int ss_output_open(char * drvname, char * filename);
421 void ss_output_init_frame(sample_t frame[]);
422 int ss_output_write(sample_t frame[]);
423 void ss_output_close(void);
425 /* in ss_input.c */
427 struct ss_wave * ss_load_wave_file(char * file,
428 double base_freq, double min_freq, double max_freq,
429 double loop_start, double loop_end);
430 int ss_load_pat_file(struct ss_ins * i, char * file);
432 /* in ss_eff.c */
434 void ss_eff_delay(struct ss_eff ** ec, double size);
435 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
436 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
437 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
438 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
439 double depth, double freq, double phase);
440 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
441 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
442 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
443 void ss_eff_reverb(struct ss_eff ** ec);
445 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
446 void ss_eff_off(struct ss_eff ** ec);
448 /* in song.c */
450 void song_clear(void);
451 void add_song_ev(union song_ev * ev);
452 void song_sort(void);
453 int song_test_measure_boundary(double ev_time, int num, int den, int line);
455 /* in ss_song.c */
457 int ss_song_render(int skip_secs);
459 /* in midi_song.c */
461 int midi_song_play(int skip_secs);
462 int midi_device_open(char * devfile);
463 void midi_device_close(void);
465 /* in compiler.y */
467 int compile_ahs_string(char * code);
468 int compile_ahs(char * file);
470 /* in support.c */
472 extern int debug;
473 extern int trace;
474 extern int show_progress;
475 void add_to_library_path(char * path, int strip);
476 FILE * path_fopen(char * filename, char * mode);
477 char * locate_file(char * filename);