Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 if (std::isnan(x) || std::isinf(x)) | 45 if (std::isnan(x) || std::isinf(x)) |
| 46 x = 0.0; | 46 x = 0.0; |
| 47 } | 47 } |
| 48 | 48 |
| 49 PannerNode::PannerNode(AudioContext* context, float sampleRate) | 49 PannerNode::PannerNode(AudioContext* context, float sampleRate) |
| 50 : AudioNode(context, sampleRate) | 50 : AudioNode(context, sampleRate) |
| 51 , m_panningModel(Panner::PanningModelHRTF) | 51 , m_panningModel(Panner::PanningModelHRTF) |
| 52 , m_lastGain(-1.0) | 52 , m_lastGain(-1.0) |
| 53 , m_connectionCount(0) | 53 , m_connectionCount(0) |
| 54 { | 54 { |
| 55 // HRTFDatabaseLoader should be created and load database for pannerNode asy nchronously. | |
| 56 m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNece ssary(context->sampleRate()); | |
| 57 | |
| 55 ScriptWrappable::init(this); | 58 ScriptWrappable::init(this); |
| 56 addInput(adoptPtr(new AudioNodeInput(this))); | 59 addInput(adoptPtr(new AudioNodeInput(this))); |
| 57 addOutput(adoptPtr(new AudioNodeOutput(this, 2))); | 60 addOutput(adoptPtr(new AudioNodeOutput(this, 2))); |
| 58 | 61 |
| 59 // Node-specific default mixing rules. | 62 // Node-specific default mixing rules. |
| 60 m_channelCount = 2; | 63 m_channelCount = 2; |
| 61 m_channelCountMode = ClampedMax; | 64 m_channelCountMode = ClampedMax; |
| 62 m_channelInterpretation = AudioBus::Speakers; | 65 m_channelInterpretation = AudioBus::Speakers; |
| 63 | 66 |
| 64 m_distanceGain = AudioParam::create(context, "distanceGain", 1.0, 0.0, 1.0); | 67 m_distanceGain = AudioParam::create(context, "distanceGain", 1.0, 0.0, 1.0); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 void PannerNode::process(size_t framesToProcess) | 102 void PannerNode::process(size_t framesToProcess) |
| 100 { | 103 { |
| 101 AudioBus* destination = output(0)->bus(); | 104 AudioBus* destination = output(0)->bus(); |
| 102 | 105 |
| 103 if (!isInitialized() || !input(0)->isConnected() || !m_panner.get()) { | 106 if (!isInitialized() || !input(0)->isConnected() || !m_panner.get()) { |
| 104 destination->zero(); | 107 destination->zero(); |
| 105 return; | 108 return; |
| 106 } | 109 } |
| 107 | 110 |
| 108 AudioBus* source = input(0)->bus(); | 111 AudioBus* source = input(0)->bus(); |
| 109 | |
| 110 if (!source) { | 112 if (!source) { |
| 111 destination->zero(); | 113 destination->zero(); |
| 112 return; | 114 return; |
| 113 } | 115 } |
| 114 | 116 |
| 117 // HRTFDatabaseLoader and HRTFDatabase should be loaded before proceed. | |
|
Raymond Toy (Google)
2014/02/24 23:01:22
Comment seems incorrect. Change "before proceed"
KhNo
2014/02/25 02:00:25
Yes. It seems to be not correct comment. I will fi
| |
| 118 if (!m_hrtfDatabaseLoader->isLoaded()) { | |
| 119 if (context()->isOfflineContext()) { | |
| 120 m_hrtfDatabaseLoader->waitForLoaderThreadCompletion(); | |
| 121 } else { | |
| 122 destination->zero(); | |
| 123 return; | |
| 124 } | |
| 125 } | |
| 126 | |
| 115 // The audio thread can't block on this lock, so we call tryLock() instead. | 127 // The audio thread can't block on this lock, so we call tryLock() instead. |
| 116 MutexTryLocker tryLocker(m_pannerLock); | 128 MutexTryLocker tryLocker(m_pannerLock); |
| 117 if (tryLocker.locked()) { | 129 if (tryLocker.locked()) { |
| 118 // Apply the panning effect. | 130 // Apply the panning effect. |
| 119 double azimuth; | 131 double azimuth; |
| 120 double elevation; | 132 double elevation; |
| 121 getAzimuthElevation(&azimuth, &elevation); | 133 getAzimuthElevation(&azimuth, &elevation); |
| 122 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); | 134 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); |
| 123 | 135 |
| 124 // Get the distance and cone gain. | 136 // Get the distance and cone gain. |
| 125 double totalGain = distanceConeGain(); | 137 double totalGain = distanceConeGain(); |
| 126 | 138 |
| 127 // Snap to desired gain at the beginning. | 139 // Snap to desired gain at the beginning. |
| 128 if (m_lastGain == -1.0) | 140 if (m_lastGain == -1.0) |
| 129 m_lastGain = totalGain; | 141 m_lastGain = totalGain; |
| 130 | 142 |
| 131 // Apply gain in-place with de-zippering. | 143 // Apply gain in-place with de-zippering. |
| 132 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); | 144 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); |
| 133 } else { | 145 } else { |
| 134 // Too bad - The tryLock() failed. We must be in the middle of changing the panner. | 146 // Too bad - The tryLock() failed. We must be in the middle of changing the panner. |
| 135 destination->zero(); | 147 destination->zero(); |
| 136 } | 148 } |
| 137 } | 149 } |
| 138 | 150 |
| 139 void PannerNode::initialize() | 151 void PannerNode::initialize() |
| 140 { | 152 { |
| 141 if (isInitialized()) | 153 if (isInitialized()) |
| 142 return; | 154 return; |
| 143 | 155 |
| 144 m_panner = Panner::create(m_panningModel, sampleRate(), context()->hrtfDatab aseLoader()); | 156 m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader .get()); |
| 145 | 157 |
| 146 AudioNode::initialize(); | 158 AudioNode::initialize(); |
| 147 } | 159 } |
| 148 | 160 |
| 149 void PannerNode::uninitialize() | 161 void PannerNode::uninitialize() |
| 150 { | 162 { |
| 151 if (!isInitialized()) | 163 if (!isInitialized()) |
| 152 return; | 164 return; |
| 153 | 165 |
| 154 m_panner.clear(); | 166 m_panner.clear(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 201 |
| 190 bool PannerNode::setPanningModel(unsigned model) | 202 bool PannerNode::setPanningModel(unsigned model) |
| 191 { | 203 { |
| 192 switch (model) { | 204 switch (model) { |
| 193 case EQUALPOWER: | 205 case EQUALPOWER: |
| 194 case HRTF: | 206 case HRTF: |
| 195 if (!m_panner.get() || model != m_panningModel) { | 207 if (!m_panner.get() || model != m_panningModel) { |
| 196 // This synchronizes with process(). | 208 // This synchronizes with process(). |
| 197 MutexLocker processLocker(m_pannerLock); | 209 MutexLocker processLocker(m_pannerLock); |
| 198 | 210 |
| 199 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), conte xt()->hrtfDatabaseLoader()); | 211 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), m_hrt fDatabaseLoader.get()); |
| 200 m_panner = newPanner.release(); | 212 m_panner = newPanner.release(); |
| 201 m_panningModel = model; | 213 m_panningModel = model; |
| 202 } | 214 } |
| 203 break; | 215 break; |
| 204 case SOUNDFIELD: | 216 case SOUNDFIELD: |
| 205 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh ow_bug.cgi?id=77367. | 217 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh ow_bug.cgi?id=77367. |
| 206 context()->executionContext()->addConsoleMessage(JSMessageSource, Warnin gMessageLevel, "'soundfield' panning model not implemented."); | 218 context()->executionContext()->addConsoleMessage(JSMessageSource, Warnin gMessageLevel, "'soundfield' panning model not implemented."); |
| 207 break; | 219 break; |
| 208 default: | 220 default: |
| 209 return false; | 221 return false; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse | 423 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse |
| 412 } | 424 } |
| 413 } | 425 } |
| 414 } | 426 } |
| 415 } | 427 } |
| 416 } | 428 } |
| 417 | 429 |
| 418 } // namespace WebCore | 430 } // namespace WebCore |
| 419 | 431 |
| 420 #endif // ENABLE(WEB_AUDIO) | 432 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |