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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 397 } |
398 | 398 |
399 void AudioBufferSourceNode::clampGrainParameters(const AudioBuffer* buffer) | 399 void AudioBufferSourceNode::clampGrainParameters(const AudioBuffer* buffer) |
400 { | 400 { |
401 ASSERT(buffer); | 401 ASSERT(buffer); |
402 | 402 |
403 // We have a buffer so we can clip the offset and duration to lie within the
buffer. | 403 // We have a buffer so we can clip the offset and duration to lie within the
buffer. |
404 double bufferDuration = buffer->duration(); | 404 double bufferDuration = buffer->duration(); |
405 | 405 |
406 m_grainOffset = clampTo(m_grainOffset, 0.0, bufferDuration); | 406 m_grainOffset = clampTo(m_grainOffset, 0.0, bufferDuration); |
407 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grainOffs
et); | 407 |
| 408 if (loop()) { |
| 409 // We're looping a grain with a grain duration specified. Schedule the l
oop to stop after |
| 410 // grainDuration seconds after starting, possibly running the loop multi
ple times if |
| 411 // grainDuration is larger than the buffer duration. The net effect is a
s if the user called |
| 412 // stop(when + grainDuration). |
| 413 m_grainDuration = clampTo(m_grainDuration, 0.0, std::numeric_limits<doub
le>::infinity()); |
| 414 m_endTime = m_startTime + m_grainDuration; |
| 415 } else { |
| 416 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grain
Offset); |
| 417 } |
408 | 418 |
409 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through | 419 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through |
410 // linear interpolation at a sub-sample position since it will degrade the q
uality. When | 420 // linear interpolation at a sub-sample position since it will degrade the q
uality. When |
411 // aligned to the sample-frame the playback will be identical to the PCM dat
a stored in the | 421 // aligned to the sample-frame the playback will be identical to the PCM dat
a stored in the |
412 // buffer. Since playbackRate == 1 is very common, it's worth considering qu
ality. | 422 // buffer. Since playbackRate == 1 is very common, it's worth considering qu
ality. |
413 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
->sampleRate()); | 423 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
->sampleRate()); |
414 } | 424 } |
415 | 425 |
416 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) | 426 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) |
417 { | 427 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 exceptionState.throwDOMException( | 462 exceptionState.throwDOMException( |
453 InvalidStateError, | 463 InvalidStateError, |
454 "Duration must be a finite non-negative number: " + String::number(g
rainDuration)); | 464 "Duration must be a finite non-negative number: " + String::number(g
rainDuration)); |
455 return; | 465 return; |
456 } | 466 } |
457 | 467 |
458 m_isGrain = true; | 468 m_isGrain = true; |
459 m_grainOffset = grainOffset; | 469 m_grainOffset = grainOffset; |
460 m_grainDuration = grainDuration; | 470 m_grainDuration = grainDuration; |
461 | 471 |
| 472 m_startTime = when; |
| 473 |
462 if (buffer()) | 474 if (buffer()) |
463 clampGrainParameters(buffer()); | 475 clampGrainParameters(buffer()); |
464 | 476 |
465 m_startTime = when; | |
466 m_playbackState = SCHEDULED_STATE; | 477 m_playbackState = SCHEDULED_STATE; |
467 } | 478 } |
468 | 479 |
469 double AudioBufferSourceNode::totalPitchRate() | 480 double AudioBufferSourceNode::totalPitchRate() |
470 { | 481 { |
471 double dopplerRate = 1.0; | 482 double dopplerRate = 1.0; |
472 if (m_pannerNode) | 483 if (m_pannerNode) |
473 dopplerRate = m_pannerNode->dopplerRate(); | 484 dopplerRate = m_pannerNode->dopplerRate(); |
474 | 485 |
475 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 486 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 { | 543 { |
533 visitor->trace(m_buffer); | 544 visitor->trace(m_buffer); |
534 visitor->trace(m_playbackRate); | 545 visitor->trace(m_playbackRate); |
535 visitor->trace(m_pannerNode); | 546 visitor->trace(m_pannerNode); |
536 AudioScheduledSourceNode::trace(visitor); | 547 AudioScheduledSourceNode::trace(visitor); |
537 } | 548 } |
538 | 549 |
539 } // namespace blink | 550 } // namespace blink |
540 | 551 |
541 #endif // ENABLE(WEB_AUDIO) | 552 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |