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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // duration. Otherwise, we want to use the user-specified value, of course. | 407 // duration. Otherwise, we want to use the user-specified value, of course. |
408 if (!m_isDurationGiven) | 408 if (!m_isDurationGiven) |
409 m_grainDuration = bufferDuration - m_grainOffset; | 409 m_grainDuration = bufferDuration - m_grainOffset; |
410 | 410 |
411 if (m_isDurationGiven && loop()) { | 411 if (m_isDurationGiven && loop()) { |
412 // We're looping a grain with a grain duration specified. Schedule the l
oop to stop after | 412 // We're looping a grain with a grain duration specified. Schedule the l
oop to stop after |
413 // grainDuration seconds after starting, possibly running the loop multi
ple times if | 413 // grainDuration seconds after starting, possibly running the loop multi
ple times if |
414 // grainDuration is larger than the buffer duration. The net effect is a
s if the user called | 414 // grainDuration is larger than the buffer duration. The net effect is a
s if the user called |
415 // stop(when + grainDuration). | 415 // stop(when + grainDuration). |
416 m_grainDuration = clampTo(m_grainDuration, 0.0, std::numeric_limits<doub
le>::infinity()); | 416 m_grainDuration = clampTo(m_grainDuration, 0.0, std::numeric_limits<doub
le>::infinity()); |
417 m_endTime = m_startTime + m_grainDuration; | 417 setEndTime(startTime() + m_grainDuration); |
418 } else { | 418 } else { |
419 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grain
Offset); | 419 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grain
Offset); |
420 } | 420 } |
421 | 421 |
422 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through | 422 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through |
423 // linear interpolation at a sub-sample position since it will degrade the q
uality. When | 423 // linear interpolation at a sub-sample position since it will degrade the q
uality. When |
424 // aligned to the sample-frame the playback will be identical to the PCM dat
a stored in the | 424 // aligned to the sample-frame the playback will be identical to the PCM dat
a stored in the |
425 // buffer. Since playbackRate == 1 is very common, it's worth considering qu
ality. | 425 // buffer. Since playbackRate == 1 is very common, it's worth considering qu
ality. |
426 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
->sampleRate()); | 426 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
->sampleRate()); |
427 } | 427 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 m_grainDuration = grainDuration; | 488 m_grainDuration = grainDuration; |
489 | 489 |
490 // The node is started. Add a reference to keep us alive so that audio | 490 // The node is started. Add a reference to keep us alive so that audio |
491 // will eventually get played even if Javascript should drop all references | 491 // will eventually get played even if Javascript should drop all references |
492 // to this node. The reference will get dropped when the source has finished | 492 // to this node. The reference will get dropped when the source has finished |
493 // playing. | 493 // playing. |
494 context()->notifySourceNodeStartedProcessing(node()); | 494 context()->notifySourceNodeStartedProcessing(node()); |
495 | 495 |
496 // If |when| < currentTime, the source must start now according to the spec. | 496 // If |when| < currentTime, the source must start now according to the spec. |
497 // So just set startTime to currentTime in this case to start the source now
. | 497 // So just set startTime to currentTime in this case to start the source now
. |
498 m_startTime = std::max(when, context()->currentTime()); | 498 setStartTime(std::max(when, context()->currentTime())); |
499 | 499 |
500 if (buffer()) | 500 if (buffer()) |
501 clampGrainParameters(buffer()); | 501 clampGrainParameters(buffer()); |
502 | 502 |
503 setPlaybackState(SCHEDULED_STATE); | 503 setPlaybackState(SCHEDULED_STATE); |
504 } | 504 } |
505 | 505 |
506 double AudioBufferSourceHandler::computePlaybackRate() | 506 double AudioBufferSourceHandler::computePlaybackRate() |
507 { | 507 { |
508 double dopplerRate = 1; | 508 double dopplerRate = 1; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 // would stop playing. This is intended to handle the (uncommon) scenario w
here start() has | 574 // would stop playing. This is intended to handle the (uncommon) scenario w
here start() has |
575 // been called but is never connected to the destination (directly or indire
ctly). By stopping | 575 // been called but is never connected to the destination (directly or indire
ctly). By stopping |
576 // the node, the node can be collected. Otherwise, the node will never get
collected, leaking | 576 // the node, the node can be collected. Otherwise, the node will never get
collected, leaking |
577 // memory. | 577 // memory. |
578 if (!loop() && buffer() && isPlayingOrScheduled() && m_minPlaybackRate > 0)
{ | 578 if (!loop() && buffer() && isPlayingOrScheduled() && m_minPlaybackRate > 0)
{ |
579 // Adjust the duration to include the playback rate. Only need to accoun
t for rate < 1 | 579 // Adjust the duration to include the playback rate. Only need to accoun
t for rate < 1 |
580 // which makes the sound last longer. For rate >= 1, the source stops s
ooner, but that's | 580 // which makes the sound last longer. For rate >= 1, the source stops s
ooner, but that's |
581 // ok. | 581 // ok. |
582 double actualDuration = buffer()->duration() / m_minPlaybackRate; | 582 double actualDuration = buffer()->duration() / m_minPlaybackRate; |
583 | 583 |
584 double stopTime = m_startTime + actualDuration; | 584 double stopTime = startTime() + actualDuration; |
585 | 585 |
586 // See crbug.com/478301. If a source node is started via start(), the so
urce may not start | 586 // See crbug.com/478301. If a source node is started via start(), the so
urce may not start |
587 // at that time but one quantum (128 frames) later. But we compute the
stop time based on | 587 // at that time but one quantum (128 frames) later. But we compute the
stop time based on |
588 // the start time and the duration, so we end up stopping one quantum ea
rly. Thus, add a | 588 // the start time and the duration, so we end up stopping one quantum ea
rly. Thus, add a |
589 // little extra time; we just need to stop the source sometime after it
should have stopped | 589 // little extra time; we just need to stop the source sometime after it
should have stopped |
590 // if it hadn't already. We don't need to be super precise on when to s
top. | 590 // if it hadn't already. We don't need to be super precise on when to s
top. |
591 double extraStopTime = kExtraStopFrames / static_cast<double>(context()-
>sampleRate()); | 591 double extraStopTime = kExtraStopFrames / static_cast<double>(context()-
>sampleRate()); |
592 | 592 |
593 stopTime += extraStopTime; | 593 stopTime += extraStopTime; |
594 if (context()->currentTime() > stopTime) { | 594 if (context()->currentTime() > stopTime) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 699 } |
700 | 700 |
701 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) | 701 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) |
702 { | 702 { |
703 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); | 703 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); |
704 } | 704 } |
705 | 705 |
706 } // namespace blink | 706 } // namespace blink |
707 | 707 |
708 #endif // ENABLE(WEB_AUDIO) | 708 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |