2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
22 evanrinehart@gmail.com
31 ticks - 384 per beat (tpb)
32 beats - 120 per minute (bpm)
33 samples - 22050 per second (srate)
35 control happens on tick boundaries
36 control must take effect on nearest sample boundary
38 samples per tick = (srate*60) / (bpm*tpb)
39 which in the above example = 28 and 32760/46080
48 int serr
= 0; // 1/1000 of a sample
51 int terr
= 0; // 1/(bpm*tpb) of a sample
52 int terrd
= 46080; //bpm * tpb
54 void set_sample_rate(int x
){ srate
= x
; }
55 void set_bpm(int x
){ bpm
= x
; }
58 void synth_init(int sample_rate
){
63 void generate(float left
[], float right
[], int count
){
66 /* supposed to mix all generators for count samples
67 this includes synthesizers and sample generators */
68 /* this loop is unsuitable as an inner loop */
69 for(i
=0; i
<count
; i
++){
75 /* instead zero them and pass them to each generator
76 which will accumulate their output into left and right
78 in the end divide by maximum number of generators
80 the final stage is master volume, which will be increased if
81 the result is too quiet */
84 void control(event
* e
){
85 /* we decided on polyphonic synth (and multiple instances of
86 a playing samlple). important to remember that all controller
87 events affect entire instrument channels. this means it affects
88 all generators for that intrument */
91 void synth_generate(float left
[], float right
[], int samples
){
94 int next
= seq_lookahead(samples
);
96 generate(left
+i
, right
+i
, next
-i
);
97 control(seq_get_event());
100 generate(left
+i
, right
+i
, samples
-i
);
101 seq_advance(samples
);
107 /* possible generators (scratch work)
112 square saw produce a band limited signal
115 this uses a karplus strong algorithm
116 noise -> variable delay (linear interpolating) -> first order low pass
120 two or three gaussians (perhaps padded) -> IFFT