[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

crogers at google.com crogers at google.com
Wed Dec 22 14:44:31 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 4820f00a1825e273ab61865c111c02b2b1832960
Author: crogers at google.com <crogers at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 19 01:59:09 2010 +0000

    2010-10-18  Chris Rogers  <crogers at google.com>
    
            Reviewed by Chris Fleizach.
    
            Add AudioResampler files
            https://bugs.webkit.org/show_bug.cgi?id=47623
    
            No new tests since audio API is not yet implemented.
    
            * platform/audio/AudioResampler.cpp: Added.
            (WebCore::AudioResampler::AudioResampler):
            (WebCore::AudioResampler::configureChannels):
            (WebCore::AudioResampler::process):
            (WebCore::AudioResampler::setRate):
            (WebCore::AudioResampler::reset):
            * platform/audio/AudioResampler.h: Added.
            (WebCore::AudioResampler::~AudioResampler):
            (WebCore::AudioResampler::rate):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70015 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f5b8972..9ab6db2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2010-10-18  Chris Rogers  <crogers at google.com>
+
+        Reviewed by Chris Fleizach.
+
+        Add AudioResampler files
+        https://bugs.webkit.org/show_bug.cgi?id=47623
+
+        No new tests since audio API is not yet implemented.
+
+        * platform/audio/AudioResampler.cpp: Added.
+        (WebCore::AudioResampler::AudioResampler):
+        (WebCore::AudioResampler::configureChannels):
+        (WebCore::AudioResampler::process):
+        (WebCore::AudioResampler::setRate):
+        (WebCore::AudioResampler::reset):
+        * platform/audio/AudioResampler.h: Added.
+        (WebCore::AudioResampler::~AudioResampler):
+        (WebCore::AudioResampler::rate):
+
 2010-10-18  Vangelis Kokkevis  <vangelis at chromium.org>
 
         Reviewed by James Robinson.
diff --git a/WebCore/platform/audio/AudioResampler.cpp b/WebCore/platform/audio/AudioResampler.cpp
new file mode 100644
index 0000000..7f8221e
--- /dev/null
+++ b/WebCore/platform/audio/AudioResampler.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(WEB_AUDIO)
+
+#include "AudioResampler.h"
+
+#include "AudioBus.h"
+#include <algorithm>
+#include <math.h>
+
+using namespace std;
+ 
+namespace WebCore {
+
+const double AudioResampler::MaxRate = 8.0;
+
+AudioResampler::AudioResampler()
+    : m_rate(1.0)
+{
+    m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
+    m_sourceBus = adoptPtr(new AudioBus(1, 0, false));
+}
+
+AudioResampler::AudioResampler(unsigned numberOfChannels)
+    : m_rate(1.0)
+{
+    for (unsigned i = 0; i < numberOfChannels; ++i)
+        m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
+
+    m_sourceBus = adoptPtr(new AudioBus(numberOfChannels, 0, false));
+}
+
+void AudioResampler::configureChannels(unsigned numberOfChannels)
+{
+    unsigned currentSize = m_kernels.size();
+    if (numberOfChannels == currentSize)
+        return; // already setup
+
+    // First deal with adding or removing kernels.
+    if (numberOfChannels > currentSize) {
+        for (unsigned i = currentSize; i < numberOfChannels; ++i)
+            m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
+    } else
+        m_kernels.resize(numberOfChannels);
+
+    // Reconfigure our source bus to the new channel size.
+    m_sourceBus = adoptPtr(new AudioBus(numberOfChannels, 0, false));
+}
+
+void AudioResampler::process(AudioSourceProvider* provider, AudioBus* destinationBus, size_t framesToProcess)
+{
+    ASSERT(provider);
+    if (!provider)
+        return;
+        
+    unsigned numberOfChannels = m_kernels.size();
+
+    // Make sure our configuration matches the bus we're rendering to.
+    bool channelsMatch = (destinationBus && destinationBus->numberOfChannels() == numberOfChannels);
+    ASSERT(channelsMatch);
+    if (!channelsMatch)
+        return;
+
+    // Setup the source bus.
+    for (unsigned i = 0; i < numberOfChannels; ++i) {
+        // Figure out how many frames we need to get from the provider, and a pointer to the buffer.
+        size_t framesNeeded;
+        float* fillPointer = m_kernels[i]->getSourcePointer(framesToProcess, &framesNeeded);
+        ASSERT(fillPointer);
+        if (!fillPointer)
+            return;
+            
+        m_sourceBus->setChannelMemory(i, fillPointer, framesNeeded);
+    }
+
+    // Ask the provider to supply the desired number of source frames.
+    provider->provideInput(m_sourceBus.get(), m_sourceBus->length());
+
+    // Now that we have the source data, resample each channel into the destination bus.
+    // FIXME: optimize for the common stereo case where it's faster to process both left/right channels in the same inner loop.
+    for (unsigned i = 0; i < numberOfChannels; ++i) {
+        float* destination = destinationBus->channel(i)->data();
+        m_kernels[i]->process(destination, framesToProcess);
+    }
+}
+
+void AudioResampler::setRate(double rate)
+{
+    if (isnan(rate) || isinf(rate) || rate <= 0.0)
+        return;
+    
+    m_rate = min(AudioResampler::MaxRate, rate);
+}
+
+void AudioResampler::reset()
+{
+    unsigned numberOfChannels = m_kernels.size();
+    for (unsigned i = 0; i < numberOfChannels; ++i)
+        m_kernels[i]->reset();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEB_AUDIO)
diff --git a/WebCore/platform/audio/AudioResampler.h b/WebCore/platform/audio/AudioResampler.h
new file mode 100644
index 0000000..ed352b8
--- /dev/null
+++ b/WebCore/platform/audio/AudioResampler.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AudioResampler_h
+#define AudioResampler_h
+
+#include "AudioBus.h"
+#include "AudioResamplerKernel.h"
+#include "AudioSourceProvider.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+// AudioResampler resamples the audio stream from an AudioSourceProvider.
+// The audio stream may be single or multi-channel.
+// The default constructor defaults to single-channel (mono).
+
+class AudioResampler {
+public:
+    AudioResampler();
+    AudioResampler(unsigned numberOfChannels);
+    ~AudioResampler() { }
+    
+    // Given an AudioSourceProvider, process() resamples the source stream into destinationBus.
+    void process(AudioSourceProvider*, AudioBus* destinationBus, size_t framesToProcess);
+
+    // Resets the processing state.
+    void reset();
+
+    void configureChannels(unsigned numberOfChannels);
+
+    // 0 < rate <= MaxRate
+    void setRate(double rate);
+    double rate() const { return m_rate; }
+
+    static const double MaxRate;
+
+private:
+    double m_rate;
+    Vector<OwnPtr<AudioResamplerKernel> > m_kernels;
+    OwnPtr<AudioBus> m_sourceBus;
+};
+
+} // namespace WebCore
+
+#endif // AudioResampler_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list