History

allow negative mbsaw freq

Matthew Wang committed 6 years ago

Commit 3eca39b1 parent 09c6e973 files · +52 −13Browse files

Unified · Split

3 files
  1. TestPlugin/Source/MyTest.cpp +6 −3
  2. leaf/Inc/leaf-math.h +2 −0
  3. leaf/Src/leaf-oscillators.c +44 −10
TestPlugin/Source/MyTest.cpp+6−3
@@ -55,6 +55,7 @@ void LEAFTest_init (float sampleRate, int blockSize) · 54 unmodified lines
55 LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);55 LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
56 56
57 tMBSaw_init(&bsaw, &leaf);57 tMBSaw_init(&bsaw, &leaf);
58 tMBSaw_setFreq(&bsaw, -500);
58 tMBTriangle_init(&btri, &leaf);59 tMBTriangle_init(&btri, &leaf);
59 tMBPulse_init(&bpulse, &leaf);60 tMBPulse_init(&bpulse, &leaf);
60 61
@@ -94,9 +95,11 @@ inline double getSawFall(double angle) { · 33 unmodified lines
94 95
95float LEAFTest_tick (float input)96float LEAFTest_tick (float input)
96{97{
97 tBuffer_tick(&samp, input);98// tBuffer_tick(&samp, input);
98 99//
99 return tMBSampler_tick(&sampler);100// return tMBSampler_tick(&sampler);
101
102 return tMBSaw_tick(&bsaw);
100 103
101 104
102// tMBSaw_setFreq(&bsaw, x);105// tMBSaw_setFreq(&bsaw, x);
leaf/Inc/leaf-math.h+2−0
@@ -190,6 +190,8 @@ extern "C" { · 189 unmodified lines
190 double fasterexp(double x);190 double fasterexp(double x);
191 191
192 float fasterexpf(float x);192 float fasterexpf(float x);
193
194 float fastsqrtf(float x);
193 195
194 float mtof(float f);196 float mtof(float f);
195 197
leaf/Src/leaf-oscillators.c+44−10
@@ -1166,13 +1166,23 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 1165 unmodified lines
1166 a = 0.5f; // when a = 1, LPfilter is disabled1166 a = 0.5f; // when a = 1, LPfilter is disabled
1167 1167
1168 t = freq / leaf->sampleRate;1168 t = freq / leaf->sampleRate;
1169 if (t < 1e-5f) t = 1e-5f;1169
1170 if (t > 0.5f) t = 0.5f;1170 if (t >= 0)
1171 dw = (t - w) ;1171 {
1172 if (t < 1e-5f) t = 1e-5f;
1173 if (t > 0.5f) t = 0.5f;
1174 }
1175 else
1176 {
1177 if (t > -1e-5f) t = -1e-5f;
1178 if (t < -0.5f) t = -0.5f;
1179 }
1180
1181 dw = (t - w);
1172 t = 0.5f * (1.0f + c->waveform );1182 t = 0.5f * (1.0f + c->waveform );
1173 if (t < w) t = w;1183 if (t < w) t = w;
1174 if (t > 1.0f - w) t = 1.0f - w;1184 if (t > 1.0f - w) t = 1.0f - w;
1175 db = (t - b) ;1185 db = (t - b);
1176 1186
1177 w += dw;1187 w += dw;
1178 b += db;1188 b += db;
@@ -1357,8 +1367,18 @@ float tMBSaw_tick(tMBSaw* const osc) · 178 unmodified lines
1357 if (c->_init) {1367 if (c->_init) {
1358 p = 0.5f;1368 p = 0.5f;
1359 w = freq / leaf->sampleRate;1369 w = freq / leaf->sampleRate;
1360 if (w < 1e-5f) w = 1e-5f;1370
1361 if (w > 0.5f) w = 0.5f;1371 if (w >= 0)
1372 {
1373 if (w < 1e-5f) w = 1e-5f;
1374 if (w > 0.5f) w = 0.5f;
1375 }
1376 else
1377 {
1378 if (w > -1e-5f) w = -1e-5f;
1379 if (w < -0.5f) w = -0.5f;
1380 }
1381
1362 /* if we valued alias-free startup over low startup time, we could do:1382 /* if we valued alias-free startup over low startup time, we could do:
1363 * p -= w;1383 * p -= w;
1364 * place_slope_dd(_f, j, 0.0f, w, -1.0f); */1384 * place_slope_dd(_f, j, 0.0f, w, -1.0f); */
@@ -1369,8 +1389,18 @@ float tMBSaw_tick(tMBSaw* const osc) · 4 unmodified lines
1369 a = 0.5f; // when a = 1, LPfilter is disabled1389 a = 0.5f; // when a = 1, LPfilter is disabled
1370 1390
1371 t = freq / leaf->sampleRate;1391 t = freq / leaf->sampleRate;
1372 if (t < 1e-5f) t = 1e-5f;1392
1373 if (t > 0.5f) t = 0.5f;1393 if (t >= 0)
1394 {
1395 if (t < 1e-5f) t = 1e-5f;
1396 if (t > 0.5f) t = 0.5f;
1397 }
1398 else
1399 {
1400 if (t > -1e-5f) t = -1e-5f;
1401 if (t < -0.5f) t = -0.5f;
1402 }
1403
1374 dw = (t - w); // n= 11404 dw = (t - w); // n= 1
1375 w += dw;1405 w += dw;
1376 p += w;1406 p += w;
@@ -1398,8 +1428,12 @@ float tMBSaw_tick(tMBSaw* const osc) · 21 unmodified lines
1398 c->syncout = p / w + 1e-20f;1428 c->syncout = p / w + 1e-20f;
1399 place_step_dd(c->_f, j, p, w, 1.0f);1429 place_step_dd(c->_f, j, p, w, 1.0f);
1400 1430
1401 } else {1431 } else if (p < 0.0f) {
1402 1432 p += 1.0f;
1433 c->syncout = p / w + 1e-20f;
1434 place_step_dd(c->_f, j, 1.0f - p, -w, -1.0f);
1435 }
1436 else {
1403 c->syncout = 0.0f;1437 c->syncout = 0.0f;
1404 }1438 }
1405 c->_f[j + DD_SAMPLE_DELAY] += 0.5f - p;1439 c->_f[j + DD_SAMPLE_DELAY] += 0.5f - p;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t