• @Gordon I'm getting fairly reliable readings now.

    I guess my next question is how do I generate sounds of varying length. Out of my depth here I think.

    I thought that this would generate 0.5seconds of...something, and then 0.5 seconds of silence, but I just get a click

    AudioContext = window.AudioContext || window.webkitAudioContext;
    audioContext = new AudioContext();
    
    gainNode = audioContext.createGain();
    gainNode.gain.value = 1;
    
    var buffer = audioContext.createBuffer(1, 44100, 44100);
    var b = buffer.getChannelData(0);
    
    for (var i = 0; i < 22050; i++) {
      b[i] = 1.0;
    }
    
    for (var i = 22050; i < 44100; i++) {
      b[i] = -1.0;
    }
    
    source = audioContext.createBufferSource();
    source.buffer = buffer;
    source.connect(gainNode);
    source.start();
    
    gainNode.connect(audioContext.destinatio­n);
    
About

Avatar for dave_irvine @dave_irvine started