Created
June 28, 2016 14:50
-
-
Save anonymous/7be16cf134e7e8b44fabffd9ac98f3c2 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/dayesorelu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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