3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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
;
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 char * filename
; /* filename (for paged files) */
62 long f_pos
; /* file position where the PCM files */
63 int p_offset
; /* offset in frames of the page */
64 int bits
; /* bits of the PCM wave (8, 16) */
65 int sign
; /* sign of the PCM wave (1, -1) */
72 int note_id
; /* note ID */
73 sample_t vol
; /* volume */
74 struct ss_wave
* w
; /* the wave data */
76 double cursor
; /* offset to next sample */
77 double inc
; /* increment (frequency) */
79 int sustain
; /* number of frames to play after release */
80 sample_t dvol
; /* volume decrement in sustain */
82 double vibrato
; /* vibrato oscillator */
83 double vib_depth
; /* vibrato depth */
84 double vib_inc
; /* increment for vibrato oscillator */
86 double portamento
; /* portamento sum to inc */
92 /* software syntesizer instruments */
96 int n_layers
; /* # of layers */
97 struct ss_wave
** layers
; /* layers */
99 struct ss_gen
* gens
; /* generator queue */
101 int n_channels
; /* number of channels */
102 sample_t
* vols
; /* volumes (1 per channel) */
103 struct ss_eff
** effs
; /* effect chains (1 per channel) */
105 double sustain
; /* sustain in msecs */
106 double vib_depth
; /* vibrato depth */
107 double vib_freq
; /* vibrato frequency */
110 /* digital effects */
114 struct ss_wave
* wave
; /* wave buffer */
115 sample_t gain
; /* effect gain */
116 sample_t igain
; /* gain increment */
118 double lfo
; /* lfo value */
119 double lfo_depth
; /* lfo depth */
120 double lfo_inc
; /* lfo increment */
122 double cursor
; /* current buffer position */
124 sample_t (* func
)(struct ss_eff
*, sample_t
); /* processing function */
126 struct ss_eff
* next
; /* next in chain */
144 SONG_EV_SS_EFF_DELAY
,
147 SONG_EV_SS_EFF_ALLPASS
,
148 SONG_EV_SS_EFF_FLANGER
,
149 SONG_EV_SS_EFF_WOBBLE
,
150 SONG_EV_SS_EFF_SQWOBBLE
,
151 SONG_EV_SS_EFF_FADER
,
152 SONG_EV_SS_EFF_REVERB
,
155 SONG_EV_MIDI_CHANNEL
,
156 SONG_EV_MIDI_PROGRAM
,
160 SONG_EV_SS_PITCH_STRETCH
,
161 SONG_EV_SS_PRINT_WAVE_TEMPO
,
170 struct song_ev_generic
172 song_ev_type type
; /* event type */
173 double time
; /* event time (1: whole note) */
174 int trk_id
; /* track id */
175 int event_id
; /* event id */
180 song_ev_type type
; /* SONG_EV_NOTE */
184 int note
; /* MIDI-like note */
185 double len
; /* note length (1: whole note) */
186 sample_t vol
; /* note volume (1: full volume) */
191 song_ev_type type
; /* SONG_EV_BACK */
195 double len
; /* note length (1: whole note) */
200 song_ev_type type
; /* SONG_EV_TEMPO */
202 int trk_id
; /* always < 0 */
204 double tempo
; /* tempo in bpm */
209 song_ev_type type
; /* SONG_EV_METER */
211 int trk_id
; /* always < 0 */
213 int num
; /* meter numerator */
214 int den
; /* meter denominator */
217 struct song_ev_measure
219 song_ev_type type
; /* SONG_EV_MEASURE */
223 int line
; /* line number */
226 struct song_ev_ss_pitch_stretch
228 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
232 int note
; /* MIDI-like note (to find the wave) */
233 double len
; /* note length (1: whole note) */
234 sample_t vol
; /* note volume (1: full volume) */
237 struct song_ev_ss_print_wave_tempo
239 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
243 int note
; /* MIDI-like note (to find the wave) */
244 double len
; /* note length (1: whole note) */
247 struct song_ev_ss_sustain
249 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
253 double sustain
; /* sustain time (in msecs) */
256 struct song_ev_ss_vibrato
258 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
262 double vib_depth
; /* vibrato depth (in msecs) */
263 double vib_freq
; /* vibrato frequency (in Hzs) */
266 struct song_ev_ss_channel
268 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
272 int channel
; /* channel */
273 sample_t vol
; /* volume */
276 struct song_ev_ss_wav
278 song_ev_type type
; /* SONG_EV_SS_WAV */
282 char * file
; /* path to .wav file */
283 int base
; /* MIDI-like base note */
284 int min
; /* MIDI-like minimum note */
285 int max
; /* MIDI-like maximum note */
286 double loop_start
; /* start of loop */
287 double loop_end
; /* end of loop */
290 struct song_ev_ss_pat
292 song_ev_type type
; /* SONG_EV_SS_PAT */
296 char * file
; /* path to .pat file */
299 struct song_ev_ss_eff
301 song_ev_type type
; /* effect type */
305 int channel
; /* channel */
306 double size
; /* size of effect */
307 sample_t gain
; /* gain */
308 double depth
; /* depth */
309 double freq
; /* freq */
310 double phase
; /* phase */
311 sample_t initial
; /* initial vol */
312 sample_t final
; /* final vol */
315 struct song_ev_midi_channel
317 song_ev_type type
; /* SONG_EV_MIDI_CHANNEL */
321 int channel
; /* midi channel (1-16) */
324 struct song_ev_midi_program
326 song_ev_type type
; /* SONG_EV_MIDI_PROGRAM */
330 int program
; /* midi program (0-127) */
335 struct song_ev_generic generic
;
337 struct song_ev_tempo tempo
;
338 struct song_ev_meter meter
;
339 struct song_ev_measure measure
;
341 struct song_ev_note note
;
342 struct song_ev_back back
;
344 struct song_ev_ss_pitch_stretch ss_pitch_stretch
;
345 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo
;
347 struct song_ev_ss_sustain ss_sustain
;
348 struct song_ev_ss_vibrato ss_vibrato
;
349 struct song_ev_ss_channel ss_channel
;
351 struct song_ev_ss_wav ss_wav
;
352 struct song_ev_ss_pat ss_pat
;
354 struct song_ev_ss_eff ss_eff
;
356 struct song_ev_midi_channel midi_channel
;
357 struct song_ev_midi_program midi_program
;
365 extern int ss_frequency
;
366 extern int ss_interpolation
;
367 extern int ss_nchannels
;
371 extern int ss_page_size
;
375 extern sample_t ss_master_volume
;
376 extern int ss_output_clipped
;
377 extern sample_t ss_optimal_volume
;
381 extern union song_ev
* song
;
382 extern int n_song_ev
;
383 extern int solo_track
;
389 extern int show_progress
;
393 /* milliseconds to frames conversion */
394 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
401 double ss_note_frequency(int note
);
402 struct ss_wave
* ss_alloc_wave(int size
, int n_channels
, int s_rate
, int p_size
);
403 void ss_free_wave(struct ss_wave
* w
);
404 void ss_prepare_wave(struct ss_wave
* w
);
405 sample_t
ss_get_sample(struct ss_wave
* w
, int channel
, double offset
);
406 double ss_tempo_from_wave(struct ss_wave
* w
, int note
, double len
);
407 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
411 void ss_gen_init(void);
412 struct ss_gen
* ss_gen_alloc(struct ss_gen
** q
);
413 void ss_gen_free(struct ss_gen
** q
, struct ss_gen
* g
);
414 void ss_gen_sustain(struct ss_gen
* g
, double sustain
);
415 void ss_gen_vibrato(struct ss_gen
* g
, double depth
, double freq
);
416 void ss_gen_play(struct ss_gen
* g
, double freq
, sample_t vol
, int note_id
,
418 void ss_gen_release(struct ss_gen
* g
);
419 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
423 void ss_ins_init(struct ss_ins
* i
);
424 void ss_ins_add_layer(struct ss_ins
* i
, struct ss_wave
* w
);
425 void ss_ins_copy_layers(struct ss_ins
* i
, struct ss_ins
* o
);
426 struct ss_wave
* ss_ins_find_layer(struct ss_ins
* i
, double freq
, int * off
);
427 void ss_ins_set_channel(struct ss_ins
* i
, int channel
, sample_t vol
);
428 void ss_ins_set_sustain(struct ss_ins
* i
, double sustain
);
429 void ss_ins_set_vibrato(struct ss_ins
* i
, double depth
, double freq
);
430 int ss_ins_play(struct ss_ins
* i
, double freq
, sample_t vol
, int note_id
,
432 int ss_ins_note_on(struct ss_ins
* i
, int note
, sample_t vol
, int note_id
);
433 void ss_ins_note_off(struct ss_ins
* i
, int note_id
);
434 void ss_ins_frame(struct ss_ins
* i
, sample_t frame
[]);
438 int ss_output_open(char * drvname
, char * filename
);
439 void ss_output_init_frame(sample_t frame
[]);
440 int ss_output_write(sample_t frame
[]);
441 void ss_output_close(void);
445 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
446 struct ss_wave
* ss_load_wave_file(char * file
,
447 double base_freq
, double min_freq
, double max_freq
,
448 double loop_start
, double loop_end
);
449 int ss_load_pat_file(struct ss_ins
* i
, char * file
);
453 void ss_eff_delay(struct ss_eff
** ec
, double size
);
454 void ss_eff_echo(struct ss_eff
** ec
, double size
, sample_t gain
);
455 void ss_eff_comb(struct ss_eff
** ec
, double size
, sample_t gain
);
456 void ss_eff_allpass(struct ss_eff
** ec
, double size
, sample_t gain
);
457 void ss_eff_flanger(struct ss_eff
** ec
, double size
, sample_t gain
,
458 double depth
, double freq
, double phase
);
459 void ss_eff_wobble(struct ss_eff
** ec
, double freq
, double phase
);
460 void ss_eff_square_wobble(struct ss_eff
** ec
, double freq
, double phase
);
461 void ss_eff_fader(struct ss_eff
** ec
, double size
, sample_t initial
, sample_t final
);
462 void ss_eff_reverb(struct ss_eff
** ec
);
464 sample_t
ss_eff_process(struct ss_eff
* e
, sample_t s
);
465 void ss_eff_off(struct ss_eff
** ec
);
469 void song_clear(void);
470 void add_song_ev(union song_ev
* ev
);
471 void song_sort(void);
472 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
476 int ss_song_render(int skip_secs
);
480 int midi_song_play(int skip_secs
);
481 int midi_device_open(char * devfile
);
482 void midi_device_close(void);
486 int compile_ahs_string(char * code
);
487 int compile_ahs(char * file
);
491 void add_to_library_path(char * path
, int strip
);
492 FILE * path_fopen(char * filename
, char * mode
);
493 char * locate_file(char * filename
);