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 double portamento
; /* portamento */
117 /* digital effects */
121 struct ss_wave
* wave
; /* wave buffer */
122 sample_t gain
; /* effect gain */
123 sample_t igain
; /* gain increment */
125 double lfo
; /* lfo value */
126 double lfo_depth
; /* lfo depth */
127 double lfo_inc
; /* lfo increment */
129 double cursor
; /* current buffer position */
131 sample_t (* func
)(struct ss_eff
*, sample_t
); /* processing function */
133 struct ss_eff
* next
; /* next in chain */
146 SONG_EV_SS_PORTAMENTO
,
153 SONG_EV_SS_EFF_DELAY
,
156 SONG_EV_SS_EFF_ALLPASS
,
157 SONG_EV_SS_EFF_FLANGER
,
158 SONG_EV_SS_EFF_WOBBLE
,
159 SONG_EV_SS_EFF_SQWOBBLE
,
160 SONG_EV_SS_EFF_HFWOBBLE
,
161 SONG_EV_SS_EFF_FADER
,
162 SONG_EV_SS_EFF_REVERB
,
163 SONG_EV_SS_EFF_FOLDBACK
,
165 SONG_EV_MIDI_CHANNEL
,
166 SONG_EV_MIDI_PROGRAM
,
170 SONG_EV_SS_PITCH_STRETCH
,
171 SONG_EV_SS_PRINT_WAVE_TEMPO
,
182 struct song_ev_generic
184 song_ev_type type
; /* event type */
185 double time
; /* event time (1: whole note) */
186 int trk_id
; /* track id */
187 int event_id
; /* event id */
192 song_ev_type type
; /* SONG_EV_NOTE */
196 int note
; /* MIDI-like note */
197 double len
; /* note length (1: whole note) */
198 sample_t vol
; /* note volume (1: full volume) */
203 song_ev_type type
; /* SONG_EV_BACK */
207 double len
; /* note length (1: whole note) */
212 song_ev_type type
; /* SONG_EV_TEMPO */
214 int trk_id
; /* always < 0 */
216 double tempo
; /* tempo in bpm */
221 song_ev_type type
; /* SONG_EV_METER */
223 int trk_id
; /* always < 0 */
225 int num
; /* meter numerator */
226 int den
; /* meter denominator */
229 struct song_ev_measure
231 song_ev_type type
; /* SONG_EV_MEASURE */
235 int line
; /* line number */
238 struct song_ev_ss_pitch_stretch
240 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
244 int note
; /* MIDI-like note (to find the wave) */
245 double len
; /* note length (1: whole note) */
246 sample_t vol
; /* note volume (1: full volume) */
249 struct song_ev_ss_print_wave_tempo
251 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
255 int note
; /* MIDI-like note (to find the wave) */
256 double len
; /* note length (1: whole note) */
259 struct song_ev_ss_sustain
261 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
265 double sustain
; /* sustain time (in msecs) */
268 struct song_ev_ss_vibrato
270 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
274 double vib_depth
; /* vibrato depth (in msecs) */
275 double vib_freq
; /* vibrato frequency (in Hzs) */
278 struct song_ev_ss_portamento
280 song_ev_type type
; /* SONG_EV_SS_PORTAMENTO */
284 double portamento
; /* portamento */
287 struct song_ev_ss_channel
289 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
293 int channel
; /* channel */
294 sample_t vol
; /* volume */
297 struct song_ev_ss_wav
299 song_ev_type type
; /* SONG_EV_SS_WAV */
303 char * file
; /* path to .wav file */
304 int base
; /* MIDI-like base note */
305 int min
; /* MIDI-like minimum note */
306 int max
; /* MIDI-like maximum note */
307 double loop_start
; /* start of loop */
308 double loop_end
; /* end of loop */
309 int first_channel
; /* first channel to start spreading */
310 int skip_channels
; /* channels to skip when spreading */
313 struct song_ev_ss_pat
315 song_ev_type type
; /* SONG_EV_SS_PAT */
319 char * file
; /* path to .pat file */
322 struct song_ev_ss_eff
324 song_ev_type type
; /* effect type */
328 int channel
; /* channel */
329 double size
; /* size of effect */
330 sample_t gain
; /* gain */
331 double depth
; /* depth */
332 double freq
; /* freq */
333 double phase
; /* phase */
334 sample_t initial
; /* initial vol */
335 sample_t final
; /* final vol */
338 struct song_ev_midi_channel
340 song_ev_type type
; /* SONG_EV_MIDI_CHANNEL */
344 int channel
; /* midi channel (1-16) */
347 struct song_ev_midi_program
349 song_ev_type type
; /* SONG_EV_MIDI_PROGRAM */
353 int program
; /* midi program (0-127) */
356 struct song_ev_song_info
358 song_ev_type type
; /* SONG_EV_SONG_INFO */
362 char * author
; /* track author */
363 char * name
; /* track name */
368 struct song_ev_generic generic
;
370 struct song_ev_tempo tempo
;
371 struct song_ev_meter meter
;
372 struct song_ev_measure measure
;
374 struct song_ev_note note
;
375 struct song_ev_back back
;
377 struct song_ev_ss_pitch_stretch ss_pitch_stretch
;
378 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo
;
380 struct song_ev_ss_sustain ss_sustain
;
381 struct song_ev_ss_vibrato ss_vibrato
;
382 struct song_ev_ss_portamento ss_portamento
;
383 struct song_ev_ss_channel ss_channel
;
385 struct song_ev_ss_wav ss_wav
;
386 struct song_ev_ss_pat ss_pat
;
388 struct song_ev_ss_eff ss_eff
;
390 struct song_ev_midi_channel midi_channel
;
391 struct song_ev_midi_program midi_program
;
393 struct song_ev_song_info song_info
;
401 extern int ss_frequency
;
402 extern int ss_interpolation
;
403 extern int ss_nchannels
;
407 extern int ss_page_size
;
411 extern sample_t ss_master_volume
;
412 extern int ss_output_clipped
;
413 extern sample_t ss_optimal_volume
;
414 extern char * ss_cue_file_name
;
418 extern union song_ev
* song
;
419 extern int n_song_ev
;
420 extern int solo_track
;
429 /* milliseconds to frames conversion */
430 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
432 /* grows a dynamic array */
433 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
439 double ss_note_frequency(int note
);
440 struct ss_wave
* ss_alloc_wave(int size
, int n_channels
, int s_rate
, int p_size
);
441 void ss_free_wave(struct ss_wave
* w
);
442 void ss_prepare_wave(struct ss_wave
* w
);
443 sample_t
ss_get_sample(struct ss_wave
* w
, int channel
, double offset
);
444 double ss_tempo_from_wave(struct ss_wave
* w
, int note
, double len
);
445 double ss_pitch_from_tempo(struct ss_wave
* w
, double tempo
, double len
);
449 void ss_gen_init(void);
450 struct ss_gen
* ss_gen_alloc(struct ss_gen
** q
);
451 void ss_gen_free(struct ss_gen
** q
, struct ss_gen
* g
);
452 void ss_gen_sustain(struct ss_gen
* g
, double sustain
);
453 void ss_gen_vibrato(struct ss_gen
* g
, double depth
, double freq
);
454 void ss_gen_portamento(struct ss_gen
* g
, double portamento
);
455 void ss_gen_play(struct ss_gen
* g
, double freq
, sample_t vol
, int note_id
,
457 void ss_gen_release(struct ss_gen
* g
);
458 int ss_gen_frame(struct ss_gen
* g
, int n_channels
, sample_t frame
[]);
462 void ss_ins_init(struct ss_ins
* i
);
463 void ss_ins_add_layer(struct ss_ins
* i
, struct ss_wave
* w
);
464 struct ss_wave
* ss_ins_find_layer(struct ss_ins
* i
, double freq
, int * off
);
465 void ss_ins_set_channel(struct ss_ins
* i
, int channel
, sample_t vol
);
466 void ss_ins_set_sustain(struct ss_ins
* i
, double sustain
);
467 void ss_ins_set_vibrato(struct ss_ins
* i
, double depth
, double freq
);
468 void ss_ins_set_portamento(struct ss_ins
* i
, double portamento
);
469 int ss_ins_play(struct ss_ins
* i
, double freq
, sample_t vol
, int note_id
,
471 int ss_ins_note_on(struct ss_ins
* i
, int note
, sample_t vol
, int note_id
);
472 void ss_ins_note_off(struct ss_ins
* i
, int note_id
);
473 void ss_ins_frame(struct ss_ins
* i
, sample_t frame
[]);
477 int ss_output_open(char * drvname
, char * filename
);
478 void ss_output_init_frame(sample_t frame
[]);
479 int ss_output_write(sample_t frame
[]);
480 void ss_output_close(void);
481 int cue_file_song_info(int frame
, char * author
, char * name
);
485 void load_pcm_wave(FILE * f
, struct ss_wave
* w
);
486 struct ss_wave
* ss_load_wav_file(char * file
,
487 double base_freq
, double min_freq
, double max_freq
,
488 double loop_start
, double loop_end
,
489 int first_channel
, int skip_channels
);
490 int ss_load_pat_file(struct ss_ins
* i
, char * file
);
494 void ss_eff_delay(struct ss_eff
** ec
, double size
);
495 void ss_eff_echo(struct ss_eff
** ec
, double size
, sample_t gain
);
496 void ss_eff_comb(struct ss_eff
** ec
, double size
, sample_t gain
);
497 void ss_eff_allpass(struct ss_eff
** ec
, double size
, sample_t gain
);
498 void ss_eff_flanger(struct ss_eff
** ec
, double size
, sample_t gain
,
499 double depth
, double freq
, double phase
);
500 void ss_eff_wobble(struct ss_eff
** ec
, double freq
, double phase
, sample_t gain
);
501 void ss_eff_square_wobble(struct ss_eff
** ec
, double freq
, double phase
);
502 void ss_eff_half_wobble(struct ss_eff
** ec
, double freq
, double phase
);
503 void ss_eff_fader(struct ss_eff
** ec
, double size
, sample_t initial
, sample_t final
);
504 void ss_eff_reverb(struct ss_eff
** ec
);
505 void ss_eff_foldback(struct ss_eff
** ec
, sample_t threshold
);
507 sample_t
ss_eff_process(struct ss_eff
* e
, sample_t s
);
508 void ss_eff_off(struct ss_eff
** ec
);
512 void song_clear(void);
513 void add_song_ev(song_ev_type type
, double time
, union song_ev
* ev
);
514 void song_sort(void);
515 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
);
519 int ss_song_render(int skip_secs
, char * driver
, char * devfile
);
523 int midi_song_play(int skip_secs
);
524 int midi_device_open(char * devfile
);
525 void midi_device_close(void);
529 int compile_ahs_string(char * code
);
530 int compile_ahs(char * file
);
534 void libpath_add(char * path
, int strip
);
535 FILE * libpath_fopen(char * filename
, char * mode
);
536 char * libpath_locate(char * filename
);
537 void transconv_add(char * from
, char * to
, char * convcmd
);
538 char * transconv(char * file
, char * ext
, char * dir
);