<h1>Analysis of Sounds from Microphone</h1>
<canvas class="visualizer";id="myCanvas";width="640" height="100"></canvas>
JavaScript
var audioContext = new AudioContext()
var input = audioContext.createGain()
var feedback = audioContext.createGain()
var delay = audioContext.createDelay()
var leftDelay = audioContext.createDelay()
var rightDelay = audioContext.createDelay()
var outputmix = audioContext.createGain()
var convolver = audioContext.createConvolver()
var buffer = audioContext.createBufferSource()
var analyser = audioContext.createAnalyser();
var WIDTH = 300;
var HEIGHT = 300;
// Check if there is microphone input.
try {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var hasMicrophoneInput = (navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
} catch(e) {
alert("getUserMedia() is not supported in your browser");
}
// Create a pcm processing "node" for the filter graph.
var bufferSize = 4096;
var myPCMProcessingNode = audioContext.createScriptProcessor(bufferSize, 1, 1);
myPCMProcessingNode.onaudioprocess = function(e) {
var input = e.inputBuffer.getChannelData(0);
var output = e.outputBuffer.getChannelData(0);
for (var i = 0; i < bufferSize; i++) {
// Modify the input and send it to the output.
output[i] = myPCMFilterFunction(input[i]);
}
}
var errorCallback = function(e) {
alert("Error in getUserMedia: " + e);
};
// Get access to the microphone and start pumping data through the graph.
navigator.getUserMedia({audio: true}, function(stream) {
// microphone -> myPCMProcessingNode -> destination.
var microphone = audioContext.createMediaStreamSource(stream);
leftDelay.delayTime.value = 0.4
rightDelay.delayTime.value = 0.4
leftDelay.connect(rightDelay)
var merger = audioContext.createChannelMerger(2)
leftDelay.connect(merger, 0, 0)
rightDelay.connect(merger, 0,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.