JSFiddle - React, Tailwind, and code Playground

by Chinmay Pendharkar

JavaScript

var context = new AudioContext(),
    phasorNode = context.createBufferSource(),
    frequencyNode = context.createBufferSource(),
    bufferFrequency = context.createBuffer(1, context.sampleRate, context.sampleRate),
    arrayFrequency = bufferFrequency.getChannelData(0),
    bufferRamp = context.createBuffer(1, context.sampleRate, context.sampleRate),
    arrayRamp = bufferRamp.getChannelData(0),
    acc = 0,
    step = 1 / context.sampleRate,
    i

for (i = 0; i < arrayRamp.length; i++) {
    arrayRamp[i] = (acc % 1)
    acc += step
}

for (i = 0; i < arrayFrequency.length; i++) {
    arrayFrequency[i] = 200
}

phasorNode.buffer = bufferRamp
phasorNode.connect(context.destination)
phasorNode.loop = true
phasorNode.start(0)

<!--       frequencyNode.buffer = bufferFrequency
frequencyNode.connect(phasorNode.playbackRate)
frequencyNode.loop = true
frequencyNode.start(0) -->