Skip to content

Commit

Permalink
Add the Squarish waveshape
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Dec 26, 2024
1 parent 63a542a commit 3cbbe95
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
37 changes: 36 additions & 1 deletion src/dsp/sintable.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct SinTable
{
SIN = 0, // these stream so you know....
SIN_FIFTH,
SQUARISH,

NUM_WAVEFORMS
};
Expand All @@ -40,7 +41,7 @@ struct SinTable
float linterpCoefficients[2][nPoints];

SIMD_M128
simdFullQuad alignas(16)[NUM_WAVEFORMS][4 * nPoints]; // for each quad it is q, q+1, dq + 1
simdFullQuad alignas(16)[NUM_WAVEFORMS][4 * nPoints]; // for each quad it is q, q+1, dq + 1
SIMD_M128 *simdQuad;
SIMD_M128 simdCubic alignas(16)[nPoints]; // it is cq, cq+1, cdq, cd1+1

Expand Down Expand Up @@ -74,6 +75,40 @@ struct SinTable
}
}

// Waveform 1: sin(x) ^ 5. Derivative is 5 sin(x)^4 cos(x)
static constexpr float winFreq{8.0};
static constexpr float dFr{1.0 / (4 * winFreq)};
for (int i = 0; i < nPoints + 1; ++i)
{
for (int Q = 0; Q < 4; ++Q)
{
auto x = (1.0 * i / (nPoints - 1) + Q) * 0.25;
float v{0}, dv{0};
if (x <= dFr || x > 1.0 - dFr)
{
v = sin(2.0 * M_PI * winFreq * x);
dv = winFreq * 2.0 * M_PI * cos(2.0 * M_PI * 4 * x);
}
else if (x <= 0.5 - dFr)
{
v = 1.0;
dv = 0.0;
}
else if (x < 0.5 + dFr)
{
v = -sin(2.0 * M_PI * winFreq * x);
dv = winFreq * -2.0 * M_PI * cos(2.0 * M_PI * winFreq * x);
}
else
{
v = -1.0;
dv = 0.0;
}
quadrantTable[2][Q][i] = v;
dQuadrantTable[2][Q][i] = dv / (nPoints - 1);
}
}

for (int i = 0; i < nPoints; ++i)
{
auto t = 1.f * i / (1 << 12);
Expand Down
20 changes: 10 additions & 10 deletions src/synth/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ struct Patch
.withRange(0, 1)
.withDefault(0)
.withUnorderedMapFormatting({{0, "+"}, {1, "x"}})),
waveForm(intMd()
.withName(name(idx) + " Waveform")
.withGroupName(name(idx))
.withID(id(5, idx))
.withRange(0, SinTable::WaveForm::NUM_WAVEFORMS - 1)
.withDefault(0)
.withUnorderedMapFormatting({
{SinTable::WaveForm::SIN, "Sin"},
{SinTable::WaveForm::SIN_FIFTH, "Sin^5"},
})),
waveForm(
intMd()
.withName(name(idx) + " Waveform")
.withGroupName(name(idx))
.withID(id(5, idx))
.withRange(0, SinTable::WaveForm::NUM_WAVEFORMS - 1)
.withDefault(0)
.withUnorderedMapFormatting({{SinTable::WaveForm::SIN, "Sin"},
{SinTable::WaveForm::SIN_FIFTH, "Sin^5"},
{SinTable::WaveForm::SQUARISH, "Squarish"}})),
DAHDSRMixin(name(idx), id(100, idx), false), LFOMixin(name(idx), id(45, idx))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/source-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct WavPainter : juce::Component
st.setWaveForm((SinTable::WaveForm)std::round(wf.value));
uint32_t phase{0};
int nPixels{getWidth()};
auto dPhase = (1 << 27) / (nPixels - 1);
auto dPhase = (1 << 26) / (nPixels - 1);
auto p = juce::Path();
for (int i = 0; i < nPixels; ++i)
{
Expand Down

0 comments on commit 3cbbe95

Please sign in to comment.