That is very interesting! I remember I looked at the code for a long time and didn't quite understand this aspect, but since it's also not documented how exactly that event is thrown, I assumed it to be correct.
I will try that with the Flash RAM when I have time and let you know. It should improve things even more there because of the smaller buffer sizes.
By the way, it seems a bit clumsy that we need an if-branch to evaluate which buffer to use. We could store references to the buffers in a 2-element array and then reduce that function to:
w.on("buffer", function(buf) {
buffers[1 - w.currentBuffer].set( /* new data */ );
});
but it would be even cooler if the native Waveform object had built-in properties that point to the current and the other buffer.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
That is very interesting! I remember I looked at the code for a long time and didn't quite understand this aspect, but since it's also not documented how exactly that event is thrown, I assumed it to be correct.
I will try that with the Flash RAM when I have time and let you know. It should improve things even more there because of the smaller buffer sizes.
By the way, it seems a bit clumsy that we need an if-branch to evaluate which buffer to use. We could store references to the buffers in a 2-element array and then reduce that function to:
but it would be even cooler if the native Waveform object had built-in properties that point to the current and the other buffer.