*** empty log message ***
[ahxm.git] / annhell.h
blob7e551757abe871ee6b707b4116b9383c173500a4
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 */
40 /* waves */
42 struct ss_wave
44 double size; /* size in frames */
45 int n_channels; /* # of channels */
46 float ** wave; /* the PCM waves */
47 int s_rate; /* original sample rate */
49 double loop_start; /* start of loop (-1, no loop) */
50 double loop_end; /* end of loop */
52 double base_freq; /* base frequency */
53 double min_freq; /* minimum frequency */
54 double max_freq; /* maximum frequency */
57 /* generators */
59 struct ss_gen
61 int note_id; /* note ID */
62 float vol; /* volume */
63 struct ss_wave * w; /* the wave data */
65 double cursor; /* offset to next sample */
66 double inc; /* increment (frequency) */
68 int sustain; /* number of frames to play after release */
69 float dvol; /* volume decrement in sustain */
71 double vibrato; /* vibrato oscillator */
72 double vib_depth; /* vibrato depth */
73 double vib_inc; /* increment for vibrato oscillator */
75 double portamento; /* portamento sum to inc */
77 struct ss_gen * next;
78 struct ss_gen * prev;
81 /* software syntesizer instruments */
83 struct ss_ins
85 int n_layers; /* # of layers */
86 struct ss_wave ** layers; /* layers */
88 struct ss_gen * gens; /* generator queue */
90 int n_channels; /* number of channels */
91 float * vols; /* volumes (1 per channel) */
92 struct ss_eff ** effs; /* effect chains (1 per channel) */
94 double sustain; /* sustain in msecs */
95 double vib_depth; /* vibrato depth */
96 double vib_freq; /* vibrato frequency */
99 /* digital effects */
101 struct ss_eff
103 float * wave; /* wave buffer */
104 double size; /* size of wave */
105 float gain; /* effect gain */
106 float igain; /* gain increment */
108 double lfo; /* lfo value */
109 double lfo_depth; /* lfo depth */
110 double lfo_inc; /* lfo increment */
112 double cursor; /* current buffer position */
114 float (* func)(struct ss_eff *, float); /* processing function */
116 struct ss_eff * next; /* next in chain */
119 /* song events */
121 typedef enum
123 SONG_EV_TEMPO,
124 SONG_EV_METER,
125 SONG_EV_MEASURE,
127 SONG_EV_SS_SUSTAIN,
128 SONG_EV_SS_VIBRATO,
129 SONG_EV_SS_CHANNEL,
131 SONG_EV_SS_WAV,
132 SONG_EV_SS_PAT,
134 SONG_EV_SS_EFF_DELAY,
135 SONG_EV_SS_EFF_ECHO,
136 SONG_EV_SS_EFF_COMB,
137 SONG_EV_SS_EFF_ALLPASS,
138 SONG_EV_SS_EFF_FLANGER,
139 SONG_EV_SS_EFF_WOBBLE,
140 SONG_EV_SS_EFF_SQWOBBLE,
141 SONG_EV_SS_EFF_FADER,
142 SONG_EV_SS_EFF_REVERB,
143 SONG_EV_SS_EFF_OFF,
145 SONG_EV_MIDI_CHANNEL,
146 SONG_EV_MIDI_PROGRAM,
148 SONG_EV_NOTE,
149 SONG_EV_SS_PITCH_STRETCH,
151 SONG_EV_NOTE_ON,
152 SONG_EV_NOTE_OFF,
154 SONG_EV_END
156 } song_ev_type;
158 struct song_ev_generic
160 song_ev_type type; /* event type */
161 double time; /* event time (1: whole note) */
162 int trk_id; /* track id */
165 struct song_ev_note
167 song_ev_type type; /* SONG_EV_NOTE */
168 double time;
169 int trk_id;
170 int note; /* MIDI-like note */
171 double len; /* note length (1: whole note) */
172 float vol; /* note volume (1: full volume) */
175 struct song_ev_tempo
177 song_ev_type type; /* SONG_EV_TEMPO */
178 double time;
179 int trk_id; /* always < 0 */
180 double tempo; /* tempo in bpm */
183 struct song_ev_meter
185 song_ev_type type; /* SONG_EV_METER */
186 double time;
187 int trk_id; /* always < 0 */
188 int num; /* meter numerator */
189 int den; /* meter denominator */
192 struct song_ev_measure
194 song_ev_type type; /* SONG_EV_MEASURE */
195 double time;
196 int trk_id;
197 int line; /* line number */
200 struct song_ev_ss_pitch_stretch
202 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
203 double time;
204 int trk_id;
205 int note; /* MIDI-like note (to find the wave) */
206 double len; /* note length (1: whole note) */
207 float vol; /* note volume (1: full volume) */
210 struct song_ev_ss_sustain
212 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
213 double time;
214 int trk_id;
215 double sustain; /* sustain time (in msecs) */
218 struct song_ev_ss_vibrato
220 song_ev_type type; /* SONG_EV_SS_VIBRATO */
221 double time;
222 int trk_id;
223 double vib_depth; /* vibrato depth (in msecs) */
224 double vib_freq; /* vibrato frequency (in Hzs) */
227 struct song_ev_ss_channel
229 song_ev_type type; /* SONG_EV_SS_CHANNEL */
230 double time;
231 int trk_id;
232 int channel; /* channel */
233 float vol; /* volume */
236 struct song_ev_ss_wav
238 song_ev_type type; /* SONG_EV_SS_WAV */
239 double time;
240 int trk_id;
241 char * file; /* path to .wav file */
242 int base; /* MIDI-like base note */
243 int min; /* MIDI-like minimum note */
244 int max; /* MIDI-like maximum note */
245 double loop_start; /* start of loop */
246 double loop_end; /* end of loop */
249 struct song_ev_ss_pat
251 song_ev_type type; /* SONG_EV_SS_PAT */
252 double time;
253 int trk_id;
254 char * file; /* path to .pat file */
257 struct song_ev_ss_eff
259 song_ev_type type; /* effect type */
260 double time;
261 int trk_id;
262 int channel; /* channel */
263 double size; /* size of effect */
264 float gain; /* gain */
265 double depth; /* depth */
266 double freq; /* freq */
267 double phase; /* phase */
268 float initial; /* initial vol */
269 float final; /* final vol */
272 struct song_ev_midi_channel
274 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
275 double time;
276 int trk_id;
277 int channel; /* midi channel (1-16) */
280 struct song_ev_midi_program
282 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
283 double time;
284 int trk_id;
285 int program; /* midi program (0-127) */
288 union song_ev
290 struct song_ev_generic generic;
292 struct song_ev_tempo tempo;
293 struct song_ev_meter meter;
294 struct song_ev_measure measure;
296 struct song_ev_note note;
298 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
299 struct song_ev_ss_sustain ss_sustain;
300 struct song_ev_ss_vibrato ss_vibrato;
301 struct song_ev_ss_channel ss_channel;
303 struct song_ev_ss_wav ss_wav;
304 struct song_ev_ss_pat ss_pat;
306 struct song_ev_ss_eff ss_eff;
308 struct song_ev_midi_channel midi_channel;
309 struct song_ev_midi_program midi_program;
313 /* GLOBALS */
315 /* in ss_core.c */
317 extern int ss_frequency;
318 extern int ss_interpolation;
319 extern int ss_nchannels;
320 extern int ss_debug;
322 /* in ss_output.c */
324 extern float ss_master_volume;
325 extern int ss_output_clipped;
326 extern float ss_optimal_volume;
328 /* in song.c */
330 extern union song_ev * song;
331 extern int n_song_ev;
334 /* MACROS */
336 /* milliseconds to frames conversion */
337 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
340 /* PROTOTYPES */
342 /* in ss_core.c */
344 double ss_note_frequency(int note);
345 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate);
346 float ss_get_sample(float * wave, double size, double offset);
347 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
348 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
350 /* in ss_gen.c */
352 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
353 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
354 void ss_gen_sustain(struct ss_gen * g, double sustain);
355 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
356 void ss_gen_play(struct ss_gen * g, double freq, float vol, int note_id,
357 struct ss_wave * w);
358 void ss_gen_release(struct ss_gen * g);
359 int ss_gen_frame(struct ss_gen * g, int n_channels, float frame[]);
361 /* in ss_ins.c */
363 void ss_ins_init(struct ss_ins * i);
364 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
365 void ss_ins_copy_layers(struct ss_ins * i, struct ss_ins * o);
366 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
367 void ss_ins_set_channel(struct ss_ins * i, int channel, float vol);
368 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
369 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
370 int ss_ins_play(struct ss_ins * i, double freq, float vol, int note_id,
371 struct ss_wave * w);
372 int ss_ins_note_on(struct ss_ins * i, int note, float vol, int note_id);
373 void ss_ins_note_off(struct ss_ins * i, int note_id);
374 void ss_ins_frame(struct ss_ins * i, float frame[]);
376 /* in ss_output.c */
378 int ss_output_open(char * drvname, char * filename);
379 void ss_output_init_frame(float frame[]);
380 int ss_output_write(float frame[]);
381 void ss_output_close(void);
383 /* in ss_input.c */
385 struct ss_wave * ss_load_wav_file(char * file,
386 double base_freq, double min_freq, double max_freq,
387 double loop_start, double loop_end);
388 int ss_load_pat_file(struct ss_ins * i, char * file);
390 /* in ss_eff.c */
392 void ss_eff_delay(struct ss_eff ** ec, double size);
393 void ss_eff_echo(struct ss_eff ** ec, double size, float gain);
394 void ss_eff_comb(struct ss_eff ** ec, double size, float gain);
395 void ss_eff_allpass(struct ss_eff ** ec, double size, float gain);
396 void ss_eff_flanger(struct ss_eff ** ec, double size, float gain,
397 double depth, double freq, double phase);
398 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
399 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
400 void ss_eff_fader(struct ss_eff ** ec, double size, float initial, float final);
401 void ss_eff_reverb(struct ss_eff ** ec);
403 float ss_eff_process(struct ss_eff * e, float s);
404 void ss_eff_off(struct ss_eff ** ec);
406 /* in song.c */
408 void song_clear(void);
409 void add_song_ev(union song_ev * ev);
410 void song_sort(void);
411 int song_test_measure_boundary(double ev_time, int num, int den, int line);
413 /* in ss_song.c */
415 int ss_song_render(int skip_secs);
417 /* in midi_song.c */
419 int midi_song_play(int skip_secs);
421 /* in compiler.y */
423 int compile(char * code);
424 int compile_file(char * file);
426 /* in support.c */
428 void add_to_library_path(char * path, int strip);
429 FILE * path_fopen(char * filename, char * mode);