The alterations command has been renamed from 'S' to 'A'.
[ahxm.git] / ahxm.h
blobba52d941cb9eb2fae63cb66634791f996b866f71
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) */
71 /* generators */
73 struct ss_gen
75 int note_id; /* note ID */
76 sample_t vol; /* volume */
77 struct ss_wave * w; /* the wave data */
79 double cursor; /* offset to next sample */
80 double inc; /* increment (frequency) */
82 int sustain; /* number of frames to play after release */
83 sample_t dvol; /* volume decrement in sustain */
85 double vibrato; /* vibrato oscillator */
86 double vib_depth; /* vibrato depth */
87 double vib_inc; /* increment for vibrato oscillator */
89 double portamento; /* portamento sum to inc */
91 struct ss_gen * next;
92 struct ss_gen * prev;
95 /* software syntesizer instruments */
97 struct ss_ins
99 int n_layers; /* # of layers */
100 struct ss_wave ** layers; /* layers */
102 struct ss_gen * gens; /* generator queue */
104 int n_channels; /* number of channels */
105 sample_t * vols; /* volumes (1 per channel) */
106 struct ss_eff ** effs; /* effect chains (1 per channel) */
108 double sustain; /* sustain in msecs */
109 double vib_depth; /* vibrato depth */
110 double vib_freq; /* vibrato frequency */
112 double portamento; /* portamento */
115 /* digital effects */
117 struct ss_eff
119 struct ss_wave * wave; /* wave buffer */
120 sample_t gain; /* effect gain */
121 sample_t igain; /* gain increment */
123 double lfo; /* lfo value */
124 double lfo_depth; /* lfo depth */
125 double lfo_inc; /* lfo increment */
127 double cursor; /* current buffer position */
129 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
131 struct ss_eff * next; /* next in chain */
134 /* song events */
136 typedef enum
138 SONG_EV_TEMPO,
139 SONG_EV_METER,
140 SONG_EV_MEASURE,
142 SONG_EV_SS_SUSTAIN,
143 SONG_EV_SS_VIBRATO,
144 SONG_EV_SS_PORTAMENTO,
145 SONG_EV_SS_CHANNEL,
147 SONG_EV_SS_WAV,
148 SONG_EV_SS_PAT,
150 SONG_EV_SS_EFF_OFF,
151 SONG_EV_SS_EFF_DELAY,
152 SONG_EV_SS_EFF_ECHO,
153 SONG_EV_SS_EFF_COMB,
154 SONG_EV_SS_EFF_ALLPASS,
155 SONG_EV_SS_EFF_FLANGER,
156 SONG_EV_SS_EFF_WOBBLE,
157 SONG_EV_SS_EFF_SQWOBBLE,
158 SONG_EV_SS_EFF_HFWOBBLE,
159 SONG_EV_SS_EFF_FADER,
160 SONG_EV_SS_EFF_REVERB,
161 SONG_EV_SS_EFF_FOLDBACK,
163 SONG_EV_MIDI_CHANNEL,
164 SONG_EV_MIDI_PROGRAM,
166 SONG_EV_BACK,
167 SONG_EV_NOTE,
168 SONG_EV_SS_PITCH_STRETCH,
169 SONG_EV_SS_PRINT_WAVE_TEMPO,
171 SONG_EV_SONG_INFO,
173 SONG_EV_NOTE_OFF,
174 SONG_EV_NOTE_ON,
176 SONG_EV_END
178 } song_ev_type;
180 struct song_ev_generic
182 song_ev_type type; /* event type */
183 double time; /* event time (1: whole note) */
184 int trk_id; /* track id */
185 int event_id; /* event id */
188 struct song_ev_note
190 song_ev_type type; /* SONG_EV_NOTE */
191 double time;
192 int trk_id;
193 int event_id;
194 int note; /* MIDI-like note */
195 double len; /* note length (1: whole note) */
196 sample_t vol; /* note volume (1: full volume) */
199 struct song_ev_back
201 song_ev_type type; /* SONG_EV_BACK */
202 double time;
203 int trk_id;
204 int event_id;
205 double len; /* note length (1: whole note) */
208 struct song_ev_tempo
210 song_ev_type type; /* SONG_EV_TEMPO */
211 double time;
212 int trk_id; /* always < 0 */
213 int event_id;
214 double tempo; /* tempo in bpm */
217 struct song_ev_meter
219 song_ev_type type; /* SONG_EV_METER */
220 double time;
221 int trk_id; /* always < 0 */
222 int event_id;
223 int num; /* meter numerator */
224 int den; /* meter denominator */
227 struct song_ev_measure
229 song_ev_type type; /* SONG_EV_MEASURE */
230 double time;
231 int trk_id;
232 int event_id;
233 int line; /* line number */
236 struct song_ev_ss_pitch_stretch
238 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
239 double time;
240 int trk_id;
241 int event_id;
242 int note; /* MIDI-like note (to find the wave) */
243 double len; /* note length (1: whole note) */
244 sample_t vol; /* note volume (1: full volume) */
247 struct song_ev_ss_print_wave_tempo
249 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
250 double time;
251 int trk_id;
252 int event_id;
253 int note; /* MIDI-like note (to find the wave) */
254 double len; /* note length (1: whole note) */
257 struct song_ev_ss_sustain
259 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
260 double time;
261 int trk_id;
262 int event_id;
263 double sustain; /* sustain time (in msecs) */
266 struct song_ev_ss_vibrato
268 song_ev_type type; /* SONG_EV_SS_VIBRATO */
269 double time;
270 int trk_id;
271 int event_id;
272 double vib_depth; /* vibrato depth (in msecs) */
273 double vib_freq; /* vibrato frequency (in Hzs) */
276 struct song_ev_ss_portamento
278 song_ev_type type; /* SONG_EV_SS_PORTAMENTO */
279 double time;
280 int trk_id;
281 int event_id;
282 double portamento; /* portamento */
285 struct song_ev_ss_channel
287 song_ev_type type; /* SONG_EV_SS_CHANNEL */
288 double time;
289 int trk_id;
290 int event_id;
291 int channel; /* channel */
292 sample_t vol; /* volume */
295 struct song_ev_ss_wav
297 song_ev_type type; /* SONG_EV_SS_WAV */
298 double time;
299 int trk_id;
300 int event_id;
301 char * file; /* path to .wav file */
302 int base; /* MIDI-like base note */
303 int min; /* MIDI-like minimum note */
304 int max; /* MIDI-like maximum note */
305 double loop_start; /* start of loop */
306 double loop_end; /* end of loop */
307 int first_channel; /* first channel to start spreading */
308 int skip_channels; /* channels to skip when spreading */
311 struct song_ev_ss_pat
313 song_ev_type type; /* SONG_EV_SS_PAT */
314 double time;
315 int trk_id;
316 int event_id;
317 char * file; /* path to .pat file */
320 struct song_ev_ss_eff
322 song_ev_type type; /* effect type */
323 double time;
324 int trk_id;
325 int event_id;
326 int channel; /* channel */
327 double size; /* size of effect */
328 sample_t gain; /* gain */
329 double depth; /* depth */
330 double freq; /* freq */
331 double phase; /* phase */
332 sample_t initial; /* initial vol */
333 sample_t final; /* final vol */
336 struct song_ev_midi_channel
338 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
339 double time;
340 int trk_id;
341 int event_id;
342 int channel; /* midi channel (1-16) */
345 struct song_ev_midi_program
347 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
348 double time;
349 int trk_id;
350 int event_id;
351 int program; /* midi program (0-127) */
354 struct song_ev_song_info
356 song_ev_type type; /* SONG_EV_SONG_INFO */
357 double time;
358 int trk_id;
359 int event_id;
360 char * author; /* track author */
361 char * name; /* track name */
364 union song_ev
366 struct song_ev_generic generic;
368 struct song_ev_tempo tempo;
369 struct song_ev_meter meter;
370 struct song_ev_measure measure;
372 struct song_ev_note note;
373 struct song_ev_back back;
375 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
376 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
378 struct song_ev_ss_sustain ss_sustain;
379 struct song_ev_ss_vibrato ss_vibrato;
380 struct song_ev_ss_portamento ss_portamento;
381 struct song_ev_ss_channel ss_channel;
383 struct song_ev_ss_wav ss_wav;
384 struct song_ev_ss_pat ss_pat;
386 struct song_ev_ss_eff ss_eff;
388 struct song_ev_midi_channel midi_channel;
389 struct song_ev_midi_program midi_program;
391 struct song_ev_song_info song_info;
395 /* GLOBALS */
397 /* in ss_core.c */
399 extern int ss_frequency;
400 extern int ss_interpolation;
401 extern int ss_nchannels;
403 /* in ss_input.c */
405 extern int ss_page_size;
407 /* in ss_output.c */
409 extern sample_t ss_master_volume;
410 extern int ss_output_clipped;
411 extern sample_t ss_optimal_volume;
412 extern char * ss_cue_file_name;
414 /* in song.c */
416 extern union song_ev * song;
417 extern int n_song_ev;
418 extern int solo_track;
420 /* in support.c */
422 extern int verbose;
423 extern int trace;
425 /* MACROS */
427 /* milliseconds to frames conversion */
428 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
430 /* grows a dynamic array */
431 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
433 /* PROTOTYPES */
435 /* in ss_core.c */
437 double ss_note_frequency(int note);
438 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
439 void ss_free_wave(struct ss_wave * w);
440 void ss_prepare_wave(struct ss_wave * w);
441 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
442 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
443 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
445 /* in ss_gen.c */
447 void ss_gen_init(void);
448 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
449 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
450 void ss_gen_sustain(struct ss_gen * g, double sustain);
451 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
452 void ss_gen_portamento(struct ss_gen * g, double portamento);
453 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
454 struct ss_wave * w);
455 void ss_gen_release(struct ss_gen * g);
456 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
458 /* in ss_ins.c */
460 void ss_ins_init(struct ss_ins * i);
461 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
462 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
463 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
464 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
465 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
466 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
467 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
468 struct ss_wave * w);
469 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
470 void ss_ins_note_off(struct ss_ins * i, int note_id);
471 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
473 /* in ss_output.c */
475 int ss_output_open(char * drvname, char * filename);
476 void ss_output_init_frame(sample_t frame[]);
477 int ss_output_write(sample_t frame[]);
478 void ss_output_close(void);
479 int cue_file_song_info(int frame, char * author, char * name);
481 /* in ss_input.c */
483 void load_pcm_wave(FILE * f, struct ss_wave * w);
484 struct ss_wave * ss_load_wav_file(char * file,
485 double base_freq, double min_freq, double max_freq,
486 double loop_start, double loop_end,
487 int first_channel, int skip_channels);
488 int ss_load_pat_file(struct ss_ins * i, char * file);
490 /* in ss_eff.c */
492 void ss_eff_delay(struct ss_eff ** ec, double size);
493 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
494 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
495 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
496 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
497 double depth, double freq, double phase);
498 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase);
499 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
500 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
501 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
502 void ss_eff_reverb(struct ss_eff ** ec);
503 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
505 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
506 void ss_eff_off(struct ss_eff ** ec);
508 /* in song.c */
510 void song_clear(void);
511 void add_song_ev(song_ev_type type, double time, union song_ev * ev);
512 void song_sort(void);
513 int song_test_measure_boundary(double ev_time, int num, int den, int line);
515 /* in ss_song.c */
517 int ss_song_render(int skip_secs, char * driver, char * devfile);
519 /* in midi_song.c */
521 int midi_song_play(int skip_secs);
522 int midi_device_open(char * devfile);
523 void midi_device_close(void);
525 /* in compiler.y */
527 int compile_ahs_string(char * code);
528 int compile_ahs(char * file);
530 /* in support.c */
532 void libpath_add(char * path, int strip);
533 FILE * libpath_fopen(char * filename, char * mode);
534 char * libpath_locate(char * filename);
535 void transconv_add(char * from, char * to, char * convcmd);
536 char * transconv(char * file, char * ext, char * dir);