The wobble effect now includes a new gain argument.
[ahxm.git] / ahxm.h
blob8c0083a3595ca65b44bf4ae2f9fae3e0d52383ca
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 int first_channel; /* first channel to spread into */
62 int skip_channels; /* channels to skip when spreading */
64 char * filename; /* filename (for paged files) */
65 long f_pos; /* file position where the PCM files */
66 int p_offset; /* offset in frames of the page */
67 int bits; /* bits of the PCM wave (8, 16) */
68 int sign; /* sign of the PCM wave (1, -1) */
70 int page_faults; /* number of times ss_load_page() was called */
73 /* generators */
75 struct ss_gen
77 int note_id; /* note ID */
78 sample_t vol; /* volume */
79 struct ss_wave * w; /* the wave data */
81 double cursor; /* offset to next sample */
82 double inc; /* increment (frequency) */
84 int sustain; /* number of frames to play after release */
85 sample_t dvol; /* volume decrement in sustain */
87 double vibrato; /* vibrato oscillator */
88 double vib_depth; /* vibrato depth */
89 double vib_inc; /* increment for vibrato oscillator */
91 double portamento; /* portamento sum to inc */
93 struct ss_gen * next;
94 struct ss_gen * prev;
97 /* software syntesizer instruments */
99 struct ss_ins
101 int n_layers; /* # of layers */
102 struct ss_wave ** layers; /* layers */
104 struct ss_gen * gens; /* generator queue */
106 int n_channels; /* number of channels */
107 sample_t * vols; /* volumes (1 per channel) */
108 struct ss_eff ** effs; /* effect chains (1 per channel) */
110 double sustain; /* sustain in msecs */
111 double vib_depth; /* vibrato depth */
112 double vib_freq; /* vibrato frequency */
114 double portamento; /* portamento */
117 /* digital effects */
119 struct ss_eff
121 struct ss_wave * wave; /* wave buffer */
122 sample_t gain; /* effect gain */
123 sample_t igain; /* gain increment */
125 double lfo; /* lfo value */
126 double lfo_depth; /* lfo depth */
127 double lfo_inc; /* lfo increment */
129 double cursor; /* current buffer position */
131 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
133 struct ss_eff * next; /* next in chain */
136 /* song events */
138 typedef enum
140 SONG_EV_TEMPO,
141 SONG_EV_METER,
142 SONG_EV_MEASURE,
144 SONG_EV_SS_SUSTAIN,
145 SONG_EV_SS_VIBRATO,
146 SONG_EV_SS_PORTAMENTO,
147 SONG_EV_SS_CHANNEL,
149 SONG_EV_SS_WAV,
150 SONG_EV_SS_PAT,
152 SONG_EV_SS_EFF_OFF,
153 SONG_EV_SS_EFF_DELAY,
154 SONG_EV_SS_EFF_ECHO,
155 SONG_EV_SS_EFF_COMB,
156 SONG_EV_SS_EFF_ALLPASS,
157 SONG_EV_SS_EFF_FLANGER,
158 SONG_EV_SS_EFF_WOBBLE,
159 SONG_EV_SS_EFF_SQWOBBLE,
160 SONG_EV_SS_EFF_HFWOBBLE,
161 SONG_EV_SS_EFF_FADER,
162 SONG_EV_SS_EFF_REVERB,
163 SONG_EV_SS_EFF_FOLDBACK,
165 SONG_EV_MIDI_CHANNEL,
166 SONG_EV_MIDI_PROGRAM,
168 SONG_EV_BACK,
169 SONG_EV_NOTE,
170 SONG_EV_SS_PITCH_STRETCH,
171 SONG_EV_SS_PRINT_WAVE_TEMPO,
173 SONG_EV_SONG_INFO,
175 SONG_EV_NOTE_OFF,
176 SONG_EV_NOTE_ON,
178 SONG_EV_END
180 } song_ev_type;
182 struct song_ev_generic
184 song_ev_type type; /* event type */
185 double time; /* event time (1: whole note) */
186 int trk_id; /* track id */
187 int event_id; /* event id */
190 struct song_ev_note
192 song_ev_type type; /* SONG_EV_NOTE */
193 double time;
194 int trk_id;
195 int event_id;
196 int note; /* MIDI-like note */
197 double len; /* note length (1: whole note) */
198 sample_t vol; /* note volume (1: full volume) */
201 struct song_ev_back
203 song_ev_type type; /* SONG_EV_BACK */
204 double time;
205 int trk_id;
206 int event_id;
207 double len; /* note length (1: whole note) */
210 struct song_ev_tempo
212 song_ev_type type; /* SONG_EV_TEMPO */
213 double time;
214 int trk_id; /* always < 0 */
215 int event_id;
216 double tempo; /* tempo in bpm */
219 struct song_ev_meter
221 song_ev_type type; /* SONG_EV_METER */
222 double time;
223 int trk_id; /* always < 0 */
224 int event_id;
225 int num; /* meter numerator */
226 int den; /* meter denominator */
229 struct song_ev_measure
231 song_ev_type type; /* SONG_EV_MEASURE */
232 double time;
233 int trk_id;
234 int event_id;
235 int line; /* line number */
238 struct song_ev_ss_pitch_stretch
240 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
241 double time;
242 int trk_id;
243 int event_id;
244 int note; /* MIDI-like note (to find the wave) */
245 double len; /* note length (1: whole note) */
246 sample_t vol; /* note volume (1: full volume) */
249 struct song_ev_ss_print_wave_tempo
251 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
252 double time;
253 int trk_id;
254 int event_id;
255 int note; /* MIDI-like note (to find the wave) */
256 double len; /* note length (1: whole note) */
259 struct song_ev_ss_sustain
261 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
262 double time;
263 int trk_id;
264 int event_id;
265 double sustain; /* sustain time (in msecs) */
268 struct song_ev_ss_vibrato
270 song_ev_type type; /* SONG_EV_SS_VIBRATO */
271 double time;
272 int trk_id;
273 int event_id;
274 double vib_depth; /* vibrato depth (in msecs) */
275 double vib_freq; /* vibrato frequency (in Hzs) */
278 struct song_ev_ss_portamento
280 song_ev_type type; /* SONG_EV_SS_PORTAMENTO */
281 double time;
282 int trk_id;
283 int event_id;
284 double portamento; /* portamento */
287 struct song_ev_ss_channel
289 song_ev_type type; /* SONG_EV_SS_CHANNEL */
290 double time;
291 int trk_id;
292 int event_id;
293 int channel; /* channel */
294 sample_t vol; /* volume */
297 struct song_ev_ss_wav
299 song_ev_type type; /* SONG_EV_SS_WAV */
300 double time;
301 int trk_id;
302 int event_id;
303 char * file; /* path to .wav file */
304 int base; /* MIDI-like base note */
305 int min; /* MIDI-like minimum note */
306 int max; /* MIDI-like maximum note */
307 double loop_start; /* start of loop */
308 double loop_end; /* end of loop */
309 int first_channel; /* first channel to start spreading */
310 int skip_channels; /* channels to skip when spreading */
313 struct song_ev_ss_pat
315 song_ev_type type; /* SONG_EV_SS_PAT */
316 double time;
317 int trk_id;
318 int event_id;
319 char * file; /* path to .pat file */
322 struct song_ev_ss_eff
324 song_ev_type type; /* effect type */
325 double time;
326 int trk_id;
327 int event_id;
328 int channel; /* channel */
329 double size; /* size of effect */
330 sample_t gain; /* gain */
331 double depth; /* depth */
332 double freq; /* freq */
333 double phase; /* phase */
334 sample_t initial; /* initial vol */
335 sample_t final; /* final vol */
338 struct song_ev_midi_channel
340 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
341 double time;
342 int trk_id;
343 int event_id;
344 int channel; /* midi channel (1-16) */
347 struct song_ev_midi_program
349 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
350 double time;
351 int trk_id;
352 int event_id;
353 int program; /* midi program (0-127) */
356 struct song_ev_song_info
358 song_ev_type type; /* SONG_EV_SONG_INFO */
359 double time;
360 int trk_id;
361 int event_id;
362 char * author; /* track author */
363 char * name; /* track name */
366 union song_ev
368 struct song_ev_generic generic;
370 struct song_ev_tempo tempo;
371 struct song_ev_meter meter;
372 struct song_ev_measure measure;
374 struct song_ev_note note;
375 struct song_ev_back back;
377 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
378 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
380 struct song_ev_ss_sustain ss_sustain;
381 struct song_ev_ss_vibrato ss_vibrato;
382 struct song_ev_ss_portamento ss_portamento;
383 struct song_ev_ss_channel ss_channel;
385 struct song_ev_ss_wav ss_wav;
386 struct song_ev_ss_pat ss_pat;
388 struct song_ev_ss_eff ss_eff;
390 struct song_ev_midi_channel midi_channel;
391 struct song_ev_midi_program midi_program;
393 struct song_ev_song_info song_info;
397 /* GLOBALS */
399 /* in ss_core.c */
401 extern int ss_frequency;
402 extern int ss_interpolation;
403 extern int ss_nchannels;
405 /* in ss_input.c */
407 extern int ss_page_size;
409 /* in ss_output.c */
411 extern sample_t ss_master_volume;
412 extern int ss_output_clipped;
413 extern sample_t ss_optimal_volume;
414 extern char * ss_cue_file_name;
416 /* in song.c */
418 extern union song_ev * song;
419 extern int n_song_ev;
420 extern int solo_track;
422 /* in support.c */
424 extern int verbose;
425 extern int trace;
427 /* MACROS */
429 /* milliseconds to frames conversion */
430 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
432 /* grows a dynamic array */
433 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
435 /* PROTOTYPES */
437 /* in ss_core.c */
439 double ss_note_frequency(int note);
440 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
441 void ss_free_wave(struct ss_wave * w);
442 void ss_prepare_wave(struct ss_wave * w);
443 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
444 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
445 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
447 /* in ss_gen.c */
449 void ss_gen_init(void);
450 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
451 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
452 void ss_gen_sustain(struct ss_gen * g, double sustain);
453 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
454 void ss_gen_portamento(struct ss_gen * g, double portamento);
455 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
456 struct ss_wave * w);
457 void ss_gen_release(struct ss_gen * g);
458 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
460 /* in ss_ins.c */
462 void ss_ins_init(struct ss_ins * i);
463 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
464 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
465 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
466 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
467 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
468 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
469 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
470 struct ss_wave * w);
471 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
472 void ss_ins_note_off(struct ss_ins * i, int note_id);
473 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
475 /* in ss_output.c */
477 int ss_output_open(char * drvname, char * filename);
478 void ss_output_init_frame(sample_t frame[]);
479 int ss_output_write(sample_t frame[]);
480 void ss_output_close(void);
481 int cue_file_song_info(int frame, char * author, char * name);
483 /* in ss_input.c */
485 void load_pcm_wave(FILE * f, struct ss_wave * w);
486 struct ss_wave * ss_load_wav_file(char * file,
487 double base_freq, double min_freq, double max_freq,
488 double loop_start, double loop_end,
489 int first_channel, int skip_channels);
490 int ss_load_pat_file(struct ss_ins * i, char * file);
492 /* in ss_eff.c */
494 void ss_eff_delay(struct ss_eff ** ec, double size);
495 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
496 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
497 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
498 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
499 double depth, double freq, double phase);
500 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase, sample_t gain);
501 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
502 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
503 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
504 void ss_eff_reverb(struct ss_eff ** ec);
505 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
507 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
508 void ss_eff_off(struct ss_eff ** ec);
510 /* in song.c */
512 void song_clear(void);
513 void add_song_ev(song_ev_type type, double time, union song_ev * ev);
514 void song_sort(void);
515 int song_test_measure_boundary(double ev_time, int num, int den, int line);
517 /* in ss_song.c */
519 int ss_song_render(int skip_secs, char * driver, char * devfile);
521 /* in midi_song.c */
523 int midi_song_play(int skip_secs);
524 int midi_device_open(char * devfile);
525 void midi_device_close(void);
527 /* in compiler.y */
529 int compile_ahs_string(char * code);
530 int compile_ahs(char * file);
532 /* in support.c */
534 void libpath_add(char * path, int strip);
535 FILE * libpath_fopen(char * filename, char * mode);
536 char * libpath_locate(char * filename);
537 void transconv_add(char * from, char * to, char * convcmd);
538 char * transconv(char * file, char * ext, char * dir);