Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  
      
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
 
const context = new AudioContext();
debugger;
const buffer = createSample(2, context, 0.5);
console.log("play sound");
//playSound(buffer, context);
function playSound(audioBuffer, audioContext) {
  const source = audioContext.createBufferSource();
  console.log("Connecting buffer");
  source.buffer = audioBuffer;
  source.connect(audioContext.destination);
  source.start();
}
function clamp(value, lower, upper) {
  
}
function createSample(channels, audioContext, volume) {
  const _volume = Math.max(0, Math.min(volume, 0.01));
  console.log(_volume);
  const frameCount = audioContext.sampleRate * 2;
  const audioBuffer = audioContext
    .createBuffer(channels, frameCount, audioContext.sampleRate);
  
  
  for (let channelIndex = 0; channelIndex < channels; channelIndex++) {
    const currentBuffer = audioBuffer.getChannelData(channelIndex);
    for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
      currentBuffer[frameIndex] 
        = create_sin(frameIndex, 1500) * _volume;
    }
  }
  
  return audioBuffer;
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers