Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Unified Diff: third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp

Issue 2799993002: Setting convolver buffer needs to update number of output channels (Closed)
Patch Set: Address review comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/ConvolverNode.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp b/third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp
index 71ef965c70af23634ad076be84ce2933168fdf9a..e6a4ba408c5f057428d52f5a05f6e0c6ec272db2 100644
--- a/third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/ConvolverNode.cpp
@@ -141,10 +141,20 @@ void ConvolverHandler::setBuffer(AudioBuffer* buffer,
context() && context()->hasRealtimeConstraint(), m_normalize));
{
+ // The context must be locked since changing the buffer can
+ // re-configure the number of channels that are output.
+ BaseAudioContext::AutoLocker contextLocker(context());
+
// Synchronize with process().
MutexLocker locker(m_processLock);
m_reverb = std::move(reverb);
m_buffer = buffer;
+ if (buffer) {
+ // This will propagate the channel count to any nodes connected further
+ // downstream in the graph.
+ output(0).setNumberOfChannels(computeNumberOfOutputChannels(
+ input(0).numberOfChannels(), m_buffer->numberOfChannels()));
+ }
}
}
@@ -177,6 +187,15 @@ double ConvolverHandler::latencyTime() const {
return std::numeric_limits<double>::infinity();
}
+unsigned ConvolverHandler::computeNumberOfOutputChannels(
+ unsigned inputChannels,
+ unsigned responseChannels) const {
+ // The number of output channels for a Convolver must be one or two.
+ // And can only be one if there's a mono source and a mono response
+ // buffer.
+ return clampTo(std::max(inputChannels, responseChannels), 1, 2);
+}
+
void ConvolverHandler::setChannelCount(unsigned long channelCount,
ExceptionState& exceptionState) {
DCHECK(isMainThread());
@@ -215,10 +234,8 @@ void ConvolverHandler::checkNumberOfChannelsForInput(AudioNodeInput* input) {
return;
if (m_buffer) {
- unsigned numberOfChannels = input->numberOfChannels();
- unsigned numberOfReverbeChannels = m_buffer->numberOfChannels();
- unsigned numberOfOutputChannels =
- std::min(2u, std::max(numberOfChannels, numberOfReverbeChannels));
+ unsigned numberOfOutputChannels = computeNumberOfOutputChannels(
+ input->numberOfChannels(), m_buffer->numberOfChannels());
if (isInitialized() &&
numberOfOutputChannels != output(0).numberOfChannels()) {
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/ConvolverNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698