Title: [264782] trunk
Revision
264782
Author
[email protected]
Date
2020-07-23 12:22:39 -0700 (Thu, 23 Jul 2020)

Log Message

Added PeriodicWave constructor according to spec
https://bugs.webkit.org/show_bug.cgi?id=214615

Patch by Clark Wang <[email protected]> on 2020-07-23
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Re-baselined existing tests that now pass, or fail further along.

* web-platform-tests/webaudio/idlharness.https.window-expected.txt:
* web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:

Source/WebCore:

Re-baselined existing tests that now pass.

Added PeriodicWave constructor according to spec: https://www.w3.org/TR/webaudio/#periodicwave.
Added PeriodicWaveConstraints, PeriodicWaveOptions files. Updated PeriodicWave::createBandLimitedTables
to normalize waveform based on spec: https://www.w3.org/TR/webaudio/#waveform-normalization.
Added updated createPeriodicWave method in BaseAudioContext, and moved old createPeriodicWave method
Into WebKitAudioContext.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::createPeriodicWave):
* Modules/webaudio/BaseAudioContext.h:
(WebCore::BaseAudioContext::createPeriodicWave):
* Modules/webaudio/BaseAudioContext.idl:
* Modules/webaudio/PeriodicWave.cpp:
(WebCore::PeriodicWave::create):
(WebCore::PeriodicWave::createBandLimitedTables):
* Modules/webaudio/PeriodicWave.h:
* Modules/webaudio/PeriodicWave.idl:
* Modules/webaudio/PeriodicWaveConstraints.h: Added.
* Modules/webaudio/PeriodicWaveConstraints.idl: Added.
* Modules/webaudio/PeriodicWaveOptions.h: Added.
* Modules/webaudio/PeriodicWaveOptions.idl: Added.
* Modules/webaudio/WebKitAudioContext.cpp:
(WebCore::WebKitAudioContext::createPeriodicWave):
* Modules/webaudio/WebKitAudioContext.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (264781 => 264782)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-07-23 19:22:39 UTC (rev 264782)
@@ -1,3 +1,16 @@
+2020-07-23  Clark Wang  <[email protected]>
+
+        Added PeriodicWave constructor according to spec
+        https://bugs.webkit.org/show_bug.cgi?id=214615
+
+        Reviewed by Chris Dumez.
+
+        Re-baselined existing tests that now pass, or fail further along.
+
+
+        * web-platform-tests/webaudio/idlharness.https.window-expected.txt:
+        * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:
+
 2020-07-23  Zalan Bujtas  <[email protected]>
 
         Unreviewed, reverting r262124.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/idlharness.https.window-expected.txt (264781 => 264782)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/idlharness.https.window-expected.txt	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/idlharness.https.window-expected.txt	2020-07-23 19:22:39 UTC (rev 264782)
@@ -968,13 +968,13 @@
 PASS AudioNode interface: new PannerNode(context) must inherit property "channelCountMode" with the proper type 
 PASS AudioNode interface: new PannerNode(context) must inherit property "channelInterpretation" with the proper type 
 PASS PeriodicWave interface: existence and properties of interface object 
-FAIL PeriodicWave interface object length assert_equals: wrong value for PeriodicWave.length expected 1 but got 0
+PASS PeriodicWave interface object length 
 PASS PeriodicWave interface object name 
 PASS PeriodicWave interface: existence and properties of interface prototype object 
 PASS PeriodicWave interface: existence and properties of interface prototype object's "constructor" property 
 PASS PeriodicWave interface: existence and properties of interface prototype object's @@unscopables property 
-FAIL PeriodicWave must be primary interface of new PeriodicWave(context) assert_equals: Unexpected exception when evaluating object expected null but got object "TypeError: function is not a constructor (evaluating 'new PeriodicWave(context)')"
-FAIL Stringification of new PeriodicWave(context) assert_equals: Unexpected exception when evaluating object expected null but got object "TypeError: function is not a constructor (evaluating 'new PeriodicWave(context)')"
+PASS PeriodicWave must be primary interface of new PeriodicWave(context) 
+PASS Stringification of new PeriodicWave(context) 
 PASS ScriptProcessorNode interface: existence and properties of interface object 
 PASS ScriptProcessorNode interface object length 
 PASS ScriptProcessorNode interface object name 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt (264781 => 264782)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt	2020-07-23 19:22:39 UTC (rev 264782)
@@ -4,12 +4,12 @@
 FAIL Executing "Test 1" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new OscillatorNode(context, {type: 'sine', frequency: freqHz})')"
 FAIL Executing "Test 2" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new OscillatorNode(context, {type: 'sine', frequency: freqHz})')"
 FAIL Executing "Test 3" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new OscillatorNode(context, {type: 'sine', frequency: freqHz})')"
-FAIL Executing "Test 4" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new PeriodicWave(
+FAIL Executing "Test 4" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new OscillatorNode(
                 context,
-                {real: [0, 1], imag: [0, 1], disableNormalization: true})')"
-FAIL Executing "Test 5" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new PeriodicWave(
+                {type: 'custom', frequency: freqHz, periodicWave: wave})')"
+FAIL Executing "Test 5" promise_test: Unhandled rejection with value: object "TypeError: function is not a constructor (evaluating 'new OscillatorNode(
                 context,
-                {real: [0, 1], imag: [0, 1], disableNormalization: true})')"
+                {type: 'custom', frequency: freqHz, periodicWave: wave})')"
 PASS Audit report 
 PASS > [Test 0] Sine wave: 100 Hz 
 PASS > [Test 1] Sine wave: -100 Hz 

Modified: trunk/Source/WebCore/CMakeLists.txt (264781 => 264782)


--- trunk/Source/WebCore/CMakeLists.txt	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/CMakeLists.txt	2020-07-23 19:22:39 UTC (rev 264782)
@@ -482,6 +482,8 @@
     Modules/webaudio/PannerOptions.idl
     Modules/webaudio/PanningModelType.idl
     Modules/webaudio/PeriodicWave.idl
+    Modules/webaudio/PeriodicWaveConstraints.idl
+    Modules/webaudio/PeriodicWaveOptions.idl
     Modules/webaudio/ScriptProcessorNode.idl
     Modules/webaudio/WaveShaperNode.idl
     Modules/webaudio/WebKitAudioContext.idl

Modified: trunk/Source/WebCore/ChangeLog (264781 => 264782)


--- trunk/Source/WebCore/ChangeLog	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/ChangeLog	2020-07-23 19:22:39 UTC (rev 264782)
@@ -1,3 +1,42 @@
+2020-07-23  Clark Wang  <[email protected]>
+
+        Added PeriodicWave constructor according to spec
+        https://bugs.webkit.org/show_bug.cgi?id=214615
+
+        Reviewed by Chris Dumez.
+
+        Re-baselined existing tests that now pass.
+
+        Added PeriodicWave constructor according to spec: https://www.w3.org/TR/webaudio/#periodicwave.
+        Added PeriodicWaveConstraints, PeriodicWaveOptions files. Updated PeriodicWave::createBandLimitedTables
+        to normalize waveform based on spec: https://www.w3.org/TR/webaudio/#waveform-normalization.
+        Added updated createPeriodicWave method in BaseAudioContext, and moved old createPeriodicWave method
+        Into WebKitAudioContext.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/webaudio/BaseAudioContext.cpp:
+        (WebCore::BaseAudioContext::createPeriodicWave):
+        * Modules/webaudio/BaseAudioContext.h:
+        (WebCore::BaseAudioContext::createPeriodicWave):
+        * Modules/webaudio/BaseAudioContext.idl:
+        * Modules/webaudio/PeriodicWave.cpp:
+        (WebCore::PeriodicWave::create):
+        (WebCore::PeriodicWave::createBandLimitedTables):
+        * Modules/webaudio/PeriodicWave.h:
+        * Modules/webaudio/PeriodicWave.idl:
+        * Modules/webaudio/PeriodicWaveConstraints.h: Added.
+        * Modules/webaudio/PeriodicWaveConstraints.idl: Added.
+        * Modules/webaudio/PeriodicWaveOptions.h: Added.
+        * Modules/webaudio/PeriodicWaveOptions.idl: Added.
+        * Modules/webaudio/WebKitAudioContext.cpp:
+        (WebCore::WebKitAudioContext::createPeriodicWave):
+        * Modules/webaudio/WebKitAudioContext.h:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2020-07-23  David Kilzer  <[email protected]>
 
         [IPC hardening] WebKit::ArgumentCoder<BlobPart>::decode() and encode() should use enum BlobPart::Type

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (264781 => 264782)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2020-07-23 19:22:39 UTC (rev 264782)
@@ -331,6 +331,8 @@
 $(PROJECT_DIR)/Modules/webaudio/PannerOptions.idl
 $(PROJECT_DIR)/Modules/webaudio/PanningModelType.idl
 $(PROJECT_DIR)/Modules/webaudio/PeriodicWave.idl
+$(PROJECT_DIR)/Modules/webaudio/PeriodicWaveConstraints.idl
+$(PROJECT_DIR)/Modules/webaudio/PeriodicWaveOptions.idl
 $(PROJECT_DIR)/Modules/webaudio/ScriptProcessorNode.idl
 $(PROJECT_DIR)/Modules/webaudio/WaveShaperNode.idl
 $(PROJECT_DIR)/Modules/webaudio/WebKitAudioContext.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (264781 => 264782)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2020-07-23 19:22:39 UTC (rev 264782)
@@ -1318,6 +1318,10 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPerformanceTiming.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWave.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWave.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWaveConstraints.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWaveConstraints.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWaveOptions.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPeriodicWaveOptions.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPictureInPictureWindow.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPictureInPictureWindow.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPlaybackDirection.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (264781 => 264782)


--- trunk/Source/WebCore/DerivedSources.make	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/DerivedSources.make	2020-07-23 19:22:39 UTC (rev 264782)
@@ -414,6 +414,8 @@
     $(WebCore)/Modules/webaudio/PannerOptions.idl \
     $(WebCore)/Modules/webaudio/PanningModelType.idl \
     $(WebCore)/Modules/webaudio/PeriodicWave.idl \
+    $(WebCore)/Modules/webaudio/PeriodicWaveConstraints.idl \
+    $(WebCore)/Modules/webaudio/PeriodicWaveOptions.idl \
     $(WebCore)/Modules/webaudio/ScriptProcessorNode.idl \
     $(WebCore)/Modules/webaudio/WaveShaperNode.idl \
     $(WebCore)/Modules/webaudio/WebKitAudioContext.idl \

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-07-23 19:22:39 UTC (rev 264782)
@@ -63,6 +63,7 @@
 #include "Page.h"
 #include "PannerNode.h"
 #include "PeriodicWave.h"
+#include "PeriodicWaveOptions.h"
 #include "PlatformMediaSessionManager.h"
 #include "ScriptController.h"
 #include "ScriptProcessorNode.h"
@@ -91,8 +92,6 @@
 #include <wtf/Scope.h>
 #include <wtf/text/WTFString.h>
 
-const unsigned MaxPeriodicWaveLength = 4096;
-
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(BaseAudioContext);
@@ -635,7 +634,7 @@
     return node;
 }
 
