From 5bf8f5269bacd5ff2f66b6b7c7f93af160a3670e Mon Sep 17 00:00:00 2001 From: xiashj Date: Sat, 15 Jun 2024 13:56:06 +0900 Subject: [PATCH] dummy-osc: output sin wave instead of silence --- platform/nts-1_mkii/dummy-osc/osc.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/nts-1_mkii/dummy-osc/osc.h b/platform/nts-1_mkii/dummy-osc/osc.h index f8326820..59eab2ef 100644 --- a/platform/nts-1_mkii/dummy-osc/osc.h +++ b/platform/nts-1_mkii/dummy-osc/osc.h @@ -150,12 +150,21 @@ class Osc { // Caching current parameter values. Consider interpolating sensitive parameters. // const Params p = params_; + + // get osc pitch from context + const unit_runtime_osc_context_t *ctxt = static_cast(runtime_desc_.hooks.runtime_context); + float w0 = osc_w0f_for_note((ctxt->pitch)>>8, ctxt->pitch & 0xFF); + float lfo = q31_to_f32(ctxt->shape_lfo); // TODO: Apply shape_lfo to the shape parameter for (; out_p != out_e; in_p += 2, out_p += 1) { // Process/generate samples here - // Note: this is a dummy unit only to demonstrate APIs, only outputting silence. - *out_p = 0.f; // sample + // update oscillator phase + w += w0; + w = modff(w, nullptr); // take fractional part to prevent overflow + + // Note: this is a dummy unit only to demonstrate APIs, only outputting sin wave + *out_p = osc_sinf(w); } } @@ -250,6 +259,8 @@ class Osc { } inline void AllNoteOff() { + // resetting the phase to zero for a more consistent attack + w = 0.f; } inline void PitchBend(uint8_t bend) { @@ -281,6 +292,8 @@ class Osc { Params params_; + float w{0.f}; // phasor in [0.0,1.0) + /*===========================================================================*/ /* Private Methods. */ /*===========================================================================*/