OK, so moved the pin and can hear a partial sound played.. (progress?).
However, I can't get the whole file playing. If I set repeat:true then I can, but it's like an echo!
function playSoundFile()
{
var f = E.openFile("/audio/1.raw","r");
var w = new Waveform(2048, {doubleBuffer:true});
// load first bits of sound file
w.buffer.set(f.read(w.buffer.length));
w.buffer2.set(f.read(w.buffer.length));
var fileBuf = f.read(w.buffer.length);
// when one buffer finishes playing, load the next one
w.on("buffer", function(buf) {
buf.set(fileBuf);
fileBuf = f.read(buf.length);
if (fileBuf===undefined) w.stop(); // end of file
});
// start output
analogWrite(A4, 0.5);
w.startOutput(A4,30000,{repeat:false});
}
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.
OK, so moved the pin and can hear a partial sound played.. (progress?).
However, I can't get the whole file playing. If I set repeat:true then I can, but it's like an echo!
function playSoundFile()
{
var f = E.openFile("/audio/1.raw","r");
var w = new Waveform(2048, {doubleBuffer:true});
// load first bits of sound file
w.buffer.set(f.read(w.buffer.length));
w.buffer2.set(f.read(w.buffer.length));
var fileBuf = f.read(w.buffer.length);
// when one buffer finishes playing, load the next one
w.on("buffer", function(buf) {
buf.set(fileBuf);
fileBuf = f.read(buf.length);
if (fileBuf===undefined) w.stop(); // end of file
});
// start output
analogWrite(A4, 0.5);
w.startOutput(A4,30000,{repeat:false});
}
1.raw attached...
Struggling with this simple thing!!!!!
1 Attachment