OLD | NEW |
---|---|
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 double AudioBufferSourceHandler::computePlaybackRate() | 482 double AudioBufferSourceHandler::computePlaybackRate() |
483 { | 483 { |
484 double dopplerRate = 1.0; | 484 double dopplerRate = 1.0; |
485 if (m_pannerNode) | 485 if (m_pannerNode) |
486 dopplerRate = m_pannerNode->dopplerRate(); | 486 dopplerRate = m_pannerNode->dopplerRate(); |
487 | 487 |
488 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 488 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. |
489 // Normally it's not an issue because buffers are loaded at the | 489 // Normally it's not an issue because buffers are loaded at the |
490 // AudioContext's sample-rate, but we can handle it in any case. | 490 // AudioContext's sample-rate, but we can handle it in any case. |
491 double sampleRateFactor = 1.0; | 491 double sampleRateFactor = 1.0; |
492 if (buffer()) | 492 if (buffer()) { |
493 sampleRateFactor = buffer()->sampleRate() / sampleRate(); | 493 // Use doubles to compute this to full accuracy. |
494 sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRa te()); | |
495 } | |
494 | 496 |
495 // Use finalValue() to incorporate changes of AudioParamTimeline and | 497 // Use finalValue() to incorporate changes of AudioParamTimeline and |
496 // AudioSummingJunction from m_playbackRate AudioParam. | 498 // AudioSummingJunction from m_playbackRate AudioParam. |
497 double basePlaybackRate = m_playbackRate->finalValue(); | 499 double basePlaybackRate = m_playbackRate->finalValue(); |
498 | 500 |
499 double finalPlaybackRate = dopplerRate * sampleRateFactor * basePlaybackRate ; | 501 double finalPlaybackRate = dopplerRate * sampleRateFactor * basePlaybackRate ; |
500 | 502 |
501 // Sanity check the total rate. It's very important that the resampler not | 503 // Sanity check the total rate. It's very important that the resampler not |
502 // get any bad rate values. | 504 // get any bad rate values. |
503 finalPlaybackRate = clampTo(finalPlaybackRate, 0.0, MaxRate); | 505 finalPlaybackRate = clampTo(finalPlaybackRate, 0.0, MaxRate); |
(...skipping 30 matching lines...) Expand all Loading... | |
534 m_pannerNode->breakConnection(); | 536 m_pannerNode->breakConnection(); |
535 m_pannerNode.clear(); | 537 m_pannerNode.clear(); |
536 } | 538 } |
537 } | 539 } |
538 | 540 |
539 void AudioBufferSourceHandler::handleStoppableSourceNode() | 541 void AudioBufferSourceHandler::handleStoppableSourceNode() |
540 { | 542 { |
541 // If the source node is not looping, and we have a buffer, we can determine when the | 543 // If the source node is not looping, and we have a buffer, we can determine when the |
542 // source would stop playing. | 544 // source would stop playing. |
543 if (!loop() && buffer() && isPlayingOrScheduled()) { | 545 if (!loop() && buffer() && isPlayingOrScheduled()) { |
544 double stopTime = m_startTime + buffer()->duration(); | 546 // See crbug.com/478301. If a source node is started via start(), the so urce won't start at |
547 // that time but one quantum (128 frames) later. But we compute the sto p time based on the | |
548 // start time and the duration, so we end up stopping one quantum too ea rly. Thus, add one | |
hongchan
2015/04/21 21:39:08
I think 'one quantum early' reads better.
Raymond Toy
2015/04/21 22:00:05
Done.
| |
549 // quantum to the stop time. Then add one more just for good measure; w e don't need to be | |
550 // extra precise here. We just need to stop the source sometime after i t should have | |
551 // stopped if it hadn't already. | |
552 // FIXME: Expose the rendering quantom somehow instead of hardwiring a v alue here. | |
hongchan
2015/04/21 21:39:08
quantom -> quantum
Raymond Toy
2015/04/21 22:00:05
Done.
| |
553 double extraStopTime = 256 / static_cast<double>(context()->sampleRate() ); | |
hongchan
2015/04/21 21:39:08
Can we use an extra variable for '256' at the top
Raymond Toy
2015/04/21 22:00:05
Done.
| |
554 double stopTime = m_startTime + buffer()->duration() + extraStopTime; | |
555 | |
545 if (context()->currentTime() > stopTime) { | 556 if (context()->currentTime() > stopTime) { |
546 // The context time has passed the time when the source nodes should have stopped | 557 // The context time has passed the time when the source nodes should have stopped |
547 // playing. Stop the node now and deref it. (But don't run the onEnd ed event because the | 558 // playing. Stop the node now and deref it. (But don't run the onEnd ed event because the |
548 // source never actually played.) | 559 // source never actually played.) |
549 finishWithoutOnEnded(); | 560 finishWithoutOnEnded(); |
550 } | 561 } |
551 } | 562 } |
552 } | 563 } |
553 | 564 |
554 void AudioBufferSourceHandler::finish() | 565 void AudioBufferSourceHandler::finish() |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 } | 654 } |
644 | 655 |
645 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState) | 656 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState) |
646 { | 657 { |
647 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State); | 658 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State); |
648 } | 659 } |
649 | 660 |
650 } // namespace blink | 661 } // namespace blink |
651 | 662 |
652 #endif // ENABLE(WEB_AUDIO) | 663 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |