3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2008 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 const 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
,
156 SONG_EV_SS_EFF_DELAY
,
159 SONG_EV_SS_EFF_ALLPASS
,
160 SONG_EV_SS_EFF_FLANGER
,
161 SONG_EV_SS_EFF_WOBBLE
,
162 SONG_EV_SS_EFF_SQWOBBLE
,
163 SONG_EV_SS_EFF_HFWOBBLE
,
164 SONG_EV_SS_EFF_FADER
,
165 SONG_EV_SS_EFF_REVERB
,
167 SONG_EV_SS_EFF_FOLDBACK
,
169 SONG_EV_SS_EFF_DISTORT
,
170 SONG_EV_SS_EFF_OVERDRIVE
,
172 SONG_EV_MIDI_CHANNEL
,
173 SONG_EV_MIDI_PROGRAM
,
178 SONG_EV_SS_PITCH_STRETCH
,
179 SONG_EV_SS_PRINT_WAVE_TEMPO
,
180 SONG_EV_SS_MASTER_VOLUME
,
192 song_ev_type type
; /* event type */
193 double time
; /* event time (1: whole note) */
194 int frame
; /* frame number (ss) */
195 int msecs
; /* milliseconds (MIDI) */
196 int trk_id
; /* track id */
197 int event_id
; /* event id */
198 int note_id
; /* note id */
199 int value
; /* MIDI-like note (or base) */
200 int min
; /* MIDI-like minimum note */
201 int max
; /* MIDI-like maximum note */
202 int channel
; /* channel (or first channel) */
203 int skip_channels
; /* channels to skip when spreading */
204 int vel
; /* MIDI velocity */
205 sample_t vol
; /* volume or gain */
206 sample_t initial
; /* initial vol */
207 sample_t final
; /* final vol */
208 double amount
; /* sust, attck or portmnt (frames), tempo in bpm */
209 double len
; /* note length (1: whole note) or effect size */
210 double depth
; /* depth */
211 double freq
; /* freq */
212 double start
; /* loop start */
213 double end
; /* loop end */
214 double phase
; /* phase */
215 const char *name
; /* file name, or track name */
216 const char *str2
; /* track author, or instrument in sf2 */
223 extern int ss_frequency
;
224 extern int ss_interpolation
;
225 extern int ss_nchannels
;
229 extern int ss_page_size
;
233 extern sample_t ss_master_volume
;
234 extern int ss_output_clipped
;
235 extern sample_t ss_optimal_volume
;
236 extern const char *ss_cue_file_name
;
240 extern struct song_ev
*song
;
241 extern int n_song_ev
;
242 extern int n_song_tracks
;
246 extern int solo_track
;
255 /* milliseconds to frames conversion */
256 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
258 /* grows a dynamic array */
259 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
265 double ss_note_frequency(int note
);
266 struct ss_wave
*ss_alloc_wave(int size
, int n_channels
, int s_rate
,
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(const struct ss_wave
*w
, int note
, double len
);
272 double ss_pitch_from_tempo(const struct ss_wave
*w
, double tempo
,
277 void ss_gen_init(void);
278 struct ss_gen
*ss_gen_alloc(struct ss_gen
**q
);
279 void ss_gen_free(struct ss_gen
**q
, struct ss_gen
*g
);
280 void ss_gen_sustain(struct ss_gen
*g
, double sustain
);
281 void ss_gen_attack(struct ss_gen
*g
, double attack
);
282 void ss_gen_vibrato(struct ss_gen
*g
, double depth
, double freq
);
283 void ss_gen_portamento(struct ss_gen
*g
, double portamento
);
284 void ss_gen_play(struct ss_gen
*g
, double freq
, sample_t vol
, int note_id
,
286 void ss_gen_release(struct ss_gen
*g
);
287 int ss_gen_frame(struct ss_gen
*g
, int n_channels
, sample_t frame
[]);
291 void ss_ins_init(struct ss_ins
*i
);
292 void ss_ins_disable(struct ss_ins
*i
);
293 void ss_ins_add_layer(struct ss_ins
*i
, struct ss_wave
*w
);
294 struct ss_wave
*ss_ins_find_layer(const struct ss_ins
*i
, double freq
,
296 void ss_ins_set_channel(struct ss_ins
*i
, int channel
, sample_t vol
);
297 void ss_ins_set_sustain(struct ss_ins
*i
, double sustain
);
298 void ss_ins_set_attack(struct ss_ins
*i
, double attack
);
299 void ss_ins_set_vibrato(struct ss_ins
*i
, double depth
, double freq
);
300 void ss_ins_set_portamento(struct ss_ins
*i
, double portamento
);
301 int ss_ins_play(struct ss_ins
*i
, double freq
, sample_t vol
, int note_id
,
303 int ss_ins_note_on(struct ss_ins
*i
, int note
, sample_t vol
, int note_id
);
304 void ss_ins_note_off(struct ss_ins
*i
, int note_id
);
305 int ss_ins_frame(struct ss_ins
*i
, sample_t frame
[]);
309 int ss_output_open(const char *drvname
, const char *filename
);
310 void ss_output_init_frame(sample_t frame
[]);
311 int ss_output_write(sample_t frame
[]);
312 void ss_output_close(void);
313 int cue_file_song_info(int frame
, const char *author
, const char *name
);
317 void load_pcm_wave(FILE * f
, struct ss_wave
*w
);
318 struct ss_wave
*ss_load_wav_file(const char *file
,
319 double base_freq
, double min_freq
,
320 double max_freq
, double loop_start
,
321 double loop_end
, int first_channel
,
323 int ss_load_pat_file(struct ss_ins
*i
, const char *file
);
324 int ss_load_sf2_file(struct ss_ins
*i
, const char *file
,
329 void ss_eff_delay(struct ss_eff
**ec
, double size
);
330 void ss_eff_echo(struct ss_eff
**ec
, double size
, sample_t gain
);
331 void ss_eff_comb(struct ss_eff
**ec
, double size
, sample_t gain
);
332 void ss_eff_allpass(struct ss_eff
**ec
, double size
, sample_t gain
);
333 void ss_eff_flanger(struct ss_eff
**ec
, double size
, sample_t gain
,
334 double depth
, double freq
, double phase
);
335 void ss_eff_wobble(struct ss_eff
**ec
, double freq
, double phase
,
337 void ss_eff_square_wobble(struct ss_eff
**ec
, double freq
, double phase
);
338 void ss_eff_half_wobble(struct ss_eff
**ec
, double freq
, double phase
);
339 void ss_eff_fader(struct ss_eff
**ec
, double size
, sample_t initial
,
341 void ss_eff_reverb(struct ss_eff
**ec
);
342 void ss_eff_foldback(struct ss_eff
**ec
, sample_t threshold
);
343 void ss_eff_atan(struct ss_eff
**ec
, sample_t gain
);
344 void ss_eff_distort(struct ss_eff
**ec
, sample_t gain
);
345 void ss_eff_overdrive(struct ss_eff
**ec
, sample_t gain
);
347 sample_t
ss_eff_process(struct ss_eff
*e
, sample_t s
);
348 void ss_eff_off(struct ss_eff
**ec
);
352 void song_clear(void);
353 struct song_ev
*add_event(struct song_ev
**song
, int *count
);
354 struct song_ev
*copy_event(struct song_ev
**song
, int *count
,
355 const struct song_ev
*e
);
356 void dump_song_event(const struct song_ev
*e
);
357 void dump_song_events(const struct song_ev
*song
, int n_song_ev
);
358 void mute_tracks(int trk_id
);
359 void song_sort(void);
360 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
364 int ss_song_render(int skip_secs
, const char *driver
, const char *devfile
);
368 int midi_song_play(int skip_secs
);
369 int midi_device_open(char *devfile
);
370 void midi_device_close(void);
374 int compile_ahs_string(const char *code
);
375 int compile_ahs(const char *file
);
379 void libpath_add(const char *path
, int strip
);
380 FILE *libpath_fopen(const char *filename
, const char *mode
);
381 char *libpath_locate(const char *filename
);
382 void libpath_print(void);
383 void transconv_add(const char *from
, const char *to
, const char *convcmd
);
384 char *transconv_pipe(const char *cmd
, const char *ext
, const char *dir
);
385 char *transconv(const char *file
, const char *ext
, const char *dir
);