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 10 matching lines...) Expand all Loading... |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/AudioBufferSourceNode.h" | 29 #include "modules/webaudio/AudioBufferSourceNode.h" |
30 | 30 |
| 31 #include "bindings/v8/ExceptionMessages.h" |
31 #include "bindings/v8/ExceptionState.h" | 32 #include "bindings/v8/ExceptionState.h" |
| 33 #include "core/dom/ExceptionCode.h" |
32 #include "core/page/PageConsole.h" | 34 #include "core/page/PageConsole.h" |
33 #include "platform/audio/AudioUtilities.h" | 35 #include "platform/audio/AudioUtilities.h" |
34 #include "modules/webaudio/AudioContext.h" | 36 #include "modules/webaudio/AudioContext.h" |
35 #include "modules/webaudio/AudioNodeOutput.h" | 37 #include "modules/webaudio/AudioNodeOutput.h" |
36 #include "platform/FloatConversion.h" | 38 #include "platform/FloatConversion.h" |
37 #include "wtf/MainThread.h" | 39 #include "wtf/MainThread.h" |
38 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
39 #include <algorithm> | 41 #include <algorithm> |
40 | 42 |
41 using namespace std; | 43 using namespace std; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 376 |
375 m_virtualReadIndex = 0; | 377 m_virtualReadIndex = 0; |
376 m_buffer = buffer; | 378 m_buffer = buffer; |
377 } | 379 } |
378 | 380 |
379 unsigned AudioBufferSourceNode::numberOfChannels() | 381 unsigned AudioBufferSourceNode::numberOfChannels() |
380 { | 382 { |
381 return output(0)->numberOfChannels(); | 383 return output(0)->numberOfChannels(); |
382 } | 384 } |
383 | 385 |
384 void AudioBufferSourceNode::start(double when) | 386 void AudioBufferSourceNode::start(ExceptionState& es) |
385 { | 387 { |
386 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0); | 388 startPlaying(false, 0, 0, buffer() ? buffer()->duration() : 0, es); |
387 } | 389 } |
388 | 390 |
389 void AudioBufferSourceNode::start(double when, double grainOffset) | 391 void AudioBufferSourceNode::start(double when, ExceptionState& es) |
390 { | 392 { |
391 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0); | 393 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0, es); |
392 } | 394 } |
393 | 395 |
394 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration) | 396 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat
e& es) |
395 { | 397 { |
396 startPlaying(true, when, grainOffset, grainDuration); | 398 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0, e
s); |
| 399 } |
| 400 |
| 401 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& es) |
| 402 { |
| 403 startPlaying(true, when, grainOffset, grainDuration, es); |
| 404 } |
| 405 |
| 406 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration, ExceptionState& es) |
| 407 { |
| 408 if (m_playbackState != UNSCHEDULED_STATE) { |
| 409 es.throwDOMException( |
| 410 InvalidStateError, |
| 411 ExceptionMessages::failedToExecute( |
| 412 "start", |
| 413 nodeTypeName(), |
| 414 "cannot call start more than once.")); |
| 415 return; |
| 416 } |
| 417 startPlaying(isGrain, when, grainOffset, grainDuration); |
397 } | 418 } |
398 | 419 |
399 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration) | 420 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration) |
400 { | 421 { |
401 ASSERT(isMainThread()); | 422 ASSERT(isMainThread()); |
402 | 423 |
403 if (m_playbackState != UNSCHEDULED_STATE) | 424 if (m_playbackState != UNSCHEDULED_STATE) |
404 return; | 425 return; |
405 | 426 |
406 if (!buffer()) | 427 if (!buffer()) |
407 return; | 428 return; |
408 | 429 |
409 if (isGrain) { | 430 if (isGrain) { |
410 // Do sanity checking of grain parameters versus buffer size. | 431 // Do sanity checking of grain parameters versus buffer size. |
411 double bufferDuration = buffer()->duration(); | 432 double bufferDuration = buffer()->duration(); |
412 | 433 |
413 grainOffset = max(0.0, grainOffset); | 434 grainOffset = max(0.0, grainOffset); |
414 grainOffset = min(bufferDuration, grainOffset); | 435 grainOffset = min(bufferDuration, grainOffset); |
415 m_grainOffset = grainOffset; | 436 m_grainOffset = grainOffset; |
416 | 437 |
417 double maxDuration = bufferDuration - grainOffset; | 438 double maxDuration = bufferDuration - grainOffset; |
418 | 439 |
419 grainDuration = max(0.0, grainDuration); | 440 grainDuration = max(0.0, grainDuration); |
420 grainDuration = min(maxDuration, grainDuration); | 441 grainDuration = min(maxDuration, grainDuration); |
421 m_grainDuration = grainDuration; | 442 m_grainDuration = grainDuration; |
422 | |
423 } else { | |
424 // Until crbug.com/306139 is implemented, we initialize m_grainOffset an
d m_grainDuration | |
425 // again. | |
426 m_grainOffset = 0.0; | |
427 m_grainDuration = DefaultGrainDuration; | |
428 } | 443 } |
429 | 444 |
430 m_isGrain = isGrain; | 445 m_isGrain = isGrain; |
431 m_startTime = when; | 446 m_startTime = when; |
432 | 447 |
433 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation | 448 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation |
434 // at a sub-sample position since it will degrade the quality. | 449 // at a sub-sample position since it will degrade the quality. |
435 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. | 450 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. |
436 // Since playbackRate == 1 is very common, it's worth considering quality. | 451 // Since playbackRate == 1 is very common, it's worth considering quality. |
437 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); | 452 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 void AudioBufferSourceNode::finish() | 520 void AudioBufferSourceNode::finish() |
506 { | 521 { |
507 clearPannerNode(); | 522 clearPannerNode(); |
508 ASSERT(!m_pannerNode); | 523 ASSERT(!m_pannerNode); |
509 AudioScheduledSourceNode::finish(); | 524 AudioScheduledSourceNode::finish(); |
510 } | 525 } |
511 | 526 |
512 } // namespace WebCore | 527 } // namespace WebCore |
513 | 528 |
514 #endif // ENABLE(WEB_AUDIO) | 529 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |