//"use strict"; // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createScriptProcessor var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); if( 'webkitAudioContext' in window) { console.log("*** Web Audio found in webkit namespace"); audioCtx = new webkitAudioContext(); } var InTheGroove = false; var MissingTheGroovePending = false; //var bufferSize = 4096; var bufferSize = 512; //window.addEventListener('load', onLoad, false); var prev_input = [0,0]; var tinnyEffectNode = null; $(document).ready(function() { $('#video').on('loadedmetadata', function() { displayDuration(this.duration); // Create a MediaElementAudioSourceNode // Feed the HTMLMediaElement into it var source = audioCtx.createMediaElementSource(this); console.log("**** video source = " + source); // connect the AudioBufferSourceNode to the tinnyEffectNode // and the tinnyEffectNode to the destination, so we can play the // music and have the filter 'kick in' when 'Missing Out' button // pressed tinnyEffectNode = audioCtx.createScriptProcessor(bufferSize, 2, 2); tinnyEffectNode.onaudioprocess = function(e) { for (var c = 0; c<2; c++) { var input = e.inputBuffer.getChannelData(c); var output = e.outputBuffer.getChannelData(c); for (var i = 0; i < bufferSize; i++) { if ( ((mediaPlaybackMode == "neutral") || (mediaPlaybackMode == "record")) || InTheGroove) { output[i] = input[i]; } else { // Make sound 'tinny' through simple high-pass filter output[i] = input[i] - prev_input[c]; } prev_input[c] = input[i]; } } } source.connect(tinnyEffectNode); tinnyEffectNode.connect(audioCtx.destination); console.log("onLoadMetadata done"); }); }); function inTheGroove() { InTheGroove = true; MissingTheGroovePending = false; } function missingTheGroove() { if (MissingTheGroovePending) { InTheGroove = false; } MissingTheGroovePending = false; } function delayedMissingTheGroove(delay) { MissingTheGroovePending = true; setTimeout(missingTheGroove,delay || 400); }