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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 m_virtualReadIndex = 0; | 370 m_virtualReadIndex = 0; |
371 m_buffer = buffer; | 371 m_buffer = buffer; |
372 } | 372 } |
373 | 373 |
374 unsigned AudioBufferSourceNode::numberOfChannels() | 374 unsigned AudioBufferSourceNode::numberOfChannels() |
375 { | 375 { |
376 return output(0)->numberOfChannels(); | 376 return output(0)->numberOfChannels(); |
377 } | 377 } |
378 | 378 |
379 void AudioBufferSourceNode::start(ExceptionState& exceptionState) | |
380 { | |
381 startPlaying(false, 0, 0, buffer() ? buffer()->duration() : 0, exceptionStat
e); | |
382 } | |
383 | |
384 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) | 379 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) |
385 { | 380 { |
386 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0, exceptionS
tate); | 381 AudioScheduledSourceNode::start(when, exceptionState); |
387 } | 382 } |
388 | 383 |
389 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat
e& exceptionState) | 384 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat
e& exceptionState) |
390 { | 385 { |
391 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0, e
xceptionState); | 386 start(when, grainOffset, buffer() ? buffer()->duration() : 0, exceptionState
); |
392 } | 387 } |
393 | 388 |
394 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) | 389 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) |
395 { | 390 { |
396 startPlaying(true, when, grainOffset, grainDuration, exceptionState); | |
397 } | |
398 | |
399 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration, ExceptionState& exceptionState) | |
400 { | |
401 ASSERT(isMainThread()); | 391 ASSERT(isMainThread()); |
402 | 392 |
403 if (m_playbackState != UNSCHEDULED_STATE) { | 393 if (m_playbackState != UNSCHEDULED_STATE) { |
404 exceptionState.throwDOMException( | 394 exceptionState.throwDOMException( |
405 InvalidStateError, | 395 InvalidStateError, |
406 "cannot call start more than once."); | 396 "cannot call start more than once."); |
407 return; | 397 return; |
408 } | 398 } |
409 | 399 |
410 if (!buffer()) | 400 if (!buffer()) |
411 return; | 401 return; |
412 | 402 |
413 if (isGrain) { | 403 // Do sanity checking of grain parameters versus buffer size. |
414 // Do sanity checking of grain parameters versus buffer size. | 404 double bufferDuration = buffer()->duration(); |
415 double bufferDuration = buffer()->duration(); | |
416 | 405 |
417 grainOffset = max(0.0, grainOffset); | 406 grainOffset = max(0.0, grainOffset); |
418 grainOffset = min(bufferDuration, grainOffset); | 407 grainOffset = min(bufferDuration, grainOffset); |
419 m_grainOffset = grainOffset; | 408 m_grainOffset = grainOffset; |
420 | 409 |
421 double maxDuration = bufferDuration - grainOffset; | 410 double maxDuration = bufferDuration - grainOffset; |
422 | 411 |
423 grainDuration = max(0.0, grainDuration); | 412 grainDuration = max(0.0, grainDuration); |
424 grainDuration = min(maxDuration, grainDuration); | 413 grainDuration = min(maxDuration, grainDuration); |
425 m_grainDuration = grainDuration; | 414 m_grainDuration = grainDuration; |
426 } | |
427 | 415 |
428 m_isGrain = isGrain; | 416 m_isGrain = true; |
429 m_startTime = when; | 417 m_startTime = when; |
430 | 418 |
431 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation | 419 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation |
432 // at a sub-sample position since it will degrade the quality. | 420 // at a sub-sample position since it will degrade the quality. |
433 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. | 421 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. |
434 // Since playbackRate == 1 is very common, it's worth considering quality. | 422 // Since playbackRate == 1 is very common, it's worth considering quality. |
435 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); | 423 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); |
436 | 424 |
437 m_playbackState = SCHEDULED_STATE; | 425 m_playbackState = SCHEDULED_STATE; |
438 } | 426 } |
439 | 427 |
440 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double
grainDuration, ExceptionState& exceptionState) | 428 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double
grainDuration, ExceptionState& exceptionState) |
441 { | 429 { |
442 // Handle unspecified duration where 0 means the rest of the buffer. | 430 // Handle unspecified duration where 0 means the rest of the buffer. |
443 if (!grainDuration && buffer()) | 431 if (!grainDuration && buffer()) |
444 grainDuration = buffer()->duration(); | 432 grainDuration = buffer()->duration(); |
445 startPlaying(true, when, grainOffset, grainDuration, exceptionState); | 433 start(when, grainOffset, grainDuration, exceptionState); |
446 } | 434 } |
447 | 435 |
448 double AudioBufferSourceNode::totalPitchRate() | 436 double AudioBufferSourceNode::totalPitchRate() |
449 { | 437 { |
450 double dopplerRate = 1.0; | 438 double dopplerRate = 1.0; |
451 if (m_pannerNode) | 439 if (m_pannerNode) |
452 dopplerRate = m_pannerNode->dopplerRate(); | 440 dopplerRate = m_pannerNode->dopplerRate(); |
453 | 441 |
454 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 442 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. |
455 // Normally it's not an issue because buffers are loaded at the AudioContext
's sample-rate, but we can handle it in any case. | 443 // Normally it's not an issue because buffers are loaded at the AudioContext
's sample-rate, but we can handle it in any case. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 void AudioBufferSourceNode::finish() | 491 void AudioBufferSourceNode::finish() |
504 { | 492 { |
505 clearPannerNode(); | 493 clearPannerNode(); |
506 ASSERT(!m_pannerNode); | 494 ASSERT(!m_pannerNode); |
507 AudioScheduledSourceNode::finish(); | 495 AudioScheduledSourceNode::finish(); |
508 } | 496 } |
509 | 497 |
510 } // namespace WebCore | 498 } // namespace WebCore |
511 | 499 |
512 #endif // ENABLE(WEB_AUDIO) | 500 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |