ref: da54fcd1e8aef1246180fae5cf321c7e7a88ce52
parent: 5a5d9902af9c8b2680721fec0ae49426488bf829
author: Matthew Wang <mjw7@princeton.edu>
date: Thu Jul 29 16:45:36 EDT 2021
revert MB oscs to int casts for negative freq handling
--- a/TestPlugin/Source/MyTest.cpp
+++ b/TestPlugin/Source/MyTest.cpp
@@ -102,11 +102,12 @@
float LEAFTest_tick (float input)
{
- float out = 0.0f;
- for (int i = 0; i < numWavetables; ++i)
- {
- out += tWaveOsc_tick(&ws);
- }
+ float out = tMBSaw_tick(&bsaw);
+
+// for (int i = 0; i < numWavetables; ++i)
+// {
+// out += tWaveOsc_tick(&ws);
+// }
return out;
}
@@ -117,7 +118,7 @@
float val = getSliderValue("slider1");
tMBTriangle_setFreq(&btri, val * 440.f);
tMBPulse_setFreq(&bpulse, val * 160000.f - 80000.0f);
- tMBSaw_setFreq(&bsaw, val * 10000.f);
+ tMBSaw_setFreq(&bsaw, -val * 2000.f + 1000.0f);
// tWaveTable_setFreq(&wt, val * 160000.f - 80000.0f);
// tWaveTableS_setFreq(&cwt, val * 10000.);
tWaveOsc_setFreq(&ws, val * 2000.f);
--- a/leaf/Inc/leaf-oscillators.h
+++ b/leaf/Inc/leaf-oscillators.h
@@ -746,8 +746,9 @@
void tMBPulse_setFreq(tMBPulse* const osc, float f);
void tMBPulse_setWidth(tMBPulse* const osc, float w);
float tMBPulse_sync(tMBPulse* const osc, float sync);
+ void tMBPulse_setPhase(tMBPulse* const osc, float phase);
void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft);
- void tMBPulse_setSampleRate (tMBPulse* const osc, float sr);
+ void tMBPulse_setSampleRate (tMBPulse* const osc, float sr);
/*!
@defgroup tmbtriangle tMBTriangle
@@ -819,8 +820,9 @@
void tMBTriangle_setFreq(tMBTriangle* const osc, float f);
void tMBTriangle_setWidth(tMBTriangle* const osc, float w);
float tMBTriangle_sync(tMBTriangle* const osc, float sync);
+ void tMBTriangle_setPhase(tMBTriangle* const osc, float phase);
void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft);
- void tMBTriangle_setSampleRate (tMBTriangle* const osc, float sr);
+ void tMBTriangle_setSampleRate (tMBTriangle* const osc, float sr);
/*!
@@ -890,8 +892,9 @@
float tMBSaw_tick(tMBSaw* const osc);
void tMBSaw_setFreq(tMBSaw* const osc, float f);
float tMBSaw_sync(tMBSaw* const osc, float sync);
+ void tMBSaw_setPhase(tMBSaw* const osc, float phase);
void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft);
- void tMBSaw_setSampleRate (tMBSaw* const osc, float sr);
+ void tMBSaw_setSampleRate (tMBSaw* const osc, float sr);
//==============================================================================
--- a/leaf/Src/leaf-oscillators.c
+++ b/leaf/Src/leaf-oscillators.c
@@ -1002,7 +1002,7 @@
if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
sw = w * c->syncdir;
- p += sw - rintf(sw - 0.5f);
+ p += sw - (int)sw;
if (sync > 0.0f && c->softsync == 0) { /* sync to master */
float eof_offset = sync * sw;
@@ -1212,6 +1212,12 @@
return value;
}
+void tMBPulse_setPhase(tMBPulse* const osc, float phase)
+{
+ _tMBPulse* c = *osc;
+ c->_p = phase;
+}
+
void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft)
{
_tMBPulse* c = *osc;
@@ -1282,7 +1288,8 @@
// + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;
w = freq * c->invSampleRate;
b = 0.5f * (1.0f + c->waveform);
- p = 0.5f * b;
+// p = 0.5f * b;
+ p = 0.f;
/* if we valued alias-free startup over low startup time, we could do:
* p -= w;
* place_slope_dd(_f, j, 0.0f, w, 1.0f / b); */
@@ -1300,7 +1307,7 @@
if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
sw = w * c->syncdir;
- p += sw - rintf(sw - 0.5f);
+ p += sw - (int)sw;
if (sync > 0.0f && c->softsync == 0) { /* sync to master */
float eof_offset = sync * sw;
@@ -1514,6 +1521,12 @@
return value;
}
+void tMBTriangle_setPhase(tMBTriangle* const osc, float phase)
+{
+ _tMBTriangle* c = *osc;
+ c->_p = phase;
+}
+
void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft)
{
_tMBTriangle* c = *osc;
@@ -1526,8 +1539,8 @@
c->invSampleRate = 1.0f/sr;
}
-//==========================================================================================================
-//==========================================================================================================
+//==================================================================================================
+//==================================================================================================
void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)
{
@@ -1577,7 +1590,8 @@
j = c->_j; /* index into buffer _f */
if (c->_init) {
- p = 0.5f;
+// p = 0.5f;
+ p = 0.f;
w = freq * c->invSampleRate;
/* if we valued alias-free startup over low startup time, we could do:
@@ -1605,7 +1619,7 @@
// else if (sw < 0) place_slope_dd(c->_f, j, 1.0f - p, -sw, -2.0f);
sw = w * c->syncdir;
- p += sw - rintf(sw - 0.5f);
+ p += sw - (int)sw;
if (sync > 0.0f && c->softsync == 0) { /* sync to master */
float eof_offset = sync * sw;
@@ -1678,6 +1692,12 @@
else c->sync = 0.f;
return value;
+}
+
+void tMBSaw_setPhase(tMBSaw* const osc, float phase)
+{
+ _tMBSaw* c = *osc;
+ c->_p = phase;
}
void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft)