Samples are internally stored in the -1..1 range instead of -32768..32767
[ahxm.git] / ss_song.c
bloba3244562e3c3216315b543b520ca4f5448634f9b
1 /*
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
26 #include "config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <math.h>
33 #include "annhell.h"
35 /*******************
36 Data
37 ********************/
39 struct ss_ev_generic
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 */
47 struct ss_ev_note_off
49 song_ev_type type; /* SONG_EV_NOTE_OFF */
50 int frame;
51 int trk_id;
52 int event_id;
53 int note_id; /* note id */
56 struct ss_ev_note_on
58 song_ev_type type; /* SONG_EV_NOTE_ON */
59 int frame;
60 int trk_id;
61 int event_id;
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 */
70 int frame;
71 int trk_id;
72 int event_id;
73 double sustain; /* sustain time (in frames) */
76 struct ss_ev_ss_vibrato
78 song_ev_type type; /* SONG_EV_SS_VIBRATO */
79 int frame;
80 int trk_id;
81 int event_id;
82 double vib_depth; /* vibrato depth (in msecs) */
83 double vib_freq; /* vibrato frequency (in Hzs) */
86 struct ss_ev_ss_channel
88 song_ev_type type; /* SONG_EV_SS_CHANNEL */
89 int frame;
90 int trk_id;
91 int event_id;
92 int channel; /* channel */
93 sample_t vol; /* volume */
96 struct ss_ev_ss_wav
98 song_ev_type type; /* SONG_EV_SS_WAV */
99 int frame;
100 int trk_id;
101 int event_id;
102 char * file; /* path to .wav file */
103 int base; /* MIDI-like base note */
104 int min; /* MIDI-like minimum note */
105 int max; /* MIDI-like maximum note */
106 double loop_start; /* loop start */
107 double loop_end; /* loop end */
108 int first_channel; /* first channel to start spreading */
109 int skip_channels; /* channels to skip when spreading */
112 struct ss_ev_ss_pat
114 song_ev_type type; /* SONG_EV_SS_PAT */
115 int frame;
116 int trk_id;
117 int event_id;
118 char * file; /* path to .pat file */
121 struct ss_ev_tempo
123 song_ev_type type; /* SONG_EV_TEMPO */
124 int frame;
125 int trk_id;
126 int event_id;
127 double tempo; /* tempo in bmp */
130 struct ss_ev_pitch_stretch
132 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
133 int frame;
134 int trk_id;
135 int event_id;
136 int note_id; /* note id */
137 int note; /* MIDI-like note (to find the wave) */
138 double len; /* note length (1: whole note) */
139 sample_t vol; /* note volume (1: full volume) */
142 struct ss_ev_print_wave_tempo
144 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
145 int frame;
146 int trk_id;
147 int event_id;
148 int note_id; /* note id */
149 int note; /* MIDI-like note (to find the wave) */
150 double len; /* note length (1: whole note) */
153 struct ss_ev_ss_eff
155 song_ev_type type; /* effect type */
156 int frame;
157 int trk_id;
158 int event_id;
159 int channel; /* channel */
160 double size; /* size of effect */
161 sample_t gain; /* gain */
162 double depth; /* depth */
163 double freq; /* freq */
164 double phase; /* phase */
165 sample_t initial; /* initial vol */
166 sample_t final; /* final vol */
169 struct ss_ev_song_info
171 song_ev_type type; /* SONG_EV_SONG_INFO */
172 int frame;
173 int trk_id;
174 int event_id;
175 char * author; /* track author */
176 char * name; /* track name */
179 union ss_ev
181 struct ss_ev_generic generic;
182 struct ss_ev_note_on note_on;
183 struct ss_ev_note_off note_off;
184 struct ss_ev_ss_sustain ss_sustain;
185 struct ss_ev_ss_vibrato ss_vibrato;
186 struct ss_ev_ss_channel ss_channel;
187 struct ss_ev_ss_wav ss_wav;
188 struct ss_ev_ss_pat ss_pat;
189 struct ss_ev_ss_eff ss_eff;
190 struct ss_ev_tempo tempo;
191 struct ss_ev_pitch_stretch ss_pitch_stretch;
192 struct ss_ev_print_wave_tempo ss_print_wave_tempo;
193 struct ss_ev_song_info song_info;
196 /* the softsynth song stream */
198 static union ss_ev * ss_song = NULL;
199 static int n_ss_ev = 0;
202 /* the instruments */
204 struct ss_ins ss_song_ins[SS_MAX_INSTRUMENTS];
206 /*******************
207 Code
208 ********************/
210 static void add_ss_ev(union ss_ev * e)
211 /* adds a softsynth song event */
213 GROW(ss_song, n_ss_ev, union ss_ev);
215 /* store */
216 memcpy(&ss_song[n_ss_ev], e, sizeof(union ss_ev));
218 n_ss_ev++;
222 static int ss_ev_cmp(const void * v1, const void * v2)
223 /* softsynth song event compare function for qsort() */
225 struct ss_ev_generic * e1;
226 struct ss_ev_generic * e2;
227 int ret;
229 e1 = (struct ss_ev_generic *)v1; e2 = (struct ss_ev_generic *)v2;
231 ret = e1->frame - e2->frame;
233 if(ret == 0)
234 ret = e1->type - e2->type;
236 if(ret == 0)
237 ret = e1->event_id - e2->event_id;
239 return(ret);
243 static void ss_song_convert_events(int * n_tracks, int * n_channels)
244 /* converts generic song_ev events to softsynth events */
246 int note_id = 1;
247 union song_ev * e;
248 union ss_ev sse;
249 int frame, frame_ac, f_frame;
250 double fpw, time_ac, time_ac_m;
251 int num, den;
252 int n;
254 *n_tracks = -1;
255 *n_channels = -1;
257 /* resets the ss stream */
258 if(ss_song != NULL)
260 free(ss_song);
261 ss_song = NULL;
264 n_ss_ev = 0;
266 /* sorts the song */
267 song_sort();
269 fpw = 0;
270 frame = frame_ac = f_frame = 0;
271 time_ac = time_ac_m = 0;
272 num = den = 4;
274 /* travels the song events generating softsynth song events */
275 for(n = 0;n < n_song_ev;n++)
277 /* gets the song event */
278 e = &song[n];
280 /* calculates the frame */
281 frame = ((e->generic.time - time_ac) * fpw) + frame_ac;
283 /* generic event data */
284 sse.generic.type = e->generic.type;
285 sse.generic.frame = frame;
286 sse.generic.trk_id = e->generic.trk_id;
287 sse.generic.event_id = e->generic.event_id;
289 /* account the biggest track seen */
290 if(*n_tracks < e->generic.trk_id) *n_tracks = e->generic.trk_id;
292 switch(e->generic.type)
294 case SONG_EV_TEMPO:
296 /* updates accumulations */
297 frame_ac = frame;
298 time_ac = e->generic.time;
300 /* calculates frames-per-whole based on new tempo */
301 fpw = (double) ss_frequency * 60.0;
302 fpw /= e->tempo.tempo / 4.0;
304 /* adds an event */
305 sse.tempo.tempo = e->tempo.tempo;
306 add_ss_ev(&sse);
308 break;
310 case SONG_EV_METER:
312 /* just store the values */
313 num = e->meter.num;
314 den = e->meter.den;
315 time_ac_m = e->meter.time;
317 break;
319 case SONG_EV_MEASURE:
321 song_test_measure_boundary(e->measure.time - time_ac_m,
322 num, den, e->measure.line);
323 break;
325 case SONG_EV_NOTE:
327 /* convert to note on / off pairs */
329 sse.note_on.type = SONG_EV_NOTE_ON;
330 sse.note_on.note_id = note_id++;
331 sse.note_on.note = e->note.note;
332 sse.note_on.vol = e->note.vol;
334 add_ss_ev(&sse);
336 frame += (int)(e->note.len * fpw);
338 sse.note_off.type = SONG_EV_NOTE_OFF;
339 sse.note_off.frame = frame;
341 add_ss_ev(&sse);
342 break;
344 case SONG_EV_BACK:
346 /* move the cursor back */
348 frame_ac -= (int)(e->back.len * fpw);
350 break;
352 case SONG_EV_SS_PITCH_STRETCH:
354 sse.ss_pitch_stretch.note_id = note_id++;
355 sse.ss_pitch_stretch.note = e->ss_pitch_stretch.note;
356 sse.ss_pitch_stretch.len = e->ss_pitch_stretch.len;
357 sse.ss_pitch_stretch.vol = e->ss_pitch_stretch.vol;
359 add_ss_ev(&sse);
361 frame += (int)(e->ss_pitch_stretch.len * fpw);
363 sse.note_off.type = SONG_EV_NOTE_OFF;
364 sse.note_off.frame = frame;
366 add_ss_ev(&sse);
367 break;
369 case SONG_EV_SS_PRINT_WAVE_TEMPO:
371 sse.ss_print_wave_tempo.note = e->ss_print_wave_tempo.note;
372 sse.ss_print_wave_tempo.len = e->ss_print_wave_tempo.len;
374 add_ss_ev(&sse);
375 break;
377 case SONG_EV_SS_WAV:
379 sse.ss_wav.file = e->ss_wav.file;
380 sse.ss_wav.base = e->ss_wav.base;
381 sse.ss_wav.min = e->ss_wav.min;
382 sse.ss_wav.max = e->ss_wav.max;
383 sse.ss_wav.loop_start = e->ss_wav.loop_start;
384 sse.ss_wav.loop_end = e->ss_wav.loop_end;
385 sse.ss_wav.first_channel = e->ss_wav.first_channel;
386 sse.ss_wav.skip_channels = e->ss_wav.skip_channels;
388 add_ss_ev(&sse);
389 break;
391 case SONG_EV_SS_PAT:
393 sse.ss_pat.file = e->ss_pat.file;
395 add_ss_ev(&sse);
396 break;
398 case SONG_EV_SS_SUSTAIN:
400 sse.ss_sustain.sustain = e->ss_sustain.sustain;
402 add_ss_ev(&sse);
403 break;
405 case SONG_EV_SS_VIBRATO:
407 sse.ss_vibrato.vib_depth = e->ss_vibrato.vib_depth;
408 sse.ss_vibrato.vib_freq = e->ss_vibrato.vib_freq;
410 add_ss_ev(&sse);
411 break;
413 case SONG_EV_SS_CHANNEL:
415 sse.ss_channel.channel = e->ss_channel.channel;
416 sse.ss_channel.vol = e->ss_channel.vol;
418 /* count channels */
419 if(*n_channels < e->ss_channel.channel)
420 *n_channels = e->ss_channel.channel;
422 add_ss_ev(&sse);
423 break;
425 case SONG_EV_SS_EFF_DELAY:
426 case SONG_EV_SS_EFF_ECHO:
427 case SONG_EV_SS_EFF_COMB:
428 case SONG_EV_SS_EFF_ALLPASS:
429 case SONG_EV_SS_EFF_FLANGER:
430 case SONG_EV_SS_EFF_WOBBLE:
431 case SONG_EV_SS_EFF_SQWOBBLE:
432 case SONG_EV_SS_EFF_FADER:
433 case SONG_EV_SS_EFF_REVERB:
434 case SONG_EV_SS_EFF_OFF:
436 sse.ss_eff.channel = e->ss_eff.channel;
437 sse.ss_eff.size = e->ss_eff.size;
438 sse.ss_eff.gain = e->ss_eff.gain;
439 sse.ss_eff.depth = e->ss_eff.depth;
440 sse.ss_eff.freq = e->ss_eff.freq;
441 sse.ss_eff.phase = e->ss_eff.phase;
442 sse.ss_eff.initial = e->ss_eff.initial;
443 sse.ss_eff.final = e->ss_eff.final;
445 add_ss_ev(&sse);
446 break;
448 case SONG_EV_SONG_INFO:
450 sse.song_info.author = e->song_info.author;
451 sse.song_info.name = e->song_info.name;
453 add_ss_ev(&sse);
454 break;
456 case SONG_EV_MIDI_CHANNEL:
457 case SONG_EV_MIDI_PROGRAM:
459 /* ignored */
460 break;
462 case SONG_EV_NOTE_ON:
463 case SONG_EV_NOTE_OFF:
464 case SONG_EV_END:
466 /* never found in generic song streams */
467 break;
470 /* store the further frame seen */
471 if(f_frame < frame) f_frame = frame;
474 /* generates an end of event mark, a time after the last one */
475 sse.generic.type = SONG_EV_END;
476 sse.generic.frame = f_frame + ss_frequency;
477 sse.generic.event_id = -1;
478 add_ss_ev(&sse);
480 /* finally sort */
481 qsort(ss_song, n_ss_ev, sizeof(union ss_ev), ss_ev_cmp);
483 /* count one more */
484 (*n_tracks)++;
485 (*n_channels)++;
489 static void ss_song_trace_events(void)
491 union ss_ev * e;
492 int n;
494 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
495 printf("%10s %5s %5s Event and information\n",
496 "Frame", "Track", "Ev.ID");
497 printf("------------------------------------------------------------\n");
499 for(n = 0, e = ss_song;n < n_ss_ev;n++, e++)
501 printf("%10d %5d %5d ",
502 e->generic.frame, e->generic.trk_id, e->generic.event_id);
504 switch(e->generic.type)
506 case SONG_EV_TEMPO:
508 printf("SONG_EV_TEMPO ");
509 printf("%lf", e->tempo.tempo);
510 break;
512 case SONG_EV_SS_SUSTAIN:
514 printf("SONG_EV_SS_SUSTAIN ");
515 printf("SUSTAIN:%lf", e->ss_sustain.sustain);
516 break;
518 case SONG_EV_SS_VIBRATO:
520 printf("SONG_EV_SS_VIBRATO ");
521 printf("DEPTH:%lf FREQ:%lf",
522 e->ss_vibrato.vib_depth,
523 e->ss_vibrato.vib_freq);
524 break;
526 case SONG_EV_SS_CHANNEL:
528 printf("SONG_EV_SS_CHANNEL ");
529 printf("CHANNEL:%d VOL:%lf",
530 e->ss_channel.channel,
531 e->ss_channel.vol);
532 break;
534 case SONG_EV_SS_WAV:
536 printf("SONG_EV_SS_WAV ");
537 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
538 e->ss_wav.file, e->ss_wav.base,
539 e->ss_wav.min, e->ss_wav.max,
540 e->ss_wav.loop_start, e->ss_wav.loop_end);
541 break;
543 case SONG_EV_SS_PAT:
545 printf("SONG_EV_SS_PAT ");
546 printf("FILE:'%s'", e->ss_pat.file);
547 break;
549 case SONG_EV_SS_EFF_DELAY:
551 printf("SONG_EV_SS_EFF_DELAY ");
552 printf("CHANNEL:%d ", e->ss_eff.channel);
553 printf("SIZE:%lf ", e->ss_eff.size);
554 break;
556 case SONG_EV_SS_EFF_ECHO:
558 printf("SONG_EV_SS_EFF_ECHO ");
559 printf("CHANNEL:%d ", e->ss_eff.channel);
560 printf("SIZE:%lf ", e->ss_eff.size);
561 printf("GAIN:%f ", e->ss_eff.gain);
562 break;
564 case SONG_EV_SS_EFF_COMB:
566 printf("SONG_EV_SS_EFF_COMB ");
567 printf("CHANNEL:%d ", e->ss_eff.channel);
568 printf("SIZE:%lf ", e->ss_eff.size);
569 printf("GAIN:%f ", e->ss_eff.gain);
570 break;
572 case SONG_EV_SS_EFF_ALLPASS:
574 printf("SONG_EV_SS_EFF_ALLPASS ");
575 printf("CHANNEL:%d ", e->ss_eff.channel);
576 printf("SIZE:%lf ", e->ss_eff.size);
577 printf("GAIN:%f ", e->ss_eff.gain);
578 break;
580 case SONG_EV_SS_EFF_FLANGER:
582 printf("SONG_EV_SS_EFF_FLANGER ");
583 printf("CHANNEL:%d ", e->ss_eff.channel);
584 printf("SIZE:%lf ", e->ss_eff.size);
585 printf("GAIN:%f ", e->ss_eff.gain);
586 printf("DEPTH:%lf ", e->ss_eff.depth);
587 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
588 e->ss_eff.phase);
589 break;
591 case SONG_EV_SS_EFF_WOBBLE:
593 printf("SONG_EV_SS_EFF_WOBBLE ");
594 printf("CHANNEL:%d ", e->ss_eff.channel);
595 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
596 e->ss_eff.phase);
597 break;
599 case SONG_EV_SS_EFF_SQWOBBLE:
601 printf("SONG_EV_SS_EFF_SQWOBBLE ");
602 printf("CHANNEL:%d ", e->ss_eff.channel);
603 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
604 e->ss_eff.phase);
605 break;
607 case SONG_EV_SS_EFF_FADER:
609 printf("SONG_EV_SS_EFF_FADER ");
610 printf("CHANNEL:%d ", e->ss_eff.channel);
611 printf("SIZE:%lf ", e->ss_eff.size);
612 printf("INITIAL:%f FINAL:%f", e->ss_eff.initial,
613 e->ss_eff.final);
614 break;
616 case SONG_EV_SS_EFF_REVERB:
618 printf("SONG_EV_SS_EFF_REVERB ");
619 printf("CHANNEL:%d ", e->ss_eff.channel);
620 break;
622 case SONG_EV_SS_EFF_OFF:
624 printf("SONG_EV_SS_EFF_OFF ");
625 printf("CHANNEL:%d ", e->ss_eff.channel);
626 break;
628 case SONG_EV_SS_PITCH_STRETCH:
630 printf("SONG_EV_SS_PITCH_STRETCH ");
631 printf("MIDI:%d LEN:%lf VOL:%f",
632 e->ss_pitch_stretch.note,
633 e->ss_pitch_stretch.len,
634 e->ss_pitch_stretch.vol);
636 break;
638 case SONG_EV_SS_PRINT_WAVE_TEMPO:
640 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
641 printf("MIDI:%d LEN:%lf",
642 e->ss_print_wave_tempo.note,
643 e->ss_print_wave_tempo.len);
644 break;
646 case SONG_EV_SONG_INFO:
648 printf("SONG_EV_SONG_INFO ");
649 printf("AUTHOR:'%s' NAME:'%s'",
650 e->song_info.author,
651 e->song_info.name);
652 break;
654 case SONG_EV_NOTE_ON:
656 printf("SONG_EV_NOTE_ON ");
657 printf("ID:%d MIDI:%d VOL:%f",
658 e->note_on.note_id, e->note_on.note,
659 e->note_on.vol);
660 break;
662 case SONG_EV_NOTE_OFF:
664 printf("SONG_EV_NOTE_OFF ");
665 printf("ID:%d", e->note_off.note_id);
666 break;
668 case SONG_EV_END:
670 printf("SONG_EV_END ");
671 break;
673 default:
674 printf("** Unexpected type: %d",
675 e->generic.type);
678 printf("\n");
681 printf("\n");
685 int ss_song_render(int skip_secs, char * driver, char * devfile)
687 union ss_ev * e;
688 int frame;
689 int go;
690 int n;
691 sample_t output[SS_MAX_CHANNELS];
692 struct ss_ins * i;
693 double tempo = 120.0;
694 int skip_frames;
695 struct ss_wave * w;
696 double freq;
697 int n_tracks;
698 int n_channels;
700 /* convert the song to ss events */
701 ss_song_convert_events(&n_tracks, &n_channels);
703 if(verbose >= 2)
704 printf("Tracks: %d Channels: %d Events: %d\n",
705 n_tracks, n_channels, n_ss_ev);
707 if(trace)
709 ss_song_trace_events();
710 return(0);
713 /* set the number of channels, unless forced */
714 if(ss_nchannels == -1)
715 ss_nchannels = n_channels > 0 ? n_channels : 2;
717 if(ss_output_open(driver, devfile) < 0)
719 printf("Error: can't init driver\n");
720 return(2);
723 frame = 0;
724 go = 1;
725 e = ss_song;
727 /* init the generators */
728 ss_gen_init();
730 /* init the instruments */
731 for(n = 0;n < n_tracks;n++)
732 ss_ins_init(&ss_song_ins[n]);
734 /* calculate the frame to start playing */
735 skip_frames = skip_secs * ss_frequency;
737 /* loop the events */
738 while(go)
740 if(verbose >= 1)
742 if(frame % ss_frequency == 0)
744 int m = frame / ss_frequency;
745 printf("[%02d:%02d]\r", m / 60, m % 60);
746 fflush(stdout);
750 /* process all events for this exact frame */
751 while(go && e->generic.frame == frame)
753 if(e->generic.type == SONG_EV_NOTE_ON ||
754 e->generic.type == SONG_EV_NOTE_OFF ||
755 e->generic.type == SONG_EV_SS_PITCH_STRETCH)
757 if(frame < skip_frames)
759 e++;
760 frame = e->generic.frame;
761 continue;
765 /* take the instrument */
766 if(e->generic.trk_id < 0)
767 i = NULL;
768 else
769 i = &ss_song_ins[e->generic.trk_id];
771 switch(e->generic.type)
773 case SONG_EV_NOTE_ON:
775 ss_ins_note_on(i, e->note_on.note,
776 e->note_on.vol, e->note_on.note_id);
778 break;
780 case SONG_EV_NOTE_OFF:
782 ss_ins_note_off(i, e->note_off.note_id);
784 break;
786 case SONG_EV_SS_SUSTAIN:
788 ss_ins_set_sustain(i, e->ss_sustain.sustain);
790 break;
792 case SONG_EV_SS_VIBRATO:
794 ss_ins_set_vibrato(i, e->ss_vibrato.vib_depth,
795 e->ss_vibrato.vib_freq);
797 break;
799 case SONG_EV_SS_CHANNEL:
801 ss_ins_set_channel(i, e->ss_channel.channel,
802 e->ss_channel.vol);
804 break;
806 case SONG_EV_SS_WAV:
808 w=ss_load_wav_file(e->ss_wav.file,
809 ss_note_frequency(e->ss_wav.base),
810 ss_note_frequency(e->ss_wav.min),
811 ss_note_frequency(e->ss_wav.max),
812 e->ss_wav.loop_start, e->ss_wav.loop_end,
813 e->ss_wav.first_channel, e->ss_wav.skip_channels);
815 /* fail if can't open wav */
816 if(w == NULL)
818 printf("Can't load wav '%s'\n", e->ss_wav.file);
819 go = 0;
821 else
822 ss_ins_add_layer(i, w);
824 break;
826 case SONG_EV_SS_PAT:
828 if(ss_load_pat_file(i, e->ss_pat.file) < 0)
830 printf("Can't load pat '%s'\n", e->ss_pat.file);
831 go = 0;
834 break;
836 case SONG_EV_SS_EFF_DELAY:
838 ss_eff_delay(&i->effs[e->ss_eff.channel],
839 e->ss_eff.size);
840 break;
842 case SONG_EV_SS_EFF_ECHO:
844 ss_eff_echo(&i->effs[e->ss_eff.channel],
845 e->ss_eff.size, e->ss_eff.gain);
846 break;
848 case SONG_EV_SS_EFF_COMB:
850 ss_eff_comb(&i->effs[e->ss_eff.channel],
851 e->ss_eff.size, e->ss_eff.gain);
852 break;
854 case SONG_EV_SS_EFF_ALLPASS:
856 ss_eff_allpass(&i->effs[e->ss_eff.channel],
857 e->ss_eff.size, e->ss_eff.gain);
858 break;
860 case SONG_EV_SS_EFF_FLANGER:
862 ss_eff_flanger(&i->effs[e->ss_eff.channel],
863 e->ss_eff.size, e->ss_eff.gain,
864 e->ss_eff.depth, e->ss_eff.freq,
865 e->ss_eff.phase);
866 break;
868 case SONG_EV_SS_EFF_WOBBLE:
870 ss_eff_wobble(&i->effs[e->ss_eff.channel],
871 e->ss_eff.freq, e->ss_eff.phase);
873 break;
875 case SONG_EV_SS_EFF_SQWOBBLE:
877 ss_eff_square_wobble(&i->effs[e->ss_eff.channel],
878 e->ss_eff.freq, e->ss_eff.phase);
880 break;
882 case SONG_EV_SS_EFF_FADER:
884 ss_eff_fader(&i->effs[e->ss_eff.channel],
885 e->ss_eff.size, e->ss_eff.initial,
886 e->ss_eff.final);
887 break;
889 case SONG_EV_SS_EFF_REVERB:
891 ss_eff_reverb(&i->effs[e->ss_eff.channel]);
892 break;
894 case SONG_EV_SS_EFF_OFF:
896 ss_eff_off(&i->effs[e->ss_eff.channel]);
897 break;
899 case SONG_EV_TEMPO:
901 /* just store the last tempo */
902 tempo = e->tempo.tempo;
903 break;
905 case SONG_EV_SS_PITCH_STRETCH:
907 /* find the wave */
908 freq = ss_note_frequency(e->ss_pitch_stretch.note);
909 w = ss_ins_find_layer(i, freq, NULL);
911 /* calculate optimal frequency */
912 freq = ss_pitch_from_tempo(w, tempo,
913 e->ss_pitch_stretch.len);
915 /* play the note */
916 ss_ins_play(i, freq, e->ss_pitch_stretch.vol,
917 e->ss_pitch_stretch.note_id, w);
919 break;
921 case SONG_EV_SS_PRINT_WAVE_TEMPO:
923 /* find the wave */
924 freq = ss_note_frequency(e->ss_print_wave_tempo.note);
925 w = ss_ins_find_layer(i, freq, NULL);
927 /* print the optimal tempo */
928 printf("Optimal tempo: %lf\n",
929 ss_tempo_from_wave(w,
930 e->ss_print_wave_tempo.note,
931 e->ss_print_wave_tempo.len));
933 break;
935 case SONG_EV_SONG_INFO:
937 /* add a new song (track) */
938 cue_file_song_info(frame, e->song_info.author,
939 e->song_info.name);
940 break;
942 case SONG_EV_END:
944 go = 0;
945 break;
947 case SONG_EV_BACK:
948 case SONG_EV_MIDI_CHANNEL:
949 case SONG_EV_MIDI_PROGRAM:
950 case SONG_EV_NOTE:
951 case SONG_EV_METER:
952 case SONG_EV_MEASURE:
954 /* never found in ss song streams */
955 break;
958 /* next event */
959 e++;
962 /* reset frame samples */
963 ss_output_init_frame(output);
965 /* generate output from all instruments */
966 for(n = 0;n < n_tracks;n++)
967 ss_ins_frame(&ss_song_ins[n], output);
969 /* dump to sampling driver */
970 ss_output_write(output);
972 /* next frame */
973 frame++;
976 if(verbose >= 1) printf("\n");
978 ss_output_close();
980 return(0);