You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Ok, I think there are a few things here...

    • 512 isn't the sample rate, it's the size of the buffer. Using 1024 could be a good idea though.
    • The sample rate is in w.startInput - you're using 2000 currently (and the code you posted up is playing back at 8000). It'd be worth trying to use 4000 for both as a starting point (8000 might be possible, but for now let's not push it)
    • You don't need analogWrite - you're trying to record so you want to input, not output.
    • You definitely don't need E.FFT or any of that code with the FOR loops. FFT is something totally different to recording sound - and on Espruino at the moment you're going to struggle to record proper audio and do an FFT to pick out frequencies.
    • Also appendFileSync has to find the file, open it, append, and close it - which can be quite slow. E.openFile is probably better.

    Something like this should work:

    var spi = new SPI(); 
    spi.setup({mosi:B15, miso:B14, sck:B10});
    E.connectSDCard(spi, B1);
    console.log(require("fs").readdirSync())­;
    var f = E.openFile("X.raw","w");
    var w = new Waveform(1024,{doubleBuffer:true,bits:16­});
    w.on("buffer", function(buf) {
      f.write(buf);
    });
    w.startInput(B0,4000,{repeat:true});
    
    setTimeout(function() {
      w.stop();
      f.close();
    },10000);
    
About

Avatar for Gordon @Gordon started