It hertz when I synth

https://youtu.be/LYSGTkNtazo?t=326

The Science of Music

440Hz

880Hz

Notes from numbers

// support for different browsers
let context = new (window.AudioContext || window.webkitAudioContext)();
let o, g;
let freq = 440;
let isPlaying = false;
function playNote() {
    // re-using an oscilator seems to result in noise being introduced into output
    o = context.createOscillator();
    g = context.createGain();

    // can be sine, square, sawtooth, triangle. defaults to sine
    o.type = sine;
    o.connect(g);
    g.connect(context.destination);

    o.start(0);
    o.frequency.setValueAtTime(freq, context.currentTime);

    // flag to be used later
    isPlaying = true;
}

function stopNote() {
    // if a wave abrubtly stops, there will be a "click" sound
    g.gain.exponentialRampToValueAtTime(
        0.00001, // api doesn't accept 0
        context.currentTime + 0.04,
    );
    
    setTimeout(function () {
        o.stop();
        isPlaying = false;
    }, 41);
}
const scaleHeight = (
        num,
        inMax = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) //viewport height
    ) => {
    const scaleMap = num * 24 / inMax;

    const hertz = ROOT_NOTE * Math.pow(1.059463094359, scaleMap);
    return hertz; 
}
function setNote(freq) {
    // we want oscillator to be initialised when we change it
    if (isPlaying) {
        o.frequency.setValueAtTime(freq, context.currentTime);
    }
}

It's going down, I'm yelling timber

It hertz when I synth

By tzyinc

It hertz when I synth

  • 471