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

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

Issue 1214463003: Split "Online" and "Offline" AudioContext processing (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Bring to ToT Created 5 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/webaudio/PannerNode.h ('k') | Source/modules/webaudio/ScriptProcessorNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #if ENABLE(WEB_AUDIO) 26 #if ENABLE(WEB_AUDIO)
27 #include "modules/webaudio/PannerNode.h" 27 #include "modules/webaudio/PannerNode.h"
28 28
29 #include "bindings/core/v8/ExceptionMessages.h" 29 #include "bindings/core/v8/ExceptionMessages.h"
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/dom/ExecutionContext.h" 32 #include "core/dom/ExecutionContext.h"
33 #include "modules/webaudio/AbstractAudioContext.h"
33 #include "modules/webaudio/AudioBufferSourceNode.h" 34 #include "modules/webaudio/AudioBufferSourceNode.h"
34 #include "modules/webaudio/AudioContext.h"
35 #include "modules/webaudio/AudioNodeInput.h" 35 #include "modules/webaudio/AudioNodeInput.h"
36 #include "modules/webaudio/AudioNodeOutput.h" 36 #include "modules/webaudio/AudioNodeOutput.h"
37 #include "platform/audio/HRTFPanner.h" 37 #include "platform/audio/HRTFPanner.h"
38 #include "wtf/MathExtras.h" 38 #include "wtf/MathExtras.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 static void fixNANs(double& x) 42 static void fixNANs(double& x)
43 { 43 {
44 if (std::isnan(x) || std::isinf(x)) 44 if (std::isnan(x) || std::isinf(x))
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (!source) { 100 if (!source) {
101 destination->zero(); 101 destination->zero();
102 return; 102 return;
103 } 103 }
104 104
105 // The audio thread can't block on this lock, so we call tryLock() instead. 105 // The audio thread can't block on this lock, so we call tryLock() instead.
106 MutexTryLocker tryLocker(m_processLock); 106 MutexTryLocker tryLocker(m_processLock);
107 MutexTryLocker tryListenerLocker(listener()->listenerLock()); 107 MutexTryLocker tryListenerLocker(listener()->listenerLock());
108 108
109 if (tryLocker.locked() && tryListenerLocker.locked()) { 109 if (tryLocker.locked() && tryListenerLocker.locked()) {
110 // HRTFDatabase should be loaded before proceeding for offline audio con text when the panning model is HRTF. 110 // HRTFDatabase should be loaded before proceeding when the panning mode l is HRTF.
111 if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDat abaseLoaded()) { 111 if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDat abaseLoaded()) {
112 if (context()->isOfflineContext()) { 112 if (context()->hasRealtimeConstraint()) {
113 listener()->waitForHRTFDatabaseLoaderThreadCompletion(); 113 // Some AbstractAudioContexts cannot block on the HRTFDatabase l oader.
114 } else {
115 destination->zero(); 114 destination->zero();
116 return; 115 return;
117 } 116 }
117
118 listener()->waitForHRTFDatabaseLoaderThreadCompletion();
118 } 119 }
119 120
120 // Apply the panning effect. 121 // Apply the panning effect.
121 double azimuth; 122 double azimuth;
122 double elevation; 123 double elevation;
123 azimuthElevation(&azimuth, &elevation); 124 azimuthElevation(&azimuth, &elevation);
124 125
125 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); 126 m_panner->pan(azimuth, elevation, source, destination, framesToProcess);
126 127
127 // Get the distance and cone gain. 128 // Get the distance and cone gain.
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (dirty & PannerHandler::DistanceConeGainDirty) 523 if (dirty & PannerHandler::DistanceConeGainDirty)
523 m_isDistanceConeGainDirty = true; 524 m_isDistanceConeGainDirty = true;
524 525
525 if (dirty & PannerHandler::DopplerRateDirty) 526 if (dirty & PannerHandler::DopplerRateDirty)
526 m_isDopplerRateDirty = true; 527 m_isDopplerRateDirty = true;
527 } 528 }
528 529
529 void PannerHandler::setChannelCount(unsigned long channelCount, ExceptionState& exceptionState) 530 void PannerHandler::setChannelCount(unsigned long channelCount, ExceptionState& exceptionState)
530 { 531 {
531 ASSERT(isMainThread()); 532 ASSERT(isMainThread());
532 AudioContext::AutoLocker locker(context()); 533 AbstractAudioContext::AutoLocker locker(context());
533 534
534 // A PannerNode only supports 1 or 2 channels 535 // A PannerNode only supports 1 or 2 channels
535 if (channelCount > 0 && channelCount <= 2) { 536 if (channelCount > 0 && channelCount <= 2) {
536 if (m_channelCount != channelCount) { 537 if (m_channelCount != channelCount) {
537 m_channelCount = channelCount; 538 m_channelCount = channelCount;
538 if (m_channelCountMode != Max) 539 if (m_channelCountMode != Max)
539 updateChannelsForInputs(); 540 updateChannelsForInputs();
540 } 541 }
541 } else { 542 } else {
542 exceptionState.throwDOMException( 543 exceptionState.throwDOMException(
543 NotSupportedError, 544 NotSupportedError,
544 ExceptionMessages::indexOutsideRange<unsigned long>( 545 ExceptionMessages::indexOutsideRange<unsigned long>(
545 "channelCount", 546 "channelCount",
546 channelCount, 547 channelCount,
547 1, 548 1,
548 ExceptionMessages::InclusiveBound, 549 ExceptionMessages::InclusiveBound,
549 2, 550 2,
550 ExceptionMessages::InclusiveBound)); 551 ExceptionMessages::InclusiveBound));
551 } 552 }
552 } 553 }
553 554
554 void PannerHandler::setChannelCountMode(const String& mode, ExceptionState& exce ptionState) 555 void PannerHandler::setChannelCountMode(const String& mode, ExceptionState& exce ptionState)
555 { 556 {
556 ASSERT(isMainThread()); 557 ASSERT(isMainThread());
557 AudioContext::AutoLocker locker(context()); 558 AbstractAudioContext::AutoLocker locker(context());
558 559
559 ChannelCountMode oldMode = m_channelCountMode; 560 ChannelCountMode oldMode = m_channelCountMode;
560 561
561 if (mode == "clamped-max") { 562 if (mode == "clamped-max") {
562 m_newChannelCountMode = ClampedMax; 563 m_newChannelCountMode = ClampedMax;
563 } else if (mode == "explicit") { 564 } else if (mode == "explicit") {
564 m_newChannelCountMode = Explicit; 565 m_newChannelCountMode = Explicit;
565 } else if (mode == "max") { 566 } else if (mode == "max") {
566 // This is not supported for a PannerNode, which can only handle 1 or 2 channels. 567 // This is not supported for a PannerNode, which can only handle 1 or 2 channels.
567 exceptionState.throwDOMException( 568 exceptionState.throwDOMException(
568 NotSupportedError, 569 NotSupportedError,
569 "Panner: 'max' is not allowed"); 570 "Panner: 'max' is not allowed");
570 m_newChannelCountMode = oldMode; 571 m_newChannelCountMode = oldMode;
571 } else { 572 } else {
572 // Do nothing for other invalid values. 573 // Do nothing for other invalid values.
573 m_newChannelCountMode = oldMode; 574 m_newChannelCountMode = oldMode;
574 } 575 }
575 576
576 if (m_newChannelCountMode != oldMode) 577 if (m_newChannelCountMode != oldMode)
577 context()->deferredTaskHandler().addChangedChannelCountMode(this); 578 context()->deferredTaskHandler().addChangedChannelCountMode(this);
578 } 579 }
579 580
580 // ---------------------------------------------------------------- 581 // ----------------------------------------------------------------
581 582
582 PannerNode::PannerNode(AudioContext& context, float sampelRate) 583 PannerNode::PannerNode(AbstractAudioContext& context, float sampelRate)
583 : AudioNode(context) 584 : AudioNode(context)
584 { 585 {
585 setHandler(PannerHandler::create(*this, sampelRate)); 586 setHandler(PannerHandler::create(*this, sampelRate));
586 } 587 }
587 588
588 PannerNode* PannerNode::create(AudioContext& context, float sampleRate) 589 PannerNode* PannerNode::create(AbstractAudioContext& context, float sampleRate)
589 { 590 {
590 return new PannerNode(context, sampleRate); 591 return new PannerNode(context, sampleRate);
591 } 592 }
592 593
593 PannerHandler& PannerNode::pannerHandler() const 594 PannerHandler& PannerNode::pannerHandler() const
594 { 595 {
595 return static_cast<PannerHandler&>(handler()); 596 return static_cast<PannerHandler&>(handler());
596 } 597 }
597 598
598 String PannerNode::panningModel() const 599 String PannerNode::panningModel() const
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 687 }
687 688
688 void PannerNode::setConeOuterGain(double gain) 689 void PannerNode::setConeOuterGain(double gain)
689 { 690 {
690 pannerHandler().setConeOuterGain(gain); 691 pannerHandler().setConeOuterGain(gain);
691 } 692 }
692 693
693 } // namespace blink 694 } // namespace blink
694 695
695 #endif // ENABLE(WEB_AUDIO) 696 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/PannerNode.h ('k') | Source/modules/webaudio/ScriptProcessorNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698