1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #define OSC_COUNT 109
23 #define OSC_LIMIT 91
24 #define WAVE_SIZE 1024
25 #define WAVE_COUNT 8
26 #define BUS_COUNT 9
27 
28 #define NEW_CLICK
29 
30 /*
31  * These are the midi note offsets for any given key harmonics.
32  */
33 static int offsets[BUS_COUNT] = {-12, 7, 0, 12, 19, 24, 28, 31, 36};
34 
35 /*
36  * Get a humungous chunk of memory, SAMPLE_COUNT should come from the audiomain
37  * structure. This is the pointer to that chunk of 'current buffer working mem'.
38  */
39 static float *oscillators = NULL;
40 
41 static int wi[256] = {
42 	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, /* Lower foldbacks not used */
43 	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, /* Lower foldbacks not used */
44 	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, /* Foldback */
45 	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, /* First octave */
46 	12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
47 	24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
48 	36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
49 	48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
50 	60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
51 	72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
52 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83, /* Foldback starts again */
53 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83, /* And repeats from here */
54 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
55 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
56 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
57 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
58 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
59 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
60 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
61 	84, 85, 86, 87, 88, 89, 90, 79, 80, 81, 82, 83,
62 };
63 
64 /*
65  * This is the compartments configuration, alterable in the tonewheel config
66  * file.
67  */
68 static int compartments[24][4] = {
69 {0,	48,	12,	60},
70 {24,	72,	37,	-1},
71 {7,	55,	19,	67},
72 {31,	79,	43,	86},
73 {2,	50,	14,	62},
74 {26,	74,	38,	-1},
75 {9,	57,	21,	69},
76 {33,	81,	45,	88},
77 {4,	52,	16,	64},
78 {28,	76,	40,	-1},
79 {11,	59,	23,	71},
80 {35,	83,	47,	90},
81 {6,	54,	18,	66},
82 {30,	78,	42,	85},
83 {1,	49,	13,	61},
84 {25,	73,	37,	-1},
85 {8,	56,	20,	68},
86 {32,	80,	44,	54},
87 {3,	51,	15,	63},
88 {27,	75,	13,	-1},
89 {10,	58,	22,	70},
90 {34,	82,	46,	89},
91 {5,	53,	17,	65},
92 {29,	77,	41,	84}
93 };
94 
95 /*
96  * This will emulate the tapering resistors of the drawbar box. Each line from
97  * the tonewheel engine was drawn through a cable tree to each note and would
98  * traverse different distances and signal loss for which tapering resistors
99  * were added to even out the gains. There is an aspect of crosstalk that has
100  * not been taken care of here. These are hidden in the tonewheel structure.
101  */
102 #define R100 0.4
103 #define R50 0.6
104 #define R34 0.8
105 #define R24 1.0
106 #define R15 1.2
107 #define R10 1.4
108 #define R0 0.4
109 #define R1 0.6
110 #define R2 0.8
111 #define R3 1.0
112 #define R4 1.2
113 #define R5 1.2
114 
115 static float tresistors[6] = {R100, R50, R34, R24, R15, R10};
116 static float deftp[BUS_COUNT] = {R100, R50, R34, R34, R24, R24, R24, R15, R10};
117 
118 /*
119  * We then need to add a tapering configuration, this should also be in the
120  * tonewheel config.
121  */
122 static float tapers[OSC_LIMIT][9] = {
123 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
124 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
125 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
126 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
127 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
128 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
129 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
130 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
131 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
132 {R0, R2, R1, R2, R5, R5, R4, R3, R3},
133 {R1, R2, R1, R2, R5, R5, R4, R3, R3},
134 {R1, R2, R1, R2, R5, R4, R4, R3, R3},
135 {R1, R2, R1, R2, R4, R4, R4, R3, R3},
136 {R1, R2, R1, R3, R4, R4, R4, R3, R3},
137 {R1, R3, R1, R3, R4, R4, R4, R3, R3},
138 {R1, R3, R2, R3, R4, R4, R4, R3, R3},
139 {R2, R3, R2, R3, R4, R4, R4, R3, R3},
140 {R2, R3, R2, R3, R4, R4, R4, R3, R3},
141 {R2, R3, R2, R3, R4, R4, R3, R3, R3},
142 {R2, R3, R2, R3, R4, R4, R3, R3, R3},
143 {R2, R3, R2, R3, R3, R3, R3, R3, R3},
144 {R2, R3, R2, R3, R3, R3, R3, R3, R3},
145 {R2, R3, R2, R3, R3, R3, R3, R3, R3},
146 {R2, R3, R3, R3, R3, R3, R3, R3, R3},
147 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
148 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
149 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
150 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
151 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
152 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
153 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
154 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
155 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
156 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
157 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
158 {R3, R3, R3, R3, R3, R3, R3, R3, R3},
159 {R4, R3, R3, R3, R3, R3, R3, R3, R3},
160 {R4, R3, R4, R3, R3, R3, R3, R3, R3},
161 {R4, R4, R4, R3, R3, R3, R3, R3, R3},
162 {R4, R4, R4, R2, R3, R3, R3, R3, R3},
163 {R4, R4, R4, R2, R2, R3, R3, R3, R3},
164 {R4, R4, R4, R2, R2, R2, R3, R3, R3},
165 {R4, R4, R4, R2, R2, R2, R2, R3, R3},
166 {R4, R4, R4, R2, R2, R2, R2, R2, R1},
167 {R4, R4, R4, R2, R2, R2, R2, R2, R1},
168 {R4, R4, R4, R2, R2, R2, R2, R2, R1},
169 {R4, R4, R4, R2, R2, R2, R2, R2, R1},
170 {R4, R4, R4, R2, R2, R2, R2, R2, R1},
171 {R5, R4, R4, R2, R2, R2, R2, R1, R1},
172 {R5, R4, R5, R2, R2, R2, R2, R1, R1},
173 {R5, R5, R5, R2, R2, R2, R2, R1, R1},
174 {R5, R5, R5, R2, R2, R2, R1, R1, R1},
175 {R5, R5, R5, R2, R1, R2, R1, R1, R1},
176 {R5, R5, R5, R2, R1, R2, R1, R1, R1},
177 {R5, R5, R5, R2, R1, R2, R1, R1, R1},
178 {R5, R5, R5, R2, R1, R1, R1, R1, R1},
179 {R5, R5, R5, R2, R1, R1, R1, R1, R1},
180 {R5, R5, R5, R2, R1, R1, R1, R1, R1},
181 {R5, R5, R5, R2, R1, R1, R1, R1, R1},
182 {R5, R5, R5, R2, R1, R1, R1, R1, R1},
183 {R5, R5, R5, R2, R1, R1, R1, R1, R1}
184 };
185 
186 #ifdef TONEMATRIX
187 static float rtapers[OSC_LIMIT][9] = {
188 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
189 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
190 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
191 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
192 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
193 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
194 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
195 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
196 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
197 {100.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
198 {50.0, 34.0, 50.0, 34.0, 10.0, 10.0, 15.0, 24.0, 24.0},
199 {50.0, 34.0, 50.0, 34.0, 10.0, 15.0, 15.0, 24.0, 24.0},
200 {50.0, 34.0, 50.0, 34.0, 15.0, 15.0, 15.0, 24.0, 24.0},
201 {50.0, 34.0, 50.0, 24.0, 15.0, 15.0, 15.0, 24.0, 24.0},
202 {50.0, 24.0, 50.0, 24.0, 15.0, 15.0, 15.0, 24.0, 24.0},
203 {50.0, 24.0, 34.0, 24.0, 15.0, 15.0, 15.0, 24.0, 24.0},
204 {34.0, 24.0, 34.0, 24.0, 15.0, 15.0, 15.0, 24.0, 24.0},
205 {34.0, 24.0, 34.0, 24.0, 15.0, 15.0, 15.0, 24.0, 24.0},
206 {34.0, 24.0, 34.0, 24.0, 15.0, 15.0, 24.0, 24.0, 24.0},
207 {34.0, 24.0, 34.0, 24.0, 15.0, 15.0, 24.0, 24.0, 24.0},
208 {34.0, 24.0, 34.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
209 {34.0, 24.0, 34.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
210 {34.0, 24.0, 34.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
211 {34.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
212 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
213 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
214 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
215 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
216 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
217 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
218 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
219 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
220 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
221 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
222 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
223 {24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
224 {15.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
225 {15.0, 24.0, 15.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
226 {15.0, 15.0, 15.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0},
227 {15.0, 15.0, 15.0, 34.0, 24.0, 24.0, 24.0, 24.0, 24.0},
228 {15.0, 15.0, 15.0, 34.0, 34.0, 24.0, 24.0, 24.0, 24.0},
229 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 24.0, 24.0, 24.0},
230 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 24.0, 24.0},
231 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 34.0, 50.0},
232 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 34.0, 50.0},
233 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 34.0, 50.0},
234 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 34.0, 50.0},
235 {15.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 34.0, 50.0},
236 {10.0, 15.0, 15.0, 34.0, 34.0, 34.0, 34.0, 50.0, 50.0},
237 {10.0, 15.0, 10.0, 34.0, 34.0, 34.0, 34.0, 50.0, 50.0},
238 {10.0, 10.0, 10.0, 34.0, 34.0, 34.0, 34.0, 50.0, 50.0},
239 {10.0, 10.0, 10.0, 34.0, 34.0, 34.0, 50.0, 50.0, 50.0},
240 {10.0, 10.0, 10.0, 34.0, 50.0, 34.0, 50.0, 50.0, 50.0},
241 {10.0, 10.0, 10.0, 34.0, 50.0, 34.0, 50.0, 50.0, 50.0},
242 {10.0, 10.0, 10.0, 34.0, 50.0, 34.0, 50.0, 50.0, 50.0},
243 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0},
244 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0},
245 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0},
246 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0},
247 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0},
248 {10.0, 10.0, 10.0, 34.0, 50.0, 50.0, 50.0, 50.0, 50.0}
249 };
250 #endif
251 
252 static float wheeltemplates[2][OSC_LIMIT][WAVE_SIZE];
253 static float *tonewheel[OSC_LIMIT];
254 static int *wheelnumbers = &wi[36];
255 static float toneindeces[OSC_LIMIT];
256 #define NORMAL 0
257 #define BRIGHT 1
258 static float toneEQ[2][OSC_LIMIT];
259 static float busEQ[2][BUS_COUNT];
260 static float damping[2][OSC_LIMIT];
261 static float tonegains[OSC_LIMIT];
262 
263 /*
264  * Crosstalk defaults.
265  */
266 #define XT_COUNT 9
267 
268 /* Compartment members: */
269 #define XT_NEAR_1	0
270 #define XT_NEAR_2	1
271 #define XT_FAR_1	2
272 #define XT_FAR_2	3
273 /* Drawbar busses */
274 #define XT_DRAWBAR	4
275 /* Filter adjacencies */
276 #define XT_FILT_1	5
277 #define XT_FILT_2	6
278 #define XT_FILT_3	7
279 #define XT_FILT_4	8
280 
281 /*
282  * The following are for the different drawbar parameters. I would like to
283  * bring them into a single structure and will start with the structures for
284  * the redefined keyclick code - nine busses, independent click and harmonic
285  * startpoints.
286  */
287 static float defct[2][XT_COUNT]
288     = {{0.03, 0.05, 0.04, 0.2, 0.02, 0.07, 0.06, 0.03, 0.02},
289        {0.05, 0.06, 0.02, 0.5, 0.02, 0.09, 0.07, 0.08, 0.6}};
290 
291 static float defbg[9] =
292 	{0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.750, 0.875, 1.0};
293 
294 /*
295  * These define the sample delays before the given bus makes contact, gives
296  * a key click and starts mixing its harmonic.
297  */
298 static struct DrawBar {
299 	float delay[2][BUS_COUNT];
300 	int delays[2][BUS_COUNT];
301 	float gain[2][BUS_COUNT];
302 	float invert[2][BUS_COUNT];
303 	float wave[2][BUS_COUNT];
304 	int pulse[2][BUS_COUNT];
305 	int tdelay[BUS_COUNT][OSC_LIMIT]; /* Target delay depending on velocity */
306 	int current[BUS_COUNT][OSC_LIMIT]; /* index into click buffer */
307 	int offset[OSC_LIMIT]; /* Current offset of note */
308 } drawbars;
309 
310