You are reading a single comment by @Dennis and its replies. Click here to read the full conversation.
  • This is my code:

    var pos;
    var w;
    function play() {
      refillBuffer = function(b) {
        pos += b.length;
      bufferEventHandler = function(b) {
        if (pos >= len) { // loop sample
, 0);
          pos = 0;
      w = new Waveform(bufSize, {doubleBuffer:true});
      pos = len;
      w.on("buffer", bufferEventHandler);
      analogWrite(B1, 0.5, {freq:100000});
      w.startOutput(B1, rate, {repeat:true});
    function stop() {
      if (w && w.running) w.stop();

    I'm not using the same cheat. Do you think it would make a huge difference? In any case the code must accomplish both (fetch new data and copy it) in the time window between two buffer events, so as long as it's fast enough, the order of those should not matter, and if it's not fast enough, you have a problem anyways.

    I just tried 44.1 kHz because it's such a nice omnipresent number (almost 42). I didn't try higher ones, maybe they would work as well. The nice thing is that you could reproduce higher frequencies. For audio (where the 8bit resolution limits quality anyways), this already covers the audible frequency range. Higher sampling rates for audio are mainly relevant in recording (for oversampling or less steep low pass cutoff before the A/D converer) but realtime recording is certainly no fun with this slow-writing flash memory.

    What I didn't consider yet is the possibility that I'm mistaken about the 44.1 kHz and I might actually already be getting significant glitches which I simply don't hear because my test signal (a sawtooth frequency sweep) doesn't reveal them. I don't assume so (since it really sounds quite clean) but it might be the case. But then again, for my audio stuff it wouldn't even matter as long as it's not noticeable :) For other applications one should double check.

    What's the maximum SPI baud rate for the Pico? The Winbond flash works up to 104 MHz. And by the way, it supports synchronous transfers of up to 4 bit on parallel data pins per 1 SPI controller (but I don't think the microcontroller can handle that).


Avatar for Dennis @Dennis started