Skip to content

Initialize oscillator history and AD envelope trigger state - #220

Open
dajiaohuang wants to merge 1 commit into
daisyaudio:masterfrom
dajiaohuang:fix/initialize-oscillator-adenv-20261015
Open

dajiaohuang wants to merge 1 commit into
daisyaudio:masterfrom
dajiaohuang:fix/initialize-oscillator-adenv-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown

Description

Initialize the processing history that Oscillator::Init and AdEnv::Init currently leave untouched.

  • Oscillator::Process reads last_out_ for WAVE_POLYBLEP_TRI, but Init never assigns it. Automatic-storage oscillators can therefore read indeterminate history. Reinitializing an oscillator that has already processed a triangle also retains its previous integrator output, despite resetting its phase. Initialize that history to zero; phase-only Reset behavior is unchanged.
  • AdEnv::Process reads trigger_ and prev_segment_ before assigning them. Initialize both so that the documented idle initial state does not depend on prior storage or a pending trigger. Fixes AdEnv does not initialize the "trigger_" data member, causing the envelope to trigger on the first call to Process () #212.

Only the missing state assignments change; parameters, waveform algorithms, and public interfaces are unchanged.

Testing

  • Built the full library with CMake, GCC 13.3.0, and C++14 on Ubuntu 24.04 (WSL).
  • Added a standalone host regression and reproduction commands under tests/initialization. It uses ordinary public calls and static initial storage, without depending on arbitrary uninitialized-memory contents. At 44.1, 48, and 96 kHz it processes a triangle, calls Init again, and checks that the first sample is zero, as follows from the phase-zero polyBLEP input and zero integrator history. It also calls Trigger, reinitializes the AD envelope, and verifies idle output without another trigger.
  • On base 2c72eaf, the regression fails both cases at all three rates: the oscillator retains nonzero output, and the envelope enters attack with output 0.0001. With this change it passes. The fixed regression also passes AddressSanitizer and UndefinedBehaviorSanitizer.
  • Additional bounded offline checks pass at all three sample rates: oscillator waveforms, OnePole sample/block equivalence, in-range Svf modulation, ADSR gate stages at sample and block control rates, and a triggered linear AD envelope.
  • Ran util/fix_style.sh; retained only relevant changes. Local formatter is the Visual Studio bundled version, not CI's pinned clang-format 10.

No audio devices, playback, firmware flashing, or benchmarks were used. ARM cross-build and physical Daisy hardware acceptance were not run locally; these host checks do not substitute for them. No native Windows default-build fix is included (tracked separately in #197).

Demos / Example Code

tests/initialization/tst_initialization.cpp is an offline public-API example and regression; it does not require libDaisy.

Suggested label: bug (I do not have repository label-assignment permissions).

This branch has not been deployed

No deployments
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.

AdEnv does not initialize the "trigger_" data member, causing the envelope to trigger on the first call to Process ()

1 participant