diff --git a/dsp.js b/dsp.js index 5af9202..b5970be 100644 --- a/dsp.js +++ b/dsp.js @@ -1310,7 +1310,7 @@ function IIRFilter2(type, cutoff, resonance, sampleRate) { this.resonance = resonance; this.sampleRate = sampleRate; - this.f = Float32Array(4); + this.f = new Float32Array(4); this.f[0] = 0.0; // lp this.f[1] = 0.0; // hp this.f[2] = 0.0; // bp @@ -1776,7 +1776,7 @@ DSP.mag2db = function(buffer) { var log = Math.log; var max = Math.max; - var result = Float32Array(buffer.length); + var result = new Float32Array(buffer.length); for (var i=0; i - + + + + + @@ -14,17 +17,23 @@ var lp12; var windowFunc; - // Setup experimental audio out - var output = new Audio(); - - if ( typeof output.mozSetup === 'function' ) { - output.mozSetup(1, sampleRate, 1); - } + //Get audio context and setup buffer + var audioCtx = new AudioContext(); + var buffArray = audioCtx.createBuffer(1, bufferSize, sampleRate); + var buff = buffArray.getChannelData(0); var audioWriter = function(s) { - if ( typeof output.mozWriteAudio === 'function' ) { - output.mozWriteAudio(s); + //Fill Buffer + for (i = 0; i < bufferSize; ++i) + { + buff[i] = s[i]; } + + //Setup an AudioNode to play the buffer + var source = audioCtx.createBufferSource(); + source.buffer = buffArray; + source.connect(audioCtx.destination); + source.start(); } diff --git a/examples/squarewave.html b/examples/squarewave.html index f6be448..baf2804 100644 --- a/examples/squarewave.html +++ b/examples/squarewave.html @@ -1,5 +1,8 @@ - - + + + + + @@ -13,15 +16,23 @@ var fft; var sine; - // Setup experimental audio out - var output = new Audio(); - - if ( typeof output.mozSetup === 'function' ) { - output.mozSetup(1, sampleRate, 1); - } + //Get audio context and setup buffer + var audioCtx = new AudioContext(); + var buffArray = audioCtx.createBuffer(1, bufferSize, sampleRate); + var buff = buffArray.getChannelData(0); var audioWriter = function(s) { - output.mozWriteAudio(s); + //Fill Buffer + for (i = 0; i < bufferSize; ++i) + { + buff[i] = s[i]; + } + + //Setup an AudioNode to play the buffer + var source = audioCtx.createBufferSource(); + source.buffer = buffArray; + source.connect(audioCtx.destination); + source.start(); }