-ExceptionOr<Ref<PeriodicWave>> BaseAudioContext::createPeriodicWave(Float32Array& real, Float32Array& imaginary)
+ExceptionOr<Ref<PeriodicWave>> BaseAudioContext::createPeriodicWave(Vector<float>&& real, Vector<float>&& imaginary, const PeriodicWaveConstraints& constraints)
 {
     ALWAYS_LOG(LOGIDENTIFIER);
     
@@ -642,11 +641,16 @@
     ASSERT(isMainThread());
     if (m_isStopScheduled)
         return Exception { InvalidStateError };
-
-    if (real.length() != imaginary.length() || (real.length() > MaxPeriodicWaveLength) || !real.length())
-        return Exception { IndexSizeError };
+    
+    if (real.size() != imaginary.size())
+        return Exception { IndexSizeError, "real and imaginary must have the same length"_s };
+    
+    PeriodicWaveOptions options;
+    options.real = WTFMove(real);
+    options.imag = WTFMove(imaginary);
+    options.disableNormalization = constraints.disableNormalization;
     lazyInitialize();
-    return PeriodicWave::create(sampleRate(), real, imaginary);
+    return PeriodicWave::create(*this, WTFMove(options));
 }
 
 void BaseAudioContext::notifyNodeFinishedProcessing(AudioNode* node)

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-07-23 19:22:39 UTC (rev 264782)
@@ -34,6 +34,7 @@
 #include "EventTarget.h"
 #include "MediaCanStartListener.h"
 #include "MediaProducer.h"
+#include "PeriodicWaveConstraints.h"
 #include "PlatformMediaSession.h"
 #include "ScriptExecutionContext.h"
 #include "VisibilityChangeClient.h"
@@ -152,7 +153,7 @@
     ExceptionOr<Ref<ChannelSplitterNode>> createChannelSplitter(size_t numberOfOutputs);
     ExceptionOr<Ref<ChannelMergerNode>> createChannelMerger(size_t numberOfInputs);
     ExceptionOr<Ref<OscillatorNode>> createOscillator();
-    ExceptionOr<Ref<PeriodicWave>> createPeriodicWave(Float32Array& real, Float32Array& imaginary);
+    ExceptionOr<Ref<PeriodicWave>> createPeriodicWave(Vector<float>&& real, Vector<float>&& imaginary, const PeriodicWaveConstraints& = { });
 
     // When a source node has no more processing to do (has finished playing), then it tells the context to dereference it.
     void notifyNodeFinishedProcessing(AudioNode*);

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.idl (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.idl	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.idl	2020-07-23 19:22:39 UTC (rev 264782)
@@ -65,7 +65,7 @@
     [MayThrowException] AnalyserNode createAnalyser();
     [MayThrowException] ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
     [MayThrowException] OscillatorNode createOscillator();
-    [MayThrowException] PeriodicWave createPeriodicWave(Float32Array real, Float32Array imag);
+    [MayThrowException] PeriodicWave createPeriodicWave(sequence<float> real, sequence<float> imag, optional PeriodicWaveOptions options);
 
     // Channel splitting and merging
     [MayThrowException] ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);

Modified: trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWave.cpp	2020-07-23 19:22:39 UTC (rev 264782)
@@ -32,6 +32,7 @@
 
 #include "PeriodicWave.h"
 
+#include "BaseAudioContext.h"
 #include "FFTFrame.h"
 #include "VectorMath.h"
 #include <algorithm>
@@ -44,6 +45,7 @@
     
 using namespace VectorMath;
 
+// FIXME: Remove once old constructor is phased out
 Ref<PeriodicWave> PeriodicWave::create(float sampleRate, Float32Array& real, Float32Array& imaginary)
 {
     ASSERT(real.length() == imaginary.length());
@@ -53,6 +55,44 @@
     return waveTable;
 }
 
+ExceptionOr<Ref<PeriodicWave>> PeriodicWave::create(BaseAudioContext& context, PeriodicWaveOptions&& options)
+{
+    Vector<float> real;
+    Vector<float> imag;
+    
+    if (options.real && options.imag) {
+        if (options.real->size() != options.imag->size())
+            return Exception { IndexSizeError, "real and imag have different lengths"_s };
+        if (options.real->size() < 2)
+            return Exception { IndexSizeError, "real's length cannot be less than 2"_s };
+        if (options.imag->size() < 2)
+            return Exception { IndexSizeError, "imag's length cannot be less than 2"_s };
+        real = WTFMove(*options.real);
+        imag = WTFMove(*options.imag);
+    } else if (options.real) {
+        if (options.real->size() < 2)
+            return Exception { IndexSizeError, "real's length cannot be less than 2"_s };
+        real = WTFMove(*options.real);
+        imag.fill(0, real.size());
+    } else if (options.imag) {
+        if (options.imag->size() < 2)
+            return Exception { IndexSizeError, "imag's length cannot be less than 2"_s };
+        imag = WTFMove(*options.imag);
+        real.fill(0, imag.size());
+    } else {
+        real.fill(0, 2);
+        imag.fill(0, 2);
+        imag[1] = 1;
+    }
+
+    real[0] = 0;
+    imag[0] = 0;
+    
+    auto waveTable = adoptRef(*new PeriodicWave(context.sampleRate()));
+    waveTable->createBandLimitedTables(real.data(), imag.data(), real.size(), options.disableNormalization ? ShouldDisableNormalization::Yes : ShouldDisableNormalization::No);
+    return waveTable;
+}
+
 Ref<PeriodicWave> PeriodicWave::createSine(float sampleRate)
 {
     Ref<PeriodicWave> waveTable = adoptRef(*new PeriodicWave(sampleRate));
@@ -142,7 +182,7 @@
 // Convert into time-domain wave tables.
 // One table is created for each range for non-aliasing playback at different playback rates.
 // Thus, higher ranges have more high-frequency partials culled out.
-void PeriodicWave::createBandLimitedTables(const float* realData, const float* imagData, unsigned numberOfComponents)
+void PeriodicWave::createBandLimitedTables(const float* realData, const float* imagData, unsigned numberOfComponents, ShouldDisableNormalization disableNormalization)
 {
     float normalizationScale = 1;
 
@@ -199,12 +239,14 @@
         frame.doInverseFFT(data);
 
         // For the first range (which has the highest power), calculate its peak value then compute normalization scale.
-        if (!rangeIndex) {
-            float maxValue;
-            vmaxmgv(data, 1, &maxValue, m_periodicWaveSize);
+        if (disableNormalization == ShouldDisableNormalization::No) {
+            if (!rangeIndex) {
+                float maxValue;
+                vmaxmgv(data, 1, &maxValue, m_periodicWaveSize);
 
-            if (maxValue)
-                normalizationScale = 1.0f / maxValue;
+                if (maxValue)
+                    normalizationScale = 1.0f / maxValue;
+            }
         }
 
         // Apply normalization scale.

Modified: trunk/Source/WebCore/Modules/webaudio/PeriodicWave.h (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWave.h	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWave.h	2020-07-23 19:22:39 UTC (rev 264782)
@@ -29,6 +29,8 @@
 #pragma once
 
 #include "AudioArray.h"
+#include "ExceptionOr.h"
+#include "PeriodicWaveOptions.h"
 #include <_javascript_Core/Float32Array.h>
 #include <memory>
 #include <wtf/RefCounted.h>
@@ -36,6 +38,10 @@
 
 namespace WebCore {
 
+class BaseAudioContext;
+
+enum class ShouldDisableNormalization : bool { No, Yes };
+
 class PeriodicWave final : public RefCounted<PeriodicWave> {
 public:
     static Ref<PeriodicWave> createSine(float sampleRate);
@@ -44,7 +50,10 @@
     static Ref<PeriodicWave> createTriangle(float sampleRate);
 
     // Creates an arbitrary wave given the frequency components (Fourier coefficients).
+    // FIXME: Remove once old constructor is phased out
     static Ref<PeriodicWave> create(float sampleRate, Float32Array& real, Float32Array& imag);
+    
+    static ExceptionOr<Ref<PeriodicWave>> create(BaseAudioContext&, PeriodicWaveOptions&& = { });
 
     // Returns pointers to the lower and higher wave data for the pitch range containing
     // the given fundamental frequency. These two tables are in adjacent "pitch" ranges
@@ -92,7 +101,7 @@
     unsigned numberOfPartialsForRange(unsigned rangeIndex) const;
 
     // Creates tables based on numberOfComponents Fourier coefficients.
-    void createBandLimitedTables(const float* real, const float* imag, unsigned numberOfComponents);
+    void createBandLimitedTables(const float* real, const float* imag, unsigned numberOfComponents, ShouldDisableNormalization = ShouldDisableNormalization::No);
     Vector<std::unique_ptr<AudioFloatArray>> m_bandLimitedTables;
 };
 

Modified: trunk/Source/WebCore/Modules/webaudio/PeriodicWave.idl (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWave.idl	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWave.idl	2020-07-23 19:22:39 UTC (rev 264782)
@@ -27,5 +27,5 @@
     Conditional=WEB_AUDIO,
     ImplementationLacksVTable
 ] interface PeriodicWave {
-
+    [MayThrowException, EnabledBySetting=ModernUnprefixedWebAudio] constructor(BaseAudioContext context, optional PeriodicWaveOptions options);
 };

Added: trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.h (0 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.h	2020-07-23 19:22:39 UTC (rev 264782)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 Apple 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUDIO)
+
+namespace WebCore {
+
+struct PeriodicWaveConstraints {
+    bool disableNormalization = false;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)

Added: trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.idl (0 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWaveConstraints.idl	2020-07-23 19:22:39 UTC (rev 264782)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2020 Apple 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,
+] dictionary PeriodicWaveConstraints {
+    boolean disableNormalization = false;
+};

Added: trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.h (0 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.h	2020-07-23 19:22:39 UTC (rev 264782)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 Apple 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUDIO)
+
+#include "PeriodicWaveConstraints.h"
+#include <wtf/Optional.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+struct PeriodicWaveOptions : public PeriodicWaveConstraints {
+    Optional<Vector<float>> real;
+    Optional<Vector<float>> imag;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)

Added: trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.idl (0 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webaudio/PeriodicWaveOptions.idl	2020-07-23 19:22:39 UTC (rev 264782)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2020 Apple 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,
+] dictionary PeriodicWaveOptions : PeriodicWaveConstraints {
+    sequence<float> real;
+    sequence<float> imag;
+};

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.cpp	2020-07-23 19:22:39 UTC (rev 264782)
@@ -30,6 +30,7 @@
 #include "WebKitAudioContext.h"
 
 #include "JSDOMPromiseDeferred.h"
+#include "PeriodicWave.h"
 #include "WebKitAudioPannerNode.h"
 #include <wtf/IsoMallocInlines.h>
 
@@ -45,6 +46,8 @@
 #include "MediaElementAudioSourceNode.h"
 #endif
 
+const unsigned MaxPeriodicWaveLength = 4096;
+
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(WebKitAudioContext);
@@ -167,6 +170,20 @@
     return WebKitAudioPannerNode::create(*this, sampleRate());
 }
 
+ExceptionOr<Ref<PeriodicWave>> WebKitAudioContext::createPeriodicWave(Float32Array& real, Float32Array& imaginary)
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+    
+    ASSERT(isMainThread());
+    if (isStopped())
+        return Exception { InvalidStateError };
+
+    if (real.length() != imaginary.length() || real.length() > MaxPeriodicWaveLength || !real.length())
+        return Exception { IndexSizeError };
+    lazyInitialize();
+    return PeriodicWave::create(sampleRate(), real, imaginary);
+}
+
 void WebKitAudioContext::close(DOMPromiseDeferred<void>&& promise)
 {
     if (isOfflineContext() || isStopped()) {

Modified: trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h (264781 => 264782)


--- trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Modules/webaudio/WebKitAudioContext.h	2020-07-23 19:22:39 UTC (rev 264782)
@@ -36,6 +36,7 @@
 class MediaStream;
 class MediaStreamAudioDestinationNode;
 class MediaStreamAudioSourceNode;
+class PeriodicWave;
 class WebKitAudioPannerNode;
 
 // AudioContext is the cornerstone of the web audio API and all AudioNodes are created from it.
@@ -60,6 +61,7 @@
     ExceptionOr<Ref<MediaStreamAudioDestinationNode>> createMediaStreamDestination();
 #endif
     ExceptionOr<Ref<WebKitAudioPannerNode>> createWebKitPanner();
+    ExceptionOr<Ref<PeriodicWave>> createPeriodicWave(Float32Array& real, Float32Array& imaginary);
 
 protected:
     explicit WebKitAudioContext(Document&);

Modified: trunk/Source/WebCore/Sources.txt (264781 => 264782)


--- trunk/Source/WebCore/Sources.txt	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/Sources.txt	2020-07-23 19:22:39 UTC (rev 264782)
@@ -3171,6 +3171,8 @@
 JSPerformanceServerTiming.cpp
 JSPerformanceTiming.cpp
 JSPeriodicWave.cpp
+JSPeriodicWaveConstraints.cpp
+JSPeriodicWaveOptions.cpp
 JSPictureInPictureWindow.cpp
 JSPlaybackDirection.cpp
 JSPointerEvent.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (264781 => 264782)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-23 18:51:49 UTC (rev 264781)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-23 19:22:39 UTC (rev 264782)
@@ -5050,6 +5050,8 @@
 		E5BA7D63151437CA00FE1E3F /* LengthFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E5BA7D62151437CA00FE1E3F /* LengthFunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E71467B324ABAEF200FB2F50 /* AudioNodeOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = E71467B124ABAEF100FB2F50 /* AudioNodeOptions.h */; };
 		E71467B624ABAF1D00FB2F50 /* PannerOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = E71467B524ABAF1D00FB2F50 /* PannerOptions.h */; };
+		E755E89224C7434B009F7C23 /* PeriodicWaveConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = E755E88F24C7434B009F7C23 /* PeriodicWaveConstraints.h */; };
+		E755E89924C7461D009F7C23 /* PeriodicWaveOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = E755E89624C7461D009F7C23 /* PeriodicWaveOptions.h */; };
 		E785D91524B4D1CA0014DB21 /* ChannelCountMode.h in Headers */ = {isa = PBXBuildFile; fileRef = E785D91124B4D1B10014DB21 /* ChannelCountMode.h */; };
 		E785D93424B636FF0014DB21 /* ChannelInterpretation.h in Headers */ = {isa = PBXBuildFile; fileRef = E785D93124B636FF0014DB21 /* ChannelInterpretation.h */; };
 		E785D96124B7F7350014DB21 /* AudioContextOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = E785D95F24B7F7340014DB21 /* AudioContextOptions.h */; };
