From e65116a9c3ae949255c157397d62ac5136178539 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 Jul 2024 21:44:32 +0200 Subject: [PATCH] randomize phase --- synth/tx_sineosc.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/synth/tx_sineosc.h b/synth/tx_sineosc.h index 5a2c184..d6cdc15 100644 --- a/synth/tx_sineosc.h +++ b/synth/tx_sineosc.h @@ -1,5 +1,6 @@ #pragma once #include +#include namespace trnr { @@ -14,13 +15,17 @@ public: , history {0.} , phase_reset {false} { + randomize_phase(); } void set_phase_resolution(float res) { phase_resolution = powf(2, res); } 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; wrap(lookup_phase); @@ -37,11 +42,19 @@ public: 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: double samplerate; float phase_resolution; float phase; float history; + std::random_device random; float sine(float x) {