Updated TODO.
[ahxm.git] / ahxm.h
blobf41b6489b8f7199ef39c597307ae5223505c971b
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2007 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 {
47 double size; /* size in frames of full wave */
48 int p_size; /* size in frames of the page */
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 */
60 int first_channel; /* first channel to spread into */
61 int skip_channels; /* channels to skip when spreading */
63 char * filename; /* filename (for paged files) */
64 long f_pos; /* file position where the PCM files */
65 int p_offset; /* offset in frames of the page */
66 int bits; /* bits of the PCM wave (8, 16) */
67 int sign; /* sign of the PCM wave (1, -1) */
69 int page_faults; /* number of times ss_load_page() was called */
72 /* generators */
74 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 dsvol; /* volume decrement in sustain */
85 int attack; /* number of frames of fade-in attack */
86 sample_t davol; /* volume increment in attack */
88 double vibrato; /* vibrato oscillator */
89 double vib_depth; /* vibrato depth */
90 double vib_inc; /* increment for vibrato oscillator */
92 double portamento; /* portamento sum to inc */
94 struct ss_gen * next;
95 struct ss_gen * prev;
98 /* software syntesizer instruments */
100 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 attack; /* attack in msecs */
112 double vib_depth; /* vibrato depth */
113 double vib_freq; /* vibrato frequency */
115 int disabled; /* if set, no processing is done */
117 double portamento; /* portamento */
120 /* digital effects */
122 struct ss_eff {
123 struct ss_wave * wave; /* wave buffer */
124 sample_t gain; /* effect gain */
125 sample_t igain; /* gain increment */
127 double lfo; /* lfo value */
128 double lfo_depth; /* lfo depth */
129 double lfo_inc; /* lfo increment */
131 double cursor; /* current buffer position */
133 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
135 struct ss_eff * next; /* next in chain */
138 /* song events */
140 typedef enum {
141 SONG_EV_TEMPO,
142 SONG_EV_METER,
143 SONG_EV_MEASURE,
145 SONG_EV_SS_SUSTAIN,
146 SONG_EV_SS_ATTACK,
147 SONG_EV_SS_VIBRATO,
148 SONG_EV_SS_PORTAMENTO,
149 SONG_EV_SS_CHANNEL,
151 SONG_EV_SS_WAV,
152 SONG_EV_SS_PAT,
154 SONG_EV_SS_EFF_OFF,
155 SONG_EV_SS_EFF_DELAY,
156 SONG_EV_SS_EFF_ECHO,
157 SONG_EV_SS_EFF_COMB,
158 SONG_EV_SS_EFF_ALLPASS,
159 SONG_EV_SS_EFF_FLANGER,
160 SONG_EV_SS_EFF_WOBBLE,
161 SONG_EV_SS_EFF_SQWOBBLE,
162 SONG_EV_SS_EFF_HFWOBBLE,
163 SONG_EV_SS_EFF_FADER,
164 SONG_EV_SS_EFF_REVERB,
166 SONG_EV_SS_EFF_FOLDBACK,
167 SONG_EV_SS_EFF_ATAN,
168 SONG_EV_SS_EFF_DISTORT,
169 SONG_EV_SS_EFF_OVERDRIVE,
171 SONG_EV_MIDI_CHANNEL,
172 SONG_EV_MIDI_PROGRAM,
174 SONG_EV_BACK,
175 SONG_EV_NOTE,
176 SONG_EV_SS_PITCH_STRETCH,
177 SONG_EV_SS_PRINT_WAVE_TEMPO,
179 SONG_EV_SONG_INFO,
181 SONG_EV_NOTE_OFF,
182 SONG_EV_NOTE_ON,
184 SONG_EV_EOT,
185 SONG_EV_END,
187 SONG_EV_NOP
189 } song_ev_type;
192 struct song_ev {
193 song_ev_type type; /* event type */
194 double time; /* event time (1: whole note) */
195 int frame; /* frame number (ss) */
196 int msecs; /* milliseconds (MIDI) */
197 int trk_id; /* track id */
198 int event_id; /* event id */
199 int note_id; /* note id */
200 int value; /* MIDI-like note (or base) */
201 int min; /* MIDI-like minimum note */
202 int max; /* MIDI-like maximum note */
203 int channel; /* channel (or first channel) */
204 int skip_channels; /* channels to skip when spreading */
205 int vel; /* MIDI velocity */
206 sample_t vol; /* volume or gain */
207 sample_t initial; /* initial vol */
208 sample_t final; /* final vol */
209 double amount; /* sust, attck or portmnt (frames), tempo in bpm */
210 double len; /* note length (1: whole note) or effect size */
211 double depth; /* depth */
212 double freq; /* freq */
213 double start; /* loop start */
214 double end; /* loop end */
215 double phase; /* phase */
216 char *name; /* file name, or track name */
217 char *author; /* track author */
220 /* GLOBALS */
222 /* in ss_core.c */
224 extern int ss_frequency;
225 extern int ss_interpolation;
226 extern int ss_nchannels;
228 /* in ss_input.c */
230 extern int ss_page_size;
232 /* in ss_output.c */
234 extern sample_t ss_master_volume;
235 extern int ss_output_clipped;
236 extern sample_t ss_optimal_volume;
237 extern char * ss_cue_file_name;
239 /* in song.c */
241 extern struct song_ev * song;
242 extern int n_song_ev;
243 extern int n_song_tracks;
245 /* in compiler.y */
247 extern int solo_track;
249 /* in support.c */
251 extern int verbose;
252 extern int trace;
254 /* MACROS */
256 /* milliseconds to frames conversion */
257 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
259 /* grows a dynamic array */
260 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
262 /* PROTOTYPES */
264 /* in ss_core.c */
266 double ss_note_frequency(int note);
267 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
268 void ss_free_wave(struct ss_wave * w);
269 void ss_prepare_wave(struct ss_wave * w);
270 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
271 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
272 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
274 /* in ss_gen.c */
276 void ss_gen_init(void);
277 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
278 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
279 void ss_gen_sustain(struct ss_gen * g, double sustain);
280 void ss_gen_attack(struct ss_gen * g, double attack);
281 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
282 void ss_gen_portamento(struct ss_gen * g, double portamento);
283 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
284 struct ss_wave * w);
285 void ss_gen_release(struct ss_gen * g);
286 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
288 /* in ss_ins.c */
290 void ss_ins_init(struct ss_ins * i);
291 void ss_ins_disable(struct ss_ins * i);
292 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
293 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
294 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
295 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
296 void ss_ins_set_attack(struct ss_ins * i, double attack);
297 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
298 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
299 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
300 struct ss_wave * w);
301 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
302 void ss_ins_note_off(struct ss_ins * i, int note_id);
303 int ss_ins_frame(struct ss_ins * i, sample_t frame[]);
305 /* in ss_output.c */
307 int ss_output_open(char * drvname, char * filename);
308 void ss_output_init_frame(sample_t frame[]);
309 int ss_output_write(sample_t frame[]);
310 void ss_output_close(void);
311 int cue_file_song_info(int frame, char * author, char * name);
313 /* in ss_input.c */
315 void load_pcm_wave(FILE * f, struct ss_wave * w);
316 struct ss_wave * ss_load_wav_file(char * file,
317 double base_freq, double min_freq, double max_freq,
318 double loop_start, double loop_end,
319 int first_channel, int skip_channels);
320 int ss_load_pat_file(struct ss_ins * i, char * file);
322 /* in ss_eff.c */
324 void ss_eff_delay(struct ss_eff ** ec, double size);
325 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
326 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
327 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
328 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
329 double depth, double freq, double phase);
330 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase, sample_t gain);
331 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
332 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
333 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
334 void ss_eff_reverb(struct ss_eff ** ec);
335 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
336 void ss_eff_atan(struct ss_eff ** ec, sample_t gain);
337 void ss_eff_distort(struct ss_eff ** ec, sample_t gain);
338 void ss_eff_overdrive(struct ss_eff ** ec, sample_t gain);
340 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
341 void ss_eff_off(struct ss_eff ** ec);
343 /* in song.c */
345 void song_clear(void);
346 struct song_ev * add_event(struct song_ev **song, int *count);
347 struct song_ev * copy_event(struct song_ev **song, int *count, struct song_ev *e);
348 void mute_tracks(int trk_id);
349 void song_sort(void);
350 int song_test_measure_boundary(double ev_time, int num, int den, int line);
352 /* in ss_song.c */
354 int ss_song_render(int skip_secs, char * driver, char * devfile);
356 /* in midi_song.c */
358 int midi_song_play(int skip_secs);
359 int midi_device_open(char * devfile);
360 void midi_device_close(void);
362 /* in compiler.y */
364 int compile_ahs_string(char * code);
365 int compile_ahs(char * file);
367 /* in support.c */
369 void libpath_add(char * path, int strip);
370 FILE * libpath_fopen(char * filename, char * mode);
371 char * libpath_locate(char * filename);
372 void transconv_add(char * from, char * to, char * convcmd);
373 char * transconv_pipe(char * cmd, char * ext, char * dir);
374 char * transconv(char * file, char * ext, char * dir);