@@ -15821,6 +15823,10 @@
 		E71467B424ABAF0B00FB2F50 /* AudioNodeOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AudioNodeOptions.idl; sourceTree = "<group>"; };
 		E71467B524ABAF1D00FB2F50 /* PannerOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PannerOptions.h; sourceTree = "<group>"; };
 		E71467B724ABAF2C00FB2F50 /* PannerOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PannerOptions.idl; sourceTree = "<group>"; };
+		E755E88F24C7434B009F7C23 /* PeriodicWaveConstraints.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PeriodicWaveConstraints.h; sourceTree = "<group>"; };
+		E755E89124C7434B009F7C23 /* PeriodicWaveConstraints.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PeriodicWaveConstraints.idl; sourceTree = "<group>"; };
+		E755E89624C7461D009F7C23 /* PeriodicWaveOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PeriodicWaveOptions.h; sourceTree = "<group>"; };
+		E755E89824C7461D009F7C23 /* PeriodicWaveOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PeriodicWaveOptions.idl; sourceTree = "<group>"; };
 		E785D91124B4D1B10014DB21 /* ChannelCountMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChannelCountMode.h; sourceTree = "<group>"; };
 		E785D91324B4D1B10014DB21 /* ChannelCountMode.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ChannelCountMode.idl; sourceTree = "<group>"; };
 		E785D93124B636FF0014DB21 /* ChannelInterpretation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChannelInterpretation.h; sourceTree = "<group>"; };
@@ -29503,6 +29509,10 @@
 				FD581FB11520F93B003A7A75 /* PeriodicWave.cpp */,
 				FD581FB21520F93B003A7A75 /* PeriodicWave.h */,
 				FD581FB31520F93B003A7A75 /* PeriodicWave.idl */,
+				E755E88F24C7434B009F7C23 /* PeriodicWaveConstraints.h */,
+				E755E89124C7434B009F7C23 /* PeriodicWaveConstraints.idl */,
+				E755E89624C7461D009F7C23 /* PeriodicWaveOptions.h */,
+				E755E89824C7461D009F7C23 /* PeriodicWaveOptions.idl */,
 				FD315FF112B0267600C1A359 /* RealtimeAnalyser.cpp */,
 				FD315FF212B0267600C1A359 /* RealtimeAnalyser.h */,
 				FD315FEB12B0267600C1A359 /* ScriptProcessorNode.cpp */,
@@ -30072,7 +30082,6 @@
 				830030F81B7D3B7800ED3AAC /* CachedHTMLCollection.h in Headers */,
 				BCB16C1C0979C3BD00467741 /* CachedImage.h in Headers */,
 				319FBD5F15D2F464009640A6 /* CachedImageClient.h in Headers */,
-				CDAC068324C6A95A002F727F /* VP9UtilitiesCocoa.h in Headers */,
 				E307DED01D81E4C700141CAF /* CachedModuleScriptLoader.h in Headers */,
 				E307DED11D81E4CB00141CAF /* CachedModuleScriptLoaderClient.h in Headers */,
 				510184690B08602A004A825F /* CachedPage.h in Headers */,
