| 412 | } |
| 413 | |
| 414 | float PannerNode::dopplerRate(ContextRenderLock & r) |
| 415 | { |
| 416 | double dopplerShift = 1.0; |
| 417 | |
| 418 | auto listener = r.context()->listener(); |
| 419 | |
| 420 | // FIXME: optimize for case when neither source nor listener has changed... |
| 421 | /// @fixme these values should be per sample, not per quantum |
| 422 | double dopplerFactor = listener->dopplerFactor()->value(); |
| 423 | |
| 424 | if (dopplerFactor > 0.0) |
| 425 | { |
| 426 | /// @fixme should be a setting |
| 427 | double speedOfSound = listener->speedOfSound()->value(); |
| 428 | |
| 429 | /// @fixme these values should be per sample, not per quantum |
| 430 | const FloatPoint3D sourceVelocity = { |
| 431 | velocityX()->value(), |
| 432 | velocityY()->value(), |
| 433 | velocityZ()->value()}; |
| 434 | /// @fixme these values should be per sample, not per quantum |
| 435 | const FloatPoint3D listenerVelocity = { |
| 436 | listener->velocityX()->value(), |
| 437 | listener->velocityY()->value(), |
| 438 | listener->velocityZ()->value()}; |
| 439 | |
| 440 | // Don't bother if both source and listener have no velocity |
| 441 | bool sourceHasVelocity = !is_zero(sourceVelocity); |
| 442 | bool listenerHasVelocity = !is_zero(listenerVelocity); |
| 443 | |
| 444 | if (sourceHasVelocity || listenerHasVelocity) |
| 445 | { |
| 446 | // Calculate the source to listener vector |
| 447 | /// @fixme these values should be per sample, not per quantum |
| 448 | FloatPoint3D listenerPosition = { |
| 449 | listener->positionX()->value(), |
| 450 | listener->positionY()->value(), |
| 451 | listener->positionZ()->value()}; |
| 452 | |
| 453 | /// @fixme these values should be per sample, not per quantum |
| 454 | FloatPoint3D sourceToListener = { |
| 455 | positionX()->value(), |
| 456 | positionY()->value(), |
| 457 | positionZ()->value()}; |
| 458 | |
| 459 | sourceToListener = sourceToListener - listenerPosition; |
| 460 | |
| 461 | double sourceListenerMagnitude = magnitude(sourceToListener); |
| 462 | |
| 463 | double listenerProjection = dot(sourceToListener, listenerVelocity) / sourceListenerMagnitude; |
| 464 | double sourceProjection = dot(sourceToListener, sourceVelocity) / sourceListenerMagnitude; |
| 465 | |
| 466 | listenerProjection = -listenerProjection; |
| 467 | sourceProjection = -sourceProjection; |
| 468 | |
| 469 | double scaledSpeedOfSound = speedOfSound / dopplerFactor; |
| 470 | listenerProjection = min(listenerProjection, scaledSpeedOfSound); |
| 471 | sourceProjection = min(sourceProjection, scaledSpeedOfSound); |
nothing calls this directly
no test coverage detected