Question

I'm trying to implement a custom Web Audio API node, by way of the ScriptProcessorNode interface. I've got most of it working, but for some reason the event passed to onaudioprocess doesn't define the playbackTime property. Why is this?

var AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
var proc = context.createScriptProcessor(16384, 0, 2);

proc.onaudioprocess = function (event) {
    if (!event.playbackTime) {
        console.log("No playback time");
    }

    proc.disconnect(0);
};

proc.connect(context.destination);

What happens is that proc.onaudioprocess gets called by the Web Audio API, but event.playbackTime is undefined. See my fiddle for a demonstration of the problem ("No playback time" should be printed to the console).

I've tested so far with Chromium 32.0.1700.107 on Linux and Chrome 33.0.1750.117 on Windows.

Was it helpful?

Solution

There is a webkit bug which you may be running into.

https://bugs.webkit.org/show_bug.cgi?id=105518

As per W3C WebAudio Spec AudioProcessingEvent Interface should have parameters like below:

interface AudioProcessingEvent : Event {

        JavaScriptAudioNode node;
        readonly attribute float playbackTime;
        readonly attribute AudioBuffer inputBuffer;
        readonly attribute AudioBuffer outputBuffer; 

    }

W3C Spec link: http://www.w3.org/TR/2012/WD-webaudio-20120802/

The parameter "playbackTime" is not present in latest WebKit-137862. Also if required, necessary calculations to update the playbackTime parameter need to be implemented in AudioProcessingEvent.

Current Implementation AudioProcessingEvent.idl:

[
    Conditional=WEB_AUDIO,
    JSGenerateToJSObject
] interface AudioProcessingEvent : Event {
    readonly attribute AudioBuffer inputBuffer;
    readonly attribute AudioBuffer outputBuffer; 
};

OTHER TIPS

Note that is the Webkit bug (i.e. the Safari one) - the Blink (Chrome) bug is at https://code.google.com/p/chromium/issues/detail?id=332782.

Obviously, I wouldn't characterize it as "core Chromium team doesn't care much about Web Audio" - there are just some issues that haven't sorted up to the top of the stack, and having lost Chris Rogers from the team last year was kind of a hit to our productivity. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top