How big are the sound files you're playing? One thing that won't help is:
myPico.wave = require("fs").readFile( myPico.filename );
myPico.waveform = new Waveform(myPico.wave.length);
myPico.waveform.buffer.set(myPico.wave);
try:
myPico.waveform = undefined; // get rid of old waveform
var wave = require("fs").readFile( myPico.filename );
myPico.waveform = new Waveform(wave.length);
myPico.waveform.buffer.set(wave);
As it was, you had 2 copies of the waveform kicking around (the string, and waveform.buffer). Also when you then went to load another waveform, you still had the first 2 in memory, so you ended up with 3 copies of the Waveform, all in RAM at the same time :)
Another thing you could do is actually to read the waveform into waveform.buffer a bit at a time, so you're not needing double the size of the waveform just to load it.
... and yes, you could potentially copy from an SD card to flash, which would be nice and easy - but if you've gone to all the trouble of wiring up an SD card then it's probably just worth using that to store all your data :)
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.
How big are the sound files you're playing? One thing that won't help is:
try:
As it was, you had 2 copies of the waveform kicking around (the string, and waveform.buffer). Also when you then went to load another waveform, you still had the first 2 in memory, so you ended up with 3 copies of the Waveform, all in RAM at the same time :)
Another thing you could do is actually to read the waveform into waveform.buffer a bit at a time, so you're not needing double the size of the waveform just to load it.
... and yes, you could potentially copy from an SD card to flash, which would be nice and easy - but if you've gone to all the trouble of wiring up an SD card then it's probably just worth using that to store all your data :)