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

Side by Side Diff: Source/modules/webaudio/PannerNode.cpp

Issue 130003002: Handle loops in audio graph better for PannerNodes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/webaudio/PannerNode.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 uninitialize(); 78 uninitialize();
79 } 79 }
80 80
81 void PannerNode::pullInputs(size_t framesToProcess) 81 void PannerNode::pullInputs(size_t framesToProcess)
82 { 82 {
83 // We override pullInputs(), so we can detect new AudioSourceNodes which hav e connected to us when new connections are made. 83 // We override pullInputs(), so we can detect new AudioSourceNodes which hav e connected to us when new connections are made.
84 // These AudioSourceNodes need to be made aware of our existence in order to handle doppler shift pitch changes. 84 // These AudioSourceNodes need to be made aware of our existence in order to handle doppler shift pitch changes.
85 if (m_connectionCount != context()->connectionCount()) { 85 if (m_connectionCount != context()->connectionCount()) {
86 m_connectionCount = context()->connectionCount(); 86 m_connectionCount = context()->connectionCount();
87 87
88 // Recursively go through all nodes connected to us. 88 // A map for keeping track if we have visited a node or not. This preven ts feedback loops
89 notifyAudioSourcesConnectedToNode(this); 89 // from recursing infinitely. See crbug.com/331446.
90 HashMap<AudioNode*, bool> visitedNodes;
91
92 // Recursively go through all nodes connected to us
93 notifyAudioSourcesConnectedToNode(this, visitedNodes);
90 } 94 }
91 95
92 AudioNode::pullInputs(framesToProcess); 96 AudioNode::pullInputs(framesToProcess);
93 } 97 }
94 98
95 void PannerNode::process(size_t framesToProcess) 99 void PannerNode::process(size_t framesToProcess)
96 { 100 {
97 AudioBus* destination = output(0)->bus(); 101 AudioBus* destination = output(0)->bus();
98 102
99 if (!isInitialized() || !input(0)->isConnected() || !m_panner.get()) { 103 if (!isInitialized() || !input(0)->isConnected() || !m_panner.get()) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 m_distanceGain->setValue(static_cast<float>(distanceGain)); 383 m_distanceGain->setValue(static_cast<float>(distanceGain));
380 384
381 // FIXME: could optimize by caching coneGain 385 // FIXME: could optimize by caching coneGain
382 double coneGain = m_coneEffect.gain(m_position, m_orientation, listenerPosit ion); 386 double coneGain = m_coneEffect.gain(m_position, m_orientation, listenerPosit ion);
383 387
384 m_coneGain->setValue(static_cast<float>(coneGain)); 388 m_coneGain->setValue(static_cast<float>(coneGain));
385 389
386 return float(distanceGain * coneGain); 390 return float(distanceGain * coneGain);
387 } 391 }
388 392
389 void PannerNode::notifyAudioSourcesConnectedToNode(AudioNode* node) 393 void PannerNode::notifyAudioSourcesConnectedToNode(AudioNode* node, HashMap<Audi oNode*, bool>& visitedNodes)
390 { 394 {
391 ASSERT(node); 395 ASSERT(node);
392 if (!node) 396 if (!node)
393 return; 397 return;
394 398
395 // First check if this node is an AudioBufferSourceNode. If so, let it know about us so that doppler shift pitch can be taken into account. 399 // First check if this node is an AudioBufferSourceNode. If so, let it know about us so that doppler shift pitch can be taken into account.
396 if (node->nodeType() == NodeTypeAudioBufferSource) { 400 if (node->nodeType() == NodeTypeAudioBufferSource) {
397 AudioBufferSourceNode* bufferSourceNode = static_cast<AudioBufferSourceN ode*>(node); 401 AudioBufferSourceNode* bufferSourceNode = static_cast<AudioBufferSourceN ode*>(node);
398 bufferSourceNode->setPannerNode(this); 402 bufferSourceNode->setPannerNode(this);
399 } else { 403 } else {
400 // Go through all inputs to this node. 404 // Go through all inputs to this node.
401 for (unsigned i = 0; i < node->numberOfInputs(); ++i) { 405 for (unsigned i = 0; i < node->numberOfInputs(); ++i) {
402 AudioNodeInput* input = node->input(i); 406 AudioNodeInput* input = node->input(i);
403 407
404 // For each input, go through all of its connections, looking for Au dioBufferSourceNodes. 408 // For each input, go through all of its connections, looking for Au dioBufferSourceNodes.
405 for (unsigned j = 0; j < input->numberOfRenderingConnections(); ++j) { 409 for (unsigned j = 0; j < input->numberOfRenderingConnections(); ++j) {
406 AudioNodeOutput* connectedOutput = input->renderingOutput(j); 410 AudioNodeOutput* connectedOutput = input->renderingOutput(j);
407 AudioNode* connectedNode = connectedOutput->node(); 411 AudioNode* connectedNode = connectedOutput->node();
408 notifyAudioSourcesConnectedToNode(connectedNode); // recurse 412 HashMap<AudioNode*, bool>::iterator iterator = visitedNodes.find (connectedNode);
413
414 // If we've seen this node already, we don't need to process it again. Otherwise,
415 // mark it as visited and recurse through the node looking for s ources.
416 if (iterator == visitedNodes.end()) {
417 visitedNodes.set(connectedNode, true);
418 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse
419 }
409 } 420 }
410 } 421 }
411 } 422 }
412 } 423 }
413 424
414 } // namespace WebCore 425 } // namespace WebCore
415 426
416 #endif // ENABLE(WEB_AUDIO) 427 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/PannerNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698