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

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

Issue 2012773005: Simplify notification of a dirty listener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PannerNode.h ('k') | no next file » | 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (hasSampleAccurateValues() || listener()->hasSampleAccurateValues()) { 141 if (hasSampleAccurateValues() || listener()->hasSampleAccurateValues()) {
142 // It's tempting to skip sample-accurate processing if isAzimuthElev ationDirty() and 142 // It's tempting to skip sample-accurate processing if isAzimuthElev ationDirty() and
143 // isDistanceConeGain() both return false. But in general we can't because something 143 // isDistanceConeGain() both return false. But in general we can't because something
144 // may scheduled to start in the middle of the rendering quantum. O n the other hand, 144 // may scheduled to start in the middle of the rendering quantum. O n the other hand,
145 // the audible effect may be small enough that we can afford to do t his optimization. 145 // the audible effect may be small enough that we can afford to do t his optimization.
146 processSampleAccurateValues(destination, source, framesToProcess); 146 processSampleAccurateValues(destination, source, framesToProcess);
147 } else { 147 } else {
148 // Apply the panning effect. 148 // Apply the panning effect.
149 double azimuth; 149 double azimuth;
150 double elevation; 150 double elevation;
151
152 // Update dirty state in case something has moved; this can happen i f the AudioParam for
153 // the position or orientation component is set directly.
154 updateDirtyState();
155
151 azimuthElevation(&azimuth, &elevation); 156 azimuthElevation(&azimuth, &elevation);
152 157
153 m_panner->pan(azimuth, elevation, source, destination, framesToProce ss); 158 m_panner->pan(azimuth, elevation, source, destination, framesToProce ss);
154 159
155 // Get the distance and cone gain. 160 // Get the distance and cone gain.
156 float totalGain = distanceConeGain(); 161 float totalGain = distanceConeGain();
157 162
158 m_lastGain = totalGain; 163 m_lastGain = totalGain;
159 164
160 // Apply gain in-place with de-zippering. 165 // Apply gain in-place with de-zippering.
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 double distanceGain = m_distanceEffect.gain(listenerDistance); 505 double distanceGain = m_distanceEffect.gain(listenerDistance);
501 double coneGain = m_coneEffect.gain(position, orientation, listenerPosition) ; 506 double coneGain = m_coneEffect.gain(position, orientation, listenerPosition) ;
502 507
503 return float(distanceGain * coneGain); 508 return float(distanceGain * coneGain);
504 } 509 }
505 510
506 void PannerHandler::azimuthElevation(double* outAzimuth, double* outElevation) 511 void PannerHandler::azimuthElevation(double* outAzimuth, double* outElevation)
507 { 512 {
508 ASSERT(context()->isAudioThread()); 513 ASSERT(context()->isAudioThread());
509 514
510 if (isAzimuthElevationDirty()) { 515 // Calculate new azimuth and elevation if the panner or the listener changed
516 // position or orientation in any way.
517 if (isAzimuthElevationDirty() || listener()->isListenerDirty()) {
511 calculateAzimuthElevation( 518 calculateAzimuthElevation(
512 &m_cachedAzimuth, 519 &m_cachedAzimuth,
513 &m_cachedElevation, 520 &m_cachedElevation,
514 position(), 521 position(),
515 listener()->position(), 522 listener()->position(),
516 listener()->orientation(), 523 listener()->orientation(),
517 listener()->upVector()); 524 listener()->upVector());
518 m_isAzimuthElevationDirty = false; 525 m_isAzimuthElevationDirty = false;
519 } 526 }
520 527
521 *outAzimuth = m_cachedAzimuth; 528 *outAzimuth = m_cachedAzimuth;
522 *outElevation = m_cachedElevation; 529 *outElevation = m_cachedElevation;
523 } 530 }
524 531
525 float PannerHandler::distanceConeGain() 532 float PannerHandler::distanceConeGain()
526 { 533 {
527 ASSERT(context()->isAudioThread()); 534 ASSERT(context()->isAudioThread());
528 535
529 if (isDistanceConeGainDirty()) { 536 // Calculate new distance and cone gain if the panner or the listener
537 // changed position or orientation in any way.
538 if (isDistanceConeGainDirty() || listener()->isListenerDirty()) {
530 m_cachedDistanceConeGain = calculateDistanceConeGain(position(), orienta tion(), listener()->position()); 539 m_cachedDistanceConeGain = calculateDistanceConeGain(position(), orienta tion(), listener()->position());
531 m_isDistanceConeGainDirty = false; 540 m_isDistanceConeGainDirty = false;
532 } 541 }
533 542
534 return m_cachedDistanceConeGain; 543 return m_cachedDistanceConeGain;
535 } 544 }
536 545
537 void PannerHandler::markPannerAsDirty(unsigned dirty) 546 void PannerHandler::markPannerAsDirty(unsigned dirty)
538 { 547 {
539 if (dirty & PannerHandler::AzimuthElevationDirty) 548 if (dirty & PannerHandler::AzimuthElevationDirty)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 return m_positionX->hasSampleAccurateValues() 608 return m_positionX->hasSampleAccurateValues()
600 || m_positionY->hasSampleAccurateValues() 609 || m_positionY->hasSampleAccurateValues()
601 || m_positionZ->hasSampleAccurateValues() 610 || m_positionZ->hasSampleAccurateValues()
602 || m_orientationX->hasSampleAccurateValues() 611 || m_orientationX->hasSampleAccurateValues()
603 || m_orientationY->hasSampleAccurateValues() 612 || m_orientationY->hasSampleAccurateValues()
604 || m_orientationZ->hasSampleAccurateValues(); 613 || m_orientationZ->hasSampleAccurateValues();
605 } 614 }
606 615
607 void PannerHandler::updateDirtyState() 616 void PannerHandler::updateDirtyState()
608 { 617 {
618 DCHECK(context()->isAudioThread());
619
609 FloatPoint3D currentPosition = position(); 620 FloatPoint3D currentPosition = position();
610 FloatPoint3D currentOrientation = orientation(); 621 FloatPoint3D currentOrientation = orientation();
611 622
612 bool hasMoved = currentPosition != m_lastPosition 623 bool hasMoved = currentPosition != m_lastPosition
613 || currentOrientation != m_lastOrientation; 624 || currentOrientation != m_lastOrientation;
614 625
615 if (hasMoved) { 626 if (hasMoved) {
616 m_lastPosition = currentPosition; 627 m_lastPosition = currentPosition;
617 m_lastOrientation = currentOrientation; 628 m_lastOrientation = currentOrientation;
618 629
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 visitor->trace(m_positionZ); 765 visitor->trace(m_positionZ);
755 766
756 visitor->trace(m_orientationX); 767 visitor->trace(m_orientationX);
757 visitor->trace(m_orientationY); 768 visitor->trace(m_orientationY);
758 visitor->trace(m_orientationZ); 769 visitor->trace(m_orientationZ);
759 770
760 AudioNode::trace(visitor); 771 AudioNode::trace(visitor);
761 } 772 }
762 773
763 } // namespace blink 774 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PannerNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698