Title: [284980] trunk
Revision
284980
Author
you...@apple.com
Date
2021-10-28 08:32:57 -0700 (Thu, 28 Oct 2021)

Log Message

Fix CARingBuffer mix mode
https://bugs.webkit.org/show_bug.cgi?id=232427
Source/WebCore:

Reviewed by Eric Carlson.

Like done for Copy, we need to use the destination offset to write data properly.

Covered by API test.

* platform/audio/cocoa/CARingBuffer.cpp:

Tools:

<rdar://problem/84747657>

Reviewed by Eric Carlson.

* TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284979 => 284980)


--- trunk/Source/WebCore/ChangeLog	2021-10-28 15:30:07 UTC (rev 284979)
+++ trunk/Source/WebCore/ChangeLog	2021-10-28 15:32:57 UTC (rev 284980)
@@ -1,5 +1,18 @@
 2021-10-28  Youenn Fablet  <you...@apple.com>
 
+        Fix CARingBuffer mix mode
+        https://bugs.webkit.org/show_bug.cgi?id=232427
+
+        Reviewed by Eric Carlson.
+
+        Like done for Copy, we need to use the destination offset to write data properly.
+
+        Covered by API test.
+
+        * platform/audio/cocoa/CARingBuffer.cpp:
+
+2021-10-28  Youenn Fablet  <you...@apple.com>
+
         [ Mac wk1 ] 2 media-capabilities/webrtc tests are flaky failures
         https://bugs.webkit.org/show_bug.cgi?id=232283
         <rdar://problem/84637007>

Modified: trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp (284979 => 284980)


--- trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp	2021-10-28 15:30:07 UTC (rev 284979)
+++ trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp	2021-10-28 15:32:57 UTC (rev 284980)
@@ -166,31 +166,33 @@
         if (destOffset > dest->mDataByteSize)
             continue;
 
+        auto* destinationData = static_cast<Byte*>(dest->mData) + destOffset;
+        auto* sourceData = pointer + srcOffset;
         nbytes = std::min<size_t>(nbytes, dest->mDataByteSize - destOffset);
         if (mode == CARingBuffer::Copy)
-            memcpy(static_cast<Byte*>(dest->mData) + destOffset, pointer + srcOffset, nbytes);
+            memcpy(destinationData, sourceData, nbytes);
         else {
             switch (format) {
             case AudioStreamDescription::Int16: {
-                int16_t* destination = static_cast<int16_t*>(dest->mData);
-                int16_t* source = reinterpret_cast<int16_t*>(pointer + srcOffset);
+                auto* destination = reinterpret_cast<int16_t*>(destinationData);
+                auto* source = reinterpret_cast<int16_t*>(sourceData);
                 for (size_t i = 0; i < nbytes / sizeof(int16_t); i++)
                     destination[i] += source[i];
                 break;
             }
             case AudioStreamDescription::Int32: {
-                int32_t* destination = static_cast<int32_t*>(dest->mData);
-                vDSP_vaddi(destination, 1, reinterpret_cast<int32_t*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(int32_t));
+                auto* destination = reinterpret_cast<int32_t*>(destinationData);
+                vDSP_vaddi(destination, 1, reinterpret_cast<int32_t*>(sourceData), 1, destination, 1, nbytes / sizeof(int32_t));
                 break;
             }
             case AudioStreamDescription::Float32: {
-                float* destination = static_cast<float*>(dest->mData);
-                vDSP_vadd(destination, 1, reinterpret_cast<float*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(float));
+                auto* destination = reinterpret_cast<float*>(destinationData);
+                vDSP_vadd(destination, 1, reinterpret_cast<float*>(sourceData), 1, destination, 1, nbytes / sizeof(float));
                 break;
             }
             case AudioStreamDescription::Float64: {
-                double* destination = static_cast<double*>(dest->mData);
-                vDSP_vaddD(destination, 1, reinterpret_cast<double*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(double));
+                auto* destination = reinterpret_cast<double*>(destinationData);
+                vDSP_vaddD(destination, 1, reinterpret_cast<double*>(sourceData), 1, destination, 1, nbytes / sizeof(double));
                 break;
             }
             case AudioStreamDescription::None:

Modified: trunk/Tools/ChangeLog (284979 => 284980)


--- trunk/Tools/ChangeLog	2021-10-28 15:30:07 UTC (rev 284979)
+++ trunk/Tools/ChangeLog	2021-10-28 15:32:57 UTC (rev 284980)
@@ -1,3 +1,13 @@
+2021-10-28  Youenn Fablet  <you...@apple.com>
+
+        Fix CARingBuffer mix mode
+        https://bugs.webkit.org/show_bug.cgi?id=232427
+        <rdar://problem/84747657>
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp:
+
 2021-10-28  Simon Fraser  <simon.fra...@apple.com>
 
         Enhance test_parser.py to find fuzzy matching metadata

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp (284979 => 284980)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp	2021-10-28 15:30:07 UTC (rev 284979)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp	2021-10-28 15:32:57 UTC (rev 284980)
@@ -152,7 +152,7 @@
 public:
     static void run(CARingBufferTest& test)
     {
-        const int sampleCount = 64;
+        const int sampleCount = 441;
 
         CAAudioStreamDescription::PCMFormat format;
         if (std::is_same<type, float>::value)
@@ -197,6 +197,20 @@
         
         for (int i = 0; i < sampleCount; i++)
             EXPECT_EQ(readBuffer[i], referenceBuffer[i]) << "Ring buffer value differs at index " << i;
+
+        test.ringBuffer().fetch(&test.bufferList(), sampleCount, 0, CARingBuffer::FetchMode::Copy);
+        err = test.ringBuffer().store(&test.bufferList(), sampleCount, sampleCount);
+        EXPECT_EQ(err, CARingBuffer::Error::Ok);
+
+        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Copy);
+        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Mix);
+        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Mix);
+
+        for (int i = 0; i < sampleCount; i++)
+            referenceBuffer[i] = sourceBuffer[i] * 3;
+
+        for (int i = 0; i < sampleCount; i++)
+            EXPECT_EQ(readBuffer[i], referenceBuffer[i]) << "Ring buffer value differs at index " << i;
     }
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to