Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Created December 3, 2012 02:04
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 kevincennis/4192135 to your computer and use it in GitHub Desktop.
Save kevincennis/4192135 to your computer and use it in GitHub Desktop.
invert polarity
var url = 'monoSound.wav'
, audio = new Audio(url)
, context = new webkitAudioContext()
, processor = context.createJavaScriptNode(512, 1, 1)
, sourceNode
audio.addEventListener('canplaythrough', function(){
sourceNode = context.createMediaElementSource(audio)
sourceNode.connect(processor)
processor.connect(context.destination)
audio.play()
}, false)
processor.onaudioprocess = function(evt){
var input = evt.inputBuffer.getChannelData(0)
, output = evt.outputBuffer.getChannelData(0)
, len = input.length
, i = 0
for ( ; i < len; i++ ) output[i] = -1 * input[i]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment