Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you optimise garbage collection in web audio apps to avoid clicking noises?

I have an ambient music generating web audio app - http://christopheralcock.github.io/falling3rds/ - which creates lots of audiocontext nodes to make a constantly evolving, fairly relaxing, musical texture.

After about 100 seconds, though, there are too many nodes and garbage collection kicks in and makes horrible, unrelaxing clicking noises and ruins everything.

I could rewrite the software so that it creates fewer nodes, but don't want to if I don't have to, not least because I think the actual effect would be end up different.

What I want is to destroy each (oscillator etc) node about 30 seconds after they're created, stopping the node-count from ever getting into the hundreds.

The code is here, fwiw: https://github.com/christopheralcock/falling3rds/tree/gh-pages

Thanks

like image 691
Christopher Alcock Avatar asked Oct 24 '25 19:10

Christopher Alcock


1 Answers

Have just come across this again and thought I may as well answer with what I did in the end to fix it, within the paradigm set out in the question:

I used the AudioNode.disconnect() method: https://developer.mozilla.org/en-US/docs/Web/API/AudioNode/disconnect

I used setTimeout and an arbitrary period of time when nodes were created and connected. Then after the time period they would be disconnected. Then when garbage collection takes place, it's just clearing up disconnected nodes, which doesn't make noise.

like image 147
Christopher Alcock Avatar answered Oct 27 '25 10:10

Christopher Alcock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!