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

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, 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 | 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 // normalize() does nothing if the length of |sourceListener| is zero.
389 // degenerate case if source and listener are at the same point
390 *outAzimuth = 0.0;
391 *outElevation = 0.0;
392 return;
393 }
394
395 sourceListener.normalize(); 389 sourceListener.normalize();
396 390
397 // Align axes 391 // Align axes
398 FloatPoint3D listenerFront = listener()->orientation(); 392 FloatPoint3D listenerFront = listener()->orientation();
399 FloatPoint3D listenerUp = listener()->upVector(); 393 FloatPoint3D listenerUp = listener()->upVector();
400 FloatPoint3D listenerRight = listenerFront.cross(listenerUp); 394 FloatPoint3D listenerRight = listenerFront.cross(listenerUp);
401 listenerRight.normalize(); 395 listenerRight.normalize();
402 396
403 FloatPoint3D listenerFrontNorm = listenerFront; 397 FloatPoint3D listenerFrontNorm = listenerFront;
404 listenerFrontNorm.normalize(); 398 listenerFrontNorm.normalize();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 bool sourceHasVelocity = !sourceVelocity.isZero(); 448 bool sourceHasVelocity = !sourceVelocity.isZero();
455 bool listenerHasVelocity = !listenerVelocity.isZero(); 449 bool listenerHasVelocity = !listenerVelocity.isZero();
456 450
457 if (sourceHasVelocity || listenerHasVelocity) { 451 if (sourceHasVelocity || listenerHasVelocity) {
458 // Calculate the source to listener vector 452 // Calculate the source to listener vector
459 FloatPoint3D listenerPosition = listener()->position(); 453 FloatPoint3D listenerPosition = listener()->position();
460 FloatPoint3D sourceToListener = m_position - listenerPosition; 454 FloatPoint3D sourceToListener = m_position - listenerPosition;
461 455
462 double sourceListenerMagnitude = sourceToListener.length(); 456 double sourceListenerMagnitude = sourceToListener.length();
463 457
464 double listenerProjection = sourceToListener.dot(listenerVelocity) / sourceListenerMagnitude; 458 if (!sourceListenerMagnitude) {
465 double sourceProjection = sourceToListener.dot(sourceVelocity) / sou rceListenerMagnitude; 459 // Source and listener are at the same position. Skip the comput ation of the doppler
460 // shift, and just return the cached value.
461 dopplerShift = m_cachedDopplerRate;
462 } else {
463 double listenerProjection = sourceToListener.dot(listenerVelocit y) / sourceListenerMagnitude;
464 double sourceProjection = sourceToListener.dot(sourceVelocity) / sourceListenerMagnitude;
466 465
467 listenerProjection = -listenerProjection; 466 listenerProjection = -listenerProjection;
468 sourceProjection = -sourceProjection; 467 sourceProjection = -sourceProjection;
469 468
470 double scaledSpeedOfSound = speedOfSound / dopplerFactor; 469 double scaledSpeedOfSound = speedOfSound / dopplerFactor;
471 listenerProjection = min(listenerProjection, scaledSpeedOfSound); 470 listenerProjection = min(listenerProjection, scaledSpeedOfSound) ;
472 sourceProjection = min(sourceProjection, scaledSpeedOfSound); 471 sourceProjection = min(sourceProjection, scaledSpeedOfSound);
473 472
474 dopplerShift = ((speedOfSound - dopplerFactor * listenerProjection) / (speedOfSound - dopplerFactor * sourceProjection)); 473 dopplerShift = ((speedOfSound - dopplerFactor * listenerProjecti on) / (speedOfSound - dopplerFactor * sourceProjection));
475 fixNANs(dopplerShift); // avoid illegal values 474 fixNANs(dopplerShift); // avoid illegal values
476 475
477 // Limit the pitch shifting to 4 octaves up and 3 octaves down. 476 // Limit the pitch shifting to 4 octaves up and 3 octaves down.
478 if (dopplerShift > 16.0) 477 if (dopplerShift > 16.0)
479 dopplerShift = 16.0; 478 dopplerShift = 16.0;
480 else if (dopplerShift < 0.125) 479 else if (dopplerShift < 0.125)
481 dopplerShift = 0.125; 480 dopplerShift = 0.125;
481 }
482 } 482 }
483 } 483 }
484 484
485 return dopplerShift; 485 return dopplerShift;
486 } 486 }
487 487
488 float PannerNode::calculateDistanceConeGain() 488 float PannerNode::calculateDistanceConeGain()
489 { 489 {
490 FloatPoint3D listenerPosition = listener()->position(); 490 FloatPoint3D listenerPosition = listener()->position();
491 491
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse 573 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse
574 } 574 }
575 } 575 }
576 } 576 }
577 } 577 }
578 } 578 }
579 579
580 } // namespace WebCore 580 } // namespace WebCore
581 581
582 #endif // ENABLE(WEB_AUDIO) 582 #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