Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: lfo phase reset

  1. #1
    Senior Member
    Join Date
    Dec 2018
    Posts
    186

    lfo phase reset

    Hello,

    I try to reset the phase of an LFO to zero each time a note is played. It has no effect. I think I misunderstand to use of phase().

    lfo.phase(0); //reset LFO phase
    envelope1.noteOn(); //new note

    Emmanuel

  2. #2
    Senior Member
    Join Date
    Apr 2019
    Posts
    187
    This has come up several times before on the forum. Have a look here: https://github.com/ElectroTechnique/.../master/TSynth You need to set the phase_accumulator to zero by adding a sync() function that you call:

    In synth_waveform.h:
    Code:
    void sync() {
      syncFlag = 1;
    }
    In synth_waveform.cpp:
    Code:
    if(syncFlag==1){
      phase_accumulator = 0;
      syncFlag = 0;
    }
    
    ph = phase_accumulator + phase_offset; //existing code

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,748
    Quote Originally Posted by emmanuel63 View Post
    Hello,

    I try to reset the phase of an LFO to zero each time a note is played. It has no effect. I think I misunderstand to use of phase().

    lfo.phase(0); //reset LFO phase
    envelope1.noteOn(); //new note

    Emmanuel
    The phase() call changes the phase of the waveform relative to the original phase, allowing phase modulation
    in steps, for instance. It doesn't change the original phase which is set at the time the object is created.

    This is not useful for syncing LFO's as you have discovered, but does allow setting up two oscillators in quadrature
    for example.

    It sounds like there should be a pull-request for adding the sync() call, it does sound useful (or perhaps an absolute
    phase call to set the phase_accumulator directly).

    By the way when making several changes that should be synchronized use AudioNoInterrupts()/AudioInterrupts() like this:

    Code:
      AudioNoInterrupts() ;
      lfo.sync();
      lfo.phase(180);
      ...
      envelope1.noteOn();     //new note
      AudioInterrupts() ;
    So that all the setup happens atomically w.r.t. the audio system.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •