randomize phase
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
namespace trnr {
|
namespace trnr {
|
||||||
|
|
||||||
@@ -14,13 +15,17 @@ public:
|
|||||||
, history {0.}
|
, history {0.}
|
||||||
, phase_reset {false}
|
, phase_reset {false}
|
||||||
{
|
{
|
||||||
|
randomize_phase();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_phase_resolution(float res) { phase_resolution = powf(2, res); }
|
void set_phase_resolution(float res) { phase_resolution = powf(2, res); }
|
||||||
|
|
||||||
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f)
|
float process_sample(bool trigger, float frequency, float phase_modulation = 0.f)
|
||||||
{
|
{
|
||||||
if (trigger && phase_reset) { phase = 0.0; }
|
if (trigger) {
|
||||||
|
if (phase_reset) phase = 0.f;
|
||||||
|
else randomize_phase();
|
||||||
|
}
|
||||||
|
|
||||||
float lookup_phase = phase + phase_modulation;
|
float lookup_phase = phase + phase_modulation;
|
||||||
wrap(lookup_phase);
|
wrap(lookup_phase);
|
||||||
@@ -37,11 +42,19 @@ public:
|
|||||||
|
|
||||||
void set_samplerate(double _samplerate) { this->samplerate = _samplerate; }
|
void set_samplerate(double _samplerate) { this->samplerate = _samplerate; }
|
||||||
|
|
||||||
|
void randomize_phase()
|
||||||
|
{
|
||||||
|
std::mt19937 gen(random());
|
||||||
|
std::uniform_real_distribution<> dis(0.0, 1.0);
|
||||||
|
phase = dis(gen);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double samplerate;
|
double samplerate;
|
||||||
float phase_resolution;
|
float phase_resolution;
|
||||||
float phase;
|
float phase;
|
||||||
float history;
|
float history;
|
||||||
|
std::random_device random;
|
||||||
|
|
||||||
float sine(float x)
|
float sine(float x)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user