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
;
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 dsvol
; /* volume decrement in sustain */
87 int attack
; /* number of frames of fade-in attack */
88 sample_t davol
; /* volume increment in attack */
90 double vibrato
; /* vibrato oscillator */
91 double vib_depth
; /* vibrato depth */
92 double vib_inc
; /* increment for vibrato oscillator */
94 double portamento
; /* portamento sum to inc */
100 /* software syntesizer instruments */
104 int n_layers
; /* # of layers */
105 struct ss_wave
** layers
; /* layers */
107 struct ss_gen
* gens
; /* generator queue */
109 int n_channels
; /* number of channels */
110 sample_t
* vols
; /* volumes (1 per channel) */
111 struct ss_eff
** effs
; /* effect chains (1 per channel) */
113 double sustain
; /* sustain in msecs */
114 double attack
; /* attack in msecs */
115 double vib_depth
; /* vibrato depth */
116 double vib_freq
; /* vibrato frequency */
118 int disabled
; /* if set, no processing is done */
120 double portamento
; /* portamento */
123 /* digital effects */
127 struct ss_wave
* wave
; /* wave buffer */
128 sample_t gain
; /* effect gain */
129 sample_t igain
; /* gain increment */
131 double lfo
; /* lfo value */
132 double lfo_depth
; /* lfo depth */
133 double lfo_inc
; /* lfo increment */
135 double cursor
; /* current buffer position */
137 sample_t (* func
)(struct ss_eff
*, sample_t
); /* processing function */
139 struct ss_eff
* next
; /* next in chain */
153 SONG_EV_SS_PORTAMENTO
,
160 SONG_EV_SS_EFF_DELAY
,
163 SONG_EV_SS_EFF_ALLPASS
,
164 SONG_EV_SS_EFF_FLANGER
,
165 SONG_EV_SS_EFF_WOBBLE
,
166 SONG_EV_SS_EFF_SQWOBBLE
,
167 SONG_EV_SS_EFF_HFWOBBLE
,
168 SONG_EV_SS_EFF_FADER
,
169 SONG_EV_SS_EFF_REVERB
,
171 SONG_EV_SS_EFF_FOLDBACK
,
173 SONG_EV_SS_EFF_DISTORT
,
174 SONG_EV_SS_EFF_OVERDRIVE
,
176 SONG_EV_MIDI_CHANNEL
,
177 SONG_EV_MIDI_PROGRAM
,
181 SONG_EV_SS_PITCH_STRETCH
,
182 SONG_EV_SS_PRINT_WAVE_TEMPO
,
194 struct song_ev_generic
196 song_ev_type type
; /* event type */
197 double time
; /* event time (1: whole note) */
198 int trk_id
; /* track id */
199 int event_id
; /* event id */
204 song_ev_type type
; /* SONG_EV_NOTE */
208 int note
; /* MIDI-like note */
209 double len
; /* note length (1: whole note) */
210 sample_t vol
; /* note volume (1: full volume) */
215 song_ev_type type
; /* SONG_EV_BACK */
219 double len
; /* note length (1: whole note) */
224 song_ev_type type
; /* SONG_EV_TEMPO */
226 int trk_id
; /* always < 0 */
228 double tempo
; /* tempo in bpm */
233 song_ev_type type
; /* SONG_EV_METER */
235 int trk_id
; /* always < 0 */
237 int num
; /* meter numerator */
238 int den
; /* meter denominator */
241 struct song_ev_measure
243 song_ev_type type
; /* SONG_EV_MEASURE */
247 int line
; /* line number */
250 struct song_ev_ss_pitch_stretch
252 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
256 int note
; /* MIDI-like note (to find the wave) */
257 double len
; /* note length (1: whole note) */
258 sample_t vol
; /* note volume (1: full volume) */
261 struct song_ev_ss_print_wave_tempo
263 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
267 int note
; /* MIDI-like note (to find the wave) */
268 double len
; /* note length (1: whole note) */
271 struct song_ev_ss_sustain
273 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
277 double sustain
; /* sustain time (in msecs) */
280 struct song_ev_ss_attack
282 song_ev_type type
; /* SONG_EV_SS_ATTACK */
286 double attack
; /* attack time (in msecs) */
289 struct song_ev_ss_vibrato
291 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
295 double vib_depth
; /* vibrato depth (in msecs) */
296 double vib_freq
; /* vibrato frequency (in Hzs) */
299 struct song_ev_ss_portamento
301 song_ev_type type
; /* SONG_EV_SS_PORTAMENTO */
305 double portamento
; /* portamento */
308 struct song_ev_ss_channel
310 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
314 int channel
; /* channel */
315 sample_t vol
; /* volume */
318 struct song_ev_ss_wav
320 song_ev_type type
; /* SONG_EV_SS_WAV */
324 char * file
; /* path to .wav file */
325 int base
; /* MIDI-like base note */
326 int min
; /* MIDI-like minimum note */
327 int max
; /* MIDI-like maximum note */
328 double loop_start
; /* start of loop */
329 double loop_end
; /* end of loop */
330 int first_channel
; /* first channel to start spreading */
331 int skip_channels
; /* channels to skip when spreading */
334 struct song_ev_ss_pat
336 song_ev_type type
; /* SONG_EV_SS_PAT */
340 char * file
; /* path to .pat file */
343 struct song_ev_ss_eff
345 song_ev_type type
; /* effect type */
349 int channel
; /* channel */
350 double size
; /* size of effect */
351 sample_t gain
; /* gain */
352 double depth
; /* depth */
353 double freq
; /* freq */
354 double phase
; /* phase */
355 sample_t initial
; /* initial vol */
356 sample_t final
; /* final vol */
359 struct song_ev_midi_channel
361 song_ev_type type
; /* SONG_EV_MIDI_CHANNEL */
365 int channel
; /* midi channel (1-16) */
368 struct song_ev_midi_program
370 song_ev_type type
; /* SONG_EV_MIDI_PROGRAM */
374 int program
; /* midi program (0-127) */
377 struct song_ev_song_info
379 song_ev_type type
; /* SONG_EV_SONG_INFO */
383 char * author
; /* track author */
384 char * name
; /* track name */
389 struct song_ev_generic generic
;
391 struct song_ev_tempo tempo
;
392 struct song_ev_meter meter
;
393 struct song_ev_measure measure
;
395 struct song_ev_note note
;
396 struct song_ev_back back
;
398 struct song_ev_ss_pitch_stretch ss_pitch_stretch
;
399 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo
;
401 struct song_ev_ss_sustain ss_sustain
;
402 struct song_ev_ss_attack ss_attack
;
403 struct song_ev_ss_vibrato ss_vibrato
;
404 struct song_ev_ss_portamento ss_portamento
;
405 struct song_ev_ss_channel ss_channel
;
407 struct song_ev_ss_wav ss_wav
;
408 struct song_ev_ss_pat ss_pat
;
410 struct song_ev_ss_eff ss_eff
;
412 struct song_ev_midi_channel midi_channel
;
413 struct song_ev_midi_program midi_program
;
415 struct song_ev_song_info song_info
;
423 extern int ss_frequency
;
424 extern int ss_interpolation
;
425 extern int ss_nchannels
;
429 extern int ss_page_size
;
433 extern sample_t ss_master_volume
;
434 extern int ss_output_clipped
;
435 extern sample_t ss_optimal_volume
;
436 extern char * ss_cue_file_name
;
440 extern union song_ev
* song
;
441 extern int n_song_ev
;
442 extern int solo_track
;
443 extern int n_song_tracks
;
452 /* milliseconds to frames conversion */
453 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
455 /* grows a dynamic array */
456 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
462 double ss_note_frequency(int note
);
463 struct ss_wave
* ss_alloc_wave(int size
, int n_channels
, int s_rate
, int p_size
);
464 void ss_free_wave(struct ss_wave
* w
);
465 void ss_prepare_wave(struct ss_wave
* w
);
466 sample_t
ss_get_sample(struct ss_wave
* w
, int channel
, double offset
);
467 double ss_tempo_from_wave(struct ss_wave
* w
, int note
, double len
);
468 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
472 void ss_gen_init(void);
473 struct ss_gen
* ss_gen_alloc(struct ss_gen
** q
);
474 void ss_gen_free(struct ss_gen
** q
, struct ss_gen
* g
);
475 void ss_gen_sustain(struct ss_gen
* g
, double sustain
);
476 void ss_gen_attack(struct ss_gen
* g
, double attack
);
477 void ss_gen_vibrato(struct ss_gen
* g
, double depth
, double freq
);
478 void ss_gen_portamento(struct ss_gen
* g
, double portamento
);
479 void ss_gen_play(struct ss_gen
* g
, double freq
, sample_t vol
, int note_id
,
481 void ss_gen_release(struct ss_gen
* g
);
482 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
486 void ss_ins_init(struct ss_ins
* i
);
487 void ss_ins_disable(struct ss_ins
* i
);
488 void ss_ins_add_layer(struct ss_ins
* i
, struct ss_wave
* w
);
489 struct ss_wave
* ss_ins_find_layer(struct ss_ins
* i
, double freq
, int * off
);
490 void ss_ins_set_channel(struct ss_ins
* i
, int channel
, sample_t vol
);
491 void ss_ins_set_sustain(struct ss_ins
* i
, double sustain
);
492 void ss_ins_set_attack(struct ss_ins
* i
, double attack
);
493 void ss_ins_set_vibrato(struct ss_ins
* i
, double depth
, double freq
);
494 void ss_ins_set_portamento(struct ss_ins
* i
, double portamento
);
495 int ss_ins_play(struct ss_ins
* i
, double freq
, sample_t vol
, int note_id
,
497 int ss_ins_note_on(struct ss_ins
* i
, int note
, sample_t vol
, int note_id
);
498 void ss_ins_note_off(struct ss_ins
* i
, int note_id
);
499 int ss_ins_frame(struct ss_ins
* i
, sample_t frame
[]);
503 int ss_output_open(char * drvname
, char * filename
);
504 void ss_output_init_frame(sample_t frame
[]);
505 int ss_output_write(sample_t frame
[]);
506 void ss_output_close(void);
507 int cue_file_song_info(int frame
, char * author
, char * name
);
511 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
512 struct ss_wave
* ss_load_wav_file(char * file
,
513 double base_freq
, double min_freq
, double max_freq
,
514 double loop_start
, double loop_end
,
515 int first_channel
, int skip_channels
);
516 int ss_load_pat_file(struct ss_ins
* i
, char * file
);
520 void ss_eff_delay(struct ss_eff
** ec
, double size
);
521 void ss_eff_echo(struct ss_eff
** ec
, double size
, sample_t gain
);
522 void ss_eff_comb(struct ss_eff
** ec
, double size
, sample_t gain
);
523 void ss_eff_allpass(struct ss_eff
** ec
, double size
, sample_t gain
);
524 void ss_eff_flanger(struct ss_eff
** ec
, double size
, sample_t gain
,
525 double depth
, double freq
, double phase
);
526 void ss_eff_wobble(struct ss_eff
** ec
, double freq
, double phase
, sample_t gain
);
527 void ss_eff_square_wobble(struct ss_eff
** ec
, double freq
, double phase
);
528 void ss_eff_half_wobble(struct ss_eff
** ec
, double freq
, double phase
);
529 void ss_eff_fader(struct ss_eff
** ec
, double size
, sample_t initial
, sample_t final
);
530 void ss_eff_reverb(struct ss_eff
** ec
);
531 void ss_eff_foldback(struct ss_eff
** ec
, sample_t threshold
);
532 void ss_eff_atan(struct ss_eff
** ec
, sample_t gain
);
533 void ss_eff_distort(struct ss_eff
** ec
, sample_t gain
);
534 void ss_eff_overdrive(struct ss_eff
** ec
, sample_t gain
);
536 sample_t
ss_eff_process(struct ss_eff
* e
, sample_t s
);
537 void ss_eff_off(struct ss_eff
** ec
);
541 void song_clear(void);
542 void add_song_ev(song_ev_type type
, double time
, union song_ev
* ev
);
543 void song_sort(void);
544 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
548 int ss_song_render(int skip_secs
, char * driver
, char * devfile
);
552 int midi_song_play(int skip_secs
);
553 int midi_device_open(char * devfile
);
554 void midi_device_close(void);
558 int compile_ahs_string(char * code
);
559 int compile_ahs(char * file
);
563 void libpath_add(char * path
, int strip
);
564 FILE * libpath_fopen(char * filename
, char * mode
);
565 char * libpath_locate(char * filename
);
566 void transconv_add(char * from
, char * to
, char * convcmd
);
567 char * transconv_pipe(char * cmd
, char * ext
, char * dir
);
568 char * transconv(char * file
, char * ext
, char * dir
);