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_vibrato
78 song_ev_type type
; /* SONG_EV_SS_VIBRATO */
82 double vib_depth
; /* vibrato depth (in msecs) */
83 double vib_freq
; /* vibrato frequency (in Hzs) */
86 struct ss_ev_ss_portamento
88 song_ev_type type
; /* SONG_EV_SS_PORTAMENTO */
92 double portamento
; /* portamento */
95 struct ss_ev_ss_channel
97 song_ev_type type
; /* SONG_EV_SS_CHANNEL */
101 int channel
; /* channel */
102 sample_t vol
; /* volume */
107 song_ev_type type
; /* SONG_EV_SS_WAV */
111 char * file
; /* path to .wav file */
112 int base
; /* MIDI-like base note */
113 int min
; /* MIDI-like minimum note */
114 int max
; /* MIDI-like maximum note */
115 double loop_start
; /* loop start */
116 double loop_end
; /* loop end */
117 int first_channel
; /* first channel to start spreading */
118 int skip_channels
; /* channels to skip when spreading */
123 song_ev_type type
; /* SONG_EV_SS_PAT */
127 char * file
; /* path to .pat file */
132 song_ev_type type
; /* SONG_EV_TEMPO */
136 double tempo
; /* tempo in bmp */
139 struct ss_ev_pitch_stretch
141 song_ev_type type
; /* SONG_EV_SS_PITCH_STRETCH */
145 int note_id
; /* note id */
146 int note
; /* MIDI-like note (to find the wave) */
147 double len
; /* note length (1: whole note) */
148 sample_t vol
; /* note volume (1: full volume) */
151 struct ss_ev_print_wave_tempo
153 song_ev_type type
; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
157 int note_id
; /* note id */
158 int note
; /* MIDI-like note (to find the wave) */
159 double len
; /* note length (1: whole note) */
164 song_ev_type type
; /* effect type */
168 int channel
; /* channel */
169 double size
; /* size of effect */
170 sample_t gain
; /* gain */
171 double depth
; /* depth */
172 double freq
; /* freq */
173 double phase
; /* phase */
174 sample_t initial
; /* initial vol */
175 sample_t final
; /* final vol */
178 struct ss_ev_song_info
180 song_ev_type type
; /* SONG_EV_SONG_INFO */
184 char * author
; /* track author */
185 char * name
; /* track name */
190 struct ss_ev_generic generic
;
191 struct ss_ev_note_on note_on
;
192 struct ss_ev_note_off note_off
;
193 struct ss_ev_ss_sustain ss_sustain
;
194 struct ss_ev_ss_vibrato ss_vibrato
;
195 struct ss_ev_ss_portamento ss_portamento
;
196 struct ss_ev_ss_channel ss_channel
;
197 struct ss_ev_ss_wav ss_wav
;
198 struct ss_ev_ss_pat ss_pat
;
199 struct ss_ev_ss_eff ss_eff
;
200 struct ss_ev_tempo tempo
;
201 struct ss_ev_pitch_stretch ss_pitch_stretch
;
202 struct ss_ev_print_wave_tempo ss_print_wave_tempo
;
203 struct ss_ev_song_info song_info
;
206 /* the softsynth song stream */
208 static union ss_ev
* ss_song
= NULL
;
209 static int n_ss_ev
= 0;
212 /* the instruments */
214 struct ss_ins ss_song_ins
[SS_MAX_INSTRUMENTS
];
218 ********************/
220 static void add_ss_ev(union ss_ev
* e
)
221 /* adds a softsynth song event */
223 GROW(ss_song
, n_ss_ev
, union ss_ev
);
226 memcpy(&ss_song
[n_ss_ev
], e
, sizeof(union ss_ev
));
232 static int ss_ev_cmp(const void * v1
, const void * v2
)
233 /* softsynth song event compare function for qsort() */
235 struct ss_ev_generic
* e1
;
236 struct ss_ev_generic
* e2
;
239 e1
= (struct ss_ev_generic
*)v1
; e2
= (struct ss_ev_generic
*)v2
;
241 ret
= e1
->frame
- e2
->frame
;
244 ret
= e1
->type
- e2
->type
;
247 ret
= e1
->event_id
- e2
->event_id
;
253 static void ss_song_convert_events(int * n_tracks
, int * n_channels
)
254 /* converts generic song_ev events to softsynth events */
259 int frame
, frame_ac
, f_frame
;
260 double fpw
, time_ac
, time_ac_m
;
267 /* resets the ss stream */
280 frame
= frame_ac
= f_frame
= 0;
281 time_ac
= time_ac_m
= 0;
284 /* travels the song events generating softsynth song events */
285 for(n
= 0;n
< n_song_ev
;n
++)
287 /* gets the song event */
290 /* calculates the frame */
291 frame
= ((e
->generic
.time
- time_ac
) * fpw
) + frame_ac
;
293 /* generic event data */
294 sse
.generic
.type
= e
->generic
.type
;
295 sse
.generic
.frame
= frame
;
296 sse
.generic
.trk_id
= e
->generic
.trk_id
;
297 sse
.generic
.event_id
= e
->generic
.event_id
;
299 /* account the biggest track seen */
300 if(*n_tracks
< e
->generic
.trk_id
) *n_tracks
= e
->generic
.trk_id
;
302 switch(e
->generic
.type
)
306 /* updates accumulations */
308 time_ac
= e
->generic
.time
;
310 /* calculates frames-per-whole based on new tempo */
311 fpw
= (double) ss_frequency
* 60.0;
312 fpw
/= e
->tempo
.tempo
/ 4.0;
315 sse
.tempo
.tempo
= e
->tempo
.tempo
;
322 /* just store the values */
325 time_ac_m
= e
->meter
.time
;
329 case SONG_EV_MEASURE
:
331 song_test_measure_boundary(e
->measure
.time
- time_ac_m
,
332 num
, den
, e
->measure
.line
);
337 /* convert to note on / off pairs */
339 sse
.note_on
.type
= SONG_EV_NOTE_ON
;
340 sse
.note_on
.note_id
= note_id
++;
341 sse
.note_on
.note
= e
->note
.note
;
342 sse
.note_on
.vol
= e
->note
.vol
;
346 frame
+= (int)(e
->note
.len
* fpw
);
348 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
349 sse
.note_off
.frame
= frame
;
356 /* move the cursor back */
358 frame_ac
-= (int)(e
->back
.len
* fpw
);
362 case SONG_EV_SS_PITCH_STRETCH
:
364 sse
.ss_pitch_stretch
.note_id
= note_id
++;
365 sse
.ss_pitch_stretch
.note
= e
->ss_pitch_stretch
.note
;
366 sse
.ss_pitch_stretch
.len
= e
->ss_pitch_stretch
.len
;
367 sse
.ss_pitch_stretch
.vol
= e
->ss_pitch_stretch
.vol
;
371 frame
+= (int)(e
->ss_pitch_stretch
.len
* fpw
);
373 sse
.note_off
.type
= SONG_EV_NOTE_OFF
;
374 sse
.note_off
.frame
= frame
;
379 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
381 sse
.ss_print_wave_tempo
.note
= e
->ss_print_wave_tempo
.note
;
382 sse
.ss_print_wave_tempo
.len
= e
->ss_print_wave_tempo
.len
;
389 sse
.ss_wav
.file
= e
->ss_wav
.file
;
390 sse
.ss_wav
.base
= e
->ss_wav
.base
;
391 sse
.ss_wav
.min
= e
->ss_wav
.min
;
392 sse
.ss_wav
.max
= e
->ss_wav
.max
;
393 sse
.ss_wav
.loop_start
= e
->ss_wav
.loop_start
;
394 sse
.ss_wav
.loop_end
= e
->ss_wav
.loop_end
;
395 sse
.ss_wav
.first_channel
= e
->ss_wav
.first_channel
;
396 sse
.ss_wav
.skip_channels
= e
->ss_wav
.skip_channels
;
403 sse
.ss_pat
.file
= e
->ss_pat
.file
;
408 case SONG_EV_SS_SUSTAIN
:
410 sse
.ss_sustain
.sustain
= e
->ss_sustain
.sustain
;
415 case SONG_EV_SS_VIBRATO
:
417 sse
.ss_vibrato
.vib_depth
= e
->ss_vibrato
.vib_depth
;
418 sse
.ss_vibrato
.vib_freq
= e
->ss_vibrato
.vib_freq
;
423 case SONG_EV_SS_PORTAMENTO
:
425 sse
.ss_portamento
.portamento
= e
->ss_portamento
.portamento
;
430 case SONG_EV_SS_CHANNEL
:
432 sse
.ss_channel
.channel
= e
->ss_channel
.channel
;
433 sse
.ss_channel
.vol
= e
->ss_channel
.vol
;
436 if(*n_channels
< e
->ss_channel
.channel
)
437 *n_channels
= e
->ss_channel
.channel
;
442 case SONG_EV_SS_EFF_DELAY
:
443 case SONG_EV_SS_EFF_ECHO
:
444 case SONG_EV_SS_EFF_COMB
:
445 case SONG_EV_SS_EFF_ALLPASS
:
446 case SONG_EV_SS_EFF_FLANGER
:
447 case SONG_EV_SS_EFF_WOBBLE
:
448 case SONG_EV_SS_EFF_SQWOBBLE
:
449 case SONG_EV_SS_EFF_HFWOBBLE
:
450 case SONG_EV_SS_EFF_FADER
:
451 case SONG_EV_SS_EFF_REVERB
:
452 case SONG_EV_SS_EFF_FOLDBACK
:
453 case SONG_EV_SS_EFF_OFF
:
455 sse
.ss_eff
.channel
= e
->ss_eff
.channel
;
456 sse
.ss_eff
.size
= e
->ss_eff
.size
;
457 sse
.ss_eff
.gain
= e
->ss_eff
.gain
;
458 sse
.ss_eff
.depth
= e
->ss_eff
.depth
;
459 sse
.ss_eff
.freq
= e
->ss_eff
.freq
;
460 sse
.ss_eff
.phase
= e
->ss_eff
.phase
;
461 sse
.ss_eff
.initial
= e
->ss_eff
.initial
;
462 sse
.ss_eff
.final
= e
->ss_eff
.final
;
467 case SONG_EV_SONG_INFO
:
469 sse
.song_info
.author
= e
->song_info
.author
;
470 sse
.song_info
.name
= e
->song_info
.name
;
475 case SONG_EV_MIDI_CHANNEL
:
476 case SONG_EV_MIDI_PROGRAM
:
481 case SONG_EV_NOTE_ON
:
482 case SONG_EV_NOTE_OFF
:
485 /* never found in generic song streams */
489 /* store the further frame seen */
490 if(f_frame
< frame
) f_frame
= frame
;
493 /* generates an end of event mark, a time after the last one */
494 sse
.generic
.type
= SONG_EV_END
;
495 sse
.generic
.frame
= f_frame
+ ss_frequency
;
496 sse
.generic
.event_id
= -1;
500 qsort(ss_song
, n_ss_ev
, sizeof(union ss_ev
), ss_ev_cmp
);
508 static void ss_song_trace_events(void)
513 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
514 printf("%10s %5s %5s Event and information\n",
515 "Frame", "Track", "Ev.ID");
516 printf("------------------------------------------------------------\n");
518 for(n
= 0, e
= ss_song
;n
< n_ss_ev
;n
++, e
++)
520 printf("%10d %5d %5d ",
521 e
->generic
.frame
, e
->generic
.trk_id
, e
->generic
.event_id
);
523 switch(e
->generic
.type
)
527 printf("SONG_EV_TEMPO ");
528 printf("%lf", e
->tempo
.tempo
);
531 case SONG_EV_SS_SUSTAIN
:
533 printf("SONG_EV_SS_SUSTAIN ");
534 printf("SUSTAIN:%lf", e
->ss_sustain
.sustain
);
537 case SONG_EV_SS_VIBRATO
:
539 printf("SONG_EV_SS_VIBRATO ");
540 printf("DEPTH:%lf FREQ:%lf",
541 e
->ss_vibrato
.vib_depth
,
542 e
->ss_vibrato
.vib_freq
);
545 case SONG_EV_SS_PORTAMENTO
:
547 printf("SONG_EV_SS_PORTAMENTO ");
549 e
->ss_portamento
.portamento
);
552 case SONG_EV_SS_CHANNEL
:
554 printf("SONG_EV_SS_CHANNEL ");
555 printf("CHANNEL:%d VOL:%lf",
556 e
->ss_channel
.channel
,
562 printf("SONG_EV_SS_WAV ");
563 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
564 e
->ss_wav
.file
, e
->ss_wav
.base
,
565 e
->ss_wav
.min
, e
->ss_wav
.max
,
566 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
);
571 printf("SONG_EV_SS_PAT ");
572 printf("FILE:'%s'", e
->ss_pat
.file
);
575 case SONG_EV_SS_EFF_DELAY
:
577 printf("SONG_EV_SS_EFF_DELAY ");
578 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
579 printf("SIZE:%lf ", e
->ss_eff
.size
);
582 case SONG_EV_SS_EFF_ECHO
:
584 printf("SONG_EV_SS_EFF_ECHO ");
585 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
586 printf("SIZE:%lf ", e
->ss_eff
.size
);
587 printf("GAIN:%f ", e
->ss_eff
.gain
);
590 case SONG_EV_SS_EFF_COMB
:
592 printf("SONG_EV_SS_EFF_COMB ");
593 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
594 printf("SIZE:%lf ", e
->ss_eff
.size
);
595 printf("GAIN:%f ", e
->ss_eff
.gain
);
598 case SONG_EV_SS_EFF_ALLPASS
:
600 printf("SONG_EV_SS_EFF_ALLPASS ");
601 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
602 printf("SIZE:%lf ", e
->ss_eff
.size
);
603 printf("GAIN:%f ", e
->ss_eff
.gain
);
606 case SONG_EV_SS_EFF_FLANGER
:
608 printf("SONG_EV_SS_EFF_FLANGER ");
609 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
610 printf("SIZE:%lf ", e
->ss_eff
.size
);
611 printf("GAIN:%f ", e
->ss_eff
.gain
);
612 printf("DEPTH:%lf ", e
->ss_eff
.depth
);
613 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
617 case SONG_EV_SS_EFF_WOBBLE
:
619 printf("SONG_EV_SS_EFF_WOBBLE ");
620 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
621 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
625 case SONG_EV_SS_EFF_SQWOBBLE
:
627 printf("SONG_EV_SS_EFF_SQWOBBLE ");
628 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
629 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
633 case SONG_EV_SS_EFF_HFWOBBLE
:
635 printf("SONG_EV_SS_EFF_HFWOBBLE ");
636 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
637 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
641 case SONG_EV_SS_EFF_FADER
:
643 printf("SONG_EV_SS_EFF_FADER ");
644 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
645 printf("SIZE:%lf ", e
->ss_eff
.size
);
646 printf("INITIAL:%f FINAL:%f", e
->ss_eff
.initial
,
650 case SONG_EV_SS_EFF_REVERB
:
652 printf("SONG_EV_SS_EFF_REVERB ");
653 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
656 case SONG_EV_SS_EFF_OFF
:
658 printf("SONG_EV_SS_EFF_OFF ");
659 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
662 case SONG_EV_SS_PITCH_STRETCH
:
664 printf("SONG_EV_SS_PITCH_STRETCH ");
665 printf("MIDI:%d LEN:%lf VOL:%f",
666 e
->ss_pitch_stretch
.note
,
667 e
->ss_pitch_stretch
.len
,
668 e
->ss_pitch_stretch
.vol
);
672 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
674 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
675 printf("MIDI:%d LEN:%lf",
676 e
->ss_print_wave_tempo
.note
,
677 e
->ss_print_wave_tempo
.len
);
680 case SONG_EV_SONG_INFO
:
682 printf("SONG_EV_SONG_INFO ");
683 printf("AUTHOR:'%s' NAME:'%s'",
688 case SONG_EV_NOTE_ON
:
690 printf("SONG_EV_NOTE_ON ");
691 printf("ID:%d MIDI:%d VOL:%f",
692 e
->note_on
.note_id
, e
->note_on
.note
,
696 case SONG_EV_NOTE_OFF
:
698 printf("SONG_EV_NOTE_OFF ");
699 printf("ID:%d", e
->note_off
.note_id
);
704 printf("SONG_EV_END ");
708 printf("** Unexpected type: %d",
719 static int process_this_frame_events(int skip_frames
)
720 /* process the events attached to this frame */
722 static union ss_ev
* e
= NULL
;
723 static double tempo
= 120.0;
724 static int frame
= 0;
727 /* from the beginning? */
737 if(frame
% ss_frequency
== 0)
739 int m
= frame
/ ss_frequency
;
740 printf("[%02d:%02d]\r", m
/ 60, m
% 60);
745 while(!nomore
&& e
->generic
.frame
== frame
)
751 if(e
->generic
.type
== SONG_EV_NOTE_ON
||
752 e
->generic
.type
== SONG_EV_NOTE_OFF
||
753 e
->generic
.type
== SONG_EV_SS_PITCH_STRETCH
)
755 if(frame
< skip_frames
)
758 frame
= e
->generic
.frame
;
763 /* take the instrument */
764 if(e
->generic
.trk_id
< 0)
767 i
= &ss_song_ins
[e
->generic
.trk_id
];
769 switch(e
->generic
.type
)
771 case SONG_EV_NOTE_ON
:
773 ss_ins_note_on(i
, e
->note_on
.note
,
774 e
->note_on
.vol
, e
->note_on
.note_id
);
778 case SONG_EV_NOTE_OFF
:
780 ss_ins_note_off(i
, e
->note_off
.note_id
);
784 case SONG_EV_SS_SUSTAIN
:
786 ss_ins_set_sustain(i
, e
->ss_sustain
.sustain
);
790 case SONG_EV_SS_VIBRATO
:
792 ss_ins_set_vibrato(i
, e
->ss_vibrato
.vib_depth
,
793 e
->ss_vibrato
.vib_freq
);
797 case SONG_EV_SS_PORTAMENTO
:
799 ss_ins_set_portamento(i
,
800 (e
->ss_portamento
.portamento
* 44100.0)
801 / ((double) ss_frequency
* 1000000.0));
805 case SONG_EV_SS_CHANNEL
:
807 ss_ins_set_channel(i
, e
->ss_channel
.channel
,
814 w
= ss_load_wav_file(e
->ss_wav
.file
,
815 ss_note_frequency(e
->ss_wav
.base
),
816 ss_note_frequency(e
->ss_wav
.min
),
817 ss_note_frequency(e
->ss_wav
.max
),
818 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
,
819 e
->ss_wav
.first_channel
, e
->ss_wav
.skip_channels
);
821 /* fail if can't open wav */
824 printf("Can't load wav '%s'\n", e
->ss_wav
.file
);
828 ss_ins_add_layer(i
, w
);
834 if(ss_load_pat_file(i
, e
->ss_pat
.file
) < 0)
836 printf("Can't load pat '%s'\n", e
->ss_pat
.file
);
842 case SONG_EV_SS_EFF_DELAY
:
844 ss_eff_delay(&i
->effs
[e
->ss_eff
.channel
], e
->ss_eff
.size
);
847 case SONG_EV_SS_EFF_ECHO
:
849 ss_eff_echo(&i
->effs
[e
->ss_eff
.channel
],
850 e
->ss_eff
.size
, e
->ss_eff
.gain
);
853 case SONG_EV_SS_EFF_COMB
:
855 ss_eff_comb(&i
->effs
[e
->ss_eff
.channel
],
856 e
->ss_eff
.size
, e
->ss_eff
.gain
);
859 case SONG_EV_SS_EFF_ALLPASS
:
861 ss_eff_allpass(&i
->effs
[e
->ss_eff
.channel
],
862 e
->ss_eff
.size
, e
->ss_eff
.gain
);
865 case SONG_EV_SS_EFF_FLANGER
:
867 ss_eff_flanger(&i
->effs
[e
->ss_eff
.channel
],
868 e
->ss_eff
.size
, e
->ss_eff
.gain
,
869 e
->ss_eff
.depth
, e
->ss_eff
.freq
,
873 case SONG_EV_SS_EFF_WOBBLE
:
875 ss_eff_wobble(&i
->effs
[e
->ss_eff
.channel
],
876 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
880 case SONG_EV_SS_EFF_SQWOBBLE
:
882 ss_eff_square_wobble(&i
->effs
[e
->ss_eff
.channel
],
883 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
887 case SONG_EV_SS_EFF_HFWOBBLE
:
889 ss_eff_half_wobble(&i
->effs
[e
->ss_eff
.channel
],
890 e
->ss_eff
.freq
, e
->ss_eff
.phase
);
894 case SONG_EV_SS_EFF_FADER
:
896 ss_eff_fader(&i
->effs
[e
->ss_eff
.channel
],
897 e
->ss_eff
.size
, e
->ss_eff
.initial
,
901 case SONG_EV_SS_EFF_REVERB
:
903 ss_eff_reverb(&i
->effs
[e
->ss_eff
.channel
]);
906 case SONG_EV_SS_EFF_FOLDBACK
:
908 ss_eff_foldback(&i
->effs
[e
->ss_eff
.channel
],
912 case SONG_EV_SS_EFF_OFF
:
914 ss_eff_off(&i
->effs
[e
->ss_eff
.channel
]);
919 /* just store the last tempo */
920 tempo
= e
->tempo
.tempo
;
923 case SONG_EV_SS_PITCH_STRETCH
:
926 freq
= ss_note_frequency(e
->ss_pitch_stretch
.note
);
927 w
= ss_ins_find_layer(i
, freq
, NULL
);
929 /* calculate optimal frequency */
930 freq
= ss_pitch_from_tempo(w
, tempo
,
931 e
->ss_pitch_stretch
.len
);
934 ss_ins_play(i
, freq
, e
->ss_pitch_stretch
.vol
,
935 e
->ss_pitch_stretch
.note_id
, w
);
939 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
942 freq
= ss_note_frequency(e
->ss_print_wave_tempo
.note
);
943 w
= ss_ins_find_layer(i
, freq
, NULL
);
945 /* print the optimal tempo */
946 printf("Optimal tempo: %lf\n",
947 ss_tempo_from_wave(w
,
948 e
->ss_print_wave_tempo
.note
,
949 e
->ss_print_wave_tempo
.len
));
953 case SONG_EV_SONG_INFO
:
955 /* add a new song (track) */
956 cue_file_song_info(frame
, e
->song_info
.author
,
966 case SONG_EV_MIDI_CHANNEL
:
967 case SONG_EV_MIDI_PROGRAM
:
970 case SONG_EV_MEASURE
:
972 /* never found in ss song streams */
989 int ss_song_render(int skip_secs
, char * driver
, char * devfile
)
992 sample_t output
[SS_MAX_CHANNELS
];
997 /* convert the song to ss events */
998 ss_song_convert_events(&n_tracks
, &n_channels
);
1001 printf("Tracks: %d Channels: %d Events: %d\n",
1002 n_tracks
, n_channels
, n_ss_ev
);
1006 ss_song_trace_events();
1010 /* set the number of channels, unless forced */
1011 if(ss_nchannels
== -1)
1012 ss_nchannels
= n_channels
> 0 ? n_channels
: 2;
1014 if(ss_output_open(driver
, devfile
) < 0)
1016 printf("Error: can't init driver\n");
1020 /* init the generators */
1023 /* init the instruments */
1024 for(n
= 0;n
< n_tracks
;n
++)
1025 ss_ins_init(&ss_song_ins
[n
]);
1027 /* calculate the frame to start playing */
1028 skip_frames
= skip_secs
* ss_frequency
;
1033 /* process all events in this frame */
1034 if(process_this_frame_events(skip_frames
))
1037 /* reset frame samples */
1038 ss_output_init_frame(output
);
1040 /* generate output from all instruments */
1041 for(n
= 0;n
< n_tracks
;n
++)
1042 ss_ins_frame(&ss_song_ins
[n
], output
);
1044 /* dump to sampling driver */
1045 ss_output_write(output
);
1048 if(verbose
>= 1) printf("\n");