Use const in ss_output.c where possible.
[ahxm.git] / ahxm.h
blobd4751eaa6fb197f665a4f2e8b32abc1fe10bd56b
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_OFF,
176 SONG_EV_NOTE,
177 SONG_EV_SS_PITCH_STRETCH,
178 SONG_EV_SS_PRINT_WAVE_TEMPO,
180 SONG_EV_SONG_INFO,
182 SONG_EV_EOT,
183 SONG_EV_END,
185 SONG_EV_NOP
187 } song_ev_type;
190 struct song_ev {
191 song_ev_type type; /* event type */
192 double time; /* event time (1: whole note) */
193 int frame; /* frame number (ss) */
194 int msecs; /* milliseconds (MIDI) */
195 int trk_id; /* track id */
196 int event_id; /* event id */
197 int note_id; /* note id */
198 int value; /* MIDI-like note (or base) */
199 int min; /* MIDI-like minimum note */
200 int max; /* MIDI-like maximum note */
201 int channel; /* channel (or first channel) */
202 int skip_channels; /* channels to skip when spreading */
203 int vel; /* MIDI velocity */
204 sample_t vol; /* volume or gain */
205 sample_t initial; /* initial vol */
206 sample_t final; /* final vol */
207 double amount; /* sust, attck or portmnt (frames), tempo in bpm */
208 double len; /* note length (1: whole note) or effect size */
209 double depth; /* depth */
210 double freq; /* freq */
211 double start; /* loop start */
212 double end; /* loop end */
213 double phase; /* phase */
214 char *name; /* file name, or track name */
215 char *author; /* track author */
218 /* GLOBALS */
220 /* in ss_core.c */
222 extern int ss_frequency;
223 extern int ss_interpolation;
224 extern int ss_nchannels;
226 /* in ss_input.c */
228 extern int ss_page_size;
230 /* in ss_output.c */
232 extern sample_t ss_master_volume;
233 extern int ss_output_clipped;
234 extern sample_t ss_optimal_volume;
235 extern const char * ss_cue_file_name;
237 /* in song.c */
239 extern struct song_ev * song;
240 extern int n_song_ev;
241 extern int n_song_tracks;
243 /* in compiler.y */
245 extern int solo_track;
247 /* in support.c */
249 extern int verbose;
250 extern int trace;
252 /* MACROS */
254 /* milliseconds to frames conversion */
255 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
257 /* grows a dynamic array */
258 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
260 /* PROTOTYPES */
262 /* in ss_core.c */
264 double ss_note_frequency(int note);
265 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
266 void ss_free_wave(struct ss_wave * w);
267 void ss_prepare_wave(struct ss_wave * w);
268 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
269 double ss_tempo_from_wave(const struct ss_wave * w, int note, double len);
270 double ss_pitch_from_tempo(const struct ss_wave * w, double tempo, double len);
272 /* in ss_gen.c */
274 void ss_gen_init(void);
275 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
276 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
277 void ss_gen_sustain(struct ss_gen * g, double sustain);
278 void ss_gen_attack(struct ss_gen * g, double attack);
279 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
280 void ss_gen_portamento(struct ss_gen * g, double portamento);
281 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
282 struct ss_wave * w);
283 void ss_gen_release(struct ss_gen * g);
284 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
286 /* in ss_ins.c */
288 void ss_ins_init(struct ss_ins * i);
289 void ss_ins_disable(struct ss_ins * i);
290 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
291 struct ss_wave * ss_ins_find_layer(const struct ss_ins * i, double freq, int * off);
292 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
293 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
294 void ss_ins_set_attack(struct ss_ins * i, double attack);
295 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
296 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
297 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
298 struct ss_wave * w);
299 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
300 void ss_ins_note_off(struct ss_ins * i, int note_id);
301 int ss_ins_frame(struct ss_ins * i, sample_t frame[]);
303 /* in ss_output.c */
305 int ss_output_open(const char * drvname, const char * filename);
306 void ss_output_init_frame(sample_t frame[]);
307 int ss_output_write(sample_t frame[]);
308 void ss_output_close(void);
309 int cue_file_song_info(int frame, const char * author, const char * name);
311 /* in ss_input.c */
313 void load_pcm_wave(FILE * f, struct ss_wave * w);
314 struct ss_wave * ss_load_wav_file(const char * file,
315 double base_freq, double min_freq, double max_freq,
316 double loop_start, double loop_end,
317 int first_channel, int skip_channels);
318 int ss_load_pat_file(struct ss_ins * i, const char * file);
320 /* in ss_eff.c */
322 void ss_eff_delay(struct ss_eff ** ec, double size);
323 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
324 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
325 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
326 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
327 double depth, double freq, double phase);
328 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase, sample_t gain);
329 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
330 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
331 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
332 void ss_eff_reverb(struct ss_eff ** ec);
333 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
334 void ss_eff_atan(struct ss_eff ** ec, sample_t gain);
335 void ss_eff_distort(struct ss_eff ** ec, sample_t gain);
336 void ss_eff_overdrive(struct ss_eff ** ec, sample_t gain);
338 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
339 void ss_eff_off(struct ss_eff ** ec);
341 /* in song.c */
343 void song_clear(void);
344 struct song_ev * add_event(struct song_ev **song, int *count);
345 struct song_ev * copy_event(struct song_ev **song, int *count, const struct song_ev *e);
346 void dump_song_event(const struct song_ev *e);
347 void dump_song_events(const struct song_ev *song, int n_song_ev);
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, const char * driver, const 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(const char * path, int strip);
370 FILE * libpath_fopen(const char * filename, const char * mode);
371 char * libpath_locate(const char * filename);
372 void transconv_add(const char * from, const char * to, const char * convcmd);
373 char * transconv_pipe(const char * cmd, const char * ext, const char * dir);
374 char * transconv(const char * file, const char * ext, const char * dir);