summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webaudio/ConvolverNode.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/webaudio/ConvolverNode.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/webaudio/ConvolverNode.cpp')
-rw-r--r--Source/WebCore/Modules/webaudio/ConvolverNode.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/Source/WebCore/Modules/webaudio/ConvolverNode.cpp b/Source/WebCore/Modules/webaudio/ConvolverNode.cpp
index c5ac5ea52..03e0a009b 100644
--- a/Source/WebCore/Modules/webaudio/ConvolverNode.cpp
+++ b/Source/WebCore/Modules/webaudio/ConvolverNode.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010, Google Inc. All rights reserved.
+ * Copyright (C) 2016, Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,12 +29,9 @@
#include "ConvolverNode.h"
-#include "AudioBuffer.h"
-#include "AudioContext.h"
#include "AudioNodeInput.h"
#include "AudioNodeOutput.h"
#include "Reverb.h"
-#include <wtf/MainThread.h>
// Note about empirical tuning:
// The maximum FFT size affects reverb performance and accuracy.
@@ -45,9 +43,8 @@ const size_t MaxFFTSize = 32768;
namespace WebCore {
-ConvolverNode::ConvolverNode(AudioContext* context, float sampleRate)
+ConvolverNode::ConvolverNode(AudioContext& context, float sampleRate)
: AudioNode(context, sampleRate)
- , m_normalize(true)
{
addInput(std::make_unique<AudioNodeInput>(this));
addOutput(std::make_unique<AudioNodeOutput>(this, 2));
@@ -73,7 +70,7 @@ void ConvolverNode::process(size_t framesToProcess)
ASSERT(outputBus);
// Synchronize with possible dynamic changes to the impulse response.
- std::unique_lock<std::mutex> lock(m_processMutex, std::try_to_lock);
+ std::unique_lock<Lock> lock(m_processMutex, std::try_to_lock);
if (!lock.owns_lock()) {
// Too bad - the try_lock() failed. We must be in the middle of setting a new impulse response.
outputBus->zero();
@@ -93,7 +90,7 @@ void ConvolverNode::process(size_t framesToProcess)
void ConvolverNode::reset()
{
- std::lock_guard<std::mutex> lock(m_processMutex);
+ std::lock_guard<Lock> lock(m_processMutex);
if (m_reverb)
m_reverb->reset();
}
@@ -102,7 +99,7 @@ void ConvolverNode::initialize()
{
if (isInitialized())
return;
-
+
AudioNode::initialize();
}
@@ -115,40 +112,46 @@ void ConvolverNode::uninitialize()
AudioNode::uninitialize();
}
-void ConvolverNode::setBuffer(AudioBuffer* buffer)
+ExceptionOr<void> ConvolverNode::setBuffer(AudioBuffer* buffer)
{
ASSERT(isMainThread());
if (!buffer)
- return;
+ return { };
+
+ if (buffer->sampleRate() != context().sampleRate())
+ return Exception { NOT_SUPPORTED_ERR };
unsigned numberOfChannels = buffer->numberOfChannels();
size_t bufferLength = buffer->length();
- // The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class).
- bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferLength;
- ASSERT(isBufferGood);
- if (!isBufferGood)
- return;
+ // The current implementation supports only 1-, 2-, or 4-channel impulse responses, with the
+ // 4-channel response being interpreted as true-stereo (see Reverb class).
+ bool isChannelCountGood = (numberOfChannels == 1 || numberOfChannels == 2 || numberOfChannels == 4) && bufferLength;
+
+ if (!isChannelCountGood)
+ return Exception { NOT_SUPPORTED_ERR };
// Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and not a memcpy().
// This memory is simply used in the Reverb constructor and no reference to it is kept for later use in that class.
- RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength, false);
+ auto bufferBus = AudioBus::create(numberOfChannels, bufferLength, false);
for (unsigned i = 0; i < numberOfChannels; ++i)
- bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), bufferLength);
+ bufferBus->setChannelMemory(i, buffer->channelData(i)->data(), bufferLength);
bufferBus->setSampleRate(buffer->sampleRate());
// Create the reverb with the given impulse response.
- bool useBackgroundThreads = !context()->isOfflineContext();
+ bool useBackgroundThreads = !context().isOfflineContext();
auto reverb = std::make_unique<Reverb>(bufferBus.get(), AudioNode::ProcessingSizeInFrames, MaxFFTSize, 2, useBackgroundThreads, m_normalize);
{
// Synchronize with process().
- std::lock_guard<std::mutex> lock(m_processMutex);
- m_reverb = std::move(reverb);
+ std::lock_guard<Lock> lock(m_processMutex);
+ m_reverb = WTFMove(reverb);
m_buffer = buffer;
}
+
+ return { };
}
AudioBuffer* ConvolverNode::buffer()