Skip to content

Add BLEP-corrected hard sync#217

Open
TXBDan wants to merge 1 commit intoelectro-smith:masterfrom
TXBDan:add-oscillator-sync
Open

Add BLEP-corrected hard sync#217
TXBDan wants to merge 1 commit intoelectro-smith:masterfrom
TXBDan:add-oscillator-sync

Conversation

@TXBDan
Copy link
Copy Markdown

@TXBDan TXBDan commented Apr 11, 2026

Before Making this Pull Request

  • Please review the Style Guide, and do your best to make sure your code fits the design ethos of the library.
    • Please be sure to run util/fix_style.sh and commit any relevant changes.
    • As appropriate, please be sure to document your code in line.
  • Please add any references to issues this PR fixes using the # tag.
  • Please add a relevant label (for example bug, documentation, etc.)
  • Fill out the sections below as relevant.
  • Thank you for your contribution!

Description

This adds hard oscillator sync support to the Oscillator class, intended for use in synthesis patches where a "master" oscillator resets a "slave" oscillator at each cycle — a classic analog synth technique (Moog, Minimoog, Korg Minilogue, etc.) that produces harmonically rich timbres when the slave is tuned above the master.

New API
void SyncReset(float frac) — resets the slave oscillator's phase with a polyBLEP correction to reduce aliasing at the discontinuity. frac is the sub-sample position (0..1) within the master's last processed sample at which the wrap occurred.

float GetEocFraction() const — returns the fractional wrap position after IsEOC() is true. Used to pass the sub-sample timing to the slave.

Usage

float m = master.Process();
if (master.IsEOC())
    slave.SyncReset(master.GetEocFraction());
float s = slave.Process();

Implementation notes
GetEocFraction() is inline; no library rebuild needed to use it.
SyncReset(float) lives in oscillator.cpp — requires a library rebuild.
The BLEP residual corrects the sample immediately after the sync event. The pre-sync sample cannot be corrected in an online implementation (causality limitation), consistent with the existing polyBLEP approach in this class.
NaiveWaveformValue() is a private helper that evaluates the unfiltered waveform at an arbitrary phase, used to compute the step magnitude at the sync discontinuity.
The built-in polyBLEP is suppressed for one sample after sync via skip_builtin_polyblep_, since its assumed step magnitude of 2 is incorrect for a sync event.

Testing

Verified sync waveforms using oscilloscope. I also compared with and without BLEP correction and observed the aliasing improvement visible on the oscilloscope and by ear.

Demos / Example Code

You can test a Korg Minilogue emulation on Daisy Pod hardware with this project: https://github.com/TXBDan/DaisyMinilogue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant