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
102 102
103float LEAFTest_tick (float input)103float LEAFTest_tick (float input)
104{104{
105 float out = 0.0f;105 float out = tMBSaw_tick(&bsaw);
106 for (int i = 0; i < numWavetables; ++i)106
107 {107// for (int i = 0; i < numWavetables; ++i)
108 out += tWaveOsc_tick(&ws);108// {
109 }109// out += tWaveOsc_tick(&ws);
110// }
110 return out;111 return out;
111}112}
112 113
@@ -117,7 +118,7 @@ void LEAFTest_block (void) · 4 unmodified lines
117 float val = getSliderValue("slider1");118 float val = getSliderValue("slider1");
118 tMBTriangle_setFreq(&btri, val * 440.f);119 tMBTriangle_setFreq(&btri, val * 440.f);
119 tMBPulse_setFreq(&bpulse, val * 160000.f - 80000.0f);120 tMBPulse_setFreq(&bpulse, val * 160000.f - 80000.0f);
120 tMBSaw_setFreq(&bsaw, val * 10000.f);121 tMBSaw_setFreq(&bsaw, -val * 2000.f + 1000.0f);
121// tWaveTable_setFreq(&wt, val * 160000.f - 80000.0f);122// tWaveTable_setFreq(&wt, val * 160000.f - 80000.0f);
122// tWaveTableS_setFreq(&cwt, val * 10000.);123// tWaveTableS_setFreq(&cwt, val * 10000.);
123 tWaveOsc_setFreq(&ws, val * 2000.f);124 tWaveOsc_setFreq(&ws, val * 2000.f);
leaf/Inc/leaf-oscillators.h+6−3
@@ -746,8 +746,9 @@ extern "C" { · 745 unmodified lines
746 void tMBPulse_setFreq(tMBPulse* const osc, float f);746 void tMBPulse_setFreq(tMBPulse* const osc, float f);
747 void tMBPulse_setWidth(tMBPulse* const osc, float w);747 void tMBPulse_setWidth(tMBPulse* const osc, float w);
748 float tMBPulse_sync(tMBPulse* const osc, float sync);748 float tMBPulse_sync(tMBPulse* const osc, float sync);
749 void tMBPulse_setPhase(tMBPulse* const osc, float phase);
749 void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft);750 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);
751 752
752 /*!753 /*!
753 @defgroup tmbtriangle tMBTriangle754 @defgroup tmbtriangle tMBTriangle
@@ -819,8 +820,9 @@ extern "C" { · 65 unmodified lines
819 void tMBTriangle_setFreq(tMBTriangle* const osc, float f);820 void tMBTriangle_setFreq(tMBTriangle* const osc, float f);
820 void tMBTriangle_setWidth(tMBTriangle* const osc, float w);821 void tMBTriangle_setWidth(tMBTriangle* const osc, float w);
821 float tMBTriangle_sync(tMBTriangle* const osc, float sync);822 float tMBTriangle_sync(tMBTriangle* const osc, float sync);
823 void tMBTriangle_setPhase(tMBTriangle* const osc, float phase);
822 void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft);824 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);
824 826
825 827
826 /*!828 /*!
@@ -890,8 +892,9 @@ extern "C" { · 63 unmodified lines
890 float tMBSaw_tick(tMBSaw* const osc);892 float tMBSaw_tick(tMBSaw* const osc);
891 void tMBSaw_setFreq(tMBSaw* const osc, float f);893 void tMBSaw_setFreq(tMBSaw* const osc, float f);
892 float tMBSaw_sync(tMBSaw* const osc, float sync);894 float tMBSaw_sync(tMBSaw* const osc, float sync);
895 void tMBSaw_setPhase(tMBSaw* const osc, float phase);
893 void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft);896 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);
895 898
896 //==============================================================================899 //==============================================================================
897 900
leaf/Src/leaf-oscillators.c+27−7
@@ -1002,7 +1002,7 @@ float tMBPulse_tick(tMBPulse* const osc) · 1001 unmodified lines
1002 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;1002 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
1003 1003
1004 sw = w * c->syncdir;1004 sw = w * c->syncdir;
1005 p += sw - rintf(sw - 0.5f);1005 p += sw - (int)sw;
1006 1006
1007 if (sync > 0.0f && c->softsync == 0) { /* sync to master */1007 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
1008 float eof_offset = sync * sw;1008 float eof_offset = sync * sw;
@@ -1212,6 +1212,12 @@ float tMBPulse_sync(tMBPulse* const osc, float value) · 203 unmodified lines
1212 return value;1212 return value;
1213}1213}
1214 1214
1215void tMBPulse_setPhase(tMBPulse* const osc, float phase)
1216{
1217 _tMBPulse* c = *osc;
1218 c->_p = phase;
1219}
1220
1215void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft)1221void tMBPulse_setSyncMode(tMBPulse* const osc, int hardOrSoft)
1216{1222{
1217 _tMBPulse* c = *osc;1223 _tMBPulse* c = *osc;
@@ -1282,7 +1288,8 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 64 unmodified lines
1282 // + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;1288 // + 1e3 * linm[1] * vco->_port[LING]) / SAMPLERATE;
1283 w = freq * c->invSampleRate;1289 w = freq * c->invSampleRate;
1284 b = 0.5f * (1.0f + c->waveform);1290 b = 0.5f * (1.0f + c->waveform);
1285 p = 0.5f * b;1291// p = 0.5f * b;
1292 p = 0.f;
1286 /* if we valued alias-free startup over low startup time, we could do:1293 /* if we valued alias-free startup over low startup time, we could do:
1287 * p -= w;1294 * p -= w;
1288 * place_slope_dd(_f, j, 0.0f, w, 1.0f / b); */1295 * place_slope_dd(_f, j, 0.0f, w, 1.0f / b); */
@@ -1300,7 +1307,7 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 11 unmodified lines
1300 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;1307 if (sync > 0.0f && c->softsync > 0) c->syncdir = -c->syncdir;
1301 1308
1302 sw = w * c->syncdir;1309 sw = w * c->syncdir;
1303 p += sw - rintf(sw - 0.5f);1310 p += sw - (int)sw;
1304 1311
1305 if (sync > 0.0f && c->softsync == 0) { /* sync to master */1312 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
1306 float eof_offset = sync * sw;1313 float eof_offset = sync * sw;
@@ -1514,6 +1521,12 @@ float tMBTriangle_sync(tMBTriangle* const osc, float value) · 207 unmodified lines
1514 return value;1521 return value;
1515}1522}
1516 1523
1524void tMBTriangle_setPhase(tMBTriangle* const osc, float phase)
1525{
1526 _tMBTriangle* c = *osc;
1527 c->_p = phase;
1528}
1529
1517void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft)1530void tMBTriangle_setSyncMode(tMBTriangle* const osc, int hardOrSoft)
1518{1531{
1519 _tMBTriangle* c = *osc;1532 _tMBTriangle* c = *osc;
@@ -1526,8 +1539,8 @@ void tMBTriangle_setSampleRate(tMBTriangle* const osc, float sr) · 6 unmodified lines
1526 c->invSampleRate = 1.0f/sr;1539 c->invSampleRate = 1.0f/sr;
1527}1540}
1528 1541
1529//==========================================================================================================1542//==================================================================================================
1530//==========================================================================================================1543//==================================================================================================
1531 1544
1532void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)1545void tMBSaw_init(tMBSaw* const osc, LEAF* const leaf)
1533{1546{
@@ -1577,7 +1590,8 @@ float tMBSaw_tick(tMBSaw* const osc) · 43 unmodified lines
1577 j = c->_j; /* index into buffer _f */1590 j = c->_j; /* index into buffer _f */
1578 1591
1579 if (c->_init) {1592 if (c->_init) {
1580 p = 0.5f;1593// p = 0.5f;
1594 p = 0.f;
1581 w = freq * c->invSampleRate;1595 w = freq * c->invSampleRate;
1582 1596
1583 /* if we valued alias-free startup over low startup time, we could do:1597 /* 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
1605 // else if (sw < 0) place_slope_dd(c->_f, j, 1.0f - p, -sw, -2.0f);1619 // else if (sw < 0) place_slope_dd(c->_f, j, 1.0f - p, -sw, -2.0f);
1606 1620
1607 sw = w * c->syncdir;1621 sw = w * c->syncdir;
1608 p += sw - rintf(sw - 0.5f);1622 p += sw - (int)sw;
1609 1623
1610 if (sync > 0.0f && c->softsync == 0) { /* sync to master */1624 if (sync > 0.0f && c->softsync == 0) { /* sync to master */
1611 float eof_offset = sync * sw;1625 float eof_offset = sync * sw;
@@ -1680,6 +1694,12 @@ float tMBSaw_sync(tMBSaw* const osc, float value) · 68 unmodified lines
1680 return value;1694 return value;
1681}1695}
1682 1696
1697void tMBSaw_setPhase(tMBSaw* const osc, float phase)
1698{
1699 _tMBSaw* c = *osc;
1700 c->_p = phase;
1701}
1702
1683void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft)1703void tMBSaw_setSyncMode(tMBSaw* const osc, int hardOrSoft)
1684{1704{
1685 _tMBSaw* c = *osc;1705 _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