Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created January 2, 2026 17:09
Show Gist options
  • Select an option

  • Save Xenakios/655ac162a49643f83187659ab452096e to your computer and use it in GitHub Desktop.

Select an option

Save Xenakios/655ac162a49643f83187659ab452096e to your computer and use it in GitHub Desktop.
struct Gendyn2026
{
struct Node
{
float x0 = 0.0f;
float y0 = 0.0f;
};
alignas(16) std::array<Node, 256> nodes;
alignas(16) double phase = 0.0;
alignas(16) double phaseincrement = 0.0;
size_t numnodes = 5;
double sr = 0.0;
float ampspread = 0.0f;
float timespread = 0.0f;
enum RANDOMDIST
{
RD_HYPCOS,
RD_CAUCHY
};
RANDOMDIST timedist = RD_HYPCOS;
RANDOMDIST ampdist = RD_HYPCOS;
xenakios::Xoroshiro128Plus rng;
Gendyn2026()
{
for (size_t i = 0; i < nodes.size(); ++i)
{
nodes[i] = {32.0f, 0.5f};
}
}
void prepare(double samplerate)
{
sr = samplerate;
phaseincrement = 1.0 / nodes[0].x0;
}
float step()
{
float y0 = nodes[0].y0;
float y1 = nodes[1].y0;
float y2 = nodes[2].y0;
float y3 = nodes[3].y0;
float intery = sst::basic_blocks::dsp::cubic_ipol(y0, y1, y2, y3, phase);
// cubic interpolation will overshoot...
intery = std::clamp(intery, -1.0f, 1.0f);
phase += phaseincrement;
if (phase >= 1.0)
{
// shift/rotate node array left, the current first node will become last node
std::rotate(nodes.begin(), nodes.begin() + 1, nodes.begin() + numnodes);
float x = nodes[numnodes - 1].x0;
if (timedist == RD_HYPCOS)
x += rng.nextHypCos(0.0, timespread);
else if (timedist == RD_CAUCHY)
x += rng.nextCauchy(0.0, timespread);
x = reflect_value(1.0f, x, 16.0f);
nodes[numnodes - 1].x0 = x;
float y = nodes[numnodes - 1].y0;
if (ampdist == RD_HYPCOS)
y += rng.nextHypCos(0.0, ampspread);
else if (ampdist == RD_CAUCHY)
y += rng.nextCauchy(0.0, ampspread);
y = reflect_value(-0.5f, y, 0.5f);
nodes[numnodes - 1].y0 = y;
phaseincrement = 1.0 / nodes[0].x0;
phase = 0.0;
}
return intery;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment