RingModulator: meter_in with MeterScale
[calf.git] / src / wavetable.cpp
blob1df035af5dab2e26f510904f6f7bd067896405dd
1 /* Calf DSP Library
2 * Example audio modules - wavetable synthesizer
4 * Copyright (C) 2009 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include <config.h>
24 #if ENABLE_EXPERIMENTAL
26 #include <calf/giface.h>
27 #include <calf/modules_synths.h>
28 #include <iostream>
30 using namespace dsp;
31 using namespace calf_plugins;
32 using namespace std;
34 wavetable_voice::wavetable_voice()
36 sample_rate = -1;
39 void wavetable_voice::set_params_ptr(wavetable_audio_module *_parent, int _srate)
41 parent = _parent;
42 params = parent->params;
43 sample_rate = _srate;
46 void wavetable_voice::reset()
48 note = -1;
51 void wavetable_voice::note_on(int note, int vel)
53 typedef wavetable_metadata md;
54 this->note = note;
55 float s = 0.001;
56 velocity = vel / 127.0;
57 lfo1.reset();
58 lfo2.reset();
59 amp.set(1.0);
60 for (int i = 0; i < OscCount; i++) {
61 oscs[i].reset();
62 oscs[i].set_freq(note_to_hz(note, 0), sample_rate);
63 last_oscshift[i] = 0;
65 // int cr = sample_rate / BlockSize;
66 int espc = md::par_eg2attack - md::par_eg1attack;
67 for (int i = 0; i < EnvCount; i++) {
68 int o = i*espc;
69 envs[i].set(*params[md::par_eg1attack + o] * s, *params[md::par_eg1decay + o] * s, *params[md::par_eg1sustain + o], *params[md::par_eg1release + o] * s, sample_rate / BlockSize, *params[md::par_eg1fade + o] * s);
70 envs[i].note_on();
72 float modsrc[wavetable_metadata::modsrc_count] = { 1.f, velocity, parent->inertia_pressure.get_last(), parent->modwheel_value, (float)envs[0].value, (float)envs[1].value, (float)envs[2].value, 0.5f+0.5f*lfo1.last, 0.5f+0.5f*lfo2.last, (float)((note - 60) / 12.0)};
73 parent->calculate_modmatrix(moddest, md::moddest_count, modsrc);
74 calc_derived_dests(0);
76 float oscshift[2] = { moddest[md::moddest_o1shift], moddest[md::moddest_o2shift] };
77 memcpy(last_oscshift, oscshift, sizeof(oscshift));
78 memcpy(last_oscamp, cur_oscamp, sizeof(cur_oscamp));
81 void wavetable_voice::note_off(int vel)
83 for (int i = 0; i < EnvCount; i++)
84 envs[i].note_off();
87 void wavetable_voice::steal()
91 void wavetable_voice::render_block(int current_snapshot)
93 typedef wavetable_metadata md;
95 const float step = 1.f / BlockSize;
97 float s = 0.001;
98 float scl[EnvCount];
99 int espc = md::par_eg2attack - md::par_eg1attack;
100 for (int j = 0; j < EnvCount; j++) {
101 int o = j*espc;
102 envs[j].set(*params[md::par_eg1attack + o] * s, *params[md::par_eg1decay + o] * s, *params[md::par_eg1sustain + o], *params[md::par_eg1release + o] * s, sample_rate / BlockSize, *params[md::par_eg1fade + o] * s);
103 scl[j] = dsp::lerp(1.f, velocity, *params[md::par_eg1velscl + o]);;
106 for (int i = 0; i < EnvCount; i++)
107 envs[i].advance();
109 uint32_t crate = parent->get_crate();
110 lfo1.set_freq(*params[md::par_lfo1rate], crate);
111 lfo2.set_freq(*params[md::par_lfo2rate], crate);
112 lfo1.last = lfo1.get();
113 lfo2.last = lfo2.get();
115 float modsrc[wavetable_metadata::modsrc_count] = { 1.f, velocity, parent->inertia_pressure.get_last(), parent->modwheel_value, (float)envs[0].value * scl[0], (float)envs[1].value * scl[1], (float)envs[2].value * scl[2], 0.5f+0.5f*lfo1.last, 0.5f+0.5f*lfo2.last, dsp::clip<float>(note / 120.0, 0.f, 1.f)};
116 parent->calculate_modmatrix(moddest, md::moddest_count, modsrc);
117 calc_derived_dests(envs[0].value * scl[0] * scl[0]);
119 int ospc = md::par_o2level - md::par_o1level;
120 float pb = moddest[md::moddest_pitch] + parent->control_snapshots[current_snapshot].pitchbend;
121 for (int j = 0; j < OscCount; j++) {
122 oscs[j].tables = parent->tables[(int)*params[md::par_o1wave + j * ospc]];
123 oscs[j].set_freq(note_to_hz(note, *params[md::par_o1transpose + j * ospc] * 100+ *params[md::par_o1detune + j * ospc] + moddest[md::moddest_o1detune + j] + pb), sample_rate);
126 float oscshift[2] = { moddest[md::moddest_o1shift], moddest[md::moddest_o2shift] };
127 for (int j = 0; j < OscCount; j++) {
128 oscshift[j] += *params[md::par_o1offset + j * ospc] * 100;
130 float osstep[2] = { (oscshift[0] - last_oscshift[0]) * step, (oscshift[1] - last_oscshift[1]) * step };
131 float oastep[2] = { (cur_oscamp[0] - last_oscamp[0]) * step, (cur_oscamp[1] - last_oscamp[1]) * step };
132 for (int i = 0; i < BlockSize; i++) {
133 float value = 0.f;
135 for (int j = 0; j < OscCount; j++) {
136 float o = last_oscshift[j] * 0.01;
137 value += last_oscamp[j] * oscs[j].get(dsp::clip(fastf2i_drm(o * 127.0 * 256), 0, 127 * 256));
138 last_oscshift[j] += osstep[j];
139 last_oscamp[j] += oastep[j];
142 output_buffer[i][0] = output_buffer[i][1] = value;
144 if (envs[0].stopped())
145 released = true;
146 memcpy(last_oscshift, oscshift, sizeof(oscshift));
147 memcpy(last_oscamp, cur_oscamp, sizeof(cur_oscamp));
150 /////////////////////////////////////////////////////////////////////////////////////////////////////
152 const int16_t *wavetable_voice::get_last_table(int osc) const
154 float os = dsp::clip<double>(last_oscshift[osc] * 1.27, 0, 127);
155 return oscs[osc].tables[(int)os];
158 bool wavetable_audio_module::get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const
160 if (!phase)
161 return false;
162 // printf("get_graph %d %p %d wave1=%d wave2=%d\n", index, data, points, wave1, wave2);
163 if (index == par_o1wave || index == par_o2wave) {
164 if (subindex)
165 return false;
166 if (active_voices.empty())
167 return false;
168 wavetable_voice *vc = last_voice;
169 const int16_t *tab = vc->get_last_table(index == par_o1wave ? 0 : 1);
170 for (int i = 0; i < points; i++)
172 double pos = i * 256 / points;
173 int ipos = (int)pos;
174 data[i] = lerp(tab[ipos] / 32767.0, tab[(ipos + 1) & 255] / 32767.0, pos - ipos);
177 return true;
179 return false;
181 /////////////////////////////////////////////////////////////////////////////////////////////////////
183 static inline float sincl(float x, float clip)
185 if (fabs(x) > clip)
186 return 0;
187 return sin(M_PI * x);
190 static inline float blip(float x, float center, float range)
192 if (x < center - range || x > center + range)
193 return 0;
194 return 1 - fabs(x - center)/range;
197 static void interpolate_wt(int16_t table[129][256], int step)
199 for (int i = 0; i < 128; i++)
201 if (!(i % step))
202 continue;
203 int prev = i - i % step;
204 int next = prev + step;
205 for (int j = 0; j < 256; j++)
207 table[i][j] = table[prev][j] + (i - prev) * (table[next][j] - table[prev][j]) / step;
212 wavetable_audio_module::wavetable_audio_module()
213 : mod_matrix_impl(mod_matrix_data, &mm_metadata)
214 , inertia_pitchbend(64)
215 , inertia_pressure(64)
217 init_voices(36);
218 last_voice = (wavetable_voice *)allocated_voices.items[0];
220 panic_flag = false;
221 modwheel_value = 0.;
222 for (int i = 0; i < 129; i += 8)
224 for (int j = 0; j < 256; j++)
226 float ph = j * 2 * M_PI / 256;
227 int harm = 1 + 2 * (i / 8);
228 float ii = i / 128.0;
229 float rezo1 = sin(harm * ph) * sin(ph);
230 float rezo2 = sin((harm+1) * ph) * sin(ph * 2);
231 float rezo3 = sin((harm+3) * ph) * sin(ph * 4);
232 float rezo = (rezo1 + rezo2 + rezo3) / 3;
233 float v = (sin (ph) + ii * ii * rezo) / 2;
234 tables[0][i][j] = 32767 * v;
237 interpolate_wt(tables[0], 8);
238 for (int i = 0; i < 129; i += 4)
240 for (int j = 0; j < 256; j++)
242 float ph = j * 2 * M_PI / 256;
243 int harm = 1 + (i / 4);
244 float ii = i / 128.0;
245 float h = sin(harm * ph);
246 float rezo1 = h * sin(ph);
247 float rezo2 = h * sin(ph * 2)/2;
248 float rezo3 = h * sin(ph * 3)/3;
249 float rezo4 = h * sin(ph * 4)/4;
250 float rezo5 = h * sin(ph * 5)/5;
251 float rezo = (rezo1 + rezo2 + rezo3 + rezo4 + rezo5) / 3;
252 float v = sin (ph + ii * rezo);
253 tables[1][i][j] = 32767 * v;
256 interpolate_wt(tables[1], 4);
257 for (int i = 0; i < 129; i++)
259 for (int j = 0; j < 256; j++)
261 float ph = j * 2 * M_PI / 256;
262 float ii = (i & ~3) / 128.0;
263 float ii2 = ((i & ~3) + 4) / 128.0;
264 float peak = (32 * ii);
265 float rezo1 = sin(floor(peak) * ph);
266 float rezo2 = sin(floor(peak + 1) * ph);
267 float widener = (0.5 + 0.3 * sin(ph) + 0.2 * sin (3 * ph));
268 float v1 = 0.5 * sin (ph) + 0.5 * ii * ii * rezo1 * widener;
269 float v2 = 0.5 * sin (ph) + 0.5 * ii2 * ii2 * rezo2 * widener;
270 tables[wavetable_metadata::wt_rezo][i][j] = 32767 * lerp(v1, v2, (i & 3) / 4.0);
273 for (int i = 0; i < 129; i++)
275 for (int j = 0; j < 256; j++)
277 float ph = j * 2 * M_PI / 256;
278 float ii = i / 128.0;
279 float v = (sin(ph) + ii * sin(ph + 2 * ii * sin(ph)) + ii * ii * sin(ph + 6 * ii * ii * sin(6 * ph)) + ii * ii * ii * ii * sin(ph + 11 * ii * ii * ii * ii * sin(11 * ph))) / 4;
280 tables[wavetable_metadata::wt_metal][i][j] = 32767 * v;
283 for (int i = 0; i < 129; i++)
285 for (int j = 0; j < 256; j++)
287 float ph = j * 2 * M_PI / 256;
288 float ii = i / 128.0;
289 float v = (sin(ph) + ii * sin(ph - 3 * ii * sin(ph)) + ii * ii * sin(5 * ph - 5 * ii * ii * ii * ii * sin(11 * ph))) / 3;
290 tables[wavetable_metadata::wt_bell][i][j] = 32767 * v;
293 for (int i = 0; i < 129; i++)
295 for (int j = 0; j < 256; j++)
297 float ph = j * 2 * M_PI / 256;
298 float ii = i / 128.0;
299 //float v = (sin(ph) + ii * sin(ph + 2 * ii * sin(ph)) + ii * ii * sin(ph + 3 * ii * ii * sin(3 * ph)) + ii * ii * ii * sin(ph + 5 * ii * ii * ii * sin(5 * ph))) / 4;
300 float v = (sin(ph) + sin(ph - 3 * sin(ii * 5 - 2) * sin(ph)) + sin(ii * 4 - 1.3) * sin(5 * ph + 3 * ii * ii * sin(6 * ph))) / 3;
301 tables[wavetable_metadata::wt_blah][i][j] = 32767 * v;
304 for (int i = 0; i < 256; i++)
306 tables[wavetable_metadata::wt_pluck][128][i] = (i < 128) ? 32000 * fabs(sin(i / 32.0 * M_PI) * sin(i / 13.0 * M_PI) * sin(i / 19.0 * M_PI)) : 0;
308 for (int i = 127; i >= 0; i--)
310 int16_t *parent = tables[wavetable_metadata::wt_pluck][i + 1];
311 float damp = 0.05;
312 for (int j = 0; j < 256; j++)
314 tables[wavetable_metadata::wt_pluck][i][j] = (1 - 2*damp) * parent[j] + damp * parent[(j+1)&255] + damp * parent[(j+2)&255];// + 0.1 * parent[(j-1)&255]+ 0.1 * parent[(j-2)&255];
317 for (int i = 0; i < 129; i++)
319 for (int j = 0; j < 256; j++)
321 float ph = j / 128.0 - 1.0;
322 float ii = i / 128.0;
323 float v = sincl(ph * (1 + 15 * ii), 1);
324 tables[wavetable_metadata::wt_stretch][i][j] = 32767 * v;
327 for (int i = 0; i < 129; i++)
329 for (int j = 0; j < 256; j++)
331 float ph = j / 128.0 - 1.0;
332 float ii = i / 128.0;
333 float v = sincl(ph * (1 + 15 * ii), 4) * sincl(j / 256.0, 1);
334 tables[wavetable_metadata::wt_stretch2][i][j] = 32000 * v;
337 for (int i = 0; i < 129; i++)
339 for (int j = 0; j < 256; j++)
341 float ph = j / 128.0 - 1.0;
342 float ii = i / 128.0;
343 float w = sincl(ph * (1 + 15 * ii), 4);
344 float v = pow(w, 9) * sincl(j / 256.0, 1);
345 tables[wavetable_metadata::wt_hardsync][i][j] = 32000 * v;
348 for (int i = 0; i < 129; i++)
350 for (int j = 0; j < 256; j++)
352 float ph = j / 128.0 - 1.0;
353 float ii = i / 128.0;
354 float w = sincl(ph * (1 + 31 * ii), 3);
355 float v = pow(w, 5) * sincl(j / 256.0, 1);
356 tables[wavetable_metadata::wt_hardsync2][i][j] = 32000 * v;
359 for (int i = 0; i < 129; i++)
361 for (int j = 0; j < 256; j++)
363 float ph = j / 128.0 - 1.0;
364 float ii = i / 128.0;
365 float w = sincl(ph * ph * (1 + 15 * ii), 2);
366 float v = pow(w, 4) * sincl(j / 256.0, 1);
367 tables[wavetable_metadata::wt_softsync][i][j] = 32000 * v;
370 for (int i = 0; i < 129; i++)
372 for (int j = 0; j < 256; j++)
374 float ph = j * 2 * M_PI / 256;
375 float ii = i / 128.0;
376 float v = (sin(ph) + ii * sin(ph - 3 * ii * sin(ph)) + ii * ii * ii * sin(7 * ph - 2 * ii * ii * ii * ii * sin(13 * ph))) / 3;
377 tables[wavetable_metadata::wt_bell2][i][j] = 32767 * v;
380 for (int i = 0; i < 129; i++)
382 for (int j = 0; j < 256; j++)
384 float ph = j * 2 * M_PI / 256;
385 float ii = i / 128.0;
386 float v = (sin(ph) + ii * sin(ph - 3 * ii * sin(ph)) + ii * ii * ii * sin(9 * ph - ii * ii * sin(11 * ph))) / 3;
387 tables[wavetable_metadata::wt_bell3][i][j] = 32767 * v;
390 for (int i = 0; i < 129; i++)
392 for (int j = 0; j < 256; j++)
394 float ph = j * 2 * M_PI / 256;
395 float ii = i / 128.0;
396 float v = (sin(ph + ii * sin(ph - 3 * ii * sin(ph) + ii * ii * ii * sin(5 * ph - ii * ii * sin(7 * ph)))));
397 tables[wavetable_metadata::wt_tine][i][j] = 32767 * v;
400 for (int i = 0; i < 129; i++)
402 for (int j = 0; j < 256; j++)
404 float ph = j * 2 * M_PI / 256;
405 float ii = i / 128.0;
406 float v = (sin(ph + ii * sin(ph - 2 * ii * sin(ph) + ii * ii * ii * sin(3 * ph - ii * ii * sin(4 * ph)))));
407 tables[wavetable_metadata::wt_tine2][i][j] = 32767 * v;
410 for (int i = 0; i < 129; i++)
412 for (int j = 0; j < 256; j++)
414 float ph = j * 2 * M_PI / 256;
415 float ph2 = j / 128.0 - 1;
416 float ii = i / 128.0;
417 float w = sincl(ph2 * (1 + 7 * ii * ii), 4) * pow(sincl(j / 256.0, 1), 2);
418 float v = sin(ph + ii * sin(ph - 2 * ii * w));
419 tables[wavetable_metadata::wt_clav][i][j] = 32767 * v;
422 for (int i = 0; i < 129; i++)
424 for (int j = 0; j < 256; j++)
426 float ph = j * 2 * M_PI / 256;
427 float ph2 = j / 128.0 - 1;
428 float ii = i / 128.0;
429 float w = sincl(ph2 * (1 + 7 * ii * ii), 6) * sincl(j / 256.0, 1);
430 float v = sin(ph + ii * sin(3 * ph - 2 * ii * w));
431 tables[wavetable_metadata::wt_clav2][i][j] = 32767 * v;
435 for (int i = 0; i < 129; i++)
437 for (int j = 0; j < 256; j++)
439 float ph = j * 2 * M_PI / 256;
440 float ph2 = j / 128.0 - 1;
441 float ii = i / 128.0;
442 float w = sincl(ph2 * (1 + 7 * ii * ii), 6) * pow(sincl(j / 256.0, 1), 1);
443 float v = sin(ph + ii * ii * ii * sin(3 * ph - ii * ii * ii * w));
444 tables[wavetable_metadata::wt_gtr][i][j] = 32767 * v;
448 for (int i = 0; i < 129; i++)
450 for (int j = 0; j < 256; j++)
452 float ph = j * 2 * M_PI / 256;
453 float ii = i / 128.0;
454 float ii2 = ii;
455 float w = pow(sincl(j / 256.0, 1), 1);
456 float v = sin(ph + ii2 * ii2 * ii2 * sin(3 * ph - ii2 * ii2 * ii2 * w * sin(ph + sin(3 * ph) + ii * sin(11 * ph) + ii * ii * sin(25 * ph))));
457 tables[wavetable_metadata::wt_gtr][i][j] = 32767 * v;
460 for (int i = 0; i < 129; i++)
462 for (int j = 0; j < 256; j++)
464 float ph = j * 2 * M_PI / 256;
465 float ii = i / 128.0;
466 float ii2 = dsp::clip(ii - 0.5, 0.0, 1.0);
467 float w = pow(sincl(j / 256.0, 1), 1);
468 float v = sin(ph + ii * ii * ii * sin(3 * ph - ii * ii * ii * w * sin(ph + sin(3 * ph + ii2 * sin(13 * ph)))));
469 tables[wavetable_metadata::wt_gtr2][i][j] = 32767 * v;
472 for (int i = 0; i < 129; i++)
474 for (int j = 0; j < 256; j++)
476 float ph = j * 2 * M_PI / 256;
477 float ii = i / 128.0;
478 float ii2 = dsp::clip(2 * (ii - 0.5), 0.0, 1.0);
479 //float w = sincl(ph2 * (1 + 15 * ii2 * ii2), 4) * pow(sincl(j / 256.0, 1), 1);
480 float w = pow(sincl(j / 256.0, 1), 1);
481 float v = sin(ph + ii * sin(3 * ph - ii * w * sin(ph + sin(3 * ph + 0.5 * ii2 * sin(13 * ph + 0.5 * sin(4 * ph))))));
482 tables[wavetable_metadata::wt_gtr3][i][j] = 32767 * v;
485 for (int i = 0; i < 129; i++)
487 for (int j = 0; j < 256; j++)
489 float ph = j * 2 * M_PI / 256;
490 float ii = i / 128.0;
491 float ii2 = dsp::clip(2 * (ii - 0.5), 0.0, 1.0);
492 //float w = sincl(ph2 * (1 + 15 * ii2 * ii2), 4) * pow(sincl(j / 256.0, 1), 1);
493 float w = pow(sincl(j / 256.0, 1), 1);
494 float v = sin(ph + ii * sin(3 * ph - ii * w * sin(2 * ph + sin(5 * ph + 0.5 * ii2 * sin(13 * ph + 0.5 * sin(4 * ph))))));
495 tables[wavetable_metadata::wt_gtr4][i][j] = 32767 * v;
498 for (int i = 0; i < 129; i++)
500 for (int j = 0; j < 256; j++)
502 float ph = j * 2 * M_PI / 256;
503 float ii = i / 128.0;
504 float ii2 = dsp::clip((ii - 0.25)/0.75, 0.0, 1.0);
505 //float w = sincl(ph2 * (1 + 15 * ii2 * ii2), 4) * pow(sincl(j / 256.0, 1), 1);
506 float w = pow(sincl(j / 256.0, 1), 3);
507 float v = sin(ph + (ii + 0.05) * sin(3 * ph - 2 * ii * w * sin(5 * ph + sin(7 * ph + 0.5 * ii2 * sin(13 * ph + 0.5 * sin(11 * ph))))));
508 tables[wavetable_metadata::wt_gtr5][i][j] = 32767 * v;
511 for (int i = 0; i < 129; i++)
513 for (int j = 0; j < 256; j++)
515 float ph = j * 2 * M_PI / 256;
516 float ii = i / 128.0;
517 float w = pow(sincl(2 * (j / 256.0), 2), 3);
518 float v = sin(ph + (ii + 0.05) * sin(7 * ph - 2 * ii * w * sin(11 * ph)));
519 tables[wavetable_metadata::wt_reed][i][j] = 32767 * v;
522 for (int i = 0; i < 129; i++)
524 for (int j = 0; j < 256; j++)
526 float ph = j * 2 * M_PI / 256;
527 float ii = i / 128.0;
528 float ii2 = dsp::clip((ii - 0.25)/0.75, 0.0, 1.0);
529 float ii3 = dsp::clip((ii - 0.5)/0.5, 0.0, 1.0);
530 float v = sin(ph + (ii + 0.05) * sin(ii * sin(2 * ph) - 2 * ii2 * sin(2 * ph + ii2 * sin(3 * ph)) + 3 * ii3 * sin(3 * ph)));
531 tables[wavetable_metadata::wt_reed2][i][j] = 32767 * v;
534 for (int i = 0; i < 129; i++)
536 for (int j = 0; j < 256; j++)
538 float ph = j * 2 * M_PI / 256;
539 float ii = i / 128.0;
540 float mod = 0;
541 for (int k = 0; k < 13; k++)
543 mod += blip(i, k * 10, 30) * sin (ph * (5 + 3 * k) + ii * cos(ph * (2 + 2 * k)));
545 float v = sin(ph + ii * mod);
546 tables[wavetable_metadata::wt_silver][i][j] = 32767 * v;
549 for (int i = 0; i < 129; i++)
551 for (int j = 0; j < 256; j++)
553 float ph = j * 2 * M_PI / 256;
554 float ii = i / 128.0;
555 float mod = 0;
556 for (int k = 0; k < 16; k++)
558 mod += 2 * blip(i, k * 8, k * 4 + 10) * cos (ph * (k + 1));
560 float v = sin(ph + ii * mod);
561 tables[wavetable_metadata::wt_brass][i][j] = 32767 * v;
564 for (int i = 0; i < 129; i++)
566 for (int j = 0; j < 256; j++)
568 float ph = j * 2 * M_PI / 256;
569 float ii = i / 128.0;
570 float mod = 0;
571 for (int k = 0; k < 16; k++)
573 mod += 2 * blip(i, k * 8, 16) * cos (ph * (2 * k + 1));
575 float v = (sin(ph + ii * mod) + ii * sin(2 * ph + ii * mod)) / 2;
576 tables[wavetable_metadata::wt_multi][i][j] = 32767 * v;
579 for (int i = 0; i < 129; i ++)
581 float h = 1 + i / 16.0;
582 for (int j = 0; j < 256; j++)
584 float ph = j * 2 * M_PI / 256;
585 float v = sin(ph), tv = 1;
586 for (int k = 1; k < 24; k++) {
587 float amp = blip(i, k * 6, 20) / k;
588 v += amp * sin((k + 1) * ph + h * sin(ph));
589 tv += amp;
591 tables[wavetable_metadata::wt_multi2][i][j] = 32767 * v / tv;
596 void wavetable_audio_module::channel_pressure(int /*channel*/, int value)
598 inertia_pressure.set_inertia(value * (1.0 / 127.0));
601 char *wavetable_audio_module::configure(const char *key, const char *value)
603 return mod_matrix_impl::configure(key, value);
606 void wavetable_audio_module::control_change(int /*channel*/, int controller, int value)
608 dsp::basic_synth::control_change(controller, value);
609 if (controller == 1)
610 modwheel_value = value * (1.0 / 127.0f);
613 const dsp::modulation_entry *wavetable_audio_module::get_default_mod_matrix_value(int row) const
615 static modulation_entry row0(modsrc_env1, mod_matrix_metadata::map_positive, modsrc_none, 50, moddest_o1shift);
616 static modulation_entry row1(modsrc_lfo2, mod_matrix_metadata::map_positive, modsrc_none, 10, moddest_o1shift);
617 if (row == 0)
618 return &row0;
619 if (row == 1)
620 return &row1;
621 return NULL;
624 #endif