Implement OfflineAudioContext constructor
authorcrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2012 01:42:43 +0000 (01:42 +0000)
committercrogers@google.com <crogers@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2012 01:42:43 +0000 (01:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=104188

Reviewed by Kentaro Hara.

Source/WebCore:

The Web Audio layout tests have relied on an undocumented way (in the specification) to render
audio faster than realtime using an OfflineAudioContext.  We want to expose a proper OfflineAudioContext
object and constructor instead of piggybacking off of the normal AudioContext.

* CMakeLists.txt:
* DerivedSources.make:
* DerivedSources.pri:
* GNUmakefile.list.am:
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::isSampleRateRangeGood):
* Modules/webaudio/AudioContext.h:
(AudioContext):
* Modules/webaudio/DOMWindowWebAudio.idl:
* Modules/webaudio/OfflineAudioContext.cpp: Added.
(WebCore):
(WebCore::OfflineAudioContext::create):
(WebCore::OfflineAudioContext::OfflineAudioContext):
(WebCore::OfflineAudioContext::~OfflineAudioContext):
* Modules/webaudio/OfflineAudioContext.h: Added.
(WebCore):
(OfflineAudioContext):
* Modules/webaudio/OfflineAudioContext.idl: Added.
* WebCore.gypi:
* WebCore.xcodeproj/project.pbxproj:
* bindings/generic/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::webkitOfflineAudioContextEnabled):
* bindings/js/JSAudioContextCustom.cpp:
(WebCore::JSAudioContextConstructor::constructJSAudioContext):
* bindings/v8/custom/V8AudioContextCustom.cpp:
(WebCore::V8AudioContext::constructorCallbackCustom):

LayoutTests:

Switch Web Audio layout tests to use OfflineAudioContext constructor.

* inspector-protocol/nmi-webaudio.html:
* inspector-protocol/resources/audio-context.html:
* webaudio/audiobuffersource-loop-comprehensive.html:
* webaudio/audiobuffersource-loop-points.html:
* webaudio/audiobuffersource-multi-channels.html:
* webaudio/audiobuffersource-playbackState.html:
* webaudio/audiobuffersource-playbackrate.html:
* webaudio/audiobuffersource-start.html:
* webaudio/audiobuffersource.html:
* webaudio/audiochannelmerger-stereo.html:
* webaudio/audiochannelsplitter.html:
* webaudio/audionode-connect-order.html:
* webaudio/audionode-expected.txt:
* webaudio/audioparam-connect-audioratesignal.html:
* webaudio/audioparam-summingjunction.html:
* webaudio/automatic-pull-node.html:
* webaudio/biquad-allpass.html:
* webaudio/biquad-bandpass.html:
* webaudio/biquad-highpass.html:
* webaudio/biquad-highshelf.html:
* webaudio/biquad-lowpass.html:
* webaudio/biquad-lowshelf.html:
* webaudio/biquad-notch.html:
* webaudio/biquad-peaking.html:
* webaudio/convolution-mono-mono.html:
* webaudio/delaynode-max-default-delay.html:
* webaudio/delaynode-max-nondefault-delay.html:
* webaudio/delaynode-maxdelay.html:
* webaudio/delaynode-maxdelaylimit.html:
* webaudio/delaynode-scheduling.html:
* webaudio/delaynode.html:
* webaudio/distance-exponential.html:
* webaudio/distance-inverse.html:
* webaudio/distance-linear.html:
* webaudio/gain.html:
* webaudio/javascriptaudionode-zero-input-channels.html:
* webaudio/javascriptaudionode.html:
* webaudio/mediaelementaudiosourcenode-gc.html:
* webaudio/mixing.html:
* webaudio/note-grain-on-play.html:
* webaudio/note-grain-on-timing.html:
* webaudio/oscillator-basic.html:
* webaudio/panner-equalpower-stereo.html:
* webaudio/panner-equalpower.html:
* webaudio/realtimeanalyser-fft-sizing.html:
* webaudio/resources/audio-codec-test.js:
(runDecodingTest):
* webaudio/resources/audioparam-testing.js:
(createAudioGraphAndTest):
* webaudio/resources/javascriptaudionode-testing.js:
(runJSNodeTest):
* webaudio/sample-accurate-scheduling.html:
* webaudio/stereo2mono-down-mixing.html:
* webaudio/up-mixing-mono-51.html:
* webaudio/up-mixing-mono-stereo.html:
* webaudio/up-mixing-stereo-51.html:
* webaudio/waveshaper.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@137398 268f45cc-cd09-0410-ab3c-d52691b4dbfc

71 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector-protocol/nmi-webaudio.html
LayoutTests/inspector-protocol/resources/audio-context.html
LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html
LayoutTests/webaudio/audiobuffersource-loop-points.html
LayoutTests/webaudio/audiobuffersource-multi-channels.html
LayoutTests/webaudio/audiobuffersource-playbackState.html
LayoutTests/webaudio/audiobuffersource-playbackrate.html
LayoutTests/webaudio/audiobuffersource-start.html
LayoutTests/webaudio/audiobuffersource.html
LayoutTests/webaudio/audiochannelmerger-stereo.html
LayoutTests/webaudio/audiochannelsplitter.html
LayoutTests/webaudio/audionode-connect-order.html
LayoutTests/webaudio/audionode-expected.txt
LayoutTests/webaudio/audioparam-connect-audioratesignal.html
LayoutTests/webaudio/audioparam-summingjunction.html
LayoutTests/webaudio/automatic-pull-node.html
LayoutTests/webaudio/biquad-allpass.html
LayoutTests/webaudio/biquad-bandpass.html
LayoutTests/webaudio/biquad-highpass.html
LayoutTests/webaudio/biquad-highshelf.html
LayoutTests/webaudio/biquad-lowpass.html
LayoutTests/webaudio/biquad-lowshelf.html
LayoutTests/webaudio/biquad-notch.html
LayoutTests/webaudio/biquad-peaking.html
LayoutTests/webaudio/convolution-mono-mono.html
LayoutTests/webaudio/delaynode-max-default-delay.html
LayoutTests/webaudio/delaynode-max-nondefault-delay.html
LayoutTests/webaudio/delaynode-maxdelay.html
LayoutTests/webaudio/delaynode-maxdelaylimit.html
LayoutTests/webaudio/delaynode-scheduling.html
LayoutTests/webaudio/delaynode.html
LayoutTests/webaudio/distance-exponential.html
LayoutTests/webaudio/distance-inverse.html
LayoutTests/webaudio/distance-linear.html
LayoutTests/webaudio/gain.html
LayoutTests/webaudio/javascriptaudionode-zero-input-channels.html
LayoutTests/webaudio/javascriptaudionode.html
LayoutTests/webaudio/mediaelementaudiosourcenode-gc.html
LayoutTests/webaudio/mixing.html
LayoutTests/webaudio/note-grain-on-play.html
LayoutTests/webaudio/note-grain-on-timing.html
LayoutTests/webaudio/oscillator-basic.html
LayoutTests/webaudio/panner-equalpower-stereo.html
LayoutTests/webaudio/panner-equalpower.html
LayoutTests/webaudio/realtimeanalyser-fft-sizing.html
LayoutTests/webaudio/resources/audio-codec-test.js
LayoutTests/webaudio/resources/audioparam-testing.js
LayoutTests/webaudio/resources/javascriptaudionode-testing.js
LayoutTests/webaudio/sample-accurate-scheduling.html
LayoutTests/webaudio/stereo2mono-down-mixing.html
LayoutTests/webaudio/up-mixing-mono-51.html
LayoutTests/webaudio/up-mixing-mono-stereo.html
LayoutTests/webaudio/up-mixing-stereo-51.html
LayoutTests/webaudio/waveshaper.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/DerivedSources.pri
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/Modules/webaudio/DOMWindowWebAudio.idl
Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp [new file with mode: 0644]
Source/WebCore/Modules/webaudio/OfflineAudioContext.h [new file with mode: 0644]
Source/WebCore/Modules/webaudio/OfflineAudioContext.idl [new file with mode: 0644]
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h
Source/WebCore/bindings/js/JSAudioContextCustom.cpp
Source/WebCore/bindings/v8/custom/V8AudioContextCustom.cpp

index e1a3bcf..86067a5 100644 (file)
@@ -1,3 +1,70 @@
+2012-12-11  Chris Rogers  <crogers@google.com>
+
+        Implement OfflineAudioContext constructor
+        https://bugs.webkit.org/show_bug.cgi?id=104188
+
+        Reviewed by Kentaro Hara.
+
+        Switch Web Audio layout tests to use OfflineAudioContext constructor.
+
+        * inspector-protocol/nmi-webaudio.html:
+        * inspector-protocol/resources/audio-context.html:
+        * webaudio/audiobuffersource-loop-comprehensive.html:
+        * webaudio/audiobuffersource-loop-points.html:
+        * webaudio/audiobuffersource-multi-channels.html:
+        * webaudio/audiobuffersource-playbackState.html:
+        * webaudio/audiobuffersource-playbackrate.html:
+        * webaudio/audiobuffersource-start.html:
+        * webaudio/audiobuffersource.html:
+        * webaudio/audiochannelmerger-stereo.html:
+        * webaudio/audiochannelsplitter.html:
+        * webaudio/audionode-connect-order.html:
+        * webaudio/audionode-expected.txt:
+        * webaudio/audioparam-connect-audioratesignal.html:
+        * webaudio/audioparam-summingjunction.html:
+        * webaudio/automatic-pull-node.html:
+        * webaudio/biquad-allpass.html:
+        * webaudio/biquad-bandpass.html:
+        * webaudio/biquad-highpass.html:
+        * webaudio/biquad-highshelf.html:
+        * webaudio/biquad-lowpass.html:
+        * webaudio/biquad-lowshelf.html:
+        * webaudio/biquad-notch.html:
+        * webaudio/biquad-peaking.html:
+        * webaudio/convolution-mono-mono.html:
+        * webaudio/delaynode-max-default-delay.html:
+        * webaudio/delaynode-max-nondefault-delay.html:
+        * webaudio/delaynode-maxdelay.html:
+        * webaudio/delaynode-maxdelaylimit.html:
+        * webaudio/delaynode-scheduling.html:
+        * webaudio/delaynode.html:
+        * webaudio/distance-exponential.html:
+        * webaudio/distance-inverse.html:
+        * webaudio/distance-linear.html:
+        * webaudio/gain.html:
+        * webaudio/javascriptaudionode-zero-input-channels.html:
+        * webaudio/javascriptaudionode.html:
+        * webaudio/mediaelementaudiosourcenode-gc.html:
+        * webaudio/mixing.html:
+        * webaudio/note-grain-on-play.html:
+        * webaudio/note-grain-on-timing.html:
+        * webaudio/oscillator-basic.html:
+        * webaudio/panner-equalpower-stereo.html:
+        * webaudio/panner-equalpower.html:
+        * webaudio/realtimeanalyser-fft-sizing.html:
+        * webaudio/resources/audio-codec-test.js:
+        (runDecodingTest):
+        * webaudio/resources/audioparam-testing.js:
+        (createAudioGraphAndTest):
+        * webaudio/resources/javascriptaudionode-testing.js:
+        (runJSNodeTest):
+        * webaudio/sample-accurate-scheduling.html:
+        * webaudio/stereo2mono-down-mixing.html:
+        * webaudio/up-mixing-mono-51.html:
+        * webaudio/up-mixing-mono-stereo.html:
+        * webaudio/up-mixing-stereo-51.html:
+        * webaudio/waveshaper.html:
+
 2012-12-11  Tim Horton  <timothy_horton@apple.com>
 
         -webkit-svg-shadow radius changes don't cause children's boundaries to be recomputed
index 79a8c83..4f7001b 100644 (file)
@@ -20,7 +20,7 @@ function runPageTest()
     testRunner.waitUntilDone();
 
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
 
     var bufferSource = context.createBufferSource();
     bufferSource.buffer = createSinWaveBuffer(context, renderLengthSeconds, 880);
index a35b4e7..062a749 100644 (file)
@@ -5,7 +5,7 @@ var sampleRate = 44100.0;
 var renderLengthSeconds = 0.125;
 
 // Create offline audio context.
-var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
 
 // This call forces AudioContext lazy initialization.
 var bufferSource = context.createBufferSource();
index 252069f..aede478 100644 (file)
@@ -97,7 +97,7 @@ function runTest() {
     window.jsTestIsAsync = true;
 
     // Create offline audio context.
-    var context = new webkitAudioContext(1, totalRenderLengthFrames, sampleRate);
+    var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
     buffer = createTestBuffer(context, bufferFrameLength);
 
     for (var i = 0; i < tests.length; ++i)
index 00ffa87..5601d02 100644 (file)
@@ -82,7 +82,7 @@ function init() {
         return;
 
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
 
     // Create the test buffer.
     // We'll loop this with the loop-points set for the 2nd half of this buffer.
index ae828f3..7b853f7 100644 (file)
@@ -23,7 +23,7 @@ function runTest() {
 
     // Create offline audio context
     var sampleRate = 44100.0;
-    var context = new webkitAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 440, toneLengthSeconds, 6); 
 
     var source = context.createBufferSource();
index c32f996..d2c3e14 100644 (file)
@@ -105,7 +105,7 @@ function runTest()
     window.jsTestIsAsync = true;
 
     // Create offline audio context, rendering for renderTime seconds.
-    context = new webkitAudioContext(2, timeToSampleFrame(renderTime, sampleRate), sampleRate);
+    context = new webkitOfflineAudioContext(2, timeToSampleFrame(renderTime, sampleRate), sampleRate);
 
     // This is only used so we can access the playback state constants.
     var bufferSource = context.createBufferSource();
index 0d4e3d6..2caa0fb 100644 (file)
@@ -71,7 +71,7 @@ function init() {
         return;
 
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
 
     // Create a single cycle of a sine wave.
     // We'll loop this to play notes of a given duration, at a given playback rate.
index b697b7e..855d019 100644 (file)
@@ -80,7 +80,7 @@ function runTest() {
     window.jsTestIsAsync = true;
 
     // Create offline audio context.
-    var context = new webkitAudioContext(1, totalRenderLengthFrames, sampleRate);
+    var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
     buffer = createTestBuffer(context, bufferFrameLength);
 
     for (var i = 0; i < tests.length; ++i)
index c00d7b2..dbe1054 100644 (file)
@@ -24,7 +24,7 @@ function init() {
         return;
         
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
     
     bufferLoader = new BufferLoader(
         context,
index c466c68..412f587 100644 (file)
@@ -78,7 +78,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create stereo offline audio context.
-    context = new webkitAudioContext(2, lengthInSampleFrames, sampleRate);
+    context = new webkitOfflineAudioContext(2, lengthInSampleFrames, sampleRate);
 
     // Create two mono buffers, one having all -1 values, the other all +1.
     buffer1 = createBufferWithDCOffset(lengthInSampleFrames, sampleRate, -1);
index ab62c0b..c7a5143 100644 (file)
@@ -81,7 +81,7 @@ function runTest() {
     window.jsTestIsAsync = true;
 
     // Create stereo offline audio context.
-    context = new webkitAudioContext(2, lengthInSampleFrames, sampleRate);
+    context = new webkitOfflineAudioContext(2, lengthInSampleFrames, sampleRate);
 
     try {
         var splitternode = context.createChannelSplitter(0);
index ab4c402..3dfb2f0 100644 (file)
@@ -40,7 +40,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createSinWaveBuffer(context, renderLengthSeconds, 880);
     
     var bufferSource = context.createBufferSource();
index 0540fe7..8358c73 100644 (file)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Deprecated AudioContext constructor: use OfflineAudioContext instead
 Basic tests for AudioNode API.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
index 173ac6f..1c1b3d3 100644 (file)
@@ -69,7 +69,7 @@ function runTest() {
     var sampleFrameLength = sampleRate * lengthInSeconds;
 
     // Create offline audio context.
-    context = new webkitAudioContext(1, sampleFrameLength, sampleRate);
+    context = new webkitOfflineAudioContext(1, sampleFrameLength, sampleRate);
 
     // Create buffer used by the source which will have its gain controlled.
     constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
index 9c267ef..a82b275 100644 (file)
@@ -82,7 +82,7 @@ function runTest() {
     var sampleFrameLength = sampleRate * lengthInSeconds;
 
     // Create offline audio context.
-    context = new webkitAudioContext(1, sampleFrameLength, sampleRate);
+    context = new webkitOfflineAudioContext(1, sampleFrameLength, sampleRate);
 
     // Create buffer used by the source which will have its gain controlled.
     var constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
index e273745..440c706 100644 (file)
@@ -30,7 +30,7 @@ var analyser;
 
 function constructCommonGraph() {
     // Create offline audio context.
-    context = new webkitAudioContext(1, renderLengthInFrames, sampleRate);
+    context = new webkitOfflineAudioContext(1, renderLengthInFrames, sampleRate);
     constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1);
 
     bufferSource = context.createBufferSource();
index ecfcc95..423446e 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 34e2567..32c2ce7 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 56730c5..eb630c8 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index ce29a43..8f83b50 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 8d5e4a9..7ebdf01 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index c0df1bc..03b07d5 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 6c4a672..52d2eca 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 8519a64..fc460eb 100644 (file)
@@ -25,7 +25,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();
index 0fb42d7..bf57f38 100644 (file)
@@ -35,7 +35,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     var squarePulse = createSquarePulseBuffer(context, pulseLengthFrames);
     var trianglePulse = createTrianglePulseBuffer(context, 2 * pulseLengthFrames);
index 6bcc260..0f0f812 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index 41ad1e2..e283353 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index e27c53c..0892d4e 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index 52e5eb2..fb206a6 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index 14dfbd2..dfaf7d9 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index 4038558..87c47e7 100644 (file)
@@ -24,7 +24,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
     
     var bufferSource = context.createBufferSource();
index c059d15..fa0f991 100644 (file)
@@ -23,7 +23,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
           // Temp panner node so we can get the EXPONENTIAL_DISTANCE value.
           var tempPanner = context.createPanner();
index 6b4448d..c54e738 100644 (file)
@@ -23,7 +23,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
           // Temp panner node so we can get the INVERSE_DISTANCE value.
           var tempPanner = context.createPanner();
index f435262..e889a39 100644 (file)
@@ -23,7 +23,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
           // Create temp panner to get LINEAR_DISTANCE value for testing.
           var pannerModel = context.createPanner();
index 1ff1ba6..386b3e0 100644 (file)
@@ -59,7 +59,7 @@ function init() {
         return;
 
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
 
     // Create a buffer for a short "note".
     sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
index 638e5ad..7b474cb 100644 (file)
@@ -33,7 +33,7 @@ function runTest()
 
     window.jsTestIsAsync = true;
 
-    var context = new webkitAudioContext(1, renderLengthInFrames, sampleRate);
+    var context = new webkitOfflineAudioContext(1, renderLengthInFrames, sampleRate);
 
     var node;
 
index 88f01eb..ab52ebc 100644 (file)
@@ -84,7 +84,7 @@ function runTest() {
     window.jsTestIsAsync = true;
 
     // Create offline audio context.
-    context = new webkitAudioContext(2, renderLengthInFrames, sampleRate);
+    context = new webkitOfflineAudioContext(2, renderLengthInFrames, sampleRate);
 
     try {
         var jsnode = context.createScriptProcessor(512, 0, 0);
index 830abb3..aca539b 100644 (file)
@@ -19,7 +19,7 @@ function runTest() {
     }
 
     audioElement = document.createElement("audio");
-    context = new webkitAudioContext(1, 1000, 44100);
+    context = new webkitOfflineAudioContext(1, 1000, 44100);
     source = context.createMediaElementSource(audioElement);
     audioElement = null;
     context = null;
index 3f68149..10b763e 100644 (file)
@@ -28,7 +28,7 @@ function init() {
         return;
         
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
         
     bufferLoader = new BufferLoader(
         context,
index b5d5965..8bdb910 100644 (file)
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderTime, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderTime, sampleRate);
 
           // Create a linear ramp for testing noteGrainOn.
           linearRampBuffer = createSignalBuffer(context,
index 136b4a2..4e5ccb1 100644 (file)
@@ -44,7 +44,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderTime, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderTime, sampleRate);
 
           squarePulseBuffer = createSignalBuffer(context, function (k) { return 1 });    
 
index d3989eb..44eb8f6 100644 (file)
@@ -36,7 +36,7 @@ function runTest()
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
     var osc = context.createOscillator();
 
     // Set each possible oscillator type (except CUSTOM) and verify that the type is correct.
index 3166cdd..18054fd 100644 (file)
@@ -29,7 +29,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
           createTestAndRun(context, nodesToCreate, 2);
       }
index eec0ddd..189046a 100644 (file)
@@ -29,7 +29,7 @@
           window.jsTestIsAsync = true;
 
           // Create offline audio context.
-          context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+          context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
           createTestAndRun(context, nodesToCreate, 1);
       }
index 90c8938..c5ae2aa 100644 (file)
@@ -19,7 +19,7 @@ if (window.testRunner) {
 }
 
 var doTest = function(fftSize, illegal) {
-    var c = new webkitAudioContext(1, 1000, 44100);
+    var c = new webkitOfflineAudioContext(1, 1000, 44100);
     var a = c.createAnalyser();
     try {
         a.fftSize = fftSize;
index e1305b6..e4148aa 100644 (file)
@@ -14,7 +14,7 @@ function runDecodingTest(url, optionalSampleRate)
     var sampleRate = (typeof optionalSampleRate === "undefined") ? defaultSampleRate : optionalSampleRate;
 
     // Create offline audio context.
-    context = new webkitAudioContext(1, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRate);
     
     bufferLoader = new BufferLoader(
         context,
index a59f67d..34cd0d0 100644 (file)
@@ -405,7 +405,7 @@ function createAudioGraphAndTest(numberOfTests, initialValue, setValueFunction,
     window.jsTestIsAsync = true;
 
     // Create offline audio context.
-    context = new webkitAudioContext(2, renderLength(numberOfTests), sampleRate);
+    context = new webkitOfflineAudioContext(2, renderLength(numberOfTests), sampleRate);
     var constantBuffer = createConstantBuffer(context, 1, renderLength(numberOfTests));
 
     // We use an AudioGainNode here simply as a convenient way to test the AudioParam
index 1197848..0454211 100644 (file)
@@ -65,7 +65,7 @@ function checkStereoOnlyData(buffer, numberOfChannels, length) {
 function runJSNodeTest()
 {
     // Create offline audio context.
-    context = new webkitAudioContext(2, renderLengthInFrames, sampleRate);
+    context = new webkitOfflineAudioContext(2, renderLengthInFrames, sampleRate);
 
     var sourceBuffer = createBuffer(context, sourceChannels, renderLengthInFrames);
 
index 6d67d70..510b1ff 100644 (file)
@@ -113,7 +113,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    context = new webkitAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
     createImpulse();    
 
     for (var i = 0; i < sampleOffsets.length; ++i) {
index f465570..17e97e9 100644 (file)
@@ -50,7 +50,7 @@ function runTest() {
     window.jsTestIsAsync = true;
 
     // Create offline audio context, the destination is mono.
-    context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
     // Create a stereo AudioBuffer.
     toneBuffer = createDataBuffer(context, renderLengthSeconds);
 
index a57451f..eb55087 100644 (file)
@@ -23,7 +23,7 @@ function runTest() {
 
     // Create offline audio context
     var sampleRate = 44100.0;
-    var context = new webkitAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 440, toneLengthSeconds, 1); 
 
     var source = context.createBufferSource();
index 93c7190..2fc07be 100644 (file)
@@ -23,7 +23,7 @@ function runTest() {
 
     // Create offline audio context
     var sampleRate = 44100.0;
-    var context = new webkitAudioContext(2, sampleRate * toneLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(2, sampleRate * toneLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 440, toneLengthSeconds, 1); 
 
     var source = context.createBufferSource();
index 0be6ea9..9323403 100644 (file)
@@ -23,7 +23,7 @@ function runTest() {
 
     // Create offline audio context
     var sampleRate = 44100.0;
-    var context = new webkitAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
+    var context = new webkitOfflineAudioContext(6, sampleRate * toneLengthSeconds, sampleRate);
     var toneBuffer = createToneBuffer(context, 440, toneLengthSeconds, 2); 
 
     var source = context.createBufferSource();
index 6c56ab5..22a5955 100644 (file)
@@ -107,7 +107,7 @@ function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    context = new webkitAudioContext(1, numberOfRenderFrames, sampleRate);
+    context = new webkitOfflineAudioContext(1, numberOfRenderFrames, sampleRate);
     
     // source -> waveshaper -> destination
     var source = context.createBufferSource();
index e3ca9c9..0a2605e 100644 (file)
@@ -281,6 +281,7 @@ set(WebCore_IDL_FILES
     Modules/webaudio/ScriptProcessorNode.idl
     Modules/webaudio/MediaElementAudioSourceNode.idl
     Modules/webaudio/MediaStreamAudioSourceNode.idl
+    Modules/webaudio/OfflineAudioContext.idl
     Modules/webaudio/OfflineAudioCompletionEvent.idl
     Modules/webaudio/OscillatorNode.idl
     Modules/webaudio/AnalyserNode.idl
@@ -929,6 +930,7 @@ set(WebCore_SOURCES
     Modules/webaudio/ScriptProcessorNode.cpp
     Modules/webaudio/MediaElementAudioSourceNode.cpp
     Modules/webaudio/MediaStreamAudioSourceNode.cpp
+    Modules/webaudio/OfflineAudioContext.cpp
     Modules/webaudio/OfflineAudioCompletionEvent.cpp
     Modules/webaudio/OfflineAudioDestinationNode.cpp
     Modules/webaudio/OscillatorNode.cpp
index 44cea85..f1bd0f8 100644 (file)
@@ -1,3 +1,41 @@
+2012-12-11  Chris Rogers  <crogers@google.com>
+
+        Implement OfflineAudioContext constructor
+        https://bugs.webkit.org/show_bug.cgi?id=104188
+
+        Reviewed by Kentaro Hara.
+
+        The Web Audio layout tests have relied on an undocumented way (in the specification) to render
+        audio faster than realtime using an OfflineAudioContext.  We want to expose a proper OfflineAudioContext
+        object and constructor instead of piggybacking off of the normal AudioContext.
+            
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * DerivedSources.pri:
+        * GNUmakefile.list.am:
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::isSampleRateRangeGood):
+        * Modules/webaudio/AudioContext.h:
+        (AudioContext):
+        * Modules/webaudio/DOMWindowWebAudio.idl:
+        * Modules/webaudio/OfflineAudioContext.cpp: Added.
+        (WebCore):
+        (WebCore::OfflineAudioContext::create):
+        (WebCore::OfflineAudioContext::OfflineAudioContext):
+        (WebCore::OfflineAudioContext::~OfflineAudioContext):
+        * Modules/webaudio/OfflineAudioContext.h: Added.
+        (WebCore):
+        (OfflineAudioContext):
+        * Modules/webaudio/OfflineAudioContext.idl: Added.
+        * WebCore.gypi:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/generic/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::webkitOfflineAudioContextEnabled):
+        * bindings/js/JSAudioContextCustom.cpp:
+        (WebCore::JSAudioContextConstructor::constructJSAudioContext):
+        * bindings/v8/custom/V8AudioContextCustom.cpp:
+        (WebCore::V8AudioContext::constructorCallbackCustom):
+
 2012-12-11  Jun Jiang  <jun.a.jiang@intel.com>
 
         WebGL: Avoid unnecessary memory copy or conversion in texImage2D and texSubImage2D for HTMLVideoElement
index 7be0d6a..9890f01 100644 (file)
@@ -142,6 +142,7 @@ BINDING_IDLS = \
     $(WebCore)/Modules/webaudio/MediaElementAudioSourceNode.idl \
     $(WebCore)/Modules/webaudio/MediaStreamAudioSourceNode.idl \
     $(WebCore)/Modules/webaudio/OscillatorNode.idl \
+    $(WebCore)/Modules/webaudio/OfflineAudioContext.idl \
     $(WebCore)/Modules/webaudio/OfflineAudioCompletionEvent.idl \
     $(WebCore)/Modules/webaudio/AnalyserNode.idl \
     $(WebCore)/Modules/webaudio/WaveShaperNode.idl \
index 55db423..d58afb9 100644 (file)
@@ -160,6 +160,7 @@ IDL_BINDINGS += \
     $$PWD/Modules/webaudio/ScriptProcessorNode.idl \
     $$PWD/Modules/webaudio/MediaElementAudioSourceNode.idl \
     $$PWD/Modules/webaudio/MediaStreamAudioSourceNode.idl \
+    $$PWD/Modules/webaudio/OfflineAudioContext.idl \
     $$PWD/Modules/webaudio/OfflineAudioCompletionEvent.idl \
     $$PWD/Modules/webaudio/OscillatorNode.idl \
     $$PWD/Modules/webaudio/AnalyserNode.idl \
index 237e723..825d961 100644 (file)
@@ -581,6 +581,8 @@ webcore_built_sources += \
        DerivedSources/WebCore/JSOESVertexArrayObject.h \
        DerivedSources/WebCore/JSOESElementIndexUint.cpp \
        DerivedSources/WebCore/JSOESElementIndexUint.h \
+       DerivedSources/WebCore/JSOfflineAudioContext.cpp \
+       DerivedSources/WebCore/JSOfflineAudioContext.h \
        DerivedSources/WebCore/JSOfflineAudioCompletionEvent.cpp \
        DerivedSources/WebCore/JSOfflineAudioCompletionEvent.h \
        DerivedSources/WebCore/JSOscillatorNode.cpp \
@@ -1288,6 +1290,7 @@ dom_binding_idls += \
        $(WebCore)/Modules/webaudio/ScriptProcessorNode.idl \
        $(WebCore)/Modules/webaudio/MediaElementAudioSourceNode.idl \
        $(WebCore)/Modules/webaudio/MediaStreamAudioSourceNode.idl \
+       $(WebCore)/Modules/webaudio/OfflineAudioContext.idl \
        $(WebCore)/Modules/webaudio/OfflineAudioCompletionEvent.idl \
     $(WebCore)/Modules/webaudio/OscillatorNode.idl \
        $(WebCore)/Modules/webaudio/AnalyserNode.idl \
@@ -2061,6 +2064,8 @@ webcore_modules_sources += \
        Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.h \
        Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.cpp \
        Source/WebCore/Modules/webaudio/MediaStreamAudioSourceNode.h \
+       Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp \
+       Source/WebCore/Modules/webaudio/OfflineAudioContext.h \
        Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.h \
        Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp \
        Source/WebCore/Modules/webaudio/OfflineAudioCompletionEvent.h \
index 714ab52..b200790 100644 (file)
@@ -95,17 +95,13 @@ const unsigned MaxNodesToDeletePerQuantum = 10;
 
 namespace WebCore {
     
-namespace {
-    
-bool isSampleRateRangeGood(float sampleRate)
+bool AudioContext::isSampleRateRangeGood(float sampleRate)
 {
     // FIXME: It would be nice if the minimum sample-rate could be less than 44.1KHz,
     // but that will require some fixes in HRTFPanner::fftSizeForSampleRate(), and some testing there.
     return sampleRate >= 44100 && sampleRate <= 96000;
 }
 
-}
-
 // Don't allow more than this number of simultaneous AudioContexts talking to hardware.
 const unsigned MaxHardwareContexts = 4;
 unsigned AudioContext::s_hardwareContextCount = 0;
@@ -124,23 +120,6 @@ PassRefPtr<AudioContext> AudioContext::create(Document* document, ExceptionCode&
     return audioContext.release();
 }
 
-PassRefPtr<AudioContext> AudioContext::createOfflineContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
-{
-    ASSERT(document);
-
-    // FIXME: offline contexts have limitations on supported sample-rates.
-    // Currently all AudioContexts must have the same sample-rate.
-    HRTFDatabaseLoader* loader = HRTFDatabaseLoader::loader();
-    if (numberOfChannels > 10 || !isSampleRateRangeGood(sampleRate) || (loader && loader->databaseSampleRate() != sampleRate)) {
-        ec = SYNTAX_ERR;
-        return 0;
-    }
-
-    RefPtr<AudioContext> audioContext(adoptRef(new AudioContext(document, numberOfChannels, numberOfFrames, sampleRate)));
-    audioContext->suspendIfNeeded();
-    return audioContext.release();
-}
-
 // Constructor for rendering to the audio hardware.
 AudioContext::AudioContext(Document* document)
     : ActiveDOMObject(document, this)
index 6da3c12..8a06668 100644 (file)
@@ -250,9 +250,13 @@ public:
 
     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
-private:
+protected:
     explicit AudioContext(Document*);
     AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
+    
+    static bool isSampleRateRangeGood(float sampleRate);
+    
+private:
     void constructCommon();
 
     void lazyInitialize();
index df88fb0..4b1b7d1 100644 (file)
@@ -30,6 +30,7 @@
 ] interface DOMWindowWebAudio {
 #if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP
     [JSCustomGetter, V8EnabledAtRuntime] attribute AudioContextConstructor webkitAudioContext;
+    [V8EnabledAtRuntime] attribute OfflineAudioContextConstructor webkitOfflineAudioContext;
     attribute PannerNodeConstructor webkitAudioPannerNode;
     attribute AudioProcessingEventConstructor AudioProcessingEvent;
     attribute OfflineAudioCompletionEventConstructor OfflineAudioCompletionEvent;
diff --git a/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp b/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
new file mode 100644 (file)
index 0000000..3fe3627
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(WEB_AUDIO)
+
+#include "OfflineAudioContext.h"
+
+#include "Document.h"
+#include "ExceptionCode.h"
+#include "HRTFDatabaseLoader.h"
+#include "ScriptExecutionContext.h"
+
+namespace WebCore {
+
+PassRefPtr<OfflineAudioContext> OfflineAudioContext::create(ScriptExecutionContext* context, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
+{
+    // FIXME: add support for workers.
+    if (!context || !context->isDocument()) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+
+    Document* document = static_cast<Document*>(context);
+
+    // FIXME: offline contexts have limitations on supported sample-rates.
+    // Currently all AudioContexts must have the same sample-rate.
+    HRTFDatabaseLoader* loader = HRTFDatabaseLoader::loader();
+    if (numberOfChannels > 10 || !isSampleRateRangeGood(sampleRate) || (loader && loader->databaseSampleRate() != sampleRate)) {
+        ec = SYNTAX_ERR;
+        return 0;
+    }
+
+    RefPtr<OfflineAudioContext> audioContext(adoptRef(new OfflineAudioContext(document, numberOfChannels, numberOfFrames, sampleRate)));
+    audioContext->suspendIfNeeded();
+    return audioContext.release();
+}
+
+OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
+    : AudioContext(document, numberOfChannels, numberOfFrames, sampleRate)
+{
+}
+
+OfflineAudioContext::~OfflineAudioContext()
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)
diff --git a/Source/WebCore/Modules/webaudio/OfflineAudioContext.h b/Source/WebCore/Modules/webaudio/OfflineAudioContext.h
new file mode 100644 (file)
index 0000000..beb6bf5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OfflineAudioContext_h
+#define OfflineAudioContext_h
+
+#include "AudioContext.h"
+
+namespace WebCore {
+
+class OfflineAudioContext : public AudioContext {
+public:
+    static PassRefPtr<OfflineAudioContext> create(ScriptExecutionContext*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode&);
+
+    virtual ~OfflineAudioContext();
+
+private:
+    OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
+};
+
+} // namespace WebCore
+
+#endif // OfflineAudioContext_h
diff --git a/Source/WebCore/Modules/webaudio/OfflineAudioContext.idl b/Source/WebCore/Modules/webaudio/OfflineAudioContext.idl
new file mode 100644 (file)
index 0000000..5403e83
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=WEB_AUDIO,
+    ActiveDOMObject,
+    JSGenerateToJSObject,
+    Constructor(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate),
+    ConstructorRaisesException,
+    CallWith=ScriptExecutionContext
+] interface OfflineAudioContext : AudioContext {
+
+};
index 7c944f5..a4f4164 100644 (file)
             'Modules/webaudio/MediaStreamAudioDestinationNode.idl',
             'Modules/webaudio/MediaStreamAudioSourceNode.idl',
             'Modules/webaudio/OfflineAudioCompletionEvent.idl',
+            'Modules/webaudio/OfflineAudioContext.idl',
             'Modules/webaudio/OscillatorNode.idl',
             'Modules/webaudio/AnalyserNode.idl',
             'Modules/webaudio/WaveShaperNode.idl',
             'Modules/webaudio/MediaStreamAudioSourceNode.h',
             'Modules/webaudio/OfflineAudioCompletionEvent.cpp',
             'Modules/webaudio/OfflineAudioCompletionEvent.h',
+            'Modules/webaudio/OfflineAudioContext.cpp',
+            'Modules/webaudio/OfflineAudioContext.h',
             'Modules/webaudio/OfflineAudioDestinationNode.cpp',
             'Modules/webaudio/OfflineAudioDestinationNode.h',
             'Modules/webaudio/OscillatorNode.cpp',
index 07845b7..4214896 100644 (file)
                FDA3E95A134A49EF008D4B5A /* OfflineAudioCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA3E956134A49EF008D4B5A /* OfflineAudioCompletionEvent.h */; };
                FDA3E95B134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDA3E957134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp */; };
                FDA3E95C134A49EF008D4B5A /* OfflineAudioDestinationNode.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA3E958134A49EF008D4B5A /* OfflineAudioDestinationNode.h */; };
+               FDA9325D16703B2A008982DC /* OfflineAudioContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDA9325A16703B2A008982DC /* OfflineAudioContext.cpp */; };
+               FDA9325E16703B2A008982DC /* OfflineAudioContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA9325B16703B2A008982DC /* OfflineAudioContext.h */; };
+               FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDA9326416703BA9008982DC /* JSOfflineAudioContext.cpp */; };
+               FDA9326716703BA9008982DC /* JSOfflineAudioContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA9326516703BA9008982DC /* JSOfflineAudioContext.h */; };
                FDAF19981513D131008DB0C3 /* DirectConvolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDAF19961513D131008DB0C3 /* DirectConvolver.cpp */; };
                FDAF19991513D131008DB0C3 /* DirectConvolver.h in Headers */ = {isa = PBXBuildFile; fileRef = FDAF19971513D131008DB0C3 /* DirectConvolver.h */; };
                FDB052DF1561A42C00B500D6 /* AudioSummingJunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FDB052DD1561A42C00B500D6 /* AudioSummingJunction.cpp */; };
                FDA3E957134A49EF008D4B5A /* OfflineAudioDestinationNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OfflineAudioDestinationNode.cpp; sourceTree = "<group>"; };
                FDA3E958134A49EF008D4B5A /* OfflineAudioDestinationNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OfflineAudioDestinationNode.h; sourceTree = "<group>"; };
                FDA3E95D134A49FF008D4B5A /* OfflineAudioCompletionEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OfflineAudioCompletionEvent.idl; sourceTree = "<group>"; };
+               FDA9325A16703B2A008982DC /* OfflineAudioContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OfflineAudioContext.cpp; sourceTree = "<group>"; };
+               FDA9325B16703B2A008982DC /* OfflineAudioContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OfflineAudioContext.h; sourceTree = "<group>"; };
+               FDA9325C16703B2A008982DC /* OfflineAudioContext.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OfflineAudioContext.idl; sourceTree = "<group>"; };
+               FDA9326416703BA9008982DC /* JSOfflineAudioContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSOfflineAudioContext.cpp; sourceTree = "<group>"; };
+               FDA9326516703BA9008982DC /* JSOfflineAudioContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSOfflineAudioContext.h; sourceTree = "<group>"; };
                FDAF19961513D131008DB0C3 /* DirectConvolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DirectConvolver.cpp; sourceTree = "<group>"; };
                FDAF19971513D131008DB0C3 /* DirectConvolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectConvolver.h; sourceTree = "<group>"; };
                FDB052DD1561A42C00B500D6 /* AudioSummingJunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSummingJunction.cpp; sourceTree = "<group>"; };
                                FD671A74159BB07000197559 /* MediaStreamAudioSourceNode.cpp */,
                                FD671A75159BB07000197559 /* MediaStreamAudioSourceNode.h */,
                                FD671A76159BB07000197559 /* MediaStreamAudioSourceNode.idl */,
+                               FDA9325A16703B2A008982DC /* OfflineAudioContext.cpp */,
+                               FDA9325B16703B2A008982DC /* OfflineAudioContext.h */,
+                               FDA9325C16703B2A008982DC /* OfflineAudioContext.idl */,
                                FDA3E955134A49EF008D4B5A /* OfflineAudioCompletionEvent.cpp */,
                                FDA3E956134A49EF008D4B5A /* OfflineAudioCompletionEvent.h */,
                                FDA3E95D134A49FF008D4B5A /* OfflineAudioCompletionEvent.idl */,
                                FD23A12413F5FA5900F67001 /* JSMediaElementAudioSourceNode.h */,
                                FDBD480A159BC6870093EB4F /* JSMediaStreamAudioSourceNode.cpp */,
                                FDBD480B159BC6870093EB4F /* JSMediaStreamAudioSourceNode.h */,
+                               FDA9326416703BA9008982DC /* JSOfflineAudioContext.cpp */,
+                               FDA9326516703BA9008982DC /* JSOfflineAudioContext.h */,
                                FDF6BAF6134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp */,
                                FDF6BAF7134A4C9800822920 /* JSOfflineAudioCompletionEvent.h */,
                                FDEA6240152102E200479DF0 /* JSOscillatorNode.cpp */,
                                31D591B316697A6C00E6BF02 /* PlugInClient.h in Headers */,
                                31D591BC166C2E6C00E6BF02 /* PlugInOriginHash.h in Headers */,
                                986EA88315FFF29000985E5E /* PrerenderClient.h in Headers */,
+                               FDA9325E16703B2A008982DC /* OfflineAudioContext.h in Headers */,
+                               FDA9326716703BA9008982DC /* JSOfflineAudioContext.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                D6489D25166FFCF1007C031B /* JSHTMLTemplateElement.cpp in Sources */,
                                D6F7960D166FFECE0076DD18 /* JSHTMLTemplateElementCustom.cpp in Sources */,
                                31D591BB166C2E6C00E6BF02 /* PlugInOriginHash.cpp in Sources */,
+                               FDA9325D16703B2A008982DC /* OfflineAudioContext.cpp in Sources */,
+                               FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 93cb839..18f661c 100644 (file)
@@ -123,6 +123,7 @@ public:
 #if ENABLE(WEB_AUDIO)
     static void setWebkitAudioContextEnabled(bool isEnabled) { isWebAudioEnabled = isEnabled; }
     static bool webkitAudioContextEnabled() { return isWebAudioEnabled; }
+    static bool webkitOfflineAudioContextEnabled() { return isWebAudioEnabled; }
 #endif
 
 #if ENABLE(TOUCH_EVENTS)
index 120fc57..61d787d 100644 (file)
@@ -32,6 +32,8 @@
 #include "JSArrayBuffer.h"
 #include "JSAudioBuffer.h"
 #include "JSAudioContext.h"
+#include "JSOfflineAudioContext.h"
+#include "OfflineAudioContext.h"
 #include <runtime/Error.h>
 #include <wtf/ArrayBuffer.h>
 
@@ -77,8 +79,12 @@ EncodedJSValue JSC_HOST_CALL JSAudioContextConstructor::constructJSAudioContext(
         if (!audioContext.get())
             return throwVMError(exec, createSyntaxError(exec, "audio resources unavailable for AudioContext construction"));
     } else {
+#if ENABLE(LEGACY_WEB_AUDIO)
         // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer.
         // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
+        document->addConsoleMessage(JSMessageSource, WarningMessageLevel,
+            "Deprecated AudioContext constructor: use OfflineAudioContext instead");
+
         if (exec->argumentCount() < 3)
             return throwVMError(exec, createNotEnoughArgumentsError(exec));
 
@@ -95,12 +101,16 @@ EncodedJSValue JSC_HOST_CALL JSAudioContextConstructor::constructJSAudioContext(
         if (sampleRate <= 0)
             return throwVMError(exec, createSyntaxError(exec, "Invalid sample rate"));
 
+
         ExceptionCode ec = 0;
-        audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec);
+        audioContext = OfflineAudioContext::create(document, numberOfChannels, numberOfFrames, sampleRate, ec);
         if (ec) {
             setDOMException(exec, ec);
             return throwVMError(exec, createSyntaxError(exec, "Error creating OfflineAudioContext"));
         }
+#else
+        return throwVMError(exec, createSyntaxError(exec, "Illegal AudioContext constructor"));
+#endif
     }
 
     if (!audioContext.get())
index 80a32ba..7cbe566 100644 (file)
 #include "AudioContext.h"
 #include "BindingState.h"
 #include "Frame.h"
+#include "OfflineAudioContext.h"
 #include "V8ArrayBuffer.h"
 #include "V8AudioBuffer.h"
 #include "V8Binding.h"
+#include "V8OfflineAudioContext.h"
 #include <wtf/ArrayBuffer.h>
 
 namespace WebCore {
@@ -54,29 +56,16 @@ v8::Handle<v8::Value> V8AudioContext::constructorCallbackCustom(const v8::Argume
         if (!audioContext.get())
             return throwError(v8SyntaxError, "audio resources unavailable for AudioContext construction", args.GetIsolate());
     } else {
+#if ENABLE(LEGACY_WEB_AUDIO)
         // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer.
         // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
-        if (args.Length() < 3)
-            return throwNotEnoughArgumentsError(args.GetIsolate());
+        document->addConsoleMessage(JSMessageSource, WarningMessageLevel,
+            "Deprecated AudioContext constructor: use OfflineAudioContext instead");
 
-        bool ok = false;
-
-        int32_t numberOfChannels = toInt32(args[0], ok);
-        if (!ok || numberOfChannels <= 0 || numberOfChannels > 10)
-            return throwError(v8SyntaxError, "Invalid number of channels", args.GetIsolate());
-
-        int32_t numberOfFrames = toInt32(args[1], ok);
-        if (!ok || numberOfFrames <= 0)
-            return throwError(v8SyntaxError, "Invalid number of frames", args.GetIsolate());
-
-        float sampleRate = toFloat(args[2]);
-        if (sampleRate <= 0)
-            return throwError(v8SyntaxError, "Invalid sample rate", args.GetIsolate());
-
-        ExceptionCode ec = 0;
-        audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec);
-        if (ec)
-            return setDOMException(ec, args.GetIsolate());
+        return V8OfflineAudioContext::constructorCallback(args);
+#else
+        return throwError(v8SyntaxError, "Illegal AudioContext constructor", args.GetIsolate());
+#endif
     }
 
     if (!audioContext.get())