Updated TODO (because I broke it).
[ahxm.git] / annhell.h
blobcb588cd9f8c2c7a455ca64f607d8ad268b669efb
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 /* STRUCTURES */
36 /* waves */
38 struct ss_wave
40 double size; /* size in frames */
41 int n_channels; /* # of channels */
42 float ** wave; /* the PCM waves */
43 int s_rate; /* original sample rate */
45 double loop_start; /* start of loop (-1, no loop) */
46 double loop_end; /* end of loop */
48 double base_freq; /* base frequency */
49 double min_freq; /* minimum frequency */
50 double max_freq; /* maximum frequency */
53 /* generators */
55 struct ss_gen
57 int note_id; /* note ID */
58 float vol; /* volume */
59 struct ss_wave * w; /* the wave data */
61 double cursor; /* offset to next sample */
62 double inc; /* increment (frequency) */
64 int sustain; /* number of frames to play after release */
65 float dvol; /* volume decrement in sustain */
67 double vibrato; /* vibrato oscillator */
68 double vib_depth; /* vibrato depth */
69 double vib_inc; /* increment for vibrato oscillator */
71 double portamento; /* portamento sum to inc */
73 struct ss_gen * next;
74 struct ss_gen * prev;
77 /* software syntesizer instruments */
79 struct ss_ins
81 int n_layers; /* # of layers */
82 struct ss_wave ** layers; /* layers */
84 struct ss_gen * gens; /* generator queue */
86 int n_channels; /* number of channels */
87 float * vols; /* volumes (1 per channel) */
88 struct ss_eff ** effs; /* effect chains (1 per channel) */
90 double sustain; /* sustain in msecs */
91 double vib_depth; /* vibrato depth */
92 double vib_freq; /* vibrato frequency */
95 /* digital effects */
97 struct ss_eff
99 float * wave; /* wave buffer */
100 double size; /* size of wave */
101 float gain; /* effect gain */
102 float igain; /* gain increment */
104 double lfo; /* lfo value */
105 double lfo_depth; /* lfo depth */
106 double lfo_inc; /* lfo increment */
108 double cursor; /* current buffer position */
110 float (* func)(struct ss_eff *, float); /* processing function */
112 struct ss_eff * next; /* next in chain */
115 /* song events */
117 typedef enum
119 SONG_EV_START,
121 SONG_EV_TEMPO,
122 SONG_EV_METER,
123 SONG_EV_MEASURE,
125 SONG_EV_SS_SUSTAIN,
126 SONG_EV_SS_VIBRATO,
127 SONG_EV_SS_CHANNEL,
129 SONG_EV_SS_WAV,
130 SONG_EV_SS_PAT,
132 SONG_EV_SS_EFF_DELAY,
133 SONG_EV_SS_EFF_ECHO,
134 SONG_EV_SS_EFF_COMB,
135 SONG_EV_SS_EFF_ALLPASS,
136 SONG_EV_SS_EFF_FLANGER,
137 SONG_EV_SS_EFF_WOBBLE,
138 SONG_EV_SS_EFF_SQWOBBLE,
139 SONG_EV_SS_EFF_FADER,
140 SONG_EV_SS_EFF_REVERB,
141 SONG_EV_SS_EFF_OFF,
143 SONG_EV_MIDI_CHANNEL,
144 SONG_EV_MIDI_PROGRAM,
146 SONG_EV_NOTE,
147 SONG_EV_SS_PITCH_STRETCH,
149 SONG_EV_NOTE_ON,
150 SONG_EV_NOTE_OFF,
152 SONG_EV_END
154 } song_ev_type;
156 struct song_ev_generic
158 song_ev_type type; /* event type */
159 double time; /* event time (1: whole note) */
160 int trk_id; /* track id */
163 struct song_ev_note
165 song_ev_type type; /* SONG_EV_NOTE */
166 double time;
167 int trk_id;
168 int note; /* MIDI-like note */
169 double len; /* note length (1: whole note) */
170 float vol; /* note volume (1: full volume) */
173 struct song_ev_tempo
175 song_ev_type type; /* SONG_EV_TEMPO */
176 double time;
177 int trk_id; /* always < 0 */
178 double tempo; /* tempo in bpm */
181 struct song_ev_meter
183 song_ev_type type; /* SONG_EV_METER */
184 double time;
185 int trk_id; /* always < 0 */
186 int num; /* meter numerator */
187 int den; /* meter denominator */
190 struct song_ev_measure
192 song_ev_type type; /* SONG_EV_MEASURE */
193 double time;
194 int trk_id;
195 int line; /* line number */
198 struct song_ev_ss_pitch_stretch
200 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
201 double time;
202 int trk_id;
203 int note; /* MIDI-like note (to find the wave) */
204 double len; /* note length (1: whole note) */
205 float vol; /* note volume (1: full volume) */
208 struct song_ev_ss_sustain
210 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
211 double time;
212 int trk_id;
213 double sustain; /* sustain time (in msecs) */
216 struct song_ev_ss_vibrato
218 song_ev_type type; /* SONG_EV_SS_VIBRATO */
219 double time;
220 int trk_id;
221 double vib_depth; /* vibrato depth (in msecs) */
222 double vib_freq; /* vibrato frequency (in Hzs) */
225 struct song_ev_ss_channel
227 song_ev_type type; /* SONG_EV_SS_CHANNEL */
228 double time;
229 int trk_id;
230 int channel; /* channel */
231 float vol; /* volume */
234 struct song_ev_ss_wav
236 song_ev_type type; /* SONG_EV_SS_WAV */
237 double time;
238 int trk_id;
239 char * file; /* path to .wav file */
240 int base; /* MIDI-like base note */
241 int min; /* MIDI-like minimum note */
242 int max; /* MIDI-like maximum note */
243 double loop_start; /* start of loop */
244 double loop_end; /* end of loop */
247 struct song_ev_ss_pat
249 song_ev_type type; /* SONG_EV_SS_PAT */
250 double time;
251 int trk_id;
252 char * file; /* path to .pat file */
255 struct song_ev_ss_eff
257 song_ev_type type; /* effect type */
258 double time;
259 int trk_id;
260 int channel; /* channel */
261 double size; /* size of effect */
262 float gain; /* gain */
263 double depth; /* depth */
264 double freq; /* freq */
265 double phase; /* phase */
266 float initial; /* initial vol */
267 float final; /* final vol */
270 struct song_ev_midi_channel
272 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
273 double time;
274 int trk_id;
275 int channel; /* midi channel (1-16) */
278 struct song_ev_midi_program
280 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
281 double time;
282 int trk_id;
283 int program; /* midi program (0-127) */
286 union song_ev
288 struct song_ev_generic generic;
290 struct song_ev_tempo tempo;
291 struct song_ev_meter meter;
292 struct song_ev_measure measure;
294 struct song_ev_note note;
296 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
297 struct song_ev_ss_sustain ss_sustain;
298 struct song_ev_ss_vibrato ss_vibrato;
299 struct song_ev_ss_channel ss_channel;
301 struct song_ev_ss_wav ss_wav;
302 struct song_ev_ss_pat ss_pat;
304 struct song_ev_ss_eff ss_eff;
306 struct song_ev_midi_channel midi_channel;
307 struct song_ev_midi_program midi_program;
311 /* GLOBALS */
313 /* in ss_core.c */
315 extern int ss_frequency;
316 extern int ss_interpolation;
317 extern int ss_nchannels;
318 extern int ss_debug;
320 /* in ss_output.c */
322 extern float ss_master_volume;
323 extern int ss_output_clipped;
324 extern float ss_optimal_volume;
326 /* in song.c */
328 extern union song_ev * song;
329 extern int n_song_ev;
332 /* MACROS */
334 /* milliseconds to frames conversion */
335 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
338 /* PROTOTYPES */
340 /* in ss_core.c */
342 double ss_note_frequency(int note);
343 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate);
344 float ss_get_sample(float * wave, double size, double offset);
345 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
346 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
348 /* in ss_gen.c */
350 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
351 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
352 void ss_gen_sustain(struct ss_gen * g, double sustain);
353 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
354 void ss_gen_play(struct ss_gen * g, double freq, float vol, int note_id,
355 struct ss_wave * w);
356 void ss_gen_release(struct ss_gen * g);
357 int ss_gen_frame(struct ss_gen * g, int n_channels, float frame[]);
359 /* in ss_ins.c */
361 void ss_ins_init(struct ss_ins * i);
362 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
363 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
364 void ss_ins_set_channel(struct ss_ins * i, int channel, float vol);
365 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
366 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
367 int ss_ins_play(struct ss_ins * i, double freq, float vol, int note_id,
368 struct ss_wave * w);
369 int ss_ins_note_on(struct ss_ins * i, int note, float vol, int note_id);
370 void ss_ins_note_off(struct ss_ins * i, int note_id);
371 void ss_ins_frame(struct ss_ins * i, float frame[]);
373 /* in ss_output.c */
375 int ss_output_open(char * drvname, char * filename);
376 void ss_output_init_frame(float frame[]);
377 int ss_output_write(float frame[]);
378 void ss_output_close(void);
380 /* in ss_input.c */
382 struct ss_wave * ss_load_wav_file(char * file,
383 double base_freq, double min_freq, double max_freq,
384 double loop_start, double loop_end);
385 int ss_load_pat_file(struct ss_ins * i, char * file);
387 /* in ss_eff.c */
389 void ss_eff_delay(struct ss_eff ** ec, double size);
390 void ss_eff_echo(struct ss_eff ** ec, double size, float gain);
391 void ss_eff_comb(struct ss_eff ** ec, double size, float gain);
392 void ss_eff_allpass(struct ss_eff ** ec, double size, float gain);
393 void ss_eff_flanger(struct ss_eff ** ec, double size, float gain,
394 double depth, double freq, double phase);
395 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
396 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
397 void ss_eff_fader(struct ss_eff ** ec, double size, float initial, float final);
398 void ss_eff_reverb(struct ss_eff ** ec);
400 float ss_eff_process(struct ss_eff * e, float s);
401 void ss_eff_off(struct ss_eff ** ec);
403 /* in song.c */
405 void song_clear(void);
406 void add_song_ev(union song_ev * ev);
407 void song_sort(void);
408 int song_test_measure_boundary(double ev_time, int num, int den, int line);
410 /* in ss_song.c */
412 int ss_song_render(void);
414 /* in midi_song.c */
416 int midi_song_play(void);
418 /* in compiler.y */
420 int compile(char * code);
421 int compile_file(char * file);
423 /* in support.c */
425 void add_to_library_path(char * path, int strip);
426 FILE * path_fopen(char * filename, char * mode);