Skip to content

Commit

Permalink
Impove wt osc
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Feb 22, 2024
1 parent ad2f167 commit 6a39703
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
51 changes: 42 additions & 9 deletions modules/gin_dsp/dsp/gin_bandlimitedlookuptable.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,71 @@ class BandLimitedLookupTable
return juce::jlimit (0, int (tables.size() - 1), int ((note - 0.5) / notesPerTable));
}

inline std::vector<float>* tableForNote (float note)
inline std::vector<float>& tableForNote (float note)
{
return &tables[size_t (tableIndexForNote (note))];
return tables[size_t (tableIndexForNote (note))];
}

inline float process (float note, float phase)
{
auto tableIndex = juce::jlimit (0, int (tables.size() - 1), int ((note - 0.5) / notesPerTable));
auto& table = tableForNote (note);
auto pos = int (phase * tableSize);

jassert (pos >= 0 && pos < tableSize);

return tables[size_t (tableIndex)][size_t (pos)];
return table[size_t (pos)];
}

inline float processLinear (float note, float phase)
{
auto& table = tableForNote (note);
auto pos = int (phase * tableSize);
auto frac = (phase * tableSize) - pos;

return (table[size_t (pos)] * (1.0f - frac)) + (table[size_t (pos + 1)] * (frac));
}

#if GIN_HAS_SIMD
inline mipp::Reg<float> process (float note, mipp::Reg<float> phase)
{
static_assert (mipp::N<float>() == 4);

auto tableIndex = juce::jlimit (0, int (tables.size() - 1), int ((note - 0.5) / notesPerTable));
auto& table = tableForNote (note);
phase *= float (tableSize);

float pos[4];
phase.store (pos);

mipp::Reg<float> res =
{
tables[size_t (tableIndex)][size_t (pos[0])],
tables[size_t (tableIndex)][size_t (pos[1])],
tables[size_t (tableIndex)][size_t (pos[2])],
tables[size_t (tableIndex)][size_t (pos[3])],
table[size_t (pos[0])],
table[size_t (pos[1])],
table[size_t (pos[2])],
table[size_t (pos[3])],
};
return res;
}

inline mipp::Reg<float> processLinear (float note, mipp::Reg<float> phase)
{
static_assert (mipp::N<float>() == 4);

auto& table = tableForNote (note);
auto pos = mipp::trunc (phase * float (tableSize));
auto frac = (phase * tableSize) - pos;

float p[4];
pos.store (p);

float f[4];
frac.store (f);

mipp::Reg<float> res =
{
(table[size_t (p[0])] * (1.0f - f[0])) + (table[size_t (p[0] + 1)] * (f[0])),
(table[size_t (p[1])] * (1.0f - f[1])) + (table[size_t (p[1] + 1)] * (f[1])),
(table[size_t (p[2])] * (1.0f - f[2])) + (table[size_t (p[2] + 1)] * (f[2])),
(table[size_t (p[3])] * (1.0f - f[3])) + (table[size_t (p[3] + 1)] * (f[3])),
};
return res;
}
Expand Down
16 changes: 8 additions & 8 deletions modules/gin_dsp/dsp/gin_wtoscillators.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class WTOscillator
mipp::Reg<float> lVec { l };
mipp::Reg<float> rVec { r };

auto s = table->process (note, math::min (almostOne, phaseVec));
auto s = table->processLinear (note, math::min (almostOne, phaseVec));
postProcess (params, s);

lVec += s * params.leftGain;
Expand All @@ -160,7 +160,7 @@ class WTOscillator

for (; todo > 0; todo--)
{
auto s = table->process (note, std::min (almostOne, phase));
auto s = table->processLinear (note, std::min (almostOne, phase));
postProcess (params, s);

*l++ += s * params.leftGain;
Expand Down Expand Up @@ -207,7 +207,7 @@ class WTOscillator
mipp::Reg<float> lVec { l };
mipp::Reg<float> rVec { r };

auto s = table->process (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));
auto s = table->processLinear (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));
postProcess (params, s);

lVec += s * params.leftGain;
Expand All @@ -222,7 +222,7 @@ class WTOscillator

for (; todo > 0; todo--)
{
auto s = table->process (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
auto s = table->processLinear (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
postProcess (params, s);

*l++ += s * params.leftGain;
Expand Down Expand Up @@ -272,8 +272,8 @@ class WTOscillator
mipp::Reg<float> lVec { l };
mipp::Reg<float> rVec { r };

auto s1 = table1->process (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));
auto s2 = table2->process (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));
auto s1 = table1->processLinear (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));
auto s2 = table2->processLinear (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant));

auto s = s1 * phase + s2 * (1.0f - phase);
postProcess (params, s);
Expand All @@ -289,8 +289,8 @@ class WTOscillator

for (; todo > 0; todo--)
{
auto s1 = table1->process (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
auto s2 = table2->process (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
auto s1 = table1->processLinear (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
auto s2 = table2->processLinear (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));

auto s = s1 * phase + s2 * (1.0f - phase);
postProcess (params, s);
Expand Down

0 comments on commit 6a39703

Please sign in to comment.