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

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

Issue 1865583002: Implement BaseAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
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"
31 #include "modules/webaudio/AudioBufferSourceNode.h" 30 #include "modules/webaudio/AudioBufferSourceNode.h"
32 #include "modules/webaudio/AudioNodeInput.h" 31 #include "modules/webaudio/AudioNodeInput.h"
33 #include "modules/webaudio/AudioNodeOutput.h" 32 #include "modules/webaudio/AudioNodeOutput.h"
33 #include "modules/webaudio/BaseAudioContext.h"
34 #include "platform/audio/HRTFPanner.h" 34 #include "platform/audio/HRTFPanner.h"
35 #include "wtf/MathExtras.h" 35 #include "wtf/MathExtras.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 static void fixNANs(double& x) 39 static void fixNANs(double& x)
40 { 40 {
41 if (std::isnan(x) || std::isinf(x)) 41 if (std::isnan(x) || std::isinf(x))
42 x = 0.0; 42 x = 0.0;
43 } 43 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 98
99 // The audio thread can't block on this lock, so we call tryLock() instead. 99 // The audio thread can't block on this lock, so we call tryLock() instead.
100 MutexTryLocker tryLocker(m_processLock); 100 MutexTryLocker tryLocker(m_processLock);
101 MutexTryLocker tryListenerLocker(listener()->listenerLock()); 101 MutexTryLocker tryListenerLocker(listener()->listenerLock());
102 102
103 if (tryLocker.locked() && tryListenerLocker.locked()) { 103 if (tryLocker.locked() && tryListenerLocker.locked()) {
104 // HRTFDatabase should be loaded before proceeding when the panning mode l is HRTF. 104 // HRTFDatabase should be loaded before proceeding when the panning mode l is HRTF.
105 if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDat abaseLoaded()) { 105 if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDat abaseLoaded()) {
106 if (context()->hasRealtimeConstraint()) { 106 if (context()->hasRealtimeConstraint()) {
107 // Some AbstractAudioContexts cannot block on the HRTFDatabase l oader. 107 // Some BaseAudioContexts cannot block on the HRTFDatabase loade r.
108 destination->zero(); 108 destination->zero();
109 return; 109 return;
110 } 110 }
111 111
112 listener()->waitForHRTFDatabaseLoaderThreadCompletion(); 112 listener()->waitForHRTFDatabaseLoaderThreadCompletion();
113 } 113 }
114 114
115 // Apply the panning effect. 115 // Apply the panning effect.
116 double azimuth; 116 double azimuth;
117 double elevation; 117 double elevation;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 if (dirty & PannerHandler::AzimuthElevationDirty) 437 if (dirty & PannerHandler::AzimuthElevationDirty)
438 m_isAzimuthElevationDirty = true; 438 m_isAzimuthElevationDirty = true;
439 439
440 if (dirty & PannerHandler::DistanceConeGainDirty) 440 if (dirty & PannerHandler::DistanceConeGainDirty)
441 m_isDistanceConeGainDirty = true; 441 m_isDistanceConeGainDirty = true;
442 } 442 }
443 443
444 void PannerHandler::setChannelCount(unsigned long channelCount, ExceptionState& exceptionState) 444 void PannerHandler::setChannelCount(unsigned long channelCount, ExceptionState& exceptionState)
445 { 445 {
446 ASSERT(isMainThread()); 446 ASSERT(isMainThread());
447 AbstractAudioContext::AutoLocker locker(context()); 447 BaseAudioContext::AutoLocker locker(context());
448 448
449 // A PannerNode only supports 1 or 2 channels 449 // A PannerNode only supports 1 or 2 channels
450 if (channelCount > 0 && channelCount <= 2) { 450 if (channelCount > 0 && channelCount <= 2) {
451 if (m_channelCount != channelCount) { 451 if (m_channelCount != channelCount) {
452 m_channelCount = channelCount; 452 m_channelCount = channelCount;
453 if (m_channelCountMode != Max) 453 if (m_channelCountMode != Max)
454 updateChannelsForInputs(); 454 updateChannelsForInputs();
455 } 455 }
456 } else { 456 } else {
457 exceptionState.throwDOMException( 457 exceptionState.throwDOMException(
458 NotSupportedError, 458 NotSupportedError,
459 ExceptionMessages::indexOutsideRange<unsigned long>( 459 ExceptionMessages::indexOutsideRange<unsigned long>(
460 "channelCount", 460 "channelCount",
461 channelCount, 461 channelCount,
462 1, 462 1,
463 ExceptionMessages::InclusiveBound, 463 ExceptionMessages::InclusiveBound,
464 2, 464 2,
465 ExceptionMessages::InclusiveBound)); 465 ExceptionMessages::InclusiveBound));
466 } 466 }
467 } 467 }
468 468
469 void PannerHandler::setChannelCountMode(const String& mode, ExceptionState& exce ptionState) 469 void PannerHandler::setChannelCountMode(const String& mode, ExceptionState& exce ptionState)
470 { 470 {
471 ASSERT(isMainThread()); 471 ASSERT(isMainThread());
472 AbstractAudioContext::AutoLocker locker(context()); 472 BaseAudioContext::AutoLocker locker(context());
473 473
474 ChannelCountMode oldMode = m_channelCountMode; 474 ChannelCountMode oldMode = m_channelCountMode;
475 475
476 if (mode == "clamped-max") { 476 if (mode == "clamped-max") {
477 m_newChannelCountMode = ClampedMax; 477 m_newChannelCountMode = ClampedMax;
478 } else if (mode == "explicit") { 478 } else if (mode == "explicit") {
479 m_newChannelCountMode = Explicit; 479 m_newChannelCountMode = Explicit;
480 } else if (mode == "max") { 480 } else if (mode == "max") {
481 // This is not supported for a PannerNode, which can only handle 1 or 2 channels. 481 // This is not supported for a PannerNode, which can only handle 1 or 2 channels.
482 exceptionState.throwDOMException( 482 exceptionState.throwDOMException(
483 NotSupportedError, 483 NotSupportedError,
484 "Panner: 'max' is not allowed"); 484 "Panner: 'max' is not allowed");
485 m_newChannelCountMode = oldMode; 485 m_newChannelCountMode = oldMode;
486 } else { 486 } else {
487 // Do nothing for other invalid values. 487 // Do nothing for other invalid values.
488 m_newChannelCountMode = oldMode; 488 m_newChannelCountMode = oldMode;
489 } 489 }
490 490
491 if (m_newChannelCountMode != oldMode) 491 if (m_newChannelCountMode != oldMode)
492 context()->deferredTaskHandler().addChangedChannelCountMode(this); 492 context()->deferredTaskHandler().addChangedChannelCountMode(this);
493 } 493 }
494 494
495 // ---------------------------------------------------------------- 495 // ----------------------------------------------------------------
496 496
497 PannerNode::PannerNode(AbstractAudioContext& context, float sampelRate) 497 PannerNode::PannerNode(BaseAudioContext& context, float sampelRate)
498 : AudioNode(context) 498 : AudioNode(context)
499 { 499 {
500 setHandler(PannerHandler::create(*this, sampelRate)); 500 setHandler(PannerHandler::create(*this, sampelRate));
501 } 501 }
502 502
503 PannerNode* PannerNode::create(AbstractAudioContext& context, float sampleRate) 503 PannerNode* PannerNode::create(BaseAudioContext& context, float sampleRate)
504 { 504 {
505 return new PannerNode(context, sampleRate); 505 return new PannerNode(context, sampleRate);
506 } 506 }
507 507
508 PannerHandler& PannerNode::pannerHandler() const 508 PannerHandler& PannerNode::pannerHandler() const
509 { 509 {
510 return static_cast<PannerHandler&>(handler()); 510 return static_cast<PannerHandler&>(handler());
511 } 511 }
512 512
513 String PannerNode::panningModel() const 513 String PannerNode::panningModel() const
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 { 600 {
601 return pannerHandler().coneOuterGain(); 601 return pannerHandler().coneOuterGain();
602 } 602 }
603 603
604 void PannerNode::setConeOuterGain(double gain) 604 void PannerNode::setConeOuterGain(double gain)
605 { 605 {
606 pannerHandler().setConeOuterGain(gain); 606 pannerHandler().setConeOuterGain(gain);
607 } 607 }
608 608
609 } // namespace blink 609 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698