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

Changeset 284980 in webkit


Ignore:
Timestamp:
Oct 28, 2021, 8:32:57 AM (5 years ago)
Author:
youenn@apple.com
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:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284976 r284980  
     12021-10-28  Youenn Fablet  <youenn@apple.com>
     2
     3        Fix CARingBuffer mix mode
     4        https://bugs.webkit.org/show_bug.cgi?id=232427
     5
     6        Reviewed by Eric Carlson.
     7
     8        Like done for Copy, we need to use the destination offset to write data properly.
     9
     10        Covered by API test.
     11
     12        * platform/audio/cocoa/CARingBuffer.cpp:
     13
    1142021-10-28  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/Source/WebCore/platform/audio/cocoa/CARingBuffer.cpp

    r281001 r284980  
    167167            continue;
    168168
     169        auto* destinationData = static_cast<Byte*>(dest->mData) + destOffset;
     170        auto* sourceData = pointer + srcOffset;
    169171        nbytes = std::min<size_t>(nbytes, dest->mDataByteSize - destOffset);
    170172        if (mode == CARingBuffer::Copy)
    171             memcpy(static_cast<Byte*>(dest->mData) + destOffset, pointer + srcOffset, nbytes);
     173            memcpy(destinationData, sourceData, nbytes);
    172174        else {
    173175            switch (format) {
    174176            case AudioStreamDescription::Int16: {
    175                 int16_t* destination = static_cast<int16_t*>(dest->mData);
    176                 int16_t* source = reinterpret_cast<int16_t*>(pointer + srcOffset);
     177                auto* destination = reinterpret_cast<int16_t*>(destinationData);
     178                auto* source = reinterpret_cast<int16_t*>(sourceData);
    177179                for (size_t i = 0; i < nbytes / sizeof(int16_t); i++)
    178180                    destination[i] += source[i];
    … …  
    180182            }
    181183            case AudioStreamDescription::Int32: {
    182                 int32_t* destination = static_cast<int32_t*>(dest->mData);
    183                 vDSP_vaddi(destination, 1, reinterpret_cast<int32_t*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(int32_t));
     184                auto* destination = reinterpret_cast<int32_t*>(destinationData);
     185                vDSP_vaddi(destination, 1, reinterpret_cast<int32_t*>(sourceData), 1, destination, 1, nbytes / sizeof(int32_t));
    184186                break;
    185187            }
    186188            case AudioStreamDescription::Float32: {
    187                 float* destination = static_cast<float*>(dest->mData);
    188                 vDSP_vadd(destination, 1, reinterpret_cast<float*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(float));
     189                auto* destination = reinterpret_cast<float*>(destinationData);
     190                vDSP_vadd(destination, 1, reinterpret_cast<float*>(sourceData), 1, destination, 1, nbytes / sizeof(float));
    189191                break;
    190192            }
    191193            case AudioStreamDescription::Float64: {
    192                 double* destination = static_cast<double*>(dest->mData);
    193                 vDSP_vaddD(destination, 1, reinterpret_cast<double*>(pointer + srcOffset), 1, destination, 1, nbytes / sizeof(double));
     194                auto* destination = reinterpret_cast<double*>(destinationData);
     195                vDSP_vaddD(destination, 1, reinterpret_cast<double*>(sourceData), 1, destination, 1, nbytes / sizeof(double));
    194196                break;
    195197            }
  • trunk/Tools/ChangeLog

    r284979 r284980  
     12021-10-28  Youenn Fablet  <youenn@apple.com>
     2
     3        Fix CARingBuffer mix mode
     4        https://bugs.webkit.org/show_bug.cgi?id=232427
     5        <rdar://problem/84747657>
     6
     7        Reviewed by Eric Carlson.
     8
     9        * TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp:
     10
    1112021-10-28  Simon Fraser  <simon.fraser@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/CARingBuffer.cpp

    r270663 r284980  
    153153    static void run(CARingBufferTest& test)
    154154    {
    155         const int sampleCount = 64;
     155        const int sampleCount = 441;
    156156
    157157        CAAudioStreamDescription::PCMFormat format;
    … …  
    198198        for (int i = 0; i < sampleCount; i++)
    199199            EXPECT_EQ(readBuffer[i], referenceBuffer[i]) << "Ring buffer value differs at index " << i;
     200
     201        test.ringBuffer().fetch(&test.bufferList(), sampleCount, 0, CARingBuffer::FetchMode::Copy);
     202        err = test.ringBuffer().store(&test.bufferList(), sampleCount, sampleCount);
     203        EXPECT_EQ(err, CARingBuffer::Error::Ok);
     204
     205        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Copy);
     206        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Mix);
     207        test.ringBuffer().fetch(&test.bufferList(), sampleCount, sampleCount, CARingBuffer::FetchMode::Mix);
     208
     209        for (int i = 0; i < sampleCount; i++)
     210            referenceBuffer[i] = sourceBuffer[i] * 3;
     211
     212        for (int i = 0; i < sampleCount; i++)
     213            EXPECT_EQ(readBuffer[i], referenceBuffer[i]) << "Ring buffer value differs at index " << i;
    200214    }
    201215};
Note: See TracChangeset for help on using the changeset viewer.