ElectroTechnique / Momentum

Momentum Synth
MIT License
12 stars 3 forks source link

Envelope.delay problem #14

Open rolfdegen opened 1 month ago

rolfdegen commented 1 month ago

Hallo TSynth. Nice projekt :) But i have a problem with envelope.delay funktion in exp. envelope. If I set envelope.delay to 6ms and play more notes, the envelope freezes. With 0ms delay, the envelope works without any problems. Envelope.delay from P. Stoffregen has no problems.

Thanks for your help :)

rolfdegen commented 3 weeks ago

It looks as if the issue is that exp_count doesn't get set in noteOn(). If you trigger a new note exactly as the release phase finishes, so state == STATE_IDLE but an update() hasn't occurred to set exp_count to the delay value, it will have the stale value from the end of the decay phase, which is -2 32, so your delay suddenly becomes very long indeed.

rolfdegen commented 3 weeks ago

Discussion in the Teensy Forum: https://forum.pjrc.com/index.php?threads/teensy-exponential-envelopes.75646/#post-348080

rolfdegen commented 3 weeks ago

Result: void AudioEffectEnvelope::noteOn(void) { //__disable_irq(); if(release_forced_count==0) state=STATE_IDLE; switch(state) { case STATE_IDLE: case STATE_IDLE_NEXT: count=delay_count; if(count>0) { state=STATE_DELAY; inc_hires=0; } else { state=STATE_ATTACK; count=attack_count; inc_hires = 0x40000000 / (int32_t)count; } exp_count=((uint32_t)(delay_count))*8; //!!!!FRE as per advise from h4yn0nnym0u5e ysum=0; break; case STATE_DELAY: case STATE_HOLD: case STATE_ATTACK: case STATE_DECAY: case STATE_SUSTAIN: case STATE_SUSTAIN_FAST_CHANGE: case STATE_RELEASE: state=STATE_FORCED; count=release_forced_count; inc_hires=(-mult_hires)/(int32_t)count; case STATE_FORCED: break; default: state=STATE_RELEASE; break; } //__enable_irq(); }