christophhart / HISE

The open source framework for sample based instruments
http://hise.audio
Other
1.07k stars 123 forks source link

[Engine] Polyphonic Script FX Prevents the Envelope/Engine From Killing Voices #564

Closed aaronventure closed 2 months ago

aaronventure commented 4 months ago
HiseSnippet 1345.3ocyX0saSbDEd13L.IkhJHjZunRcunW.RnfcH.UpUBm3e.WhSr7lFwcVCqGGOJ6NypYlMAWDpuR8QfGIdCZOyr6ZOqwM33xeAIzdNyYl4672b9R5IEgTkRHQdabzjDJx653fIb83FiILNpSSj2MvcIJMU5moZuIIDkhND44U4oFEdarNx9y6dxdjHBOjNSEBcrfER2mEyzyz1q9yYQQsICoGwhcrdm5cBE7FhHQJfmJ3pnDR3ojSnGPLlsFF4ckVCYZgLPSzTEXydhgSBFKNmmY+wLE6kQTiPMT.bPYpQMFyhF1qvWUHjGt2LOuRlmeabW1P1T8yh.emcA+Y6vMF3s1EAoZWBH44.o0yfzMwAgRVhd1JF77M3NbHgLh.gZWnjYKx6s3FBv.tdqXxoz1RPX5FtyipV8d9v+c2ecTJOTyDbeA+.gldH+N2cyWu4Fa9lM8meoQiV3ZlqQJhhnxEtrI6JunMdGdZ7Kox64eFIJkN0Pv8KGSuxxESCy7ZGCE7Nbl9vDZtbaQzPSrx786mAP4gM3q+nSShlXRJ45.6RnRMy.Gulzyfp5rTzF3lT0oZQBTW+d4OnxQLLMhnKWNY5axW.hGkxglDEWwzSb6qtD0XUuvZrkEh2D2ioCGuXLt1BvHDo9Tfw7NyuE2ZzHZndF.WG29EqZa3xe8+X10eKbfVRIwL9IAj3Dnb2hgMw4R09X7nXxR+nXOIMRPFFv9SGyda88RgXjrr1+tt8p1MVjxKcW4HuOMgRzPZ1Ed062+oRQZx765cOwVTbjDdTFBEtKbHmBwZsqO1PJTpQf6XOKk6R8RkmXhUyzzmdFUpJq6fzXHey4zHXyXOOSWohZxurvtDsj8JWqs2R0iH1bLLovJWaN4smS9AyIuybxObN4GMm7imI6gKW+csk6IqtjjdDvEcrbOVdUFrVllxOW3X5zXrEGNyACnZMjhTN1tfANW4S0Lv0WtluOvqwe8+bZoQ1aTfw.lI60heFzlBZLX7VvPhQjzHcg1xOYzUvEIiEbVX4lBnH+jSnRWruPGZWsF5Imo4106SinDkSW8OWeeFmRjk60uTwhKO8kElu9AbFb8Muy4++Iu8YsL6BGIVYoFI9QGueAFOtnz7Mv8DQSxXeB2qA.euUUVMse1J9seQop90Jnq9S3EQMzgMH9iTIpC+tCn5yExSsNT92Huqlg7joHefxBwAidUMztQQhyaHhSX4oeHpZ0MyQMNUlEz7IWEiPwdqAW5yHpiHrHqump.RoCOjG.FaYG3U4XXDn8fuJt5Vv+f5mCrcq31jPv+mzinGaJDM7bgLMUtU3zL9+ErcKBLmVAQBrmcHsHN1DPrSvp3vwMKOajfJ50LWv0wcTGaVMjDgN1vW23GHyYZqJIR3WRC9kLLB6IDmFSrg2OoLouQNCLenzPp+J+AjqisbF7MT79RA09hTCufB5SXfiU.TNDRcYZYJUykqVTnD.EqVg+A9IewZEzxLKVqXQTXwQA9V921J.uJTtglhs2OBH7E49VoBXuZfDTHhT1jZLP+ALMS.HT0WHrcR+FX89hmSmTH7Lliv9hiMGbFpeFKW3uL9dFq1BP2FZ7x96JzB+5d8O72a03nAsOb+ls5+llct+tlJ87W5U2GZWMcbp6qf.G+jA0FnRUiFMX6sgOqs04jyPMSShfdCssU9yRfNlDJECByduzDtulUCDn4V+ZCbWireMzYYsqyh1w.WtAggkOp2aiaupa7Aq5F2YU23CW0M9nUciOdU23u7g2ngp8toZQb1jFDpauVY8Pdsl1CUA8u.+ybTOC

Add a sample to the sampler to test it out, then try bypassing the polyphonic script fx in the modules browser. Keep an eye on the voice count.

sampler polyphonic voice bug

aaronventure commented 4 months ago

Seems unrelated to the sampler, as it happens with the waveform generator, too.

HiseSnippet 1125.3oc2W0saaaCElJNLsNsqXcnEc2McwtHEnHvNsqa.6h57maMViiQTVZuKfkhNlHTjBjTI0XXua6QXOB6QXuAaGRZGI03k4XztrMY.Cc9i77yGO7nA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Eh+wCHvsx.3yM7GToY50oWTw+qb6pIb2pM8lUbDxmPxxbID+Gbznxfeg5riBPwK41f6h6YNxIkRDnibCw5hCjaM8nRhF9xEXxaGwVJ0oYDe58S73kvkt+6tUwivvk+aD66WDeyzv3.UgkKOYOBbsALhBteQVBfAnSAolo3yIzslhNR.Dpm3OfmIBa6nilHr8Tg+irGYDpVcLMzevAQusmCD2R+GM2D95cfNtM5r.7rLYlAykbLkVeotjgarnF9zE0vmsnF9MKpgOeQM7aWTC+t+dCciMtYgUkENa.yROXWeWinnvXz9iIn+TTBlrQ
davidhealey commented 4 months ago

No issue here with your snippet... but did you try changing the envelope between mono and polyphonic mode?

aaronventure commented 4 months ago

You can't reproduce it? What about Windows?

voices win

Happens on Windows, too

The envelope is the default one, if I disable the monophonic mode, I just get a mumbo jumbo of all the notes played whenever I press a note.

davidhealey commented 4 months ago

Ah ok I see what you mean. Yes I get the same issue on Windows and Linux.

aaronventure commented 4 months ago

Yeah just discovered that this scales with modulator usage as well. This is a pretty serious issue with more complex setups like complex envelope script modulators as the voice processing just goes on indefinitely as the voice object doesn't get killed, resulting in a CPU "leak".

christoph-hart commented 2 months ago

Feature, not a bug. The polyphonic FX has the power to keep a voice alive - that's how you can use it to create synthesisers with scriptnode when you combine it with the silent synth sound generator (I'm using this method in Triaz to have 3 drum layers work with the same sound generator).

The solution to the voice leak is to turn off the HasTail property of the network - if you do this, the network will not act as possible generator and stop affecting the voice handling.

Now the question is how and where to write the documentation so that power users like you two don't run into this problem again?

aaronventure commented 2 months ago

Ah that's simple and sensible.

Is there a polyphonic script FX doc section? Probably there.

This whole solution means that the silent killer should be added if has_tail is still on, right? If so, it's not working.

christoph-hart commented 2 months ago

If so, it's not working.

Interesting. At first I thought that's because you haven't added a ScriptVoiceKiller envelope to the gain mod which you need to do when using a script synthesiser, but then I realized that the PolyScriptFX module has that already build in.

The actual reason why it doesn't kill the note is a bit weirder: apparently the signal flow of the Waveform Generator is not as advertised here:

routing (Source: https://docs.hise.dev/hise-modules/sound-generators/index.html)

but instead the order of the voice rendering is reversed, so it will first calculate the polyphonic effects for each voice and then apply the gain modulation:

https://github.com/christophhart/HISE/blob/583f242851c4ddf1e5b8759cedde2cb6ea162ec4/hi_core/hi_modules/synthesisers/synths/WaveSynth.cpp#L562

For reference here is the sine synth code with the correct order:

https://github.com/christophhart/HISE/blob/583f242851c4ddf1e5b8759cedde2cb6ea162ec4/hi_core/hi_modules/synthesisers/synths/SineSynth.cpp#L183

Usually this does not cause any issues (which is why it went undetected for all those years) but in this specific case it leads to the silent killer being fed the unmodulated full scale waveform and thus never firing because the envelope will turn it down later in the chain.

So I guess I will have to go through all sound generators and check that the order is as described, then I'll tackle the polyscript FX docs...

christoph-hart commented 2 months ago

Alright, curiously it was about 50/50:

Now it should be consistent. Now the problem is that changing the order might have a drastic impact on the sound - especially when using polyphonic non-linear processing. The most obviuos example I could think of is the poly shaper:

HiseSnippet 1047.3oc2X0saaaCEVJNrKNsMscXE6VcwtHEnXvJoqa.6h5D+SiwpiMhxZ6tpfk53XhHQJPQ4Uigc2dE16SeD1ivdD1av1gR1VhMtdYFqadyWX3yejemeIoGpjLHMUpbbqe9zDvw8VjfoB83ViobgSu1Nt6Q5SS0fxqf0wSSnooPniqasmZX3Veam7O+1SNlFQELnjkiyykbF7LdLWWxcXyugGE0kFBmyiqn8iZ1iIEsjQxLDO0HMbRnrKoW.mRMpsEww8FcB4ZoJPS0Ppi61GKCmFLV98hB8eNOk+5HvP36DfKTA6txnPChMbcZMlGENbtem533RFVFEpUDE9DRedHeA+xnwcyE3UZQ03g6V1vqlE77qBuFUf2RfjaEHscAjtGIfo3I5RIF7bSROAlbFQwvdUnTnqi6aIsjnBB8mGSuD5pPhEFr+iaz3gd3WO3qGkIXZtT3IEmJ0v.w9OX2eX2569i658thFMZoxLaiRFEApkJ1joUqxv8EYwuFTOzaBMJCVnH591wTx6OlVMkyJ75JJJE8Db8fDP79JDblEpve8s8ZS0TShXFOTuDPo4FH31FlfU0Eok5j1P5kZYBVWekbFVsHCyhnZ6RHSeyLAXLvJuYRNhTtdZ09p+1pqttP7djgbMa7xw3VKAiXj5CAFm0MdaRmQi.ltDfaS59xOLsdU296Wr82j7B5DHerX9le+b5QRUr2SAAnLwN+ULX7WttCFSt1CFGvzHDNWQEoIxTvu5J+NxNnpr1fNSXqdAKKsLtWWz87qVDNmYEM2o4PpvZwPZqUpO+Mkj+5S5HnXRH.PuIbPJCcVSryZAxhRgWvC0i8qZXI6Cpx9DpJDyKLqBwZq5LB+07LharwcFw+AF2XcL1cJv3GQN5j1AmMaLS9u85Hl.Q37U6ln9RgLYrTvsRumAZE+hK.UUDuT23HsFu9PqL0DvtdmQmdEtEJeUNOCPnUk8IXcRI8m0Le4Vv3m94lAYoZq1+u6smAQ.M0pgtCShoDXMC69qNrStlkF2lT3jd4ia17NFZu43qHKr4AvaQxS+apwu6PlULtwF.2iLq2XSMDtxaBU6+02DxZ58Ny2+gxnooioI.tsE0XK3308k1SvmMkEe31QoSiMCtYznRlsU7ECgad3gMaZOQ7tMGLAToz3jHt3h0LB6+W9cVKsL3iI4f0ai9V6l6c7lMaH9oD7ZeG3k2S48uSS0YxLMVO0mhki3kSImlEGf2qlAHJEBHx7FS2sLuFrftgg1.g.PDlS763mYB8MztyD5OW3+H6QLkojuhU75YSs7N4bP+Vj+2kTmz2P646j+h5pAyX75ouhwrWpqX3AqqgGttF9n00vuXcM7wqqge45Z3W8man40CGkokwE8F3qnF1I+uiv0s3AT4sIN+gLASiw

Before the decay was applied after the shaping so the sound is a pure fade-out of the highly distorted sine wave. After the change, the shaper is being applied to the dynamic signal which causes the distortion to reduce with the volume.

I think I have to add a preprocessor that keeps the old order so that existing projects with existing presets will not break...