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 int first_channel
; /* first channel to spread into */
62 int skip_channels
; /* channels to skip when spreading */
64 char * filename
; /* filename (for paged files) */
65 long f_pos
; /* file position where the PCM files */
66 int p_offset
; /* offset in frames of the page */
67 int bits
; /* bits of the PCM wave (8, 16) */
68 int sign
; /* sign of the PCM wave (1, -1) */
70 int page_faults
; /* number of times ss_load_page() was called */
77 int note_id
; /* note ID */
78 sample_t vol
; /* volume */
79 struct ss_wave
* w
; /* the wave data */
81 double cursor
; /* offset to next sample */
82 double inc
; /* increment (frequency) */
84 int sustain
; /* number of frames to play after release */
85 sample_t dvol
; /* volume decrement in sustain */
87 double vibrato
; /* vibrato oscillator */
88 double vib_depth
; /* vibrato depth */
89 double vib_inc
; /* increment for vibrato oscillator */
91 double portamento
; /* portamento sum to inc */
97 /* 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 vib_depth
; /* vibrato depth */
112 double vib_freq
; /* vibrato frequency */
114 int disabled
; /* if set, no processing is done */
116 double portamento
; /* portamento */
119 /* 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
,
165 SONG_EV_SS_EFF_FOLDBACK
,
167 SONG_EV_MIDI_CHANNEL
,
168 SONG_EV_MIDI_PROGRAM
,
172 SONG_EV_SS_PITCH_STRETCH
,
173 SONG_EV_SS_PRINT_WAVE_TEMPO
,
185 struct song_ev_generic
187 song_ev_type type
; /* event type */
188 double time
; /* event time (1: whole note) */
189 int trk_id
; /* track id */
190 int event_id
; /* event id */
195 song_ev_type type
; /* SONG_EV_NOTE */
199 int note
; /* MIDI-like note */
200 double len
; /* note length (1: whole note) */
201 sample_t vol
; /* note volume (1: full volume) */
206 song_ev_type type
; /* SONG_EV_BACK */
210 double len
; /* note length (1: whole note) */
215 song_ev_type type
; /* SONG_EV_TEMPO */
217 int trk_id
; /* always < 0 */
219 double tempo
; /* tempo in bpm */
224 song_ev_type type
; /* SONG_EV_METER */
226 int trk_id
; /* always < 0 */
228 int num
; /* meter numerator */
229 int den
; /* meter denominator */
232 struct song_ev_measure
234 song_ev_type type
; /* SONG_EV_MEASURE */
238 int line
; /* line number */
241 struct song_ev_ss_pitch_stretch
243 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
247 int note
; /* MIDI-like note (to find the wave) */
248 double len
; /* note length (1: whole note) */
249 sample_t vol
; /* note volume (1: full volume) */
252 struct song_ev_ss_print_wave_tempo
254 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
258 int note
; /* MIDI-like note (to find the wave) */
259 double len
; /* note length (1: whole note) */
262 struct song_ev_ss_sustain
264 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
268 double sustain
; /* sustain time (in msecs) */
271 struct song_ev_ss_vibrato
273 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
277 double vib_depth
; /* vibrato depth (in msecs) */
278 double vib_freq
; /* vibrato frequency (in Hzs) */
281 struct song_ev_ss_portamento
283 song_ev_type type
; /* SONG_EV_SS_PORTAMENTO */
287 double portamento
; /* portamento */
290 struct song_ev_ss_channel
292 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
296 int channel
; /* channel */
297 sample_t vol
; /* volume */
300 struct song_ev_ss_wav
302 song_ev_type type
; /* SONG_EV_SS_WAV */
306 char * file
; /* path to .wav file */
307 int base
; /* MIDI-like base note */
308 int min
; /* MIDI-like minimum note */
309 int max
; /* MIDI-like maximum note */
310 double loop_start
; /* start of loop */
311 double loop_end
; /* end of loop */
312 int first_channel
; /* first channel to start spreading */
313 int skip_channels
; /* channels to skip when spreading */
316 struct song_ev_ss_pat
318 song_ev_type type
; /* SONG_EV_SS_PAT */
322 char * file
; /* path to .pat file */
325 struct song_ev_ss_eff
327 song_ev_type type
; /* effect type */
331 int channel
; /* channel */
332 double size
; /* size of effect */
333 sample_t gain
; /* gain */
334 double depth
; /* depth */
335 double freq
; /* freq */
336 double phase
; /* phase */
337 sample_t initial
; /* initial vol */
338 sample_t final
; /* final vol */
341 struct song_ev_midi_channel
343 song_ev_type type
; /* SONG_EV_MIDI_CHANNEL */
347 int channel
; /* midi channel (1-16) */
350 struct song_ev_midi_program
352 song_ev_type type
; /* SONG_EV_MIDI_PROGRAM */
356 int program
; /* midi program (0-127) */
359 struct song_ev_song_info
361 song_ev_type type
; /* SONG_EV_SONG_INFO */
365 char * author
; /* track author */
366 char * name
; /* track name */
371 struct song_ev_generic generic
;
373 struct song_ev_tempo tempo
;
374 struct song_ev_meter meter
;
375 struct song_ev_measure measure
;
377 struct song_ev_note note
;
378 struct song_ev_back back
;
380 struct song_ev_ss_pitch_stretch ss_pitch_stretch
;
381 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo
;
383 struct song_ev_ss_sustain ss_sustain
;
384 struct song_ev_ss_vibrato ss_vibrato
;
385 struct song_ev_ss_portamento ss_portamento
;
386 struct song_ev_ss_channel ss_channel
;
388 struct song_ev_ss_wav ss_wav
;
389 struct song_ev_ss_pat ss_pat
;
391 struct song_ev_ss_eff ss_eff
;
393 struct song_ev_midi_channel midi_channel
;
394 struct song_ev_midi_program midi_program
;
396 struct song_ev_song_info song_info
;
404 extern int ss_frequency
;
405 extern int ss_interpolation
;
406 extern int ss_nchannels
;
410 extern int ss_page_size
;
414 extern sample_t ss_master_volume
;
415 extern int ss_output_clipped
;
416 extern sample_t ss_optimal_volume
;
417 extern char * ss_cue_file_name
;
421 extern union song_ev
* song
;
422 extern int n_song_ev
;
423 extern int solo_track
;
424 extern int n_song_tracks
;
433 /* milliseconds to frames conversion */
434 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
436 /* grows a dynamic array */
437 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
443 double ss_note_frequency(int note
);
444 struct ss_wave
* ss_alloc_wave(int size
, int n_channels
, int s_rate
, int p_size
);
445 void ss_free_wave(struct ss_wave
* w
);
446 void ss_prepare_wave(struct ss_wave
* w
);
447 sample_t
ss_get_sample(struct ss_wave
* w
, int channel
, double offset
);
448 double ss_tempo_from_wave(struct ss_wave
* w
, int note
, double len
);
449 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
453 void ss_gen_init(void);
454 struct ss_gen
* ss_gen_alloc(struct ss_gen
** q
);
455 void ss_gen_free(struct ss_gen
** q
, struct ss_gen
* g
);
456 void ss_gen_sustain(struct ss_gen
* g
, double sustain
);
457 void ss_gen_vibrato(struct ss_gen
* g
, double depth
, double freq
);
458 void ss_gen_portamento(struct ss_gen
* g
, double portamento
);
459 void ss_gen_play(struct ss_gen
* g
, double freq
, sample_t vol
, int note_id
,
461 void ss_gen_release(struct ss_gen
* g
);
462 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
466 void ss_ins_init(struct ss_ins
* i
);
467 void ss_ins_disable(struct ss_ins
* i
);
468 void ss_ins_add_layer(struct ss_ins
* i
, struct ss_wave
* w
);
469 struct ss_wave
* ss_ins_find_layer(struct ss_ins
* i
, double freq
, int * off
);
470 void ss_ins_set_channel(struct ss_ins
* i
, int channel
, sample_t vol
);
471 void ss_ins_set_sustain(struct ss_ins
* i
, double sustain
);
472 void ss_ins_set_vibrato(struct ss_ins
* i
, double depth
, double freq
);
473 void ss_ins_set_portamento(struct ss_ins
* i
, double portamento
);
474 int ss_ins_play(struct ss_ins
* i
, double freq
, sample_t vol
, int note_id
,
476 int ss_ins_note_on(struct ss_ins
* i
, int note
, sample_t vol
, int note_id
);
477 void ss_ins_note_off(struct ss_ins
* i
, int note_id
);
478 void ss_ins_frame(struct ss_ins
* i
, sample_t frame
[]);
482 int ss_output_open(char * drvname
, char * filename
);
483 void ss_output_init_frame(sample_t frame
[]);
484 int ss_output_write(sample_t frame
[]);
485 void ss_output_close(void);
486 int cue_file_song_info(int frame
, char * author
, char * name
);
490 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
491 struct ss_wave
* ss_load_wav_file(char * file
,
492 double base_freq
, double min_freq
, double max_freq
,
493 double loop_start
, double loop_end
,
494 int first_channel
, int skip_channels
);
495 int ss_load_pat_file(struct ss_ins
* i
, char * file
);
499 void ss_eff_delay(struct ss_eff
** ec
, double size
);
500 void ss_eff_echo(struct ss_eff
** ec
, double size
, sample_t gain
);
501 void ss_eff_comb(struct ss_eff
** ec
, double size
, sample_t gain
);
502 void ss_eff_allpass(struct ss_eff
** ec
, double size
, sample_t gain
);
503 void ss_eff_flanger(struct ss_eff
** ec
, double size
, sample_t gain
,
504 double depth
, double freq
, double phase
);
505 void ss_eff_wobble(struct ss_eff
** ec
, double freq
, double phase
, sample_t gain
);
506 void ss_eff_square_wobble(struct ss_eff
** ec
, double freq
, double phase
);
507 void ss_eff_half_wobble(struct ss_eff
** ec
, double freq
, double phase
);
508 void ss_eff_fader(struct ss_eff
** ec
, double size
, sample_t initial
, sample_t final
);
509 void ss_eff_reverb(struct ss_eff
** ec
);
510 void ss_eff_foldback(struct ss_eff
** ec
, sample_t threshold
);
512 sample_t
ss_eff_process(struct ss_eff
* e
, sample_t s
);
513 void ss_eff_off(struct ss_eff
** ec
);
517 void song_clear(void);
518 void add_song_ev(song_ev_type type
, double time
, union song_ev
* ev
);
519 void song_sort(void);
520 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
524 int ss_song_render(int skip_secs
, char * driver
, char * devfile
);
528 int midi_song_play(int skip_secs
);
529 int midi_device_open(char * devfile
);
530 void midi_device_close(void);
534 int compile_ahs_string(char * code
);
535 int compile_ahs(char * file
);
539 void libpath_add(char * path
, int strip
);
540 FILE * libpath_fopen(char * filename
, char * mode
);
541 char * libpath_locate(char * filename
);
542 void transconv_add(char * from
, char * to
, char * convcmd
);
543 char * transconv(char * file
, char * ext
, char * dir
);