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