| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 #include "modules/webaudio/PannerNode.h" | 25 #include "modules/webaudio/PannerNode.h" |
| 26 #include "bindings/core/v8/ExceptionMessages.h" | 26 #include "bindings/core/v8/ExceptionMessages.h" |
| 27 #include "bindings/core/v8/ExceptionState.h" | 27 #include "bindings/core/v8/ExceptionState.h" |
| 28 #include "core/dom/ExceptionCode.h" | 28 #include "core/dom/ExceptionCode.h" |
| 29 #include "core/dom/ExecutionContext.h" | 29 #include "core/dom/ExecutionContext.h" |
| 30 #include "modules/webaudio/AbstractAudioContext.h" | 30 #include "modules/webaudio/AbstractAudioContext.h" |
| 31 #include "modules/webaudio/AudioBufferSourceNode.h" | 31 #include "modules/webaudio/AudioBufferSourceNode.h" |
| 32 #include "modules/webaudio/AudioNodeInput.h" | 32 #include "modules/webaudio/AudioNodeInput.h" |
| 33 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
| 34 #include "platform/Histogram.h" |
| 34 #include "platform/audio/HRTFPanner.h" | 35 #include "platform/audio/HRTFPanner.h" |
| 35 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 static void fixNANs(double& x) | 40 static void fixNANs(double& x) |
| 40 { | 41 { |
| 41 if (std::isnan(x) || std::isinf(x)) | 42 if (std::isnan(x) || std::isinf(x)) |
| 42 x = 0.0; | 43 x = 0.0; |
| 43 } | 44 } |
| 44 | 45 |
| 45 PannerHandler::PannerHandler( | 46 PannerHandler::PannerHandler( |
| 46 AudioNode& node, float sampleRate, | 47 AudioNode& node, float sampleRate, |
| 47 AudioParamHandler& positionX, | 48 AudioParamHandler& positionX, |
| 48 AudioParamHandler& positionY, | 49 AudioParamHandler& positionY, |
| 49 AudioParamHandler& positionZ, | 50 AudioParamHandler& positionZ, |
| 50 AudioParamHandler& orientationX, | 51 AudioParamHandler& orientationX, |
| 51 AudioParamHandler& orientationY, | 52 AudioParamHandler& orientationY, |
| 52 AudioParamHandler& orientationZ) | 53 AudioParamHandler& orientationZ) |
| 53 : AudioHandler(NodeTypePanner, node, sampleRate) | 54 : AudioHandler(NodeTypePanner, node, sampleRate) |
| 54 , m_listener(node.context()->listener()) | 55 , m_listener(node.context()->listener()) |
| 55 , m_panningModel(Panner::PanningModelEqualPower) | |
| 56 , m_distanceModel(DistanceEffect::ModelInverse) | 56 , m_distanceModel(DistanceEffect::ModelInverse) |
| 57 , m_isAzimuthElevationDirty(true) | 57 , m_isAzimuthElevationDirty(true) |
| 58 , m_isDistanceConeGainDirty(true) | 58 , m_isDistanceConeGainDirty(true) |
| 59 , m_lastGain(-1.0) | 59 , m_lastGain(-1.0) |
| 60 , m_cachedAzimuth(0) | 60 , m_cachedAzimuth(0) |
| 61 , m_cachedElevation(0) | 61 , m_cachedElevation(0) |
| 62 , m_cachedDistanceConeGain(1.0f) | 62 , m_cachedDistanceConeGain(1.0f) |
| 63 , m_positionX(positionX) | 63 , m_positionX(positionX) |
| 64 , m_positionY(positionY) | 64 , m_positionY(positionY) |
| 65 , m_positionZ(positionZ) | 65 , m_positionZ(positionZ) |
| 66 , m_orientationX(orientationX) | 66 , m_orientationX(orientationX) |
| 67 , m_orientationY(orientationY) | 67 , m_orientationY(orientationY) |
| 68 , m_orientationZ(orientationZ) | 68 , m_orientationZ(orientationZ) |
| 69 { | 69 { |
| 70 // Load the HRTF database asynchronously so we don't block the Javascript th
read while creating the HRTF database. | 70 // Load the HRTF database asynchronously so we don't block the Javascript th
read while creating the HRTF database. |
| 71 // The HRTF panner will return zeroes until the database is loaded. | 71 // The HRTF panner will return zeroes until the database is loaded. |
| 72 listener()->createAndLoadHRTFDatabaseLoader(node.context()->sampleRate()); | 72 listener()->createAndLoadHRTFDatabaseLoader(node.context()->sampleRate()); |
| 73 | 73 |
| 74 addInput(); | 74 addInput(); |
| 75 addOutput(2); | 75 addOutput(2); |
| 76 | 76 |
| 77 // Node-specific default mixing rules. | 77 // Node-specific default mixing rules. |
| 78 m_channelCount = 2; | 78 m_channelCount = 2; |
| 79 m_channelCountMode = ClampedMax; | 79 m_channelCountMode = ClampedMax; |
| 80 m_channelInterpretation = AudioBus::Speakers; | 80 m_channelInterpretation = AudioBus::Speakers; |
| 81 | 81 |
| 82 // Explicitly set the default panning model here so that the histograms |
| 83 // include the default value. |
| 84 setPanningModel("equalpower"); |
| 85 |
| 82 initialize(); | 86 initialize(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 PassRefPtr<PannerHandler> PannerHandler::create( | 89 PassRefPtr<PannerHandler> PannerHandler::create( |
| 86 AudioNode& node, float sampleRate, | 90 AudioNode& node, float sampleRate, |
| 87 AudioParamHandler& positionX, | 91 AudioParamHandler& positionX, |
| 88 AudioParamHandler& positionY, | 92 AudioParamHandler& positionY, |
| 89 AudioParamHandler& positionZ, | 93 AudioParamHandler& positionZ, |
| 90 AudioParamHandler& orientationX, | 94 AudioParamHandler& orientationX, |
| 91 AudioParamHandler& orientationY, | 95 AudioParamHandler& orientationY, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 void PannerHandler::setPanningModel(const String& model) | 276 void PannerHandler::setPanningModel(const String& model) |
| 273 { | 277 { |
| 274 if (model == "equalpower") | 278 if (model == "equalpower") |
| 275 setPanningModel(Panner::PanningModelEqualPower); | 279 setPanningModel(Panner::PanningModelEqualPower); |
| 276 else if (model == "HRTF") | 280 else if (model == "HRTF") |
| 277 setPanningModel(Panner::PanningModelHRTF); | 281 setPanningModel(Panner::PanningModelHRTF); |
| 278 } | 282 } |
| 279 | 283 |
| 280 bool PannerHandler::setPanningModel(unsigned model) | 284 bool PannerHandler::setPanningModel(unsigned model) |
| 281 { | 285 { |
| 286 DEFINE_STATIC_LOCAL(SparseHistogram, panningModelHistogram, ("WebAudio.Panne
rNode.PanningModel")); |
| 287 panningModelHistogram.sample(model); |
| 288 |
| 282 switch (model) { | 289 switch (model) { |
| 283 case Panner::PanningModelEqualPower: | 290 case Panner::PanningModelEqualPower: |
| 284 case Panner::PanningModelHRTF: | 291 case Panner::PanningModelHRTF: |
| 285 if (!m_panner.get() || model != m_panningModel) { | 292 if (!m_panner.get() || model != m_panningModel) { |
| 286 // This synchronizes with process(). | 293 // This synchronizes with process(). |
| 287 MutexLocker processLocker(m_processLock); | 294 MutexLocker processLocker(m_processLock); |
| 288 m_panner = Panner::create(model, sampleRate(), listener()->hrtfDatab
aseLoader()); | 295 m_panner = Panner::create(model, sampleRate(), listener()->hrtfDatab
aseLoader()); |
| 289 m_panningModel = model; | 296 m_panningModel = model; |
| 290 } | 297 } |
| 291 break; | 298 break; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 visitor->trace(m_positionZ); | 761 visitor->trace(m_positionZ); |
| 755 | 762 |
| 756 visitor->trace(m_orientationX); | 763 visitor->trace(m_orientationX); |
| 757 visitor->trace(m_orientationY); | 764 visitor->trace(m_orientationY); |
| 758 visitor->trace(m_orientationZ); | 765 visitor->trace(m_orientationZ); |
| 759 | 766 |
| 760 AudioNode::trace(visitor); | 767 AudioNode::trace(visitor); |
| 761 } | 768 } |
| 762 | 769 |
| 763 } // namespace blink | 770 } // namespace blink |
| OLD | NEW |