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
5555 LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
5656
5757 tMBSaw_init(&bsaw, &leaf);
58+ tMBSaw_setFreq(&bsaw, -500);
5859 tMBTriangle_init(&btri, &leaf);
5960 tMBPulse_init(&bpulse, &leaf);
6061
@@ -94,9 +95,11 @@ inline double getSawFall(double angle) { · 33 unmodified lines
9495
9596 float LEAFTest_tick (float input)
9697 {
97− tBuffer_tick(&samp, input);
98−
99− return tMBSampler_tick(&sampler);
98+// tBuffer_tick(&samp, input);
99+//
100+// return tMBSampler_tick(&sampler);
101+
102+ return tMBSaw_tick(&bsaw);
100103
101104
102105 // tMBSaw_setFreq(&bsaw, x);
leaf/Inc/leaf-math.h+2−0
@@ -190,6 +190,8 @@ extern "C" { · 189 unmodified lines
190190 double fasterexp(double x);
191191
192192 float fasterexpf(float x);
193+
194+ float fastsqrtf(float x);
193195
194196 float mtof(float f);
195197
leaf/Src/leaf-oscillators.c+44−10
@@ -1166,13 +1166,23 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 1165 unmodified lines
11661166 a = 0.5f; // when a = 1, LPfilter is disabled
11671167
11681168 t = freq / leaf->sampleRate;
1169− if (t < 1e-5f) t = 1e-5f;
1170− if (t > 0.5f) t = 0.5f;
1171− dw = (t - w) ;
1169+
1170+ if (t >= 0)
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);
11721182 t = 0.5f * (1.0f + c->waveform );
11731183 if (t < w) t = w;
11741184 if (t > 1.0f - w) t = 1.0f - w;
1175− db = (t - b) ;
1185+ db = (t - b);
11761186
11771187 w += dw;
11781188 b += db;
@@ -1357,8 +1367,18 @@ float tMBSaw_tick(tMBSaw* const osc) · 178 unmodified lines
13571367 if (c->_init) {
13581368 p = 0.5f;
13591369 w = freq / leaf->sampleRate;
1360− if (w < 1e-5f) w = 1e-5f;
1361− if (w > 0.5f) w = 0.5f;
1370+
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+
13621382 /* if we valued alias-free startup over low startup time, we could do:
13631383 * p -= w;
13641384 * place_slope_dd(_f, j, 0.0f, w, -1.0f); */
@@ -1369,8 +1389,18 @@ float tMBSaw_tick(tMBSaw* const osc) · 4 unmodified lines
13691389 a = 0.5f; // when a = 1, LPfilter is disabled
13701390
13711391 t = freq / leaf->sampleRate;
1372− if (t < 1e-5f) t = 1e-5f;
1373− if (t > 0.5f) t = 0.5f;
1392+
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+
13741404 dw = (t - w); // n= 1
13751405 w += dw;
13761406 p += w;
@@ -1398,8 +1428,12 @@ float tMBSaw_tick(tMBSaw* const osc) · 21 unmodified lines
13981428 c->syncout = p / w + 1e-20f;
13991429 place_step_dd(c->_f, j, p, w, 1.0f);
14001430
1401− } else {
1402−
1431+ } else if (p < 0.0f) {
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 {
14031437 c->syncout = 0.0f;
14041438 }
14051439 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