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
26 #ifndef SS_MAX_CHANNELS
27 #define SS_MAX_CHANNELS 16
30 #ifndef SS_MAX_GENERATORS
31 #define SS_MAX_GENERATORS 256
34 #ifndef SS_MAX_INSTRUMENTS
35 #define SS_MAX_INSTRUMENTS 256
38 /* STRUCTURES AND TYPES */
42 typedef double sample_t
;
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 */
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 */
98 /* software syntesizer instruments */
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 */
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 */
148 SONG_EV_SS_PORTAMENTO
,
155 SONG_EV_SS_EFF_DELAY
,
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
,
168 SONG_EV_SS_EFF_DISTORT
,
169 SONG_EV_SS_EFF_OVERDRIVE
,
171 SONG_EV_MIDI_CHANNEL
,
172 SONG_EV_MIDI_PROGRAM
,
176 SONG_EV_SS_PITCH_STRETCH
,
177 SONG_EV_SS_PRINT_WAVE_TEMPO
,
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 */
222 extern int ss_frequency
;
223 extern int ss_interpolation
;
224 extern int ss_nchannels
;
228 extern int ss_page_size
;
232 extern sample_t ss_master_volume
;
233 extern int ss_output_clipped
;
234 extern sample_t ss_optimal_volume
;
235 extern char * ss_cue_file_name
;
239 extern struct song_ev
* song
;
240 extern int n_song_ev
;
244 extern int solo_track
;
245 extern int n_song_tracks
;
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))
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(struct ss_wave
* w
, int note
, double len
);
270 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
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
,
283 void ss_gen_release(struct ss_gen
* g
);
284 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
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(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
,
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
[]);
305 int ss_output_open(char * drvname
, 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
, char * author
, char * name
);
313 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
314 struct ss_wave
* ss_load_wav_file(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
, char * file
);
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
);
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
, struct song_ev
*e
);
346 void song_sort(void);
347 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
351 int ss_song_render(int skip_secs
, char * driver
, char * devfile
);
355 int midi_song_play(int skip_secs
);
356 int midi_device_open(char * devfile
);
357 void midi_device_close(void);
361 int compile_ahs_string(char * code
);
362 int compile_ahs(char * file
);
366 void libpath_add(char * path
, int strip
);
367 FILE * libpath_fopen(char * filename
, char * mode
);
368 char * libpath_locate(char * filename
);
369 void transconv_add(char * from
, char * to
, char * convcmd
);
370 char * transconv_pipe(char * cmd
, char * ext
, char * dir
);
371 char * transconv(char * file
, char * ext
, char * dir
);