⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267361 in webkit


Ignore:
Timestamp:
Sep 21, 2020, 1:22:27 PM (6 years ago)
Author:
Chris Dumez
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:

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:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267357 r267361  
     12020-09-21  Chris Dumez  <cdumez@apple.com>
     2
     3        Remove emphasis/de-emphasis filters from DynamicsCompressor
     4        https://bugs.webkit.org/show_bug.cgi?id=216796
     5
     6        Reviewed by Darin Adler.
     7
     8        Rebaseline tests that are now passing.
     9
     10        * webaudio/AudioParam/audioparam-processing-expected.txt:
     11        * webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt:
     12        * webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt:
     13
    1142020-09-21  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/LayoutTests/webaudio/AudioParam/audioparam-processing-expected.txt

    r267253 r267361  
    2525PASS > [DynamicsCompressorNode] 
    2626PASS   DynamicsCompressorNode.attack ramp final value is not equal to 0.003000000026077032.
    27 FAIL X DynamicsCompressorNode.attack.value is not equal to 0.5. Got 0.003000000026077032. assert_true: expected true got false
     27PASS   DynamicsCompressorNode.attack.value is equal to 0.5.
    2828PASS   DynamicsCompressorNode.knee ramp final value is not equal to 30.
    29 FAIL X DynamicsCompressorNode.knee.value is not equal to 25. Got 30. assert_true: expected true got false
     29PASS   DynamicsCompressorNode.knee.value is equal to 25.
    3030PASS   DynamicsCompressorNode.ratio ramp final value is not equal to 12.
    31 FAIL X DynamicsCompressorNode.ratio.value is not equal to 15. Got 12. assert_true: expected true got false
     31PASS   DynamicsCompressorNode.ratio.value is equal to 15.
    3232PASS   DynamicsCompressorNode.release ramp final value is not equal to 0.25.
    33 FAIL X DynamicsCompressorNode.release.value is not equal to 0.75. Got 0.25. assert_true: expected true got false
     33PASS   DynamicsCompressorNode.release.value is equal to 0.75.
    3434PASS   DynamicsCompressorNode.threshold ramp final value is not equal to -24.
    35 FAIL X DynamicsCompressorNode.threshold.value is not equal to -10. Got -24. assert_true: expected true got false
    36 FAIL < [DynamicsCompressorNode] 5 out of 10 assertions were failed. assert_true: expected true got false
     35PASS   DynamicsCompressorNode.threshold.value is equal to -10.
     36PASS < [DynamicsCompressorNode] All assertions passed. (total 10 assertions)
    3737PASS > [GainNode] 
    3838PASS   GainNode.gain ramp final value is not equal to 1.
     
    7777FAIL X AudioListener.upZ.value is not equal to 137. Got 0. assert_true: expected true got false
    7878FAIL < [AudioListener] 9 out of 18 assertions were failed. assert_true: expected true got false
    79 FAIL # AUDIT TASK RUNNER FINISHED: 7 out of 7 tasks were failed. assert_true: expected true got false
     79FAIL # AUDIT TASK RUNNER FINISHED: 6 out of 7 tasks were failed. assert_true: expected true got false
    8080
  • trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-clear-internal-state-expected.txt

    r267307 r267361  
    44PASS Audit report
    55PASS > [test] Validate Reduction Value of DynamicsCompressor after Disabling
    6 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
    7 FAIL < [test] 1 out of 1 assertions were failed. assert_true: expected true got false
    8 FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
     6PASS   Math.abs(compressor.reduction) (0.048222921788692474) is less than or equal to 0.048223.
     7PASS < [test] All assertions passed. (total 1 assertions)
     8PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully.
    99
  • trunk/LayoutTests/webaudio/DynamicsCompressor/dynamicscompressor-simple-expected.txt

    r267307 r267361  
    44PASS Audit report
    55PASS > [test] Test pre-emphasis in DynamicsCompressor is removed
    6 FAIL X Pre-emphasis effect not applied is not true. Got false. assert_true: expected true got false
     6PASS   Pre-emphasis effect not applied is true.
    77PASS   Reduction value changed is true.
    8 FAIL < [test] 1 out of 2 assertions were failed. assert_true: expected true got false
    9 FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
     8PASS < [test] All assertions passed. (total 2 assertions)
     9PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully.
    1010
  • trunk/Source/WebCore/ChangeLog

    r267357 r267361  
     12020-09-21  Chris Dumez  <cdumez@apple.com>
     2
     3        Remove emphasis/de-emphasis filters from DynamicsCompressor
     4        https://bugs.webkit.org/show_bug.cgi?id=216796
     5
     6        Reviewed by Darin Adler.
     7
     8        Remove emphasis/de-emphasis filters from DynamicsCompressor as these have been removed
     9        from the specification.
     10
     11        This is a merge of the following Blink change:
     12        - https://codereview.chromium.org/152333003
     13
     14        No new tests, rebaselined existing tests.
     15
     16        * platform/audio/DynamicsCompressor.cpp:
     17        (WebCore::DynamicsCompressor::DynamicsCompressor):
     18        (WebCore::DynamicsCompressor::process):
     19        (WebCore::DynamicsCompressor::reset):
     20        (WebCore::DynamicsCompressor::setNumberOfChannels):
     21        * platform/audio/DynamicsCompressor.h:
     22        * platform/audio/DynamicsCompressorKernel.cpp:
     23        (WebCore::DynamicsCompressorKernel::process):
     24        (WebCore::DynamicsCompressorKernel::tailTime const):
     25        * platform/audio/DynamicsCompressorKernel.h:
     26
    1272020-09-21  Chris Dumez  <cdumez@apple.com>
    228
  • trunk/Source/WebCore/platform/audio/DynamicsCompressor.cpp

    r248846 r267361  
    4747    , m_compressor(sampleRate, numberOfChannels)
    4848{
    49     // Uninitialized state - for parameter recalculation.
    50     m_lastFilterStageRatio = -1;
    51     m_lastAnchor = -1;
    52     m_lastFilterStageGain = -1;
    53 
    5449    setNumberOfChannels(numberOfChannels);
    5550    initializeParameters();
     
    7974    m_parameters[ParamReleaseZone3] = 0.42f;
    8075    m_parameters[ParamReleaseZone4] = 0.98f;
    81 
    82     m_parameters[ParamFilterStageGain] = 4.4f; // dB
    83     m_parameters[ParamFilterStageRatio] = 2;
    84     m_parameters[ParamFilterAnchor] = 15000 / nyquist();
    8576   
    8677    m_parameters[ParamPostGain] = 0; // dB
     
    9586    ASSERT(parameterID < ParamLast);
    9687    return m_parameters[parameterID];
    97 }
    98 
    99 void DynamicsCompressor::setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */)
    100 {
    101     float gk = 1 - gain / 20;
    102     float f1 = normalizedFrequency * gk;
    103     float f2 = normalizedFrequency / gk;
    104     float r1 = expf(-f1 * piFloat);
    105     float r2 = expf(-f2 * piFloat);
    106 
    107     ASSERT(m_numberOfChannels == m_preFilterPacks.size());
    108 
    109     for (unsigned i = 0; i < m_numberOfChannels; ++i) {
    110         // Set pre-filter zero and pole to create an emphasis filter.
    111         ZeroPole& preFilter = m_preFilterPacks[i]->filters[stageIndex];
    112         preFilter.setZero(r1);
    113         preFilter.setPole(r2);
    114 
    115         // Set post-filter with zero and pole reversed to create the de-emphasis filter.
    116         // If there were no compressor kernel in between, they would cancel each other out (allpass filter).
    117         ZeroPole& postFilter = m_postFilterPacks[i]->filters[stageIndex];
    118         postFilter.setZero(r2);
    119         postFilter.setPole(r1);
    120     }
    121 }
    122 
    123 void DynamicsCompressor::setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio)
    124 {
    125     setEmphasisStageParameters(0, gain, anchorFreq);
    126     setEmphasisStageParameters(1, gain, anchorFreq / filterStageRatio);
    127     setEmphasisStageParameters(2, gain, anchorFreq / (filterStageRatio * filterStageRatio));
    128     setEmphasisStageParameters(3, gain, anchorFreq / (filterStageRatio * filterStageRatio * filterStageRatio));
    12988}
    13089
     
    166125        m_destinationChannels[i] = destinationBus->channel(i)->mutableData();
    167126
    168     float filterStageGain = parameterValue(ParamFilterStageGain);
    169     float filterStageRatio = parameterValue(ParamFilterStageRatio);
    170     float anchor = parameterValue(ParamFilterAnchor);
    171 
    172     if (filterStageGain != m_lastFilterStageGain || filterStageRatio != m_lastFilterStageRatio || anchor != m_lastAnchor) {
    173         m_lastFilterStageGain = filterStageGain;
    174         m_lastFilterStageRatio = filterStageRatio;
    175         m_lastAnchor = anchor;
    176 
    177         setEmphasisParameters(filterStageGain, anchor, filterStageRatio);
    178     }
    179 
    180     // Apply pre-emphasis filter.
    181     // Note that the final three stages are computed in-place in the destination buffer.
    182     for (unsigned i = 0; i < numberOfChannels; ++i) {
    183         const float* sourceData = m_sourceChannels[i];
    184         float* destinationData = m_destinationChannels[i];
    185         ZeroPole* preFilters = m_preFilterPacks[i]->filters;
    186 
    187         preFilters[0].process(sourceData, destinationData, framesToProcess);
    188         preFilters[1].process(destinationData, destinationData, framesToProcess);
    189         preFilters[2].process(destinationData, destinationData, framesToProcess);
    190         preFilters[3].process(destinationData, destinationData, framesToProcess);
    191     }
    192 
    193127    float dbThreshold = parameterValue(ParamThreshold);
    194128    float dbKnee = parameterValue(ParamKnee);
     
    211145    float releaseZone4 = parameterValue(ParamReleaseZone4);
    212146
    213     // Apply compression to the pre-filtered signal.
    214     // The processing is performed in place.
    215     m_compressor.process(m_destinationChannels.get(),
     147    // Apply compression to the source signal.
     148    m_compressor.process(m_sourceChannels.get(),
    216149                         m_destinationChannels.get(),
    217150                         numberOfChannels,
     
    235168    // Update the compression amount.                     
    236169    setParameterValue(ParamReduction, m_compressor.meteringGain());
    237 
    238     // Apply de-emphasis filter.
    239     for (unsigned i = 0; i < numberOfChannels; ++i) {
    240         float* destinationData = m_destinationChannels[i];
    241         ZeroPole* postFilters = m_postFilterPacks[i]->filters;
    242 
    243         postFilters[0].process(destinationData, destinationData, framesToProcess);
    244         postFilters[1].process(destinationData, destinationData, framesToProcess);
    245         postFilters[2].process(destinationData, destinationData, framesToProcess);
    246         postFilters[3].process(destinationData, destinationData, framesToProcess);
    247     }
    248170}
    249171
    250172void DynamicsCompressor::reset()
    251173{
    252     m_lastFilterStageRatio = -1; // for recalc
    253     m_lastAnchor = -1;
    254     m_lastFilterStageGain = -1;
    255 
    256     for (unsigned channel = 0; channel < m_numberOfChannels; ++channel) {
    257         for (unsigned stageIndex = 0; stageIndex < 4; ++stageIndex) {
    258             m_preFilterPacks[channel]->filters[stageIndex].reset();
    259             m_postFilterPacks[channel]->filters[stageIndex].reset();
    260         }
    261     }
    262 
    263174    m_compressor.reset();
    264175}
     
    266177void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels)
    267178{
    268     if (m_preFilterPacks.size() == numberOfChannels)
    269         return;
    270 
    271     m_preFilterPacks.clear();
    272     m_postFilterPacks.clear();
    273     for (unsigned i = 0; i < numberOfChannels; ++i) {
    274         m_preFilterPacks.append(makeUnique<ZeroPoleFilterPack4>());
    275         m_postFilterPacks.append(makeUnique<ZeroPoleFilterPack4>());
    276     }
    277 
    278179    m_sourceChannels = makeUniqueArray<const float*>(numberOfChannels);
    279180    m_destinationChannels = makeUniqueArray<float*>(numberOfChannels);
  • trunk/Source/WebCore/platform/audio/DynamicsCompressor.h

    r266417 r267361  
    6060        ParamReleaseZone4,
    6161        ParamPostGain,
    62         ParamFilterStageGain,
    63         ParamFilterStageRatio,
    64         ParamFilterAnchor,
    6562        ParamEffectBlend,
    6663        ParamReduction,
     
    8077    float nyquist() const { return m_sampleRate / 2; }
    8178
    82     double tailTime() const { return 0; }
     79    double tailTime() const { return m_compressor.tailTime(); }
    8380    double latencyTime() const { return m_compressor.latencyFrames() / static_cast<double>(sampleRate()); }
    8481    bool requiresTailProcessing() const
     
    9794    float m_sampleRate;
    9895
    99     // Emphasis filter controls.
    100     float m_lastFilterStageRatio;
    101     float m_lastAnchor;
    102     float m_lastFilterStageGain;
    103 
    104     struct ZeroPoleFilterPack4 {
    105         WTF_MAKE_STRUCT_FAST_ALLOCATED;
    106         ZeroPole filters[4];
    107     };
    108 
    109     // Per-channel emphasis filters.
    110     Vector<std::unique_ptr<ZeroPoleFilterPack4>> m_preFilterPacks;
    111     Vector<std::unique_ptr<ZeroPoleFilterPack4>> m_postFilterPacks;
    112 
    11396    UniqueArray<const float*> m_sourceChannels;
    11497    UniqueArray<float*> m_destinationChannels;
    115 
    116     void setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */);
    117     void setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio);
    11898
    11999    // The core compressor.
  • trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.cpp

    r248846 r267361  
    200200}
    201201
    202 void DynamicsCompressorKernel::process(float* sourceChannels[],
     202void DynamicsCompressorKernel::process(const float* sourceChannels[],
    203203                                       float* destinationChannels[],
    204204                                       unsigned numberOfChannels,
     
    473473}
    474474
     475double DynamicsCompressorKernel::tailTime() const
     476{
     477    // The reduction value of the compressor is computed from the gain using an exponential filter
     478    // with a time constant of |meteringReleaseTimeConstant|. We need to keep he compressor running
     479    // for some time after the inputs go away so that the reduction value approaches 0. This is a
     480    // tradeoff between how long we keep the node alive and how close we approach the final value.
     481    // A value of 5 to 10 times the time constant is a reasonable trade-off.
     482    return 5 * meteringReleaseTimeConstant;
     483}
     484
    475485} // namespace WebCore
    476486
  • trunk/Source/WebCore/platform/audio/DynamicsCompressorKernel.h

    r248762 r267361  
    4444
    4545    // Performs stereo-linked compression.
    46     void process(float* sourceChannels[],
     46    void process(const float* sourceChannels[],
    4747                 float* destinationChannels[],
    4848                 unsigned numberOfChannels,
     
    7171
    7272    float meteringGain() const { return m_meteringGain; }
     73
     74    double tailTime() const;
    7375
    7476protected:
Note: See TracChangeset for help on using the changeset viewer.