Chromium Code Reviews| Index: Source/modules/webaudio/PannerNode.cpp |
| diff --git a/Source/modules/webaudio/PannerNode.cpp b/Source/modules/webaudio/PannerNode.cpp |
| index 80e5099488100a0b98b6fe253d10b98f0d5688eb..32a9597b9ef2b641cc3804e0157b18de2e1e129d 100644 |
| --- a/Source/modules/webaudio/PannerNode.cpp |
| +++ b/Source/modules/webaudio/PannerNode.cpp |
| @@ -52,6 +52,10 @@ PannerNode::PannerNode(AudioContext* context, float sampleRate) |
| , m_lastGain(-1.0) |
| , m_connectionCount(0) |
| { |
| + // Load the HRTF database asynchronously so we don't block the Javascript thread while create the HRTF database. |
|
Raymond Toy (Google)
2014/02/25 17:13:58
Nit: "create" -> "creating"
|
| + // The HRTF panner will return zeroes until the database is loaded. |
| + m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(context->sampleRate()); |
| + |
| ScriptWrappable::init(this); |
| addInput(adoptPtr(new AudioNodeInput(this))); |
| addOutput(adoptPtr(new AudioNodeOutput(this, 2))); |
| @@ -106,12 +110,21 @@ void PannerNode::process(size_t framesToProcess) |
| } |
| AudioBus* source = input(0)->bus(); |
| - |
| if (!source) { |
| destination->zero(); |
| return; |
| } |
| + // HRTFDatabase should be loaded before proceeding for offline audio context when panningModel() is "HRTF". |
| + if (panningModel() == "HRTF" && !m_hrtfDatabaseLoader->isLoaded()) { |
| + if (context()->isOfflineContext()) { |
| + m_hrtfDatabaseLoader->waitForLoaderThreadCompletion(); |
| + } else { |
| + destination->zero(); |
| + return; |
| + } |
| + } |
| + |
| // The audio thread can't block on this lock, so we call tryLock() instead. |
| MutexTryLocker tryLocker(m_pannerLock); |
| if (tryLocker.locked()) { |
| @@ -141,7 +154,7 @@ void PannerNode::initialize() |
| if (isInitialized()) |
| return; |
| - m_panner = Panner::create(m_panningModel, sampleRate(), context()->hrtfDatabaseLoader()); |
| + m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader.get()); |
| AudioNode::initialize(); |
| } |
| @@ -196,7 +209,7 @@ bool PannerNode::setPanningModel(unsigned model) |
| // This synchronizes with process(). |
| MutexLocker processLocker(m_pannerLock); |
| - OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), context()->hrtfDatabaseLoader()); |
| + OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), m_hrtfDatabaseLoader.get()); |
| m_panner = newPanner.release(); |
| m_panningModel = model; |
| } |