Skip to content
Permalink
Browse files
2010-10-27 Chris Rogers <crogers@google.com>
        Reviewed by Kenneth Russell.

        Fixup files affected by VectorMath and related API changes
        https://bugs.webkit.org/show_bug.cgi?id=48481

        No new tests since audio API is not yet implemented.

        * platform/audio/AudioBus.cpp:
        * platform/audio/AudioChannel.cpp:
        * platform/audio/Biquad.cpp:
        * platform/audio/FFTConvolver.cpp:
        * platform/audio/FFTConvolver.h:
        * platform/audio/Panner.cpp:
        (WebCore::Panner::create):
        * platform/audio/Reverb.cpp:
        (WebCore::calculateNormalizationScale):
        (WebCore::Reverb::initialize):
        (WebCore::Reverb::process):
        * platform/audio/ReverbAccumulationBuffer.cpp:
        * platform/audio/ReverbAccumulationBuffer.h:
        * platform/audio/ReverbConvolver.cpp:
        (WebCore::ReverbConvolver::ReverbConvolver):
        (WebCore::ReverbConvolver::process):
        * platform/audio/ReverbConvolver.h:
        * platform/audio/ReverbConvolverStage.cpp:
        (WebCore::ReverbConvolverStage::ReverbConvolverStage):
        * platform/audio/ReverbConvolverStage.h:
        * platform/audio/ReverbInputBuffer.h:

Canonical link: https://commits.webkit.org/61258@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@70742 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Chris Rogers committed Oct 28, 2010
1 parent ef7fcb1 commit 002cb2b730ec8238f9a446ae64c14fce8dd031df
Showing 15 changed files with 74 additions and 28 deletions.
@@ -1,3 +1,34 @@
2010-10-27 Chris Rogers <crogers@google.com>

Reviewed by Kenneth Russell.

Fixup files affected by VectorMath and related API changes
https://bugs.webkit.org/show_bug.cgi?id=48481

No new tests since audio API is not yet implemented.

* platform/audio/AudioBus.cpp:
* platform/audio/AudioChannel.cpp:
* platform/audio/Biquad.cpp:
* platform/audio/FFTConvolver.cpp:
* platform/audio/FFTConvolver.h:
* platform/audio/Panner.cpp:
(WebCore::Panner::create):
* platform/audio/Reverb.cpp:
(WebCore::calculateNormalizationScale):
(WebCore::Reverb::initialize):
(WebCore::Reverb::process):
* platform/audio/ReverbAccumulationBuffer.cpp:
* platform/audio/ReverbAccumulationBuffer.h:
* platform/audio/ReverbConvolver.cpp:
(WebCore::ReverbConvolver::ReverbConvolver):
(WebCore::ReverbConvolver::process):
* platform/audio/ReverbConvolver.h:
* platform/audio/ReverbConvolverStage.cpp:
(WebCore::ReverbConvolverStage::ReverbConvolverStage):
* platform/audio/ReverbConvolverStage.h:
* platform/audio/ReverbInputBuffer.h:

2010-10-27 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by Dumitru Daniliuc.
@@ -32,7 +32,7 @@

#include "AudioBus.h"

#include "Accelerate.h"
#include "VectorMath.h"
#include <algorithm>
#include <assert.h>
#include <math.h>
@@ -41,6 +41,8 @@

