Title: [267361] trunk
Revision
267361
Author
[email protected]
Date
2020-09-21 13:22:27 -0700 (Mon, 21 Sep 2020)

Log Message

Remove emphasis/de-emphasis filters from DynamicsCompressor
https://bugs.webkit.org/show_bug.cgi?id=216796

Reviewed by Darin Adler.

Source/WebCore:

Remove emphasis/de-emphasis filters from DynamicsCompressor as these have been removed
from the specification.

This is a merge of the following Blink change:
- https://codereview.chromium.org/152333003

No new tests, rebaselined existing tests.

* platform/audio/DynamicsCompressor.cpp:
(WebCore::DynamicsCompressor::DynamicsCompressor):
(WebCore::DynamicsCompressor::process):
(WebCore::DynamicsCompressor::reset):
(WebCore::DynamicsCompressor::setNumberOfChannels):
* platform/audio/DynamicsCompressor.h:
* platform/audio/DynamicsCompressorKernel.cpp:
(WebCore::DynamicsCompressorKernel::process):
(WebCore::DynamicsCompressorKernel::tailTime const):
* platform/audio/DynamicsCompressorKernel.h:

LayoutTests:

Rebaseline tests that are now passing.

* webaudio/AudioParam/audioparam-processing-expected.txt:
* webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt:
* webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267360 => 267361)


--- trunk/LayoutTests/ChangeLog	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/LayoutTests/ChangeLog	2020-09-21 20:22:27 UTC (rev 267361)
@@ -1,5 +1,18 @@
 2020-09-21  Chris Dumez  <[email protected]>
 
+        Remove emphasis/de-emphasis filters from DynamicsCompressor
+        https://bugs.webkit.org/show_bug.cgi?id=216796
+
+        Reviewed by Darin Adler.
+
+        Rebaseline tests that are now passing.
+
+        * webaudio/AudioParam/audioparam-processing-expected.txt:
+        * webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt:
+        * webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt:
+
+2020-09-21  Chris Dumez  <[email protected]>
+
         Vectorize linearRampToValueAtTime processing in AudioParamTimeline
         https://bugs.webkit.org/show_bug.cgi?id=216788
 

Modified: trunk/LayoutTests/webaudio/AudioParam/audioparam-processing-expected.txt (267360 => 267361)


--- trunk/LayoutTests/webaudio/AudioParam/audioparam-processing-expected.txt	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/LayoutTests/webaudio/AudioParam/audioparam-processing-expected.txt	2020-09-21 20:22:27 UTC (rev 267361)
@@ -24,16 +24,16 @@
 FAIL < [DelayNode] 1 out of 2 assertions were failed. assert_true: expected true got false
 PASS > [DynamicsCompressorNode]  
 PASS   DynamicsCompressorNode.attack ramp final value is not equal to 0.003000000026077032. 
-FAIL X DynamicsCompressorNode.attack.value is not equal to 0.5. Got 0.003000000026077032. assert_true: expected true got false
+PASS   DynamicsCompressorNode.attack.value is equal to 0.5. 
 PASS   DynamicsCompressorNode.knee ramp final value is not equal to 30. 
-FAIL X DynamicsCompressorNode.knee.value is not equal to 25. Got 30. assert_true: expected true got false
+PASS   DynamicsCompressorNode.knee.value is equal to 25. 
 PASS   DynamicsCompressorNode.ratio ramp final value is not equal to 12. 
-FAIL X DynamicsCompressorNode.ratio.value is not equal to 15. Got 12. assert_true: expected true got false
+PASS   DynamicsCompressorNode.ratio.value is equal to 15. 
 PASS   DynamicsCompressorNode.release ramp final value is not equal to 0.25. 
-FAIL X DynamicsCompressorNode.release.value is not equal to 0.75. Got 0.25. assert_true: expected true got false
+PASS   DynamicsCompressorNode.release.value is equal to 0.75. 
 PASS   DynamicsCompressorNode.threshold ramp final value is not equal to -24. 
-FAIL X DynamicsCompressorNode.threshold.value is not equal to -10. Got -24. assert_true: expected true got false
-FAIL < [DynamicsCompressorNode] 5 out of 10 assertions were failed. assert_true: expected true got false
+PASS   DynamicsCompressorNode.threshold.value is equal to -10. 
+PASS < [DynamicsCompressorNode] All assertions passed. (total 10 assertions) 
 PASS > [GainNode]  
 PASS   GainNode.gain ramp final value is not equal to 1. 
 FAIL X GainNode.gain.value is not equal to 0.5. Got 1. assert_true: expected true got false
@@ -76,5 +76,5 @@
 PASS   AudioListener.upZ ramp final value is not equal to 0. 
 FAIL X AudioListener.upZ.value is not equal to 137. Got 0. assert_true: expected true got false
 FAIL < [AudioListener] 9 out of 18 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 7 out of 7 tasks were failed. assert_true: expected true got false
+FAIL # AUDIT TASK RUNNER FINISHED: 6 out of 7 tasks were failed. assert_true: expected true got false
 

Modified: trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt (267360 => 267361)


--- trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt	2020-09-21 20:22:27 UTC (rev 267361)
@@ -3,7 +3,7 @@
 PASS Executing "test" 
 PASS Audit report 
 PASS > [test] Validate Reduction Value of DynamicsCompressor after Disabling 
-FAIL X Math.abs(compressor.reduction) (6.09318733215332) is not less than or equal to 0.048223. Got 6.09318733215332. assert_true: expected true got false
-FAIL < [test] 1 out of 1 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
+PASS   Math.abs(compressor.reduction) (0.048222921788692474) is less than or equal to 0.048223. 
+PASS < [test] All assertions passed. (total 1 assertions) 
+PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully. 
 

Modified: trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt (267360 => 267361)


--- trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt	2020-09-21 20:22:27 UTC (rev 267361)
@@ -3,8 +3,8 @@
 PASS Executing "test" 
 PASS Audit report 
 PASS > [test] Test pre-emphasis in DynamicsCompressor is removed 
-FAIL X Pre-emphasis effect not applied is not true. Got false. assert_true: expected true got false
+PASS   Pre-emphasis effect not applied is true. 
 PASS   Reduction value changed is true. 
-FAIL < [test] 1 out of 2 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
+PASS < [test] All assertions passed. (total 2 assertions) 
+PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully. 
 

Modified: trunk/Source/WebCore/ChangeLog (267360 => 267361)


--- trunk/Source/WebCore/ChangeLog	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/Source/WebCore/ChangeLog	2020-09-21 20:22:27 UTC (rev 267361)
@@ -1,5 +1,31 @@
 2020-09-21  Chris Dumez  <[email protected]>
 
+        Remove emphasis/de-emphasis filters from DynamicsCompressor
+        https://bugs.webkit.org/show_bug.cgi?id=216796
+
+        Reviewed by Darin Adler.
+
+        Remove emphasis/de-emphasis filters from DynamicsCompressor as these have been removed
+        from the specification.
+
+        This is a merge of the following Blink change:
+        - https://codereview.chromium.org/152333003 
+
+        No new tests, rebaselined existing tests.
+
+        * platform/audio/DynamicsCompressor.cpp:
+        (WebCore::DynamicsCompressor::DynamicsCompressor):
+        (WebCore::DynamicsCompressor::process):
+        (WebCore::DynamicsCompressor::reset):
+        (WebCore::DynamicsCompressor::setNumberOfChannels):
+        * platform/audio/DynamicsCompressor.h:
+        * platform/audio/DynamicsCompressorKernel.cpp:
+        (WebCore::DynamicsCompressorKernel::process):
+        (WebCore::DynamicsCompressorKernel::tailTime const):
+        * platform/audio/DynamicsCompressorKernel.h:
+
+2020-09-21  Chris Dumez  <[email protected]>
+
         Vectorize linearRampToValueAtTime processing in AudioParamTimeline
         https://bugs.webkit.org/show_bug.cgi?id=216788
 

Modified: trunk/Source/WebCore/platform/audio/DynamicsCompressor.cpp (267360 => 267361)


--- trunk/Source/WebCore/platform/audio/DynamicsCompressor.cpp	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/Source/WebCore/platform/audio/DynamicsCompressor.cpp	2020-09-21 20:22:27 UTC (rev 267361)
@@ -46,11 +46,6 @@
     , m_sampleRate(sampleRate)
     , m_compressor(sampleRate, numberOfChannels)
 {
-    // Uninitialized state - for parameter recalculation.
-    m_lastFilterStageRatio = -1;
-    m_lastAnchor = -1;
-    m_lastFilterStageGain = -1;
-
     setNumberOfChannels(numberOfChannels);
     initializeParameters();
 }
@@ -78,10 +73,6 @@
     m_parameters[ParamReleaseZone2] = 0.16f;
     m_parameters[ParamReleaseZone3] = 0.42f;
     m_parameters[ParamReleaseZone4] = 0.98f;
-
-    m_parameters[ParamFilterStageGain] = 4.4f; // dB
-    m_parameters[ParamFilterStageRatio] = 2;
-    m_parameters[ParamFilterAnchor] = 15000 / nyquist();
     
     m_parameters[ParamPostGain] = 0; // dB
     m_parameters[ParamReduction] = 0; // dB
@@ -96,38 +87,6 @@
     return m_parameters[parameterID];
 }
 
-void DynamicsCompressor::setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */)
-{
-    float gk = 1 - gain / 20;
-    float f1 = normalizedFrequency * gk;
-    float f2 = normalizedFrequency / gk;
-    float r1 = expf(-f1 * piFloat);
-    float r2 = expf(-f2 * piFloat);
-
-    ASSERT(m_numberOfChannels == m_preFilterPacks.size());
-
-    for (unsigned i = 0; i < m_numberOfChannels; ++i) {
-        // Set pre-filter zero and pole to create an emphasis filter.
-        ZeroPole& preFilter = m_preFilterPacks[i]->filters[stageIndex];
-        preFilter.setZero(r1);
-        preFilter.setPole(r2);
-
-        // Set post-filter with zero and pole reversed to create the de-emphasis filter.
-        // If there were no compressor kernel in between, they would cancel each other out (allpass filter).
-        ZeroPole& postFilter = m_postFilterPacks[i]->filters[stageIndex];
-        postFilter.setZero(r2);
-        postFilter.setPole(r1);
-    }
-}
-
-void DynamicsCompressor::setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio)
-{
-    setEmphasisStageParameters(0, gain, anchorFreq);
-    setEmphasisStageParameters(1, gain, anchorFreq / filterStageRatio);
-    setEmphasisStageParameters(2, gain, anchorFreq / (filterStageRatio * filterStageRatio));
-    setEmphasisStageParameters(3, gain, anchorFreq / (filterStageRatio * filterStageRatio * filterStageRatio));
-}
-
 void DynamicsCompressor::process(const AudioBus* sourceBus, AudioBus* destinationBus, unsigned framesToProcess)
 {
     // Though numberOfChannels is retrived from destinationBus, we still name it numberOfChannels instead of numberOfDestinationChannels.
@@ -165,31 +124,6 @@
     for (unsigned i = 0; i < numberOfChannels; ++i)
         m_destinationChannels[i] = destinationBus->channel(i)->mutableData();
 
-    float filterStageGain = parameterValue(ParamFilterStageGain);
-    float filterStageRatio = parameterValue(ParamFilterStageRatio);
-    float anchor = parameterValue(ParamFilterAnchor);
-
-    if (filterStageGain != m_lastFilterStageGain || filterStageRatio != m_lastFilterStageRatio || anchor != m_lastAnchor) {
-        m_lastFilterStageGain = filterStageGain;
-        m_lastFilterStageRatio = filterStageRatio;
-        m_lastAnchor = anchor;
-
-        setEmphasisParameters(filterStageGain, anchor, filterStageRatio);
-    }
-
-    // Apply pre-emphasis filter.
-    // Note that the final three stages are computed in-place in the destination buffer.
-    for (unsigned i = 0; i < numberOfChannels; ++i) {
-        const float* sourceData = m_sourceChannels[i];
-        float* destinationData = m_destinationChannels[i];
-        ZeroPole* preFilters = m_preFilterPacks[i]->filters;
-
-        preFilters[0].process(sourceData, destinationData, framesToProcess);
-        preFilters[1].process(destinationData, destinationData, framesToProcess);
-        preFilters[2].process(destinationData, destinationData, framesToProcess);
-        preFilters[3].process(destinationData, destinationData, framesToProcess);
-    }
-
     float dbThreshold = parameterValue(ParamThreshold);
     float dbKnee = parameterValue(ParamKnee);
     float ratio = parameterValue(ParamRatio);
@@ -210,9 +144,8 @@
     float releaseZone3 = parameterValue(ParamReleaseZone3);
     float releaseZone4 = parameterValue(ParamReleaseZone4);
 
-    // Apply compression to the pre-filtered signal.
-    // The processing is performed in place.
-    m_compressor.process(m_destinationChannels.get(),
+    // Apply compression to the source signal.
+    m_compressor.process(m_sourceChannels.get(),
                          m_destinationChannels.get(),
                          numberOfChannels,
                          framesToProcess,
@@ -234,47 +167,15 @@
                          
     // Update the compression amount.                     
     setParameterValue(ParamReduction, m_compressor.meteringGain());
-
-    // Apply de-emphasis filter.
-    for (unsigned i = 0; i < numberOfChannels; ++i) {
-        float* destinationData = m_destinationChannels[i];
-        ZeroPole* postFilters = m_postFilterPacks[i]->filters;
-
-        postFilters[0].process(destinationData, destinationData, framesToProcess);
-        postFilters[1].process(destinationData, destinationData, framesToProcess);
-        postFilters[2].process(destinationData, destinationData, framesToProcess);
-        postFilters[3].process(destinationData, destinationData, framesToProcess);
-    }
 }
 
 void DynamicsCompressor::reset()
 {
-    m_lastFilterStageRatio = -1; // for recalc
-    m_lastAnchor = -1;
-    m_lastFilterStageGain = -1;
-
-    for (unsigned channel = 0; channel < m_numberOfChannels; ++channel) {
-        for (unsigned stageIndex = 0; stageIndex < 4; ++stageIndex) {
-            m_preFilterPacks[channel]->filters[stageIndex].reset();
-            m_postFilterPacks[channel]->filters[stageIndex].reset();
-        }
-    }
-
     m_compressor.reset();
 }
 
 void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels)
 {
-    if (m_preFilterPacks.size() == numberOfChannels)
-        return;
-
-    m_preFilterPacks.clear();
-    m_postFilterPacks.clear();
-    for (unsigned i = 0; i < numberOfChannels; ++i) {
-        m_preFilterPacks.append(makeUnique<ZeroPoleFilterPack4>());
-        m_postFilterPacks.append(makeUnique<ZeroPoleFilterPack4>());
-    }
-
     m_sourceChannels = makeUniqueArray<const float*>(numberOfChannels);
     m_destinationChannels = makeUniqueArray<float*>(numberOfChannels);
 

Modified: trunk/Source/WebCore/platform/audio/DynamicsCompressor.h (267360 => 267361)


--- trunk/Source/WebCore/platform/audio/DynamicsCompressor.h	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/Source/WebCore/platform/audio/DynamicsCompressor.h	2020-09-21 20:22:27 UTC (rev 267361)
@@ -59,9 +59,6 @@
         ParamReleaseZone3,
         ParamReleaseZone4,
         ParamPostGain,
-        ParamFilterStageGain,
-        ParamFilterStageRatio,
-        ParamFilterAnchor,
         ParamEffectBlend,
         ParamReduction,
         ParamLast
@@ -79,7 +76,7 @@
     float sampleRate() const { return m_sampleRate; }
     float nyquist() const { return m_sampleRate / 2; }
 
-    double tailTime() const { return 0; }
+    double tailTime() const { return m_compressor.tailTime(); }
     double latencyTime() const { return m_compressor.latencyFrames() / static_cast<double>(sampleRate()); }
     bool requiresTailProcessing() const
     {
@@ -96,26 +93,9 @@
 
     float m_sampleRate;
 
-    // Emphasis filter controls.
-    float m_lastFilterStageRatio;
-    float m_lastAnchor;
-    float m_lastFilterStageGain;
-
-    struct ZeroPoleFilterPack4 {
-        WTF_MAKE_STRUCT_FAST_ALLOCATED;
-        ZeroPole filters[4];
-    };
-
-    // Per-channel emphasis filters.
-    Vector<std::unique_ptr<ZeroPoleFilterPack4>> m_preFilterPacks;
-    Vector<std::unique_ptr<ZeroPoleFilterPack4>> m_postFilterPacks;
-
     UniqueArray<const float*> m_sourceChannels;
     UniqueArray<float*> m_destinationChannels;
 
-    void setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */);
-    void setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio);
-
     // The core compressor.
     DynamicsCompressorKernel m_compressor;
 };

Modified: trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.cpp (267360 => 267361)


--- trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.cpp	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.cpp	2020-09-21 20:22:27 UTC (rev 267361)
@@ -199,7 +199,7 @@
     return m_K;
 }
 
-void DynamicsCompressorKernel::process(float* sourceChannels[],
+void DynamicsCompressorKernel::process(const float* sourceChannels[],
                                        float* destinationChannels[],
                                        unsigned numberOfChannels,
                                        unsigned framesToProcess,
@@ -472,6 +472,16 @@
     m_maxAttackCompressionDiffDb = -1; // uninitialized state
 }
 
+double DynamicsCompressorKernel::tailTime() const
+{
+    // The reduction value of the compressor is computed from the gain using an exponential filter
+    // with a time constant of |meteringReleaseTimeConstant|. We need to keep he compressor running
+    // for some time after the inputs go away so that the reduction value approaches 0. This is a
+    // tradeoff between how long we keep the node alive and how close we approach the final value.
+    // A value of 5 to 10 times the time constant is a reasonable trade-off.
+    return 5 * meteringReleaseTimeConstant;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.h (267360 => 267361)


--- trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.h	2020-09-21 20:08:53 UTC (rev 267360)
+++ trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.h	2020-09-21 20:22:27 UTC (rev 267361)
@@ -43,7 +43,7 @@
     void setNumberOfChannels(unsigned);
 
     // Performs stereo-linked compression.
-    void process(float* sourceChannels[],
+    void process(const float* sourceChannels[],
                  float* destinationChannels[],
                  unsigned numberOfChannels,
                  unsigned framesToProcess,
@@ -71,6 +71,8 @@
 
     float meteringGain() const { return m_meteringGain; }
 
+    double tailTime() const;
+
 protected:
     float m_sampleRate;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to