Chrome 27 beta throws a SyntatxError when I try to execute the following javascript line:
offlineContext = new webkitOfflineAudioContext(2, 7*48000, 48000);
This is in conformance with the W3C Recommendation, and after hours of searching the web I've seen dozens of examples that apparently work with this exact form. I know the API can be subject to change, but I can't find any hint that it has. Where am I going wrong?
Strangely, it doesn't fail when I try it in jsfiddle. I even tried running in jsfiddle the entire function in which this snippet exists, stubbing out a couple items. Below is the function that I'm trying to run. A "SyntaxError Dom Exception 12" occurs where indicated when the function is executed.
I have a working audio app, and I'm just trying to add background processing for later rendering using an OfflineAudioContext. If I define the OfflineAudoiContext in my init function, I don't get the syntax error there. But I need to define it in the createRenderData() function because I need to set the length and sample rate for each media source, and if I call the OfflineAudioContext constructor with no arguments, I get a TypeError. Also I don't see any way in the API to set the length and sample rate on an existing OfflineAudioContext.
AudioUI.createRenderData = function() {
var url = BGAudioUI.renderQueue.pop();
if (url) {
BGAudioUI.media = new Audio(url);
BGAudioUI.media.addEventListener('durationchange', function() {
console.log("background duration: " + BGAudioUI.media.duration);
BGAudioUI.duration = BGAudioUI.media.duration;
//BGAudioUI.allData = new Float32Array(Math.floor((AudioUI.context.sampleRate.toFixed() / AudioUI.downsampleFactor.toFixed() * BGAudioUI.duration)) + 1);
//console.log("calculated sample rate: " + Math.floor(AudioUI.context.sampleRate / AudioUI.downsampleFactor.toFixed()));
//console.log("duration: " + BGAudioUI.duration);
BGAudioUI.offlineContext = new webkitOfflineAudioContext(2, 7*48000, 48000); //SyntaxError DOM Exception 12 occurs here
BGAudioUI.mediaSource = BGAudioUI.offlineContext.createMediaElementSource(BGAudioUI.media);
BGAudioUI.offlineContext.oncomplete = function(buffer) {
data = buffer.getChannelData(0);
console.log(data.length + " records processed offline");
};
BGAudioUI.offlineContext.startRendering();
BGAudioUI.media.play();
console.log("created background media source for " + BGAudioUI.media.src);
}, false);
BGAudioUI.media.load();
console.log("created background media object for " + BGAudioUI.media.src);
} else {
alert("Background rendering complete");
}
};