Skip to content

Instantly share code, notes, and snippets.

@samgiles
Forked from anonymous/index.html
Created June 28, 2016 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samgiles/8b490c8bac2207e607e6237350ccd95a to your computer and use it in GitHub Desktop.
Save samgiles/8b490c8bac2207e607e6237350ccd95a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/dayesorelu
<!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>
<script id="jsbin-javascript">
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;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">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;
}</script></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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment