<script src="https://code.jquery.com/jquery-1.5.2.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<h1>Audio feedback and noise demo</h1>
<p>You should hear your own voice played back with a delay mixed with noise.</p>
<p>Adjust the noise level using the slider.</p>
<p> Notice how the susceptibilty to audio feedback varies.</p>
<div id="slider"></div>
<p>Noise volume: <span id="slider-value"></span> dB</p>
<p>You may need to press the "allow" button above</p>
<a href="http://papers.traustikristjansson.info/?p=486">See the tutorial here.</a>
// Ripples on a lake.
var noiseVolume = Math.pow(0, -4.0 / 20.0); // Initial noise voluem
function myPCMFilterFunction(inputSample) {
var noiseSample = Math.random() * 2 - 1;
return inputSample + noiseSample * noiseVolume; // For example, add noise samples.
}
// The rest is boilerplate.
// Check if Web Audio API is supported.
var audioContext;
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
audioContext = new AudioContext();
} catch(e) {
alert('Web Audio API is not supported in this browser');
}
// 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 =input;
}
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);
microphone.connect(myPCMProcessingNode);
myPCMProcessingNode.connect(audioContext.destination);
//microphone.start(0);
}, errorCallback);
$("#slider").slider(
{
value:-4,
min: -30,
max: 0,
step: 2,
slide: function( event, ui ) {
$( "#slider-value" ).html( ui.value );
noiseVolume = Math.pow(10.0, ui.value / 20.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.