mirror of
https://codeberg.org/armin/monostep.git
synced 2026-09-01 12:20:46 +02:00
Prototype
This commit is contained in:
parent
c117906a7f
commit
4271fc34bb
14 changed files with 950 additions and 169 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
namespace monostep
|
||||
{
|
||||
|
|
@ -11,7 +12,11 @@ enum class Waveform : int
|
|||
sine = 0,
|
||||
triangle = 1,
|
||||
saw = 2,
|
||||
square = 3
|
||||
square = 3,
|
||||
pulse = 4,
|
||||
noise = 5,
|
||||
sub = 6,
|
||||
pluck = 7
|
||||
};
|
||||
|
||||
inline float frac (float x)
|
||||
|
|
@ -63,6 +68,31 @@ inline float renderWave (Waveform w, float phase, float inc)
|
|||
v -= polyBlep (frac (f + 0.5f), inc);
|
||||
return v;
|
||||
}
|
||||
|
||||
case Waveform::pulse:
|
||||
{
|
||||
const float f = frac (phase);
|
||||
return (f < 0.3f) ? 1.0f : -1.0f;
|
||||
}
|
||||
|
||||
case Waveform::sub:
|
||||
{
|
||||
const float f = frac (phase * 0.25f);
|
||||
return 4.0f * std::min (f, 1.0f - f) - 1.0f;
|
||||
}
|
||||
|
||||
case Waveform::noise:
|
||||
{
|
||||
thread_local static std::mt19937 rng { std::random_device {}() };
|
||||
thread_local static std::uniform_real_distribution<float> dist (-1.0f, 1.0f);
|
||||
return dist (rng);
|
||||
}
|
||||
|
||||
case Waveform::pluck:
|
||||
{
|
||||
const float f = frac (phase);
|
||||
return 2.0f * std::sin (f * 6.283185307179586f * 2.0f) * std::exp (-10.0f * f);
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue