3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 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_vibrato ss_vibrato
;
204 struct ss_ev_ss_portamento ss_portamento
;
205 struct ss_ev_ss_channel ss_channel
;
206 struct ss_ev_ss_wav ss_wav
;
207 struct ss_ev_ss_pat ss_pat
;
208 struct ss_ev_ss_eff ss_eff
;
209 struct ss_ev_tempo tempo
;
210 struct ss_ev_pitch_stretch ss_pitch_stretch
;
211 struct ss_ev_print_wave_tempo ss_print_wave_tempo
;
212 struct ss_ev_song_info song_info
;
215 /* the softsynth song stream */
217 static union ss_ev
* ss_song
= NULL
;
218 static int n_ss_ev
= 0;
221 /* the instruments */
223 struct ss_ins ss_song_ins
[SS_MAX_INSTRUMENTS
];
227 ********************/
229 static void add_ss_ev(union ss_ev
* e
)
230 /* adds a softsynth song event */
232 GROW(ss_song
, n_ss_ev
, union ss_ev
);
235 memcpy(&ss_song
[n_ss_ev
], e
, sizeof(union ss_ev
));
241 static int ss_ev_cmp(const void * v1
, const void * v2
)
242 /* softsynth song event compare function for qsort() */
244 struct ss_ev_generic
* e1
;
245 struct ss_ev_generic
* e2
;
248 e1
= (struct ss_ev_generic
*)v1
; e2
= (struct ss_ev_generic
*)v2
;
250 ret
= e1
->frame
- e2
->frame
;
253 ret
= e1
->type
- e2
->type
;
256 ret
= e1
->event_id
- e2
->event_id
;
262 static void ss_song_convert_events(int * n_channels
)
263 /* converts generic song_ev events to softsynth events */
268 int frame
, frame_ac
, f_frame
;
269 double fpw
, time_ac
, time_ac_m
;
275 /* resets the ss stream */
288 frame
= frame_ac
= f_frame
= 0;
289 time_ac
= time_ac_m
= 0;
292 /* travels the song events generating softsynth song events */
293 for(n
= 0;n
< n_song_ev
;n
++)
295 /* gets the song event */
298 /* calculates the frame */
299 frame
= ((e
->generic
.time
- time_ac
) * fpw
) + frame_ac
;
301 /* generic event data */
302 sse
.generic
.type
= e
->generic
.type
;
303 sse
.generic
.frame
= frame
;
304 sse
.generic
.trk_id
= e
->generic
.trk_id
;
305 sse
.generic
.event_id
= e
->generic
.event_id
;
307 switch(e
->generic
.type
)
311 /* updates accumulations */
313 time_ac
= e
->generic
.time
;
315 /* calculates frames-per-whole based on new tempo */
316 fpw
= (double) ss_frequency
* 60.0;
317 fpw
/= e
->tempo
.tempo
/ 4.0;
320 sse
.tempo
.tempo
= e
->tempo
.tempo
;
327 /* just store the values */
330 time_ac_m
= e
->meter
.time
;
334 case SONG_EV_MEASURE
:
336 song_test_measure_boundary(e
->measure
.time
- time_ac_m
,
337 num
, den
, e
->measure
.line
);
342 /* convert to note on / off pairs */
344 sse
.note_on
.type
= SONG_EV_NOTE_ON
;
345 sse
.note_on
.note_id
= note_id
++;
346 sse
.note_on
.note
= e
->note
.note
;
347 sse
.note_on
.vol
= e
->note
.vol
;
351 frame
+= (int)(e
->note
.len
* fpw
);
353 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
354 sse
.note_off
.frame
= frame
;
361 /* move the cursor back */
363 frame_ac
-= (int)(e
->back
.len
* fpw
);
367 case SONG_EV_SS_PITCH_STRETCH
:
369 sse
.ss_pitch_stretch
.note_id
= note_id
++;
370 sse
.ss_pitch_stretch
.note
= e
->ss_pitch_stretch
.note
;
371 sse
.ss_pitch_stretch
.len
= e
->ss_pitch_stretch
.len
;
372 sse
.ss_pitch_stretch
.vol
= e
->ss_pitch_stretch
.vol
;
376 frame
+= (int)(e
->ss_pitch_stretch
.len
* fpw
);
378 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
379 sse
.note_off
.frame
= frame
;
384 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
386 sse
.ss_print_wave_tempo
.note
= e
->ss_print_wave_tempo
.note
;
387 sse
.ss_print_wave_tempo
.len
= e
->ss_print_wave_tempo
.len
;
394 sse
.ss_wav
.file
= e
->ss_wav
.file
;
395 sse
.ss_wav
.base
= e
->ss_wav
.base
;
396 sse
.ss_wav
.min
= e
->ss_wav
.min
;
397 sse
.ss_wav
.max
= e
->ss_wav
.max
;
398 sse
.ss_wav
.loop_start
= e
->ss_wav
.loop_start
;
399 sse
.ss_wav
.loop_end
= e
->ss_wav
.loop_end
;
400 sse
.ss_wav
.first_channel
= e
->ss_wav
.first_channel
;
401 sse
.ss_wav
.skip_channels
= e
->ss_wav
.skip_channels
;
408 sse
.ss_pat
.file
= e
->ss_pat
.file
;
413 case SONG_EV_SS_SUSTAIN
:
415 sse
.ss_sustain
.sustain
= e
->ss_sustain
.sustain
;
420 case SONG_EV_SS_ATTACK
:
422 sse
.ss_attack
.attack
= e
->ss_attack
.attack
;
427 case SONG_EV_SS_VIBRATO
:
429 sse
.ss_vibrato
.vib_depth
= e
->ss_vibrato
.vib_depth
;
430 sse
.ss_vibrato
.vib_freq
= e
->ss_vibrato
.vib_freq
;
435 case SONG_EV_SS_PORTAMENTO
:
437 sse
.ss_portamento
.portamento
= e
->ss_portamento
.portamento
;
442 case SONG_EV_SS_CHANNEL
:
444 sse
.ss_channel
.channel
= e
->ss_channel
.channel
;
445 sse
.ss_channel
.vol
= e
->ss_channel
.vol
;
448 if(*n_channels
< e
->ss_channel
.channel
)
449 *n_channels
= e
->ss_channel
.channel
;
454 case SONG_EV_SS_EFF_DELAY
:
455 case SONG_EV_SS_EFF_ECHO
:
456 case SONG_EV_SS_EFF_COMB
:
457 case SONG_EV_SS_EFF_ALLPASS
:
458 case SONG_EV_SS_EFF_FLANGER
:
459 case SONG_EV_SS_EFF_WOBBLE
:
460 case SONG_EV_SS_EFF_SQWOBBLE
:
461 case SONG_EV_SS_EFF_HFWOBBLE
:
462 case SONG_EV_SS_EFF_FADER
:
463 case SONG_EV_SS_EFF_REVERB
:
464 case SONG_EV_SS_EFF_FOLDBACK
:
465 case SONG_EV_SS_EFF_OFF
:
467 sse
.ss_eff
.channel
= e
->ss_eff
.channel
;
468 sse
.ss_eff
.size
= e
->ss_eff
.size
;
469 sse
.ss_eff
.gain
= e
->ss_eff
.gain
;
470 sse
.ss_eff
.depth
= e
->ss_eff
.depth
;
471 sse
.ss_eff
.freq
= e
->ss_eff
.freq
;
472 sse
.ss_eff
.phase
= e
->ss_eff
.phase
;
473 sse
.ss_eff
.initial
= e
->ss_eff
.initial
;
474 sse
.ss_eff
.final
= e
->ss_eff
.final
;
479 case SONG_EV_SONG_INFO
:
481 sse
.song_info
.author
= e
->song_info
.author
;
482 sse
.song_info
.name
= e
->song_info
.name
;
492 case SONG_EV_MIDI_CHANNEL
:
493 case SONG_EV_MIDI_PROGRAM
:
498 case SONG_EV_NOTE_ON
:
499 case SONG_EV_NOTE_OFF
:
502 /* never found in generic song streams */
506 /* store the further frame seen */
507 if(f_frame
< frame
) f_frame
= frame
;
510 /* generates an end of event mark, a time after the last one */
511 sse
.generic
.type
= SONG_EV_END
;
512 sse
.generic
.frame
= f_frame
+ ss_frequency
;
513 sse
.generic
.event_id
= -1;
517 qsort(ss_song
, n_ss_ev
, sizeof(union ss_ev
), ss_ev_cmp
);
524 static void ss_song_trace_events(void)
529 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
530 printf("%10s %5s %5s Event and information\n",
531 "Frame", "Track", "Ev.ID");
532 printf("------------------------------------------------------------\n");
534 for(n
= 0, e
= ss_song
;n
< n_ss_ev
;n
++, e
++)
536 printf("%10d %5d %5d ",
537 e
->generic
.frame
, e
->generic
.trk_id
, e
->generic
.event_id
);
539 switch(e
->generic
.type
)
543 printf("SONG_EV_TEMPO ");
544 printf("%lf", e
->tempo
.tempo
);
547 case SONG_EV_SS_SUSTAIN
:
549 printf("SONG_EV_SS_SUSTAIN ");
550 printf("SUSTAIN:%lf", e
->ss_sustain
.sustain
);
553 case SONG_EV_SS_ATTACK
:
555 printf("SONG_EV_SS_ATTACK ");
556 printf("ATTACK:%lf", e
->ss_attack
.attack
);
559 case SONG_EV_SS_VIBRATO
:
561 printf("SONG_EV_SS_VIBRATO ");
562 printf("DEPTH:%lf FREQ:%lf",
563 e
->ss_vibrato
.vib_depth
,
564 e
->ss_vibrato
.vib_freq
);
567 case SONG_EV_SS_PORTAMENTO
:
569 printf("SONG_EV_SS_PORTAMENTO ");
571 e
->ss_portamento
.portamento
);
574 case SONG_EV_SS_CHANNEL
:
576 printf("SONG_EV_SS_CHANNEL ");
577 printf("CHANNEL:%d VOL:%lf",
578 e
->ss_channel
.channel
,
584 printf("SONG_EV_SS_WAV ");
585 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
586 e
->ss_wav
.file
, e
->ss_wav
.base
,
587 e
->ss_wav
.min
, e
->ss_wav
.max
,
588 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
);
593 printf("SONG_EV_SS_PAT ");
594 printf("FILE:'%s'", e
->ss_pat
.file
);
597 case SONG_EV_SS_EFF_DELAY
:
599 printf("SONG_EV_SS_EFF_DELAY ");
600 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
601 printf("SIZE:%lf ", e
->ss_eff
.size
);
604 case SONG_EV_SS_EFF_ECHO
:
606 printf("SONG_EV_SS_EFF_ECHO ");
607 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
608 printf("SIZE:%lf ", e
->ss_eff
.size
);
609 printf("GAIN:%f ", e
->ss_eff
.gain
);
612 case SONG_EV_SS_EFF_COMB
:
614 printf("SONG_EV_SS_EFF_COMB ");
615 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
616 printf("SIZE:%lf ", e
->ss_eff
.size
);
617 printf("GAIN:%f ", e
->ss_eff
.gain
);
620 case SONG_EV_SS_EFF_ALLPASS
:
622 printf("SONG_EV_SS_EFF_ALLPASS ");
623 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
624 printf("SIZE:%lf ", e
->ss_eff
.size
);
625 printf("GAIN:%f ", e
->ss_eff
.gain
);
628 case SONG_EV_SS_EFF_FLANGER
:
630 printf("SONG_EV_SS_EFF_FLANGER ");
631 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
632 printf("SIZE:%lf ", e
->ss_eff
.size
);
633 printf("GAIN:%f ", e
->ss_eff
.gain
);
634 printf("DEPTH:%lf ", e
->ss_eff
.depth
);
635 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
639 case SONG_EV_SS_EFF_WOBBLE
:
641 printf("SONG_EV_SS_EFF_WOBBLE ");
642 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
643 printf("FREQ:%lf PHASE:%lf GAIN:%lf", e
->ss_eff
.freq
,
644 e
->ss_eff
.phase
, e
->ss_eff
.gain
);
647 case SONG_EV_SS_EFF_SQWOBBLE
:
649 printf("SONG_EV_SS_EFF_SQWOBBLE ");
650 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
651 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
655 case SONG_EV_SS_EFF_HFWOBBLE
:
657 printf("SONG_EV_SS_EFF_HFWOBBLE ");
658 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
659 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
663 case SONG_EV_SS_EFF_FADER
:
665 printf("SONG_EV_SS_EFF_FADER ");
666 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
667 printf("SIZE:%lf ", e
->ss_eff
.size
);
668 printf("INITIAL:%f FINAL:%f", e
->ss_eff
.initial
,
672 case SONG_EV_SS_EFF_REVERB
:
674 printf("SONG_EV_SS_EFF_REVERB ");
675 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
678 case SONG_EV_SS_EFF_OFF
:
680 printf("SONG_EV_SS_EFF_OFF ");
681 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
684 case SONG_EV_SS_PITCH_STRETCH
:
686 printf("SONG_EV_SS_PITCH_STRETCH ");
687 printf("MIDI:%d LEN:%lf VOL:%f",
688 e
->ss_pitch_stretch
.note
,
689 e
->ss_pitch_stretch
.len
,
690 e
->ss_pitch_stretch
.vol
);
694 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
696 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
697 printf("MIDI:%d LEN:%lf",
698 e
->ss_print_wave_tempo
.note
,
699 e
->ss_print_wave_tempo
.len
);
702 case SONG_EV_SONG_INFO
:
704 printf("SONG_EV_SONG_INFO ");
705 printf("AUTHOR:'%s' NAME:'%s'",
710 case SONG_EV_NOTE_ON
:
712 printf("SONG_EV_NOTE_ON ");
713 printf("ID:%d MIDI:%d VOL:%f",
714 e
->note_on
.note_id
, e
->note_on
.note
,
718 case SONG_EV_NOTE_OFF
:
720 printf("SONG_EV_NOTE_OFF ");
721 printf("ID:%d", e
->note_off
.note_id
);
726 printf("SONG_EV_EOT ");
731 printf("SONG_EV_END ");
735 printf("** Unexpected type: %d",
746 static union ss_ev
* process_this_frame_events(union ss_ev
* e
, int skip_frames
)
747 /* process the events attached to this frame */
749 static double tempo
= 120.0;
750 static int frame
= 0;
752 /* from the beginning? */
762 if(frame
% ss_frequency
== 0)
764 int m
= frame
/ ss_frequency
;
765 printf("[%02d:%02d]\r", m
/ 60, m
% 60);
770 while(e
!= NULL
&& e
->generic
.frame
== frame
)
776 if(e
->generic
.type
== SONG_EV_NOTE_ON
||
777 e
->generic
.type
== SONG_EV_NOTE_OFF
||
778 e
->generic
.type
== SONG_EV_SS_PITCH_STRETCH
)
780 if(frame
< skip_frames
)
783 frame
= e
->generic
.frame
;
788 /* take the instrument */
789 if(e
->generic
.trk_id
< 0)
792 i
= &ss_song_ins
[e
->generic
.trk_id
];
794 switch(e
->generic
.type
)
796 case SONG_EV_NOTE_ON
:
798 if(ss_ins_note_on(i
, e
->note_on
.note
,
799 e
->note_on
.vol
, e
->note_on
.note_id
) < 0 &&
801 printf("ss_ins_note_on error: track %d note %d\n",
802 e
->note_on
.trk_id
, e
->note_on
.note
);
806 case SONG_EV_NOTE_OFF
:
808 ss_ins_note_off(i
, e
->note_off
.note_id
);
812 case SONG_EV_SS_SUSTAIN
:
814 ss_ins_set_sustain(i
, e
->ss_sustain
.sustain
);
818 case SONG_EV_SS_ATTACK
:
820 ss_ins_set_attack(i
, e
->ss_attack
.attack
);
824 case SONG_EV_SS_VIBRATO
:
826 ss_ins_set_vibrato(i
, e
->ss_vibrato
.vib_depth
,
827 e
->ss_vibrato
.vib_freq
);
831 case SONG_EV_SS_PORTAMENTO
:
833 ss_ins_set_portamento(i
,
834 (e
->ss_portamento
.portamento
* 44100.0)
835 / ((double) ss_frequency
* 1000000.0));
839 case SONG_EV_SS_CHANNEL
:
841 ss_ins_set_channel(i
, e
->ss_channel
.channel
,
848 w
= ss_load_wav_file(e
->ss_wav
.file
,
849 ss_note_frequency(e
->ss_wav
.base
),
850 ss_note_frequency(e
->ss_wav
.min
),
851 ss_note_frequency(e
->ss_wav
.max
),
852 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
,
853 e
->ss_wav
.first_channel
, e
->ss_wav
.skip_channels
);
855 /* fail if can't open wav */
858 printf("Can't load wav '%s'\n", e
->ss_wav
.file
);
862 ss_ins_add_layer(i
, w
);
868 if(ss_load_pat_file(i
, e
->ss_pat
.file
) < 0)
870 printf("Can't load pat '%s'\n", e
->ss_pat
.file
);
876 case SONG_EV_SS_EFF_DELAY
:
878 ss_eff_delay(&i
->effs
[e
->ss_eff
.channel
], e
->ss_eff
.size
);
881 case SONG_EV_SS_EFF_ECHO
:
883 ss_eff_echo(&i
->effs
[e
->ss_eff
.channel
],
884 e
->ss_eff
.size
, e
->ss_eff
.gain
);
887 case SONG_EV_SS_EFF_COMB
:
889 ss_eff_comb(&i
->effs
[e
->ss_eff
.channel
],
890 e
->ss_eff
.size
, e
->ss_eff
.gain
);
893 case SONG_EV_SS_EFF_ALLPASS
:
895 ss_eff_allpass(&i
->effs
[e
->ss_eff
.channel
],
896 e
->ss_eff
.size
, e
->ss_eff
.gain
);
899 case SONG_EV_SS_EFF_FLANGER
:
901 ss_eff_flanger(&i
->effs
[e
->ss_eff
.channel
],
902 e
->ss_eff
.size
, e
->ss_eff
.gain
,
903 e
->ss_eff
.depth
, e
->ss_eff
.freq
,
907 case SONG_EV_SS_EFF_WOBBLE
:
909 ss_eff_wobble(&i
->effs
[e
->ss_eff
.channel
],
910 e
->ss_eff
.freq
, e
->ss_eff
.phase
,
915 case SONG_EV_SS_EFF_SQWOBBLE
:
917 ss_eff_square_wobble(&i
->effs
[e
->ss_eff
.channel
],
918 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
922 case SONG_EV_SS_EFF_HFWOBBLE
:
924 ss_eff_half_wobble(&i
->effs
[e
->ss_eff
.channel
],
925 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
929 case SONG_EV_SS_EFF_FADER
:
931 ss_eff_fader(&i
->effs
[e
->ss_eff
.channel
],
932 e
->ss_eff
.size
, e
->ss_eff
.initial
,
936 case SONG_EV_SS_EFF_REVERB
:
938 ss_eff_reverb(&i
->effs
[e
->ss_eff
.channel
]);
941 case SONG_EV_SS_EFF_FOLDBACK
:
943 ss_eff_foldback(&i
->effs
[e
->ss_eff
.channel
],
947 case SONG_EV_SS_EFF_OFF
:
949 ss_eff_off(&i
->effs
[e
->ss_eff
.channel
]);
954 /* just store the last tempo */
955 tempo
= e
->tempo
.tempo
;
958 case SONG_EV_SS_PITCH_STRETCH
:
961 freq
= ss_note_frequency(e
->ss_pitch_stretch
.note
);
962 w
= ss_ins_find_layer(i
, freq
, NULL
);
964 /* calculate optimal frequency */
965 freq
= ss_pitch_from_tempo(w
, tempo
,
966 e
->ss_pitch_stretch
.len
);
969 if(ss_ins_play(i
, freq
, e
->ss_pitch_stretch
.vol
,
970 e
->ss_pitch_stretch
.note_id
, w
) < 0 &&
972 printf("ss_ins_play error: track %d freq %f\n",
973 e
->ss_pitch_stretch
.trk_id
, freq
);
977 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
980 freq
= ss_note_frequency(e
->ss_print_wave_tempo
.note
);
981 w
= ss_ins_find_layer(i
, freq
, NULL
);
983 /* print the optimal tempo */
984 printf("Optimal tempo: %lf\n",
985 ss_tempo_from_wave(w
,
986 e
->ss_print_wave_tempo
.note
,
987 e
->ss_print_wave_tempo
.len
));
991 case SONG_EV_SONG_INFO
:
993 /* add a new song (track) */
994 cue_file_song_info(frame
, e
->song_info
.author
,
1000 /* end of track; trigger possible cleaning */
1010 case SONG_EV_MIDI_CHANNEL
:
1011 case SONG_EV_MIDI_PROGRAM
:
1014 case SONG_EV_MEASURE
:
1016 /* never found in ss song streams */
1030 int ss_song_render(int skip_secs
, char * driver
, char * devfile
)
1033 sample_t output
[SS_MAX_CHANNELS
];
1036 union ss_ev
* e
= NULL
;
1038 /* convert the song to ss events */
1039 ss_song_convert_events(&n_channels
);
1042 printf("Tracks: %d Channels: %d Events: %d\n",
1043 n_song_tracks
, n_channels
, n_ss_ev
);
1047 ss_song_trace_events();
1051 /* set the number of channels, unless forced */
1052 if(ss_nchannels
== -1)
1053 ss_nchannels
= n_channels
> 0 ? n_channels
: 2;
1055 if(ss_output_open(driver
, devfile
) < 0)
1057 printf("Error: can't init driver\n");
1061 /* init the generators */
1064 /* init the instruments */
1065 for(n
= 0;n
< n_song_tracks
;n
++)
1066 ss_ins_init(&ss_song_ins
[n
]);
1068 /* calculate the frame to start playing */
1069 skip_frames
= skip_secs
* ss_frequency
;
1074 /* process all events in this frame */
1075 /* if((e = process_this_frame_events(e, skip_frames)) == NULL)
1077 e
= process_this_frame_events(e
, skip_frames
);
1079 /* reset frame samples */
1080 ss_output_init_frame(output
);
1082 /* generate output from all instruments */
1083 for(n
= i
= 0;n
< n_song_tracks
;n
++)
1084 i
+= ss_ins_frame(&ss_song_ins
[n
], output
);
1086 /* dump to sampling driver */
1087 ss_output_write(output
);
1090 if(verbose
>= 1) printf("\n");