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

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

Issue 301733002: Make panner's doppler rate continuous as the source position approaches the listener position. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | « no previous file | 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 378 }
379 379
380 void PannerNode::calculateAzimuthElevation(double* outAzimuth, double* outElevat ion) 380 void PannerNode::calculateAzimuthElevation(double* outAzimuth, double* outElevat ion)
381 { 381 {
382 double azimuth = 0.0; 382 double azimuth = 0.0;
383 383
384 // Calculate the source-listener vector 384 // Calculate the source-listener vector
385 FloatPoint3D listenerPosition = listener()->position(); 385 FloatPoint3D listenerPosition = listener()->position();
386 FloatPoint3D sourceListener = m_position - listenerPosition; 386 FloatPoint3D sourceListener = m_position - listenerPosition;
387 387
388 if (sourceListener.isZero()) { 388 if (sourceListener.isZero()) {
KhNo 2014/05/28 13:57:20 How do you think if we remove line from 388 to 394
Raymond Toy 2014/05/28 17:19:16 I think sourceListener.normalize() will fail (retu
Raymond Toy 2014/05/28 18:25:26 Oh, wait. normalize() does nothing if the length
Raymond Toy 2014/05/29 18:22:13 This is ok. The special case is removed.
389 // degenerate case if source and listener are at the same point 389 // Degenerate case if source and listener are at the same point. To pres erve continuity,
Ken Russell (switch to Gerrit) 2014/05/27 23:24:43 Comparing against zero seems fragile. You're the e
Raymond Toy 2014/05/28 17:17:22 I think this is ok here. If it's not zero, sourceL
390 *outAzimuth = 0.0; 390 // don't change anything; just use the cached values.
391 *outElevation = 0.0; 391 *outAzimuth = m_cachedAzimuth;
392 *outElevation = m_cachedElevation;
392 return; 393 return;
393 } 394 }
394 395
395 sourceListener.normalize(); 396 sourceListener.normalize();
396 397
397 // Align axes 398 // Align axes
398 FloatPoint3D listenerFront = listener()->orientation(); 399 FloatPoint3D listenerFront = listener()->orientation();
399 FloatPoint3D listenerUp = listener()->upVector(); 400 FloatPoint3D listenerUp = listener()->upVector();
400 FloatPoint3D listenerRight = listenerFront.cross(listenerUp); 401 FloatPoint3D listenerRight = listenerFront.cross(listenerUp);
401 listenerRight.normalize(); 402 listenerRight.normalize();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 bool sourceHasVelocity = !sourceVelocity.isZero(); 455 bool sourceHasVelocity = !sourceVelocity.isZero();
455 bool listenerHasVelocity = !listenerVelocity.isZero(); 456 bool listenerHasVelocity = !listenerVelocity.isZero();
456 457
457 if (sourceHasVelocity || listenerHasVelocity) { 458 if (sourceHasVelocity || listenerHasVelocity) {
458 // Calculate the source to listener vector 459 // Calculate the source to listener vector
459 FloatPoint3D listenerPosition = listener()->position(); 460 FloatPoint3D listenerPosition = listener()->position();
460 FloatPoint3D sourceToListener = m_position - listenerPosition; 461 FloatPoint3D sourceToListener = m_position - listenerPosition;
461 462
462 double sourceListenerMagnitude = sourceToListener.length(); 463 double sourceListenerMagnitude = sourceToListener.length();
463 464
464 double listenerProjection = sourceToListener.dot(listenerVelocity) / sourceListenerMagnitude; 465 if (!sourceListenerMagnitude) {
Ken Russell (switch to Gerrit) 2014/05/27 23:24:43 Same comment here.
Raymond Toy 2014/05/28 17:17:22 I believe this is ok here too. It's only a proble
465 double sourceProjection = sourceToListener.dot(sourceVelocity) / sou rceListenerMagnitude; 466 // Source and listener are at the same position. Skip the comput ation of the doppler
467 // shift, and just return the cached value.
468 dopplerShift = m_cachedDopplerRate;
469 } else {
470 double listenerProjection = sourceToListener.dot(listenerVelocit y) / sourceListenerMagnitude;
471 double sourceProjection = sourceToListener.dot(sourceVelocity) / sourceListenerMagnitude;
466 472
467 listenerProjection = -listenerProjection; 473 listenerProjection = -listenerProjection;
468 sourceProjection = -sourceProjection; 474 sourceProjection = -sourceProjection;
469 475
470 double scaledSpeedOfSound = speedOfSound / dopplerFactor; 476 double scaledSpeedOfSound = speedOfSound / dopplerFactor;
471 listenerProjection = min(listenerProjection, scaledSpeedOfSound); 477 listenerProjection = min(listenerProjection, scaledSpeedOfSound) ;
472 sourceProjection = min(sourceProjection, scaledSpeedOfSound); 478 sourceProjection = min(sourceProjection, scaledSpeedOfSound);
473 479
474 dopplerShift = ((speedOfSound - dopplerFactor * listenerProjection) / (speedOfSound - dopplerFactor * sourceProjection)); 480 dopplerShift = ((speedOfSound - dopplerFactor * listenerProjecti on) / (speedOfSound - dopplerFactor * sourceProjection));
475 fixNANs(dopplerShift); // avoid illegal values 481 fixNANs(dopplerShift); // avoid illegal values
476 482
477 // Limit the pitch shifting to 4 octaves up and 3 octaves down. 483 // Limit the pitch shifting to 4 octaves up and 3 octaves down.
478 if (dopplerShift > 16.0) 484 if (dopplerShift > 16.0)
479 dopplerShift = 16.0; 485 dopplerShift = 16.0;
480 else if (dopplerShift < 0.125) 486 else if (dopplerShift < 0.125)
481 dopplerShift = 0.125; 487 dopplerShift = 0.125;
488 }
482 } 489 }
483 } 490 }
484 491
485 return dopplerShift; 492 return dopplerShift;
486 } 493 }
487 494
488 float PannerNode::calculateDistanceConeGain() 495 float PannerNode::calculateDistanceConeGain()
489 { 496 {
490 FloatPoint3D listenerPosition = listener()->position(); 497 FloatPoint3D listenerPosition = listener()->position();
491 498
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse 580 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse
574 } 581 }
575 } 582 }
576 } 583 }
577 } 584 }
578 } 585 }
579 586
580 } // namespace WebCore 587 } // namespace WebCore
581 588
582 #endif // ENABLE(WEB_AUDIO) 589 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698