You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi, I was just messing around, and realised I'd added the ability to play more than one Waveform at once on the same output a while back, but had never shown it in use.

    So...

    var pitches = {
      'A':440.00, 'B':493.88, 'C':523.25, 'D':587.33,
      'E':659.26, 'F':698.46, 'G':783.99, 'a':880
    };
    var tune = "E BCD CBA ACE DCB  CD E C A A    D Fa GFE  CE DCB BCD E C A A   ";
    
    var s = atob("f4GBgoODh5GtnmgkE1m435g/MobgzYJbd4­1YHkHD/7UoEZPysyscl/K5PSqLy5tLToqdfHGdrX­I1V7vUeiVIqceEUG2kmWVfj6qIWFuKpZFpXXiXkn­NthZB9cH6LgG5vgJKSdWF7oZVoXHuRioJ8c3iJjH­tweomLf3JygpCHdHOCiYJ8fYCBg4ODgn53d4CGiI­Z8cHGAjo1+dn6Jh3pzeoWHfXd8hYd8d3+Gg3t1e4­F9d36KiHp0fYZ+cneLlol3cnyEgXt8g4WBeXV8ho­qDdnOCjoNxc4aRhnd3f4J6cXmNlIJxd4mKeXJ5iI­2Denh9fX1/f4B/g4N2bnuSlYJzdoOIgXp7g4V+dn­mDhoF9gIF+eHqDioJyb3+Oi3xzeIOHgXp7gIB+fH­+DgHt8hIh/cnOEjoVzb32Mi3pxeYeLf3N2hIqBdX­aBhoB7fYSGfXZ7hYeAeXl9goJ9e36BgYGCgoF8e4­GDgHp6f4ODgHo=");
    var w = new Waveform(s.length);
    var w2 = new Waveform(s.length);
    var w3 = new Waveform(s.length);
    w.buffer.set(s);
    w2.buffer.set(s);
    w3.buffer.set(s);
    s=undefined;
    
    function step() {
      var ch = tune[pos];
      if (ch !== undefined) pos++; else pos=0;
      if (ch in pitches) {
        if (!w.running)
          w.startOutput(B0, 4000*pitches[ch]/2500);
        else if (!w2.running)
          w2.startOutput(B0, 4000*pitches[ch]/2500);
        else if (!w3.running)
          w3.startOutput(B0, 4000*pitches[ch]/2500);
      }
    }
    
    
    var pos=0;
    function onInit() {
      pinMode(B0, "af_opendrain");
      analogWrite(B0, 0.5, {freq:20000});
      setInterval(step, 150);
    }
    

    Tetris music - not hi-fi quality, but it sounds pretty old-school :)

    You might want to change pinMode(B0, "af_opendrain"); if you're not using a Pico (it was running on the FET output to get a bit of volume).

    It'd be great if someone wanted to add another track so it actually was properly polyphonic. At the moment it's just playing overlapping waveforms (rather than actual different notes).

About

Avatar for Gordon @Gordon started