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