Skip to content

Commit

Permalink
dummy-osc: output sin wave instead of silence
Browse files Browse the repository at this point in the history
  • Loading branch information
xiashj24 committed Jun 15, 2024
1 parent 45a60e1 commit 5bf8f52
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions platform/nts-1_mkii/dummy-osc/osc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const unit_runtime_osc_context_t *>(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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -281,6 +292,8 @@ class Osc {

Params params_;

float w{0.f}; // phasor in [0.0,1.0)

/*===========================================================================*/
/* Private Methods. */
/*===========================================================================*/
Expand Down

0 comments on commit 5bf8f52

Please sign in to comment.