I've spent hours so far helping you get your code working. I've posted code above (at the end of last post) that I just tested, and that is working perfectly, without any loss of memory. In fact you could use the code below, which allows you to just call _playSoundFile without worrying about calling _stopSoundFile first:
var AUDIOUT = A0;
var w = new Waveform(2048, {doubleBuffer:true});
var fileBuf, f;
w.buffers = [ w.buffer, w.buffer2 ];
w.on("buffer", function(buf) {
buf.set(fileBuf);
fileBuf = f.read(buf.length);
if (fileBuf===undefined)
_stopSoundFile();
});
function _playSoundFile(file) {
_stopSoundFile();
LED3.write(1);
var filename = file;
f = E.openFile(filename,"r");
w.buffer.set(f.read(w.buffer.length));
w.buffer2.set(f.read(w.buffer.length));
fileBuf = f.read(w.buffer.length);
analogWrite(AUDIOUT, 0.5, {freq:20000});
w.startOutput(AUDIOUT,8000,{repeat:true});
}
function _stopSoundFile() {
LED3.write(0);
if (w.running) w.stop();
AUDIOUT.write(0);
if (f) f.close();
f = undefined;
fileBuf = undefined;
}
I'm afraid I just don't have time to help you throw everything away and start again from scratch, especially when I offered to fix your code and you can't be bothered to strip it down enough that you can post it up for me.
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.
I've spent hours so far helping you get your code working. I've posted code above (at the end of last post) that I just tested, and that is working perfectly, without any loss of memory. In fact you could use the code below, which allows you to just call
_playSoundFile
without worrying about calling_stopSoundFile
first:I'm afraid I just don't have time to help you throw everything away and start again from scratch, especially when I offered to fix your code and you can't be bothered to strip it down enough that you can post it up for me.