Web Audio onaudioprocess works in Firefox, JSFiddle in Chrome but not Chrome

I am working in Chrome 39.0.2171.71 (64-bit) with a WebAudio / WebMIDI app. I have the Jazz-soft webmidi plugin installed.

I'm having trouble turning it off completely. I split everything into the most basic code:

<!DOCTYPE html>
<html lang="en">
    <head></head>
    <body>
        Page Loaded.
        <script>
             var context;
             if (window.AudioContext) {
                 context = new AudioContext(); 
             } else {
                 context = new webkitAudioContext(); 
             }
             console.log('Javascript is working.');

             oscillator = context.createOscillator();
             oscillator.start(0);

             myscriptnode = context.createScriptProcessor(4096, 1, 1);
             myscriptnode.onaudioprocess = function(event) {
                  console.log('ONAUDIOPROCESS works!');
             };

             oscillator.connect(myscriptnode);
         </script>
     </body>
</html>

      

This works in Firefox. In fact, most of the things I played with worked in Firefox, but not Chrome. However, the following two examples work for me in a JSFiddle running in Chrome:

http://jsfiddle.net/78yKV/3/ (This example works, but seems slow / slick with the onaudioprocess callback and it gets cut sometimes and needs to be restarted.)

http://jsfiddle.net/99rxd/ (for this example I have to add a third function argument () {console.log ('error');} for getUserMedia () for it to execute. This gives me an untested reference error r undefined when I run it, but then it runs and the onaudioprocess callback works reliably.)

Things i have tried

I have searched exhaustively and it seems that there are some problems with Chrome using createScriptProcessor. I've tried everything to cover my process globally (declaring it at the top, declaring it without "var", setting myscriptnode.onaudioprocess = window.audioProcess = function (event)) and nothing worked. Everything works in Firefox.

The only reason I hope is because of the working JSFiddle examples. The main reason code seemed to be running in the JSFiddle and not in the browser, it has to do with waiting for the DOM to load. I doubt this is the problem, but I tried to include javascript in (function (/ code /) (); adding the oninit () function to the body tag and putting my code in the init () function {} etc. With no lucky.

I have no idea what's going on. If it works in the JSFiddle, can't I get it to work in the browser? Is there some other way to change the scope so that my event handler doesn't get garbage collected (which is what I assume this is the problem) ... or is there something more fundamental wrong? I have yet to see even one callback using onaudioprocess working from the browser, which makes me feel like this is perhaps more fundamental than a garbage collection / removal issue. Could this be a jazz soft plug?

Thanks for the help!

+3


source to share


1 answer


Chrome still has a bug where the script processor needs to be attached to the receiver.



Add "myscriptnode.connect (context.destination);" through to the end, and I think you will find it works as expected.

+3


source







All Articles