namespace WebCore {

using namespace VectorMath;

AudioBus::AudioBus(unsigned numberOfChannels, size_t length, bool allocate)
: m_length(length)
, m_busGain(1.0)
@@ -32,13 +32,15 @@

#include "AudioChannel.h"

#include "Accelerate.h"
#include "VectorMath.h"
#include <algorithm>
#include <math.h>
#include <wtf/OwnPtr.h>

namespace WebCore {

using namespace VectorMath;

void AudioChannel::scale(double scale)
{
float s = static_cast<float>(scale);
@@ -32,12 +32,15 @@

#include "Biquad.h"

#include "Accelerate.h"
#include <algorithm>
#include <float.h>
#include <math.h>
#include <stdio.h>

#if OS(DARWIN)
#include <Accelerate/Accelerate.h>
#endif

namespace WebCore {

const int kBufferSize = 1024;
@@ -32,10 +32,12 @@

#include "FFTConvolver.h"

#include "Accelerate.h"
#include "VectorMath.h"

namespace WebCore {

using namespace VectorMath;

FFTConvolver::FFTConvolver(size_t fftSize)
: m_frame(fftSize)
, m_readWriteIndex(0)
@@ -29,7 +29,7 @@
#ifndef FFTConvolver_h
#define FFTConvolver_h

#include "AudioFloatArray.h"
#include "AudioArray.h"
#include "FFTFrame.h"

namespace WebCore {
@@ -45,7 +45,7 @@ PassOwnPtr<Panner> Panner::create(PanningModel model, double sampleRate)

switch (model) {
case PanningModelEqualPower:
panner = adoptPtr(new EqualPowerPanner());
panner = adoptPtr(new EqualPowerPanner(sampleRate));
break;

case PanningModelHRTF:
@@ -56,12 +56,12 @@ static double calculateNormalizationScale(AudioBus* response)
{
// Normalize by RMS power
size_t numberOfChannels = response->numberOfChannels();
size_t frameSize = response->frameSize();
size_t length = response->length();

double power = 0.0;

for (size_t i = 0; i < numberOfChannels; ++i) {
int n = frameSize;
int n = length;
float* p = response->channel(i)->data();

while (n--) {
@@ -70,7 +70,7 @@ static double calculateNormalizationScale(AudioBus* response)
}
}

power = sqrt(power / (numberOfChannels * frameSize));
power = sqrt(power / (numberOfChannels * length));

// Protect against accidental overload
if (isinf(power) || isnan(power) || power < MinPower)
@@ -102,7 +102,7 @@ Reverb::Reverb(AudioBus* impulseResponse, size_t renderSliceSize, size_t maxFFTS

void Reverb::initialize(AudioBus* impulseResponseBuffer, size_t renderSliceSize, size_t maxFFTSize, size_t numberOfChannels, bool useBackgroundThreads)
{
m_impulseResponseLength = impulseResponseBuffer->frameSize();
m_impulseResponseLength = impulseResponseBuffer->length();

// The reverb can handle a mono impulse response and still do stereo processing
size_t numResponseChannels = impulseResponseBuffer->numberOfChannels();
@@ -112,8 +112,8 @@ void Reverb::initialize(AudioBus* impulseResponseBuffer, size_t renderSliceSize,
for (size_t i = 0; i < numResponseChannels; ++i) {
AudioChannel* channel = impulseResponseBuffer->channel(i);

ReverbConvolver* convolver = new ReverbConvolver(channel, renderSliceSize, maxFFTSize, convolverRenderPhase, useBackgroundThreads);
m_convolvers.append(convolver);
OwnPtr<ReverbConvolver> convolver = adoptPtr(new ReverbConvolver(channel, renderSliceSize, maxFFTSize, convolverRenderPhase, useBackgroundThreads));
m_convolvers.append(convolver.release());

convolverRenderPhase += renderSliceSize;
}
@@ -129,7 +129,7 @@ void Reverb::process(AudioBus* sourceBus, AudioBus* destinationBus, size_t frame
// Do a fairly comprehensive sanity check.
// If these conditions are satisfied, all of the source and destination pointers will be valid for the various matrixing cases.
bool isSafeToProcess = sourceBus && destinationBus && sourceBus->numberOfChannels() > 0 && destinationBus->numberOfChannels() > 0
&& framesToProcess <= MaxFrameSize && framesToProcess <= sourceBus->frameSize() && framesToProcess <= destinationBus->frameSize();
&& framesToProcess <= MaxFrameSize && framesToProcess <= sourceBus->length() && framesToProcess <= destinationBus->length();

ASSERT(isSafeToProcess);
if (!isSafeToProcess)
@@ -167,7 +167,7 @@ void Reverb::process(AudioBus* sourceBus, AudioBus* destinationBus, size_t frame

// simply copy L -> R
AudioChannel* destinationChannelR = destinationBus->channel(1);
bool isCopySafe = destinationChannelL->data() && destinationChannelR->data() && destinationChannelL->frameSize() >= framesToProcess && destinationChannelR->frameSize() >= framesToProcess;
bool isCopySafe = destinationChannelL->data() && destinationChannelR->data() && destinationChannelL->length() >= framesToProcess && destinationChannelR->length() >= framesToProcess;
ASSERT(isCopySafe);
if (!isCopySafe)
return;
@@ -32,10 +32,12 @@

#include "ReverbAccumulationBuffer.h"

#include "Accelerate.h"
#include "VectorMath.h"

namespace WebCore {

using namespace VectorMath;

ReverbAccumulationBuffer::ReverbAccumulationBuffer(size_t length)
: m_buffer(length)
, m_readIndex(0)
@@ -29,7 +29,7 @@
#ifndef ReverbAccumulationBuffer_h
#define ReverbAccumulationBuffer_h

#include "AudioFloatArray.h"
#include "AudioArray.h"

namespace WebCore {

@@ -32,11 +32,13 @@

#include "ReverbConvolver.h"

#include "Accelerate.h"
#include "VectorMath.h"
#include "AudioBus.h"

namespace WebCore {

using namespace VectorMath;

const int InputBufferSize = 8 * 16384;

// We only process the leading portion of the impulse response in the real-time thread. We don't exceed this length.
@@ -59,8 +61,8 @@ static void* backgroundThreadEntry(void* threadData)
}

ReverbConvolver::ReverbConvolver(AudioChannel* impulseResponse, size_t renderSliceSize, size_t maxFFTSize, size_t convolverRenderPhase, bool useBackgroundThreads)
: m_impulseResponseLength(impulseResponse->frameSize())
, m_accumulationBuffer(impulseResponse->frameSize() + renderSliceSize)
: m_impulseResponseLength(impulseResponse->length())
, m_accumulationBuffer(impulseResponse->length() + renderSliceSize)
, m_inputBuffer(InputBufferSize)
, m_renderSliceSize(renderSliceSize)
, m_minFFTSize(MinFFTSize) // First stage will have this size - successive stages will double in size each time
@@ -81,7 +83,7 @@ ReverbConvolver::ReverbConvolver(AudioChannel* impulseResponse, size_t renderSli
bool hasRealtimeConstraint = useBackgroundThreads;

float* response = impulseResponse->data();
size_t totalResponseLength = impulseResponse->frameSize();
size_t totalResponseLength = impulseResponse->length();

// Because we're not using direct-convolution in the leading portion, the reverb has an overall latency of half the first-stage FFT size
size_t reverbTotalLatency = m_minFFTSize / 2;
@@ -175,7 +177,7 @@ void ReverbConvolver::backgroundThreadEntry()

void ReverbConvolver::process(AudioChannel* sourceChannel, AudioChannel* destinationChannel, size_t framesToProcess)
{
bool isSafe = sourceChannel && destinationChannel && sourceChannel->frameSize() >= framesToProcess && destinationChannel->frameSize() >= framesToProcess;
bool isSafe = sourceChannel && destinationChannel && sourceChannel->length() >= framesToProcess && destinationChannel->length() >= framesToProcess;
ASSERT(isSafe);
if (!isSafe)
return;
@@ -29,7 +29,7 @@
#ifndef ReverbConvolver_h
#define ReverbConvolver_h

#include "AudioFloatArray.h"
#include "AudioArray.h"
#include "FFTConvolver.h"
#include "ReverbAccumulationBuffer.h"
#include "ReverbConvolverStage.h"
@@ -32,7 +32,7 @@

#include "ReverbConvolverStage.h"

#include "Accelerate.h"
#include "VectorMath.h"
#include "ReverbAccumulationBuffer.h"
#include "ReverbConvolver.h"
#include "ReverbInputBuffer.h"
@@ -41,6 +41,8 @@

namespace WebCore {

using namespace VectorMath;

ReverbConvolverStage::ReverbConvolverStage(float* impulseResponse, size_t responseLength, size_t reverbTotalLatency, size_t stageOffset, size_t stageLength,
size_t fftSize, size_t renderPhase, size_t renderSliceSize, ReverbAccumulationBuffer* accumulationBuffer)
: m_fftKernel(fftSize)
@@ -53,8 +55,8 @@ ReverbConvolverStage::ReverbConvolverStage(float* impulseResponse, size_t respon
ASSERT(accumulationBuffer);

m_fftKernel.doPaddedFFT(impulseResponse + stageOffset, stageLength);
m_convolver = new FFTConvolver(fftSize);
m_temporaryBuffer.allocate(renderSliceSize);
m_convolver = adoptPtr(new FFTConvolver(fftSize));
m_temporaryBuffer.resize(renderSliceSize);

// The convolution stage at offset stageOffset needs to have a corresponding delay to cancel out the offset.
size_t totalDelay = stageOffset + reverbTotalLatency;
@@ -76,7 +78,7 @@ ReverbConvolverStage::ReverbConvolverStage(float* impulseResponse, size_t respon
m_preReadWriteIndex = 0;
m_framesProcessed = 0; // total frames processed so far

m_preDelayBuffer.allocate(m_preDelayLength < fftSize ? fftSize : m_preDelayLength);
m_preDelayBuffer.resize(m_preDelayLength < fftSize ? fftSize : m_preDelayLength);
}

void ReverbConvolverStage::processInBackground(ReverbConvolver* convolver, size_t framesToProcess)
@@ -29,7 +29,7 @@
#ifndef ReverbConvolverStage_h
#define ReverbConvolverStage_h

#include "AudioFloatArray.h"
#include "AudioArray.h"
#include "FFTFrame.h"
#include <wtf/OwnPtr.h>

@@ -29,7 +29,7 @@
#ifndef ReverbInputBuffer_h
#define ReverbInputBuffer_h

#include "AudioFloatArray.h"
#include "AudioArray.h"

namespace WebCore {

0 comments on commit 002cb2b

Please sign in to comment.