<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[270155] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/270155">270155</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2020-11-21 19:03:46 -0800 (Sat, 21 Nov 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>Unreviewed, reverting <a href="http://trac.webkit.org/projects/webkit/changeset/270141">r270141</a>.

Caused assertions on bots

Reverted changeset:

"Poor resampling quality when using AudioContext sampleRate
parameter"
https://bugs.webkit.org/show_bug.cgi?id=219201
https://trac.webkit.org/changeset/270141</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMultiChannelResamplercpp">trunk/Source/WebCore/platform/audio/MultiChannelResampler.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMultiChannelResamplerh">trunk/Source/WebCore/platform/audio/MultiChannelResampler.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioSincResamplercpp">trunk/Source/WebCore/platform/audio/SincResampler.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioSincResamplerh">trunk/Source/WebCore/platform/audio/SincResampler.h</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestswebaudioaudiocontextlargesamplerateexpectedtxt">trunk/LayoutTests/webaudio/audiocontext-large-samplerate-expected.txt</a></li>
<li><a href="#trunkLayoutTestswebaudioaudiocontextlargesampleratehtml">trunk/LayoutTests/webaudio/audiocontext-large-samplerate.html</a></li>
<li><a href="#trunkLayoutTestswebaudioaudiocontextlowsamplerateexpectedtxt">trunk/LayoutTests/webaudio/audiocontext-low-samplerate-expected.txt</a></li>
<li><a href="#trunkLayoutTestswebaudioaudiocontextlowsampleratehtml">trunk/LayoutTests/webaudio/audiocontext-low-samplerate.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/LayoutTests/ChangeLog 2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2020-11-21  Chris Dumez  <cdumez@apple.com>
+
+        Unreviewed, reverting r270141.
+
+        Caused assertions on bots
+
+        Reverted changeset:
+
+        "Poor resampling quality when using AudioContext sampleRate
+        parameter"
+        https://bugs.webkit.org/show_bug.cgi?id=219201
+        https://trac.webkit.org/changeset/270141
+
</ins><span class="cx"> 2020-11-21  Antti Koivisto  <antti@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [LFC][Integration] Remove ensureLineBoxes call from RenderedPosition constructor
</span></span></pre></div>
<a id="trunkLayoutTestswebaudioaudiocontextlargesamplerateexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/webaudio/audiocontext-large-samplerate-expected.txt (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/audiocontext-large-samplerate-expected.txt    2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/LayoutTests/webaudio/audiocontext-large-samplerate-expected.txt       2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,11 +0,0 @@
</span><del>-Tests that we do not crash when using a very large sample rate
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS context.sampleRate is 384000
-PASS context.state is "running"
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
</del></span></pre></div>
<a id="trunkLayoutTestswebaudioaudiocontextlargesampleratehtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/webaudio/audiocontext-large-samplerate.html (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/audiocontext-large-samplerate.html    2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/LayoutTests/webaudio/audiocontext-large-samplerate.html       2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,22 +0,0 @@
</span><del>-<!DOCTYPE html>
-<html>
-<script src="../resources/js-test.js"></script>
-<body>
-<script>
-description("Tests that we do not crash when using a very large sample rate");
-jsTestIsAsync = true;
-
-context = new AudioContext({ sampleRate: 384000 });
-shouldBe("context.sampleRate", "384000");
-
-node = new ConstantSourceNode(context, { offset: 0.5 });
-node.connect(context.destination);
-node.start();
-
-setTimeout(() => {
-    shouldBeEqualToString("context.state", "running");
-    finishJSTest();
-}, 100);
-</script>
-</body>
-</html>
</del></span></pre></div>
<a id="trunkLayoutTestswebaudioaudiocontextlowsamplerateexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/webaudio/audiocontext-low-samplerate-expected.txt (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/audiocontext-low-samplerate-expected.txt      2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/LayoutTests/webaudio/audiocontext-low-samplerate-expected.txt 2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,11 +0,0 @@
</span><del>-Tests that we do not crash when using a very low sample rate
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS context.sampleRate is 3000
-PASS context.state is "running"
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
</del></span></pre></div>
<a id="trunkLayoutTestswebaudioaudiocontextlowsampleratehtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/webaudio/audiocontext-low-samplerate.html (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webaudio/audiocontext-low-samplerate.html      2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/LayoutTests/webaudio/audiocontext-low-samplerate.html 2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,22 +0,0 @@
</span><del>-<!DOCTYPE html>
-<html>
-<script src="../resources/js-test.js"></script>
-<body>
-<script>
-description("Tests that we do not crash when using a very low sample rate");
-jsTestIsAsync = true;
-
-context = new AudioContext({ sampleRate: 3000 });
-shouldBe("context.sampleRate", "3000");
-
-node = new ConstantSourceNode(context, { offset: 0.5 });
-node.connect(context.destination);
-node.start();
-
-setTimeout(() => {
-    shouldBeEqualToString("context.state", "running");
-    finishJSTest();
-}, 100);
-</script>
-</body>
-</html>
</del></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/Source/WebCore/ChangeLog      2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2020-11-21  Chris Dumez  <cdumez@apple.com>
+
+        Unreviewed, reverting r270141.
+
+        Caused assertions on bots
+
+        Reverted changeset:
+
+        "Poor resampling quality when using AudioContext sampleRate
+        parameter"
+        https://bugs.webkit.org/show_bug.cgi?id=219201
+        https://trac.webkit.org/changeset/270141
+
</ins><span class="cx"> 2020-11-21  Andres Gonzalez  <andresg_22@apple.com>
</span><span class="cx"> 
</span><span class="cx">         AccessibilityObject::FocusedUIElement should not call AXObjectCache::focusedUIElementForPage that can return an isolated object.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMultiChannelResamplercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MultiChannelResampler.cpp (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MultiChannelResampler.cpp    2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/Source/WebCore/platform/audio/MultiChannelResampler.cpp       2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -33,34 +33,30 @@
</span><span class="cx"> #include "MultiChannelResampler.h"
</span><span class="cx"> 
</span><span class="cx"> #include "AudioBus.h"
</span><del>-#include "AudioUtilities.h"
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> // ChannelProvider provides a single channel of audio data (one channel at a time) for each channel
</span><span class="cx"> // of data provided to us in a multi-channel provider.
</span><del>-class MultiChannelResampler::ChannelProvider {
</del><ins>+class MultiChannelResampler::ChannelProvider : public AudioSourceProvider {
</ins><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx">     explicit ChannelProvider(unsigned numberOfChannels)
</span><del>-        : m_multiChannelBus(AudioBus::create(numberOfChannels, AudioUtilities::renderQuantumSize))
</del><ins>+        : m_numberOfChannels(numberOfChannels)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void setProvider(AudioSourceProvider* multiChannelProvider)
</span><span class="cx">     {
</span><ins>+        m_currentChannel = 0;
+        m_framesToProcess = 0;
</ins><span class="cx">         m_multiChannelProvider = multiChannelProvider;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // provideInput() will be called once for each channel, starting with the first channel.
</span><span class="cx">     // Each time it's called, it will provide the next channel of data.
</span><del>-    void provideInputForChannel(AudioBus* bus, size_t framesToProcess, unsigned channelIndex)
</del><ins>+    void provideInput(AudioBus* bus, size_t framesToProcess) override
</ins><span class="cx">     {
</span><del>-        ASSERT(channelIndex < m_multiChannelBus->numberOfChannels());
-        ASSERT(framesToProcess <= AudioUtilities::renderQuantumSize);
-        if (framesToProcess > AudioUtilities::renderQuantumSize)
-            return;
-
</del><span class="cx">         bool isBusGood = bus && bus->numberOfChannels() == 1;
</span><span class="cx">         ASSERT(isBusGood);
</span><span class="cx">         if (!isBusGood)
</span><span class="lines">@@ -68,24 +64,31 @@
</span><span class="cx"> 
</span><span class="cx">         // Get the data from the multi-channel provider when the first channel asks for it.
</span><span class="cx">         // For subsequent channels, we can just dish out the channel data from that (stored in m_multiChannelBus).
</span><del>-        if (!channelIndex) {
</del><ins>+        if (!m_currentChannel) {
</ins><span class="cx">             m_framesToProcess = framesToProcess;
</span><ins>+            m_multiChannelBus = AudioBus::create(m_numberOfChannels, framesToProcess);
</ins><span class="cx">             m_multiChannelProvider->provideInput(m_multiChannelBus.get(), framesToProcess);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // All channels must ask for the same amount. This should always be the case, but let's just make sure.
</span><del>-        bool isGood = framesToProcess == m_framesToProcess;
</del><ins>+        bool isGood = m_multiChannelBus.get() && framesToProcess == m_framesToProcess;
</ins><span class="cx">         ASSERT(isGood);
</span><span class="cx">         if (!isGood)
</span><span class="cx">             return;
</span><span class="cx"> 
</span><span class="cx">         // Copy the channel data from what we received from m_multiChannelProvider.
</span><del>-        memcpy(bus->channel(0)->mutableData(), m_multiChannelBus->channel(channelIndex)->data(), sizeof(float) * framesToProcess);
</del><ins>+        ASSERT(m_currentChannel <= m_numberOfChannels);
+        if (m_currentChannel < m_numberOfChannels) {
+            memcpy(bus->channel(0)->mutableData(), m_multiChannelBus->channel(m_currentChannel)->data(), sizeof(float) * framesToProcess);
+            ++m_currentChannel;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     AudioSourceProvider* m_multiChannelProvider { nullptr };
</span><span class="cx">     RefPtr<AudioBus> m_multiChannelBus;
</span><ins>+    unsigned m_numberOfChannels { 0 };
+    unsigned m_currentChannel { 0 };
</ins><span class="cx">     size_t m_framesToProcess { 0 }; // Used to verify that all channels ask for the same amount.
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -109,25 +112,14 @@
</span><span class="cx">     // channelProvider wraps the original multi-channel provider and dishes out one channel at a time.
</span><span class="cx">     m_channelProvider->setProvider(provider);
</span><span class="cx"> 
</span><del>-    // We need to ensure that SincResampler only calls provideInput() once for each channel or it will confuse the logic
-    // inside ChannelProvider. To ensure this, we chunk the number of requested frames into SincResampler::chunkSize()
-    // sized chunks. SincResampler guarantees it will only call provideInput() once once we resample this way.
-    m_outputFramesReady = 0;
-    while (m_outputFramesReady < framesToProcess) {
-        size_t chunkSize = m_kernels[0]->chunkSize();
-        size_t framesThisTime = std::min(framesToProcess - m_outputFramesReady, chunkSize);
-
-        for (unsigned channelIndex = 0; channelIndex < m_numberOfChannels; ++channelIndex) {
-            ASSERT(chunkSize == m_kernels[channelIndex]->chunkSize());
-            bool wasProvideInputCalled = false;
-            m_kernels[channelIndex]->process(destination->channel(channelIndex)->mutableData() + m_outputFramesReady, framesThisTime, [this, channelIndex, &wasProvideInputCalled](AudioBus* bus, size_t framesToProcess) {
-                ASSERT_WITH_MESSAGE(!wasProvideInputCalled, "provideInputForChannel should only be called once");
-                wasProvideInputCalled = true;
-                m_channelProvider->provideInputForChannel(bus, framesToProcess, channelIndex);
-            });
-        }
-
-        m_outputFramesReady += framesThisTime;
</del><ins>+    for (unsigned channelIndex = 0; channelIndex < m_numberOfChannels; ++channelIndex) {
+        // Depending on the sample-rate scale factor, and the internal buffering used in a SincResampler
+        // kernel, this call to process() will only sometimes call provideInput() on the channelProvider.
+        // However, if it calls provideInput() for the first channel, then it will call it for the remaining
+        // channels, since they all buffer in the same way and are processing the same number of frames.
+        m_kernels[channelIndex]->process(m_channelProvider.get(),
+                                         destination->channel(channelIndex)->mutableData(),
+                                         framesToProcess);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_channelProvider->setProvider(nullptr);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMultiChannelResamplerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MultiChannelResampler.h (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MultiChannelResampler.h      2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/Source/WebCore/platform/audio/MultiChannelResampler.h 2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -59,7 +59,6 @@
</span><span class="cx"> 
</span><span class="cx">     class ChannelProvider;
</span><span class="cx">     std::unique_ptr<ChannelProvider> m_channelProvider;
</span><del>-    size_t m_outputFramesReady { 0 };
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioSincResamplercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/SincResampler.cpp (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/SincResampler.cpp    2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/Source/WebCore/platform/audio/SincResampler.cpp       2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -115,11 +115,6 @@
</span><span class="cx"> constexpr unsigned kernelSize { 32 };
</span><span class="cx"> constexpr unsigned numberOfKernelOffsets { 32 };
</span><span class="cx"> 
</span><del>-static size_t calculateChunkSize(unsigned blockSize, double scaleFactor)
-{
-    return blockSize / scaleFactor;
-}
-
</del><span class="cx"> SincResampler::SincResampler(double scaleFactor, Optional<unsigned> requestFrames)
</span><span class="cx">     : m_scaleFactor(scaleFactor)
</span><span class="cx">     , m_kernelStorage(kernelSize * (numberOfKernelOffsets + 1))
</span><span class="lines">@@ -142,7 +137,6 @@
</span><span class="cx">     m_r3 = m_r0 + m_requestFrames - kernelSize;
</span><span class="cx">     m_r4 = m_r0 + m_requestFrames - kernelSize / 2;
</span><span class="cx">     m_blockSize = m_r4 - m_r2;
</span><del>-    m_chunkSize = calculateChunkSize(m_blockSize, m_scaleFactor);
</del><span class="cx"> 
</span><span class="cx">     // m_r1 at the beginning of the buffer.
</span><span class="cx">     ASSERT(m_r1 == m_inputBuffer.data());
</span><span class="lines">@@ -193,10 +187,10 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SincResampler::consumeSource(float* buffer, unsigned numberOfSourceFrames, const Function<void(AudioBus* bus, size_t framesToProcess)>& provideInput)
</del><ins>+void SincResampler::consumeSource(float* buffer, unsigned numberOfSourceFrames)
</ins><span class="cx"> {
</span><del>-    ASSERT(provideInput);
-    if (!provideInput)
</del><ins>+    ASSERT(m_sourceProvider);
+    if (!m_sourceProvider)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // Wrap the provided buffer by an AudioBus for use by the source provider.
</span><span class="lines">@@ -206,14 +200,14 @@
</span><span class="cx">     // FIXME: Find a way to make the following const-correct:
</span><span class="cx">     m_internalBus->setChannelMemory(0, buffer, numberOfSourceFrames);
</span><span class="cx">     
</span><del>-    provideInput(m_internalBus.get(), numberOfSourceFrames);
</del><ins>+    m_sourceProvider->provideInput(m_internalBus.get(), numberOfSourceFrames);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> namespace {
</span><span class="cx"> 
</span><del>-// BufferSourceProvider is an audio source provider wrapping an in-memory buffer.
</del><ins>+// BufferSourceProvider is an AudioSourceProvider wrapping an in-memory buffer.
</ins><span class="cx"> 
</span><del>-class BufferSourceProvider {
</del><ins>+class BufferSourceProvider : public AudioSourceProvider {
</ins><span class="cx"> public:
</span><span class="cx">     explicit BufferSourceProvider(const float* source, size_t numberOfSourceFrames)
</span><span class="cx">         : m_source(source)
</span><span class="lines">@@ -222,7 +216,7 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     // Consumes samples from the in-memory buffer.
</span><del>-    void provideInput(AudioBus* bus, size_t framesToProcess)
</del><ins>+    void provideInput(AudioBus* bus, size_t framesToProcess) override
</ins><span class="cx">     {
</span><span class="cx">         ASSERT(m_source && bus);
</span><span class="cx">         if (!m_source || !bus)
</span><span class="lines">@@ -259,9 +253,7 @@
</span><span class="cx">     
</span><span class="cx">     while (remaining) {
</span><span class="cx">         unsigned framesThisTime = std::min(remaining, m_requestFrames);
</span><del>-        process(destination, framesThisTime, [&sourceProvider](AudioBus* bus, size_t framesToProcess) {
-            sourceProvider.provideInput(bus, framesToProcess);
-        });
</del><ins>+        process(&sourceProvider, destination, framesThisTime);
</ins><span class="cx">         
</span><span class="cx">         destination += framesThisTime;
</span><span class="cx">         remaining -= framesThisTime;
</span><span class="lines">@@ -268,11 +260,13 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SincResampler::process(float* destination, size_t framesToProcess, const Function<void(AudioBus* bus, size_t framesToProcess)>& provideInput)
</del><ins>+void SincResampler::process(AudioSourceProvider* sourceProvider, float* destination, size_t framesToProcess)
</ins><span class="cx"> {
</span><del>-    ASSERT(provideInput);
-    if (!provideInput)
</del><ins>+    ASSERT(sourceProvider);
+    if (!sourceProvider)
</ins><span class="cx">         return;
</span><ins>+    
+    m_sourceProvider = sourceProvider;
</ins><span class="cx"> 
</span><span class="cx">     unsigned numberOfDestinationFrames = framesToProcess;
</span><span class="cx"> 
</span><span class="lines">@@ -279,7 +273,7 @@
</span><span class="cx">     // Step (1)
</span><span class="cx">     // Prime the input buffer at the start of the input stream.
</span><span class="cx">     if (!m_isBufferPrimed) {
</span><del>-        consumeSource(m_r0, m_requestFrames, provideInput);
</del><ins>+        consumeSource(m_r0, m_requestFrames);
</ins><span class="cx">         m_isBufferPrimed = true;
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="lines">@@ -527,7 +521,7 @@
</span><span class="cx"> 
</span><span class="cx">         // Step (5)
</span><span class="cx">         // Refresh the buffer with more input.
</span><del>-        consumeSource(m_r0, m_requestFrames, provideInput);
</del><ins>+        consumeSource(m_r0, m_requestFrames);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioSincResamplerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/SincResampler.h (270154 => 270155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/SincResampler.h      2020-11-21 23:03:28 UTC (rev 270154)
+++ trunk/Source/WebCore/platform/audio/SincResampler.h 2020-11-22 03:03:46 UTC (rev 270155)
</span><span class="lines">@@ -45,17 +45,15 @@
</span><span class="cx">     // requestFrames controls the size in frames of the buffer requested by each provideInput() call.
</span><span class="cx">     SincResampler(double scaleFactor, Optional<unsigned> requestFrames = WTF::nullopt);
</span><span class="cx">     
</span><del>-    size_t chunkSize() const { return m_chunkSize; }
-
</del><span class="cx">     // Processes numberOfSourceFrames from source to produce numberOfSourceFrames / scaleFactor frames in destination.
</span><span class="cx">     void process(const float* source, float* destination, unsigned numberOfSourceFrames);
</span><span class="cx"> 
</span><del>-    // Process with provideInput callback function for streaming applications.
-    void process(float* destination, size_t framesToProcess, const Function<void(AudioBus* bus, size_t framesToProcess)>& provideInput);
</del><ins>+    // Process with input source callback function for streaming applications.
+    void process(AudioSourceProvider*, float* destination, size_t framesToProcess);
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     void initializeKernel();
</span><del>-    void consumeSource(float* buffer, unsigned numberOfSourceFrames, const Function<void(AudioBus* bus, size_t framesToProcess)>& provideInput);
</del><ins>+    void consumeSource(float* buffer, unsigned numberOfSourceFrames);
</ins><span class="cx">     void updateRegions(bool isSecondLoad);
</span><span class="cx">     
</span><span class="cx">     double m_scaleFactor;
</span><span class="lines">@@ -74,8 +72,6 @@
</span><span class="cx">     // The number of source frames processed per pass.
</span><span class="cx">     unsigned m_blockSize { 0 };
</span><span class="cx"> 
</span><del>-    size_t m_chunkSize { 0 };
-
</del><span class="cx">     // Source is copied into this buffer for each processing pass.
</span><span class="cx">     AudioFloatArray m_inputBuffer;
</span><span class="cx"> 
</span><span class="lines">@@ -89,6 +85,9 @@
</span><span class="cx"> 
</span><span class="cx">     const float* m_source { nullptr };
</span><span class="cx">     unsigned m_sourceFramesAvailable { 0 };
</span><ins>+    
+    // m_sourceProvider is used to provide the audio input stream to the resampler.
+    AudioSourceProvider* m_sourceProvider { nullptr };
</ins><span class="cx"> 
</span><span class="cx">     // The buffer is primed once at the very beginning of processing.
</span><span class="cx">     bool m_isBufferPrimed { false };
</span></span></pre>
</div>
</div>

</body>
</html>