3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2007 Angel Ortega <angel@triptico.com>
6 ss_song.c - Software synth song event stream management
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
41 song_ev_type type
; /* event type */
42 int frame
; /* frame number (time) */
43 int trk_id
; /* track id */
44 int event_id
; /* event id */
49 song_ev_type type
; /* SONG_EV_NOTE_OFF */
53 int note_id
; /* note id */
58 song_ev_type type
; /* SONG_EV_NOTE_ON */
62 int note_id
; /* note id */
63 int note
; /* MIDI-like note */
64 sample_t vol
; /* volume */
67 struct ss_ev_ss_sustain
69 song_ev_type type
; /* SONG_EV_SS_SUSTAIN */
73 double sustain
; /* sustain time (in frames) */
76 struct ss_ev_ss_attack
78 song_ev_type type
; /* SONG_EV_SS_ATTACK */
82 double attack
; /* attack time (in frames) */
85 struct ss_ev_ss_vibrato
87 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
91 double vib_depth
; /* vibrato depth (in msecs) */
92 double vib_freq
; /* vibrato frequency (in Hzs) */
95 struct ss_ev_ss_portamento
97 song_ev_type type
; /* SONG_EV_SS_PORTAMENTO */
101 double portamento
; /* portamento */
104 struct ss_ev_ss_channel
106 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
110 int channel
; /* channel */
111 sample_t vol
; /* volume */
116 song_ev_type type
; /* SONG_EV_SS_WAV */
120 char * file
; /* path to .wav file */
121 int base
; /* MIDI-like base note */
122 int min
; /* MIDI-like minimum note */
123 int max
; /* MIDI-like maximum note */
124 double loop_start
; /* loop start */
125 double loop_end
; /* loop end */
126 int first_channel
; /* first channel to start spreading */
127 int skip_channels
; /* channels to skip when spreading */
132 song_ev_type type
; /* SONG_EV_SS_PAT */
136 char * file
; /* path to .pat file */
141 song_ev_type type
; /* SONG_EV_TEMPO */
145 double tempo
; /* tempo in bmp */
148 struct ss_ev_pitch_stretch
150 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
154 int note_id
; /* note id */
155 int note
; /* MIDI-like note (to find the wave) */
156 double len
; /* note length (1: whole note) */
157 sample_t vol
; /* note volume (1: full volume) */
160 struct ss_ev_print_wave_tempo
162 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
166 int note_id
; /* note id */
167 int note
; /* MIDI-like note (to find the wave) */
168 double len
; /* note length (1: whole note) */
173 song_ev_type type
; /* effect type */
177 int channel
; /* channel */
178 double size
; /* size of effect */
179 sample_t gain
; /* gain */
180 double depth
; /* depth */
181 double freq
; /* freq */
182 double phase
; /* phase */
183 sample_t initial
; /* initial vol */
184 sample_t final
; /* final vol */
187 struct ss_ev_song_info
189 song_ev_type type
; /* SONG_EV_SONG_INFO */
193 char * author
; /* track author */
194 char * name
; /* track name */
199 struct ss_ev_generic generic
;
200 struct ss_ev_note_on note_on
;
201 struct ss_ev_note_off note_off
;
202 struct ss_ev_ss_sustain ss_sustain
;
203 struct ss_ev_ss_attack ss_attack
;
204 struct ss_ev_ss_vibrato ss_vibrato
;
205 struct ss_ev_ss_portamento ss_portamento
;
206 struct ss_ev_ss_channel ss_channel
;
207 struct ss_ev_ss_wav ss_wav
;
208 struct ss_ev_ss_pat ss_pat
;
209 struct ss_ev_ss_eff ss_eff
;
210 struct ss_ev_tempo tempo
;
211 struct ss_ev_pitch_stretch ss_pitch_stretch
;
212 struct ss_ev_print_wave_tempo ss_print_wave_tempo
;
213 struct ss_ev_song_info song_info
;
216 /* the softsynth song stream */
218 static union ss_ev
* ss_song
= NULL
;
219 static int n_ss_ev
= 0;
222 /* the instruments */
224 struct ss_ins ss_song_ins
[SS_MAX_INSTRUMENTS
];
228 ********************/
230 static void add_ss_ev(union ss_ev
* e
)
231 /* adds a softsynth song event */
233 GROW(ss_song
, n_ss_ev
, union ss_ev
);
236 memcpy(&ss_song
[n_ss_ev
], e
, sizeof(union ss_ev
));
242 static int ss_ev_cmp(const void * v1
, const void * v2
)
243 /* softsynth song event compare function for qsort() */
245 struct ss_ev_generic
* e1
;
246 struct ss_ev_generic
* e2
;
249 e1
= (struct ss_ev_generic
*)v1
; e2
= (struct ss_ev_generic
*)v2
;
251 ret
= e1
->frame
- e2
->frame
;
254 ret
= e1
->type
- e2
->type
;
257 ret
= e1
->event_id
- e2
->event_id
;
263 static void ss_song_convert_events(int * n_channels
)
264 /* converts generic song_ev events to softsynth events */
269 int frame
, frame_ac
, f_frame
;
270 double fpw
, time_ac
, time_ac_m
;
276 /* resets the ss stream */
289 frame
= frame_ac
= f_frame
= 0;
290 time_ac
= time_ac_m
= 0;
293 /* travels the song events generating softsynth song events */
294 for(n
= 0;n
< n_song_ev
;n
++)
296 /* gets the song event */
299 /* calculates the frame */
300 frame
= ((e
->generic
.time
- time_ac
) * fpw
) + frame_ac
;
302 /* generic event data */
303 sse
.generic
.type
= e
->generic
.type
;
304 sse
.generic
.frame
= frame
;
305 sse
.generic
.trk_id
= e
->generic
.trk_id
;
306 sse
.generic
.event_id
= e
->generic
.event_id
;
308 switch(e
->generic
.type
)
312 /* updates accumulations */
314 time_ac
= e
->generic
.time
;
316 /* calculates frames-per-whole based on new tempo */
317 fpw
= (double) ss_frequency
* 60.0;
318 fpw
/= e
->tempo
.tempo
/ 4.0;
321 sse
.tempo
.tempo
= e
->tempo
.tempo
;
328 /* just store the values */
331 time_ac_m
= e
->meter
.time
;
335 case SONG_EV_MEASURE
:
337 song_test_measure_boundary(e
->measure
.time
- time_ac_m
,
338 num
, den
, e
->measure
.line
);
343 /* convert to note on / off pairs */
345 sse
.note_on
.type
= SONG_EV_NOTE_ON
;
346 sse
.note_on
.note_id
= note_id
++;
347 sse
.note_on
.note
= e
->note
.note
;
348 sse
.note_on
.vol
= e
->note
.vol
;
352 frame
+= (int)(e
->note
.len
* fpw
);
354 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
355 sse
.note_off
.frame
= frame
;
362 /* move the cursor back */
364 frame_ac
-= (int)(e
->back
.len
* fpw
);
368 case SONG_EV_SS_PITCH_STRETCH
:
370 sse
.ss_pitch_stretch
.note_id
= note_id
++;
371 sse
.ss_pitch_stretch
.note
= e
->ss_pitch_stretch
.note
;
372 sse
.ss_pitch_stretch
.len
= e
->ss_pitch_stretch
.len
;
373 sse
.ss_pitch_stretch
.vol
= e
->ss_pitch_stretch
.vol
;
377 frame
+= (int)(e
->ss_pitch_stretch
.len
* fpw
);
379 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
380 sse
.note_off
.frame
= frame
;
385 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
387 sse
.ss_print_wave_tempo
.note
= e
->ss_print_wave_tempo
.note
;
388 sse
.ss_print_wave_tempo
.len
= e
->ss_print_wave_tempo
.len
;
395 sse
.ss_wav
.file
= e
->ss_wav
.file
;
396 sse
.ss_wav
.base
= e
->ss_wav
.base
;
397 sse
.ss_wav
.min
= e
->ss_wav
.min
;
398 sse
.ss_wav
.max
= e
->ss_wav
.max
;
399 sse
.ss_wav
.loop_start
= e
->ss_wav
.loop_start
;
400 sse
.ss_wav
.loop_end
= e
->ss_wav
.loop_end
;
401 sse
.ss_wav
.first_channel
= e
->ss_wav
.first_channel
;
402 sse
.ss_wav
.skip_channels
= e
->ss_wav
.skip_channels
;
409 sse
.ss_pat
.file
= e
->ss_pat
.file
;
414 case SONG_EV_SS_SUSTAIN
:
416 sse
.ss_sustain
.sustain
= e
->ss_sustain
.sustain
;
421 case SONG_EV_SS_ATTACK
:
423 sse
.ss_attack
.attack
= e
->ss_attack
.attack
;
428 case SONG_EV_SS_VIBRATO
:
430 sse
.ss_vibrato
.vib_depth
= e
->ss_vibrato
.vib_depth
;
431 sse
.ss_vibrato
.vib_freq
= e
->ss_vibrato
.vib_freq
;
436 case SONG_EV_SS_PORTAMENTO
:
438 sse
.ss_portamento
.portamento
= e
->ss_portamento
.portamento
;
443 case SONG_EV_SS_CHANNEL
:
445 sse
.ss_channel
.channel
= e
->ss_channel
.channel
;
446 sse
.ss_channel
.vol
= e
->ss_channel
.vol
;
449 if(*n_channels
< e
->ss_channel
.channel
)
450 *n_channels
= e
->ss_channel
.channel
;
455 case SONG_EV_SS_EFF_DELAY
:
456 case SONG_EV_SS_EFF_ECHO
:
457 case SONG_EV_SS_EFF_COMB
:
458 case SONG_EV_SS_EFF_ALLPASS
:
459 case SONG_EV_SS_EFF_FLANGER
:
460 case SONG_EV_SS_EFF_WOBBLE
:
461 case SONG_EV_SS_EFF_SQWOBBLE
:
462 case SONG_EV_SS_EFF_HFWOBBLE
:
463 case SONG_EV_SS_EFF_FADER
:
464 case SONG_EV_SS_EFF_REVERB
:
465 case SONG_EV_SS_EFF_FOLDBACK
:
466 case SONG_EV_SS_EFF_ATAN
:
467 case SONG_EV_SS_EFF_DISTORT
:
468 case SONG_EV_SS_EFF_OVERDRIVE
:
469 case SONG_EV_SS_EFF_OFF
:
471 sse
.ss_eff
.channel
= e
->ss_eff
.channel
;
472 sse
.ss_eff
.size
= e
->ss_eff
.size
;
473 sse
.ss_eff
.gain
= e
->ss_eff
.gain
;
474 sse
.ss_eff
.depth
= e
->ss_eff
.depth
;
475 sse
.ss_eff
.freq
= e
->ss_eff
.freq
;
476 sse
.ss_eff
.phase
= e
->ss_eff
.phase
;
477 sse
.ss_eff
.initial
= e
->ss_eff
.initial
;
478 sse
.ss_eff
.final
= e
->ss_eff
.final
;
483 case SONG_EV_SONG_INFO
:
485 sse
.song_info
.author
= e
->song_info
.author
;
486 sse
.song_info
.name
= e
->song_info
.name
;
496 case SONG_EV_MIDI_CHANNEL
:
497 case SONG_EV_MIDI_PROGRAM
:
502 case SONG_EV_NOTE_ON
:
503 case SONG_EV_NOTE_OFF
:
506 /* never found in generic song streams */
510 /* store the further frame seen */
511 if(f_frame
< frame
) f_frame
= frame
;
514 /* generates an end of event mark, a time after the last one */
515 sse
.generic
.type
= SONG_EV_END
;
516 sse
.generic
.frame
= f_frame
+ ss_frequency
;
517 sse
.generic
.event_id
= -1;
521 qsort(ss_song
, n_ss_ev
, sizeof(union ss_ev
), ss_ev_cmp
);
528 static void ss_song_trace_events(void)
533 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
534 printf("%10s %5s %5s Event and information\n",
535 "Frame", "Track", "Ev.ID");
536 printf("------------------------------------------------------------\n");
538 for(n
= 0, e
= ss_song
;n
< n_ss_ev
;n
++, e
++)
540 printf("%10d %5d %5d ",
541 e
->generic
.frame
, e
->generic
.trk_id
, e
->generic
.event_id
);
543 switch(e
->generic
.type
)
547 printf("SONG_EV_TEMPO ");
548 printf("%lf", e
->tempo
.tempo
);
551 case SONG_EV_SS_SUSTAIN
:
553 printf("SONG_EV_SS_SUSTAIN ");
554 printf("SUSTAIN:%lf", e
->ss_sustain
.sustain
);
557 case SONG_EV_SS_ATTACK
:
559 printf("SONG_EV_SS_ATTACK ");
560 printf("ATTACK:%lf", e
->ss_attack
.attack
);
563 case SONG_EV_SS_VIBRATO
:
565 printf("SONG_EV_SS_VIBRATO ");
566 printf("DEPTH:%lf FREQ:%lf",
567 e
->ss_vibrato
.vib_depth
,
568 e
->ss_vibrato
.vib_freq
);
571 case SONG_EV_SS_PORTAMENTO
:
573 printf("SONG_EV_SS_PORTAMENTO ");
575 e
->ss_portamento
.portamento
);
578 case SONG_EV_SS_CHANNEL
:
580 printf("SONG_EV_SS_CHANNEL ");
581 printf("CHANNEL:%d VOL:%lf",
582 e
->ss_channel
.channel
,
588 printf("SONG_EV_SS_WAV ");
589 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
590 e
->ss_wav
.file
, e
->ss_wav
.base
,
591 e
->ss_wav
.min
, e
->ss_wav
.max
,
592 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
);
597 printf("SONG_EV_SS_PAT ");
598 printf("FILE:'%s'", e
->ss_pat
.file
);
601 case SONG_EV_SS_EFF_DELAY
:
603 printf("SONG_EV_SS_EFF_DELAY ");
604 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
605 printf("SIZE:%lf ", e
->ss_eff
.size
);
608 case SONG_EV_SS_EFF_ECHO
:
610 printf("SONG_EV_SS_EFF_ECHO ");
611 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
612 printf("SIZE:%lf ", e
->ss_eff
.size
);
613 printf("GAIN:%f ", e
->ss_eff
.gain
);
616 case SONG_EV_SS_EFF_COMB
:
618 printf("SONG_EV_SS_EFF_COMB ");
619 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
620 printf("SIZE:%lf ", e
->ss_eff
.size
);
621 printf("GAIN:%f ", e
->ss_eff
.gain
);
624 case SONG_EV_SS_EFF_ALLPASS
:
626 printf("SONG_EV_SS_EFF_ALLPASS ");
627 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
628 printf("SIZE:%lf ", e
->ss_eff
.size
);
629 printf("GAIN:%f ", e
->ss_eff
.gain
);
632 case SONG_EV_SS_EFF_FLANGER
:
634 printf("SONG_EV_SS_EFF_FLANGER ");
635 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
636 printf("SIZE:%lf ", e
->ss_eff
.size
);
637 printf("GAIN:%f ", e
->ss_eff
.gain
);
638 printf("DEPTH:%lf ", e
->ss_eff
.depth
);
639 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
643 case SONG_EV_SS_EFF_WOBBLE
:
645 printf("SONG_EV_SS_EFF_WOBBLE ");
646 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
647 printf("FREQ:%lf PHASE:%lf GAIN:%lf", e
->ss_eff
.freq
,
648 e
->ss_eff
.phase
, e
->ss_eff
.gain
);
651 case SONG_EV_SS_EFF_SQWOBBLE
:
653 printf("SONG_EV_SS_EFF_SQWOBBLE ");
654 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
655 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
659 case SONG_EV_SS_EFF_HFWOBBLE
:
661 printf("SONG_EV_SS_EFF_HFWOBBLE ");
662 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
663 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
667 case SONG_EV_SS_EFF_FADER
:
669 printf("SONG_EV_SS_EFF_FADER ");
670 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
671 printf("SIZE:%lf ", e
->ss_eff
.size
);
672 printf("INITIAL:%f FINAL:%f", e
->ss_eff
.initial
,
676 case SONG_EV_SS_EFF_REVERB
:
678 printf("SONG_EV_SS_EFF_REVERB ");
679 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
682 case SONG_EV_SS_EFF_FOLDBACK
:
684 printf("SONG_EV_SS_EFF_FOLDBACK ");
685 printf("CHANNEL:%d THRESHOLD:%f", e
->ss_eff
.channel
,
689 case SONG_EV_SS_EFF_ATAN
:
691 printf("SONG_EV_SS_EFF_ATAN ");
692 printf("CHANNEL:%d GAIN:%f", e
->ss_eff
.channel
,
696 case SONG_EV_SS_EFF_DISTORT
:
698 printf("SONG_EV_SS_EFF_DISTORT ");
699 printf("CHANNEL:%d GAIN:%f", e
->ss_eff
.channel
,
703 case SONG_EV_SS_EFF_OVERDRIVE
:
705 printf("SONG_EV_SS_EFF_OVERDRIVE ");
706 printf("CHANNEL:%d GAIN:%f", e
->ss_eff
.channel
,
710 case SONG_EV_SS_EFF_OFF
:
712 printf("SONG_EV_SS_EFF_OFF ");
713 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
716 case SONG_EV_SS_PITCH_STRETCH
:
718 printf("SONG_EV_SS_PITCH_STRETCH ");
719 printf("MIDI:%d LEN:%lf VOL:%f",
720 e
->ss_pitch_stretch
.note
,
721 e
->ss_pitch_stretch
.len
,
722 e
->ss_pitch_stretch
.vol
);
726 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
728 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
729 printf("MIDI:%d LEN:%lf",
730 e
->ss_print_wave_tempo
.note
,
731 e
->ss_print_wave_tempo
.len
);
734 case SONG_EV_SONG_INFO
:
736 printf("SONG_EV_SONG_INFO ");
737 printf("AUTHOR:'%s' NAME:'%s'",
742 case SONG_EV_NOTE_ON
:
744 printf("SONG_EV_NOTE_ON ");
745 printf("ID:%d MIDI:%d VOL:%f",
746 e
->note_on
.note_id
, e
->note_on
.note
,
750 case SONG_EV_NOTE_OFF
:
752 printf("SONG_EV_NOTE_OFF ");
753 printf("ID:%d", e
->note_off
.note_id
);
758 printf("SONG_EV_EOT ");
763 printf("SONG_EV_END ");
767 printf("** Unexpected type: %d",
778 static union ss_ev
* process_this_frame_events(union ss_ev
* e
, int skip_frames
)
779 /* process the events attached to this frame */
781 static double tempo
= 120.0;
782 static int frame
= 0;
784 /* from the beginning? */
794 if(frame
% ss_frequency
== 0)
796 int m
= frame
/ ss_frequency
;
797 printf("[%02d:%02d]\r", m
/ 60, m
% 60);
802 while(e
!= NULL
&& e
->generic
.frame
== frame
)
808 if(e
->generic
.type
== SONG_EV_NOTE_ON
||
809 e
->generic
.type
== SONG_EV_NOTE_OFF
||
810 e
->generic
.type
== SONG_EV_SS_PITCH_STRETCH
)
812 if(frame
< skip_frames
)
815 frame
= e
->generic
.frame
;
820 /* take the instrument */
821 if(e
->generic
.trk_id
< 0)
824 i
= &ss_song_ins
[e
->generic
.trk_id
];
826 switch(e
->generic
.type
)
828 case SONG_EV_NOTE_ON
:
830 if(ss_ins_note_on(i
, e
->note_on
.note
,
831 e
->note_on
.vol
, e
->note_on
.note_id
) < 0 &&
833 printf("ss_ins_note_on error: track %d note %d\n",
834 e
->note_on
.trk_id
, e
->note_on
.note
);
838 case SONG_EV_NOTE_OFF
:
840 ss_ins_note_off(i
, e
->note_off
.note_id
);
844 case SONG_EV_SS_SUSTAIN
:
846 ss_ins_set_sustain(i
, e
->ss_sustain
.sustain
);
850 case SONG_EV_SS_ATTACK
:
852 ss_ins_set_attack(i
, e
->ss_attack
.attack
);
856 case SONG_EV_SS_VIBRATO
:
858 ss_ins_set_vibrato(i
, e
->ss_vibrato
.vib_depth
,
859 e
->ss_vibrato
.vib_freq
);
863 case SONG_EV_SS_PORTAMENTO
:
865 ss_ins_set_portamento(i
,
866 (e
->ss_portamento
.portamento
* 44100.0)
867 / ((double) ss_frequency
* 1000000.0));
871 case SONG_EV_SS_CHANNEL
:
873 ss_ins_set_channel(i
, e
->ss_channel
.channel
,
880 w
= ss_load_wav_file(e
->ss_wav
.file
,
881 ss_note_frequency(e
->ss_wav
.base
),
882 ss_note_frequency(e
->ss_wav
.min
),
883 ss_note_frequency(e
->ss_wav
.max
),
884 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
,
885 e
->ss_wav
.first_channel
, e
->ss_wav
.skip_channels
);
887 /* fail if can't open wav */
890 printf("Can't load wav '%s'\n", e
->ss_wav
.file
);
894 ss_ins_add_layer(i
, w
);
900 if(ss_load_pat_file(i
, e
->ss_pat
.file
) < 0)
902 printf("Can't load pat '%s'\n", e
->ss_pat
.file
);
908 case SONG_EV_SS_EFF_DELAY
:
910 ss_eff_delay(&i
->effs
[e
->ss_eff
.channel
], e
->ss_eff
.size
);
913 case SONG_EV_SS_EFF_ECHO
:
915 ss_eff_echo(&i
->effs
[e
->ss_eff
.channel
],
916 e
->ss_eff
.size
, e
->ss_eff
.gain
);
919 case SONG_EV_SS_EFF_COMB
:
921 ss_eff_comb(&i
->effs
[e
->ss_eff
.channel
],
922 e
->ss_eff
.size
, e
->ss_eff
.gain
);
925 case SONG_EV_SS_EFF_ALLPASS
:
927 ss_eff_allpass(&i
->effs
[e
->ss_eff
.channel
],
928 e
->ss_eff
.size
, e
->ss_eff
.gain
);
931 case SONG_EV_SS_EFF_FLANGER
:
933 ss_eff_flanger(&i
->effs
[e
->ss_eff
.channel
],
934 e
->ss_eff
.size
, e
->ss_eff
.gain
,
935 e
->ss_eff
.depth
, e
->ss_eff
.freq
,
939 case SONG_EV_SS_EFF_WOBBLE
:
941 ss_eff_wobble(&i
->effs
[e
->ss_eff
.channel
],
942 e
->ss_eff
.freq
, e
->ss_eff
.phase
,
947 case SONG_EV_SS_EFF_SQWOBBLE
:
949 ss_eff_square_wobble(&i
->effs
[e
->ss_eff
.channel
],
950 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
954 case SONG_EV_SS_EFF_HFWOBBLE
:
956 ss_eff_half_wobble(&i
->effs
[e
->ss_eff
.channel
],
957 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
961 case SONG_EV_SS_EFF_FADER
:
963 ss_eff_fader(&i
->effs
[e
->ss_eff
.channel
],
964 e
->ss_eff
.size
, e
->ss_eff
.initial
,
968 case SONG_EV_SS_EFF_REVERB
:
970 ss_eff_reverb(&i
->effs
[e
->ss_eff
.channel
]);
973 case SONG_EV_SS_EFF_FOLDBACK
:
975 ss_eff_foldback(&i
->effs
[e
->ss_eff
.channel
],
979 case SONG_EV_SS_EFF_ATAN
:
981 ss_eff_atan(&i
->effs
[e
->ss_eff
.channel
],
985 case SONG_EV_SS_EFF_DISTORT
:
987 ss_eff_distort(&i
->effs
[e
->ss_eff
.channel
],
991 case SONG_EV_SS_EFF_OVERDRIVE
:
993 ss_eff_overdrive(&i
->effs
[e
->ss_eff
.channel
],
997 case SONG_EV_SS_EFF_OFF
:
999 ss_eff_off(&i
->effs
[e
->ss_eff
.channel
]);
1004 /* just store the last tempo */
1005 tempo
= e
->tempo
.tempo
;
1008 case SONG_EV_SS_PITCH_STRETCH
:
1011 freq
= ss_note_frequency(e
->ss_pitch_stretch
.note
);
1012 w
= ss_ins_find_layer(i
, freq
, NULL
);
1014 /* calculate optimal frequency */
1015 freq
= ss_pitch_from_tempo(w
, tempo
,
1016 e
->ss_pitch_stretch
.len
);
1019 if(ss_ins_play(i
, freq
, e
->ss_pitch_stretch
.vol
,
1020 e
->ss_pitch_stretch
.note_id
, w
) < 0 &&
1022 printf("ss_ins_play error: track %d freq %f\n",
1023 e
->ss_pitch_stretch
.trk_id
, freq
);
1027 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
1030 freq
= ss_note_frequency(e
->ss_print_wave_tempo
.note
);
1031 w
= ss_ins_find_layer(i
, freq
, NULL
);
1033 /* print the optimal tempo */
1034 printf("Optimal tempo: %lf\n",
1035 ss_tempo_from_wave(w
,
1036 e
->ss_print_wave_tempo
.note
,
1037 e
->ss_print_wave_tempo
.len
));
1041 case SONG_EV_SONG_INFO
:
1043 /* add a new song (track) */
1044 cue_file_song_info(frame
, e
->song_info
.author
,
1050 /* end of track; trigger possible cleaning */
1060 case SONG_EV_MIDI_CHANNEL
:
1061 case SONG_EV_MIDI_PROGRAM
:
1064 case SONG_EV_MEASURE
:
1066 /* never found in ss song streams */
1080 int ss_song_render(int skip_secs
, char * driver
, char * devfile
)
1083 sample_t output
[SS_MAX_CHANNELS
];
1086 union ss_ev
* e
= NULL
;
1088 /* convert the song to ss events */
1089 ss_song_convert_events(&n_channels
);
1092 printf("Tracks: %d Channels: %d Events: %d\n",
1093 n_song_tracks
, n_channels
, n_ss_ev
);
1097 ss_song_trace_events();
1101 /* set the number of channels, unless forced */
1102 if(ss_nchannels
== -1)
1103 ss_nchannels
= n_channels
> 0 ? n_channels
: 2;
1105 if(ss_output_open(driver
, devfile
) < 0)
1107 printf("Error: can't init driver\n");
1111 /* init the generators */
1114 /* init the instruments */
1115 for(n
= 0;n
< n_song_tracks
;n
++)
1116 ss_ins_init(&ss_song_ins
[n
]);
1118 /* calculate the frame to start playing */
1119 skip_frames
= skip_secs
* ss_frequency
;
1124 /* process all events in this frame */
1125 /* if((e = process_this_frame_events(e, skip_frames)) == NULL)
1127 e
= process_this_frame_events(e
, skip_frames
);
1129 /* reset frame samples */
1130 ss_output_init_frame(output
);
1132 /* generate output from all instruments */
1133 for(n
= i
= 0;n
< n_song_tracks
;n
++)
1134 i
+= ss_ins_frame(&ss_song_ins
[n
], output
);
1136 /* dump to sampling driver */
1137 ss_output_write(output
);
1140 if(verbose
>= 1) printf("\n");