grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.58k stars 322 forks source link

libfaust: dsp_poly not clearing voices with instanceClear() when voice control is off #628

Closed DBraun closed 3 years ago

DBraun commented 3 years ago

I'm seeing an issue when voice control is off, but there's no issue when voice control is on. I do m_dsp_poly = m_poly_factory->createPolyDSPInstance(8, false, true);

My code does m_dsp_poly->keyOn, m_dsp_poly->keyOff a bunch of times and then m_dsp_poly->instanceClear();

After a few cycles of this, all of the voices become used, and I get warnings about stealing voices. However, if voice control was on, there's no problem.

I think that this code is executing https://github.com/grame-cncm/faust/blob/c10910171a197066f15679631d71ed346ccb1751/architecture/faust/dsp/poly-dsp.h#L763

but fVoiceTable is std::vector<dsp_voice*> fVoiceTable; and dsp_voice does not implement instanceClear() in a way to modify its internal fCurNote, fRelease etc.

And those vars do get "reset" when voice control is on: https://github.com/grame-cncm/faust/blob/c10910171a197066f15679631d71ed346ccb1751/architecture/faust/dsp/poly-dsp.h#L790-L802 I think this happens naturally as more compute() gets called.

So maybe dsp_voice needs a new instanceClear() function to reset fCurNote and fRelease?

sletz commented 3 years ago

Yes, this could make sense. What is your use-case for "control is off" ? And please prepare a PR if you have a fix.

DBraun commented 3 years ago

Cool, thanks. No particular use case. It was just the first setting I chose without thinking about it much. I'll try to prepare a PR soon.

sletz commented 3 years ago

Thanks for the PR.