3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 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
,
172 struct song_ev_generic
174 song_ev_type type
; /* event type */
175 double time
; /* event time (1: whole note) */
176 int trk_id
; /* track id */
177 int event_id
; /* event id */
182 song_ev_type type
; /* SONG_EV_NOTE */
186 int note
; /* MIDI-like note */
187 double len
; /* note length (1: whole note) */
188 sample_t vol
; /* note volume (1: full volume) */
193 song_ev_type type
; /* SONG_EV_BACK */
197 double len
; /* note length (1: whole note) */
202 song_ev_type type
; /* SONG_EV_TEMPO */
204 int trk_id
; /* always < 0 */
206 double tempo
; /* tempo in bpm */
211 song_ev_type type
; /* SONG_EV_METER */
213 int trk_id
; /* always < 0 */
215 int num
; /* meter numerator */
216 int den
; /* meter denominator */
219 struct song_ev_measure
221 song_ev_type type
; /* SONG_EV_MEASURE */
225 int line
; /* line number */
228 struct song_ev_ss_pitch_stretch
230 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
234 int note
; /* MIDI-like note (to find the wave) */
235 double len
; /* note length (1: whole note) */
236 sample_t vol
; /* note volume (1: full volume) */
239 struct song_ev_ss_print_wave_tempo
241 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
245 int note
; /* MIDI-like note (to find the wave) */
246 double len
; /* note length (1: whole note) */
249 struct song_ev_ss_sustain
251 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
255 double sustain
; /* sustain time (in msecs) */
258 struct song_ev_ss_vibrato
260 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
264 double vib_depth
; /* vibrato depth (in msecs) */
265 double vib_freq
; /* vibrato frequency (in Hzs) */
268 struct song_ev_ss_channel
270 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
274 int channel
; /* channel */
275 sample_t vol
; /* volume */
278 struct song_ev_ss_wav
280 song_ev_type type
; /* SONG_EV_SS_WAV */
284 char * file
; /* path to .wav file */
285 int base
; /* MIDI-like base note */
286 int min
; /* MIDI-like minimum note */
287 int max
; /* MIDI-like maximum note */
288 double loop_start
; /* start of loop */
289 double loop_end
; /* end of loop */
292 struct song_ev_ss_pat
294 song_ev_type type
; /* SONG_EV_SS_PAT */
298 char * file
; /* path to .pat file */
301 struct song_ev_ss_eff
303 song_ev_type type
; /* effect type */
307 int channel
; /* channel */
308 double size
; /* size of effect */
309 sample_t gain
; /* gain */
310 double depth
; /* depth */
311 double freq
; /* freq */
312 double phase
; /* phase */
313 sample_t initial
; /* initial vol */
314 sample_t final
; /* final vol */
317 struct song_ev_midi_channel
319 song_ev_type type
; /* SONG_EV_MIDI_CHANNEL */
323 int channel
; /* midi channel (1-16) */
326 struct song_ev_midi_program
328 song_ev_type type
; /* SONG_EV_MIDI_PROGRAM */
332 int program
; /* midi program (0-127) */
335 struct song_ev_song_info
337 song_ev_type type
; /* SONG_EV_SONG_INFO */
341 char * author
; /* track author */
342 char * name
; /* track name */
347 struct song_ev_generic generic
;
349 struct song_ev_tempo tempo
;
350 struct song_ev_meter meter
;
351 struct song_ev_measure measure
;
353 struct song_ev_note note
;
354 struct song_ev_back back
;
356 struct song_ev_ss_pitch_stretch ss_pitch_stretch
;
357 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo
;
359 struct song_ev_ss_sustain ss_sustain
;
360 struct song_ev_ss_vibrato ss_vibrato
;
361 struct song_ev_ss_channel ss_channel
;
363 struct song_ev_ss_wav ss_wav
;
364 struct song_ev_ss_pat ss_pat
;
366 struct song_ev_ss_eff ss_eff
;
368 struct song_ev_midi_channel midi_channel
;
369 struct song_ev_midi_program midi_program
;
371 struct song_ev_song_info song_info
;
379 extern int ss_frequency
;
380 extern int ss_interpolation
;
381 extern int ss_nchannels
;
385 extern int ss_page_size
;
389 extern sample_t ss_master_volume
;
390 extern int ss_output_clipped
;
391 extern sample_t ss_optimal_volume
;
392 extern char * ss_cue_file_name
;
396 extern union song_ev
* song
;
397 extern int n_song_ev
;
398 extern int solo_track
;
407 /* milliseconds to frames conversion */
408 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
410 /* grows a dynamic array */
411 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
417 double ss_note_frequency(int note
);
418 struct ss_wave
* ss_alloc_wave(int size
, int n_channels
, int s_rate
, int p_size
);
419 void ss_free_wave(struct ss_wave
* w
);
420 void ss_prepare_wave(struct ss_wave
* w
);
421 sample_t
ss_get_sample(struct ss_wave
* w
, int channel
, double offset
);
422 double ss_tempo_from_wave(struct ss_wave
* w
, int note
, double len
);
423 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
427 void ss_gen_init(void);
428 struct ss_gen
* ss_gen_alloc(struct ss_gen
** q
);
429 void ss_gen_free(struct ss_gen
** q
, struct ss_gen
* g
);
430 void ss_gen_sustain(struct ss_gen
* g
, double sustain
);
431 void ss_gen_vibrato(struct ss_gen
* g
, double depth
, double freq
);
432 void ss_gen_play(struct ss_gen
* g
, double freq
, sample_t vol
, int note_id
,
434 void ss_gen_release(struct ss_gen
* g
);
435 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
439 void ss_ins_init(struct ss_ins
* i
);
440 void ss_ins_add_layer(struct ss_ins
* i
, struct ss_wave
* w
);
441 void ss_ins_copy_layers(struct ss_ins
* i
, struct ss_ins
* o
);
442 struct ss_wave
* ss_ins_find_layer(struct ss_ins
* i
, double freq
, int * off
);
443 void ss_ins_set_channel(struct ss_ins
* i
, int channel
, sample_t vol
);
444 void ss_ins_set_sustain(struct ss_ins
* i
, double sustain
);
445 void ss_ins_set_vibrato(struct ss_ins
* i
, double depth
, double freq
);
446 int ss_ins_play(struct ss_ins
* i
, double freq
, sample_t vol
, int note_id
,
448 int ss_ins_note_on(struct ss_ins
* i
, int note
, sample_t vol
, int note_id
);
449 void ss_ins_note_off(struct ss_ins
* i
, int note_id
);
450 void ss_ins_frame(struct ss_ins
* i
, sample_t frame
[]);
454 int ss_output_open(char * drvname
, char * filename
);
455 void ss_output_init_frame(sample_t frame
[]);
456 int ss_output_write(sample_t frame
[]);
457 void ss_output_close(void);
458 int cue_file_song_info(int frame
, char * author
, char * name
);
462 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
463 struct ss_wave
* ss_load_wav_file(char * file
,
464 double base_freq
, double min_freq
, double max_freq
,
465 double loop_start
, double loop_end
);
466 int ss_load_pat_file(struct ss_ins
* i
, char * file
);
470 void ss_eff_delay(struct ss_eff
** ec
, double size
);
471 void ss_eff_echo(struct ss_eff
** ec
, double size
, sample_t gain
);
472 void ss_eff_comb(struct ss_eff
** ec
, double size
, sample_t gain
);
473 void ss_eff_allpass(struct ss_eff
** ec
, double size
, sample_t gain
);
474 void ss_eff_flanger(struct ss_eff
** ec
, double size
, sample_t gain
,
475 double depth
, double freq
, double phase
);
476 void ss_eff_wobble(struct ss_eff
** ec
, double freq
, double phase
);
477 void ss_eff_square_wobble(struct ss_eff
** ec
, double freq
, double phase
);
478 void ss_eff_fader(struct ss_eff
** ec
, double size
, sample_t initial
, sample_t final
);
479 void ss_eff_reverb(struct ss_eff
** ec
);
481 sample_t
ss_eff_process(struct ss_eff
* e
, sample_t s
);
482 void ss_eff_off(struct ss_eff
** ec
);
486 void song_clear(void);
487 void add_song_ev(union song_ev
* ev
);
488 void song_sort(void);
489 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
493 int ss_song_render(int skip_secs
);
497 int midi_song_play(int skip_secs
);
498 int midi_device_open(char * devfile
);
499 void midi_device_close(void);
503 int compile_ahs_string(char * code
);
504 int compile_ahs(char * file
);
508 void libpath_add(char * path
, int strip
);
509 FILE * libpath_fopen(char * filename
, char * mode
);
510 char * libpath_locate(char * filename
);
511 void transconv_add(char * from
, char * to
, char * convcmd
);
512 char * transconv(char * file
, char * ext
, char * dir
);