History

revert MB oscs to int casts for negative freq handling

Matthew Wang committed 5 years ago

Commit da54fcd1 parent 5a5d9903 files · +40 −16Browse files

Unified · Split

3 files
  1. TestPlugin/Source/MyTest.cpp +7 −6
  2. leaf/Inc/leaf-oscillators.h +6 −3
  3. leaf/Src/leaf-oscillators.c +27 −7
TestPlugin/Source/MyTest.cpp+7−6
@@ -102,11 +102,12 @@ inline double getSawFall(double angle) { · 101 unmodified lines
102102
103103 float LEAFTest_tick (float input)
104104 {
105− float out = 0.0f;
106− for (int i = 0; i < numWavetables; ++i)
107− {
108− out += tWaveOsc_tick(&ws);
109− }
105+ float out = tMBSaw_tick(&bsaw);
106+
107+// for (int i = 0; i < numWavetables; ++i)
108+// {
109+// out += tWaveOsc_tick(&ws);
110+// }
110111 return out;
111112 }
112113
@@ -117,7 +118,7 @@ void LEAFTest_block (void) · 4 unmodified lines
117118 float val = getSliderValue("slider1");
118119 tMBTriangle_setFreq(&btri, val * 440.f);
119120 tMBPulse_setFreq(&bpulse, val * 160000.f - 80000.0f);
120− tMBSaw_setFreq(&bsaw, val * 10000.f);
121+ tMBSaw_setFreq(&bsaw, -val * 2000.f + 1000.0f);
121122 // tWaveTable_setFreq(&wt, val * 160000.f - 80000.0f);
122123 // tWaveTableS_setFreq(&cwt, val * 10000.);
123124 tWaveOsc_setFreq(&ws, val * 2000.f);
leaf/Inc/leaf-oscillators.h+6−3
@@ -746,8 +746,9 @@ extern "C" { · 745 unmodified lines
746746 void tMBPulse_setFreq(tMBPulse* const osc, float f);
747747 void tMBPulse_setWidth(tMBPulse* const osc, float w);
748748 float tMBPulse_sync(tMBPulse* const osc, float sync);
749+ void tMBPulse_setPhase(tMBPulse* const osc, float phase);
749750 void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft);
750− void tMBPulse_setSampleRate (tMBPulse* const osc, float sr);
751+ void tMBPulse_setSampleRate (tMBPulse* const osc, float sr);
751752
752753 /*!
753754 @defgroup tmbtriangle tMBTriangle
@@ -819,8 +820,9 @@ extern "C" { · 65 unmodified lines
819820 void tMBTriangle_setFreq(tMBTriangle* const osc, float f);
820821 void tMBTriangle_setWidth(tMBTriangle* const osc, float w);
821822 float tMBTriangle_sync(tMBTriangle* const osc, float sync);
823+ void tMBTriangle_setPhase(tMBTriangle* const osc, float phase);
822824 void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft);
823− void tMBTriangle_setSampleRate (tMBTriangle* const osc, float sr);
825+ void tMBTriangle_setSampleRate (tMBTriangle* const osc, float sr);
824826
825827
826828 /*!
@@ -890,8 +892,9 @@ extern "C" { · 63 unmodified lines
890892 float tMBSaw_tick(tMBSaw* const osc);
891893 void tMBSaw_setFreq(tMBSaw* const osc, float f);
892894 float tMBSaw_sync(tMBSaw* const osc, float sync);
895+ void tMBSaw_setPhase(tMBSaw* const osc, float phase);
893896 void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft);
894− void tMBSaw_setSampleRate (tMBSaw* const osc, float sr);
897+ void tMBSaw_setSampleRate (tMBSaw* const osc, float sr);
895898
896899 //==============================================================================
897900
leaf/Src/leaf-oscillators.c+27−7
@@ -1002,7 +1002,7 @@ float tMBPulse_tick(tMBPulse* const osc) · 1001 unmodified lines
10021002 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
10031003
10041004 sw = w * c->syncdir;
1005− p += sw - rintf(sw - 0.5f);
1005+ p += sw - (int)sw;
10061006
10071007 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
10081008 float eof_offset = sync * sw;
@@ -1212,6 +1212,12 @@ float tMBPulse_sync(tMBPulse* const osc, float value) · 203 unmodified lines
12121212 return value;
12131213 }
12141214
1215+void tMBPulse_setPhase(tMBPulse* const osc, float phase)
1216+{
1217+ _tMBPulse* c = *osc;
1218+ c->_p = phase;
1219+}
1220+
12151221 void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft)
12161222 {
12171223 _tMBPulse* c = *osc;
@@ -1282,7 +1288,8 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 64 unmodified lines
12821288 // + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;
12831289 w = freq * c->invSampleRate;
12841290 b = 0.5f * (1.0f + c->waveform);
1285− p = 0.5f * b;
1291+// p = 0.5f * b;
1292+ p = 0.f;
12861293 /* if we valued alias-free startup over low startup time, we could do:
12871294 * p -= w;
12881295 * place_slope_dd(_f, j, 0.0f, w, 1.0f / b); */
@@ -1300,7 +1307,7 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 11 unmodified lines
13001307 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
13011308
13021309 sw = w * c->syncdir;
1303− p += sw - rintf(sw - 0.5f);
1310+ p += sw - (int)sw;
13041311
13051312 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
13061313 float eof_offset = sync * sw;
@@ -1514,6 +1521,12 @@ float tMBTriangle_sync(tMBTriangle* const osc, float value) · 207 unmodified lines
15141521 return value;
15151522 }
15161523
1524+void tMBTriangle_setPhase(tMBTriangle* const osc, float phase)
1525+{
1526+ _tMBTriangle* c = *osc;
1527+ c->_p = phase;
1528+}
1529+
15171530 void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft)
15181531 {
15191532 _tMBTriangle* c = *osc;
@@ -1526,8 +1539,8 @@ void tMBTriangle_setSampleRate(tMBTriangle* const osc, float sr) · 6 unmodified lines
15261539 c->invSampleRate = 1.0f/sr;
15271540 }
15281541
1529−//==========================================================================================================
1530−//==========================================================================================================
1542+//==================================================================================================
1543+//==================================================================================================
15311544
15321545 void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)
15331546 {
@@ -1577,7 +1590,8 @@ float tMBSaw_tick(tMBSaw* const osc) · 43 unmodified lines
15771590 j = c->_j; /* index into buffer _f */
15781591
15791592 if (c->_init) {
1580− p = 0.5f;
1593+// p = 0.5f;
1594+ p = 0.f;
15811595 w = freq * c->invSampleRate;
15821596
15831597 /* if we valued alias-free startup over low startup time, we could do:
@@ -1605,7 +1619,7 @@ float tMBSaw_tick(tMBSaw* const osc) · 21 unmodified lines
16051619 // else if (sw < 0) place_slope_dd(c->_f, j, 1.0f - p, -sw, -2.0f);
16061620
16071621 sw = w * c->syncdir;
1608− p += sw - rintf(sw - 0.5f);
1622+ p += sw - (int)sw;
16091623
16101624 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
16111625 float eof_offset = sync * sw;
@@ -1680,6 +1694,12 @@ float tMBSaw_sync(tMBSaw* const osc, float value) · 68 unmodified lines
16801694 return value;
16811695 }
16821696
1697+void tMBSaw_setPhase(tMBSaw* const osc, float phase)
1698+{
1699+ _tMBSaw* c = *osc;
1700+ c->_p = phase;
1701+}
1702+
16831703 void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft)
16841704 {
16851705 _tMBSaw* c = *osc;

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