From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/Modules/webaudio/ConvolverNode.cpp | 43 ++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'Source/WebCore/Modules/webaudio/ConvolverNode.cpp') 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 // 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(this)); addOutput(std::make_unique(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 lock(m_processMutex, std::try_to_lock); + std::unique_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 lock(m_processMutex); + std::lock_guard 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 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 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(bufferBus.get(), AudioNode::ProcessingSizeInFrames, MaxFFTSize, 2, useBackgroundThreads, m_normalize); { // Synchronize with process(). - std::lock_guard lock(m_processMutex); - m_reverb = std::move(reverb); + std::lock_guard lock(m_processMutex); + m_reverb = WTFMove(reverb); m_buffer = buffer; } + + return { }; } AudioBuffer* ConvolverNode::buffer() -- cgit v1.2.1