@@ -31145,7 +31154,6 @@
 				519DBC6F1DC011A700329BF5 /* IDBGetAllRecordsData.h in Headers */,
 				519DBC721DC10F5200329BF5 /* IDBGetAllResult.h in Headers */,
 				5105F0691D4BA9D900FB80BC /* IDBGetRecordData.h in Headers */,
-				CD9CC58524C6BBEB00CD3C64 /* VP9Utilities.h in Headers */,
 				5185FC8F1BB4C4E80012898F /* IDBGetResult.h in Headers */,
 				5185FC911BB4C4E80012898F /* IDBIndex.h in Headers */,
 				51F798F01BE880E7008AE491 /* IDBIndexInfo.h in Headers */,
@@ -32680,6 +32688,8 @@
 				8AF4E55C11DC5A63000ED3DE /* PerformanceTiming.h in Headers */,
 				A554B5F31E38393A001D4E03 /* PerformanceUserTiming.h in Headers */,
 				FD581FB51520F93B003A7A75 /* PeriodicWave.h in Headers */,
+				E755E89224C7434B009F7C23 /* PeriodicWaveConstraints.h in Headers */,
+				E755E89924C7461D009F7C23 /* PeriodicWaveOptions.h in Headers */,
 				49D5DC2E0F423A73008F20FD /* PerspectiveTransformOperation.h in Headers */,
 				1DBC1B562347B3D200B901AF /* PictureInPictureObserver.h in Headers */,
 				1D2C82B7236A3F6A0055D6C5 /* PictureInPictureSupport.h in Headers */,
@@ -33826,6 +33836,8 @@
 				419BC2DF1685329900D64D6D /* VisitedLinkState.h in Headers */,
 				1ABA80001897341200DCE9D6 /* VisitedLinkStore.h in Headers */,
 				E44613B60CD6344E00FADA75 /* VoidCallback.h in Headers */,
+				CD9CC58524C6BBEB00CD3C64 /* VP9Utilities.h in Headers */,
+				CDAC068324C6A95A002F727F /* VP9UtilitiesCocoa.h in Headers */,
 				BE20507A18A4586B0080647E /* VTTCue.h in Headers */,
 				7AF9B20318CFB2DF00C64BEF /* VTTRegion.h in Headers */,
 				7AF9B20618CFB2DF00C64BEF /* VTTRegionList.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to