SeanArchibald / scale-workshop

Design microtonal scales and play them in your web browser. Export your scales for use with VST instruments. Convert Scala files to various tuning formats.
https://sevish.com/scaleworkshop/
146 stars 23 forks source link

Sound cuts out - oscillators/gain nodes not being reused #126

Closed meszaros-lajos-gyorgy closed 3 years ago

meszaros-lajos-gyorgy commented 3 years ago

Found a nice debug tool for chrome to inspect web audio nodes: https://chrome.google.com/webstore/detail/web-audio-inspector/cmhomipkklckpomafalojobppmmidlgl

This tool shows that Scale Workshop is not re-using oscillator and gain nodes after playing a single note with it and since web audio doesn't do any garbage collection it can pile up and possibly cause all the audio stopping issues that have been reported here.

Please keep in mind, that on the screenshots these notes are pressed and released immediately, yet their nodes won't get cleaned up.

1 note 2 notes 5 notes 14 notes

In the screenshots I'm using the percussive long setting: https://sevish.com/scaleworkshop/?name=12%20equal%20divisions%20of%202%2F1&data=100.%0A200.%0A300.%0A400.%0A500.%0A600.%0A700.%0A800.%0A900.%0A1000.%0A1100.%0A1200.&freq=440&midi=69&vert=5&horiz=1&colors=white%20black%20white%20white%20black%20white%20black%20white%20white%20black%20white%20black&waveform=triangle&ampenv=organ

meszaros-lajos-gyorgy commented 3 years ago

One possible solution is to pre-create N oscillator and gain nodes, wire them up and keep an internal counter, that goes through all the nodes one after another as you press notes. The counter would loop over and start from the first node and skip all notes, which are currently being played. Similarly to synthesizers with fixed number of voices, there would be a limit on how many sounds you can press simultaniously and subsequent notes could either be ignored, or played by force-releasing pressed notes in various order.

meszaros-lajos-gyorgy commented 3 years ago

Delay also looks cool, as seen in this screenshot delay

SeanArchibald commented 3 years ago

Ok! Think I have enough info to try fixing this. Good investigation!

SeanArchibald commented 3 years ago

Fix is now in the develop branch!

When the synth is initialised it will start a limited number of oscillators which are then reused. It's a round-robin style voice allocation which tries to avoid voice stealing. Max polyphony will be 6 by default (less taxing on low powered systems) but users can increase the max polyphony in a setting which will be automatically saved/recalled in browser localStorage.

It's been a long time coming...

SeanArchibald commented 3 years ago

Fixed in 1.4.1