Chromium Code Reviews| 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 start(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 start(when, grainOffset, buffer()->duration() - grainOffset); | |
| 392 } | |
| 393 | |
| 394 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration) | |
| 391 { | 395 { |
| 392 ASSERT(isMainThread()); | 396 ASSERT(isMainThread()); |
| 393 | 397 |
| 394 if (m_playbackState != UNSCHEDULED_STATE) | 398 if (m_playbackState != UNSCHEDULED_STATE) |
| 395 return; | 399 return; |
| 396 | 400 |
| 397 if (!buffer()) | 401 if (!buffer()) |
| 398 return; | 402 return; |
| 399 | 403 |
| 400 // Do sanity checking of grain parameters versus buffer size. | 404 // Do sanity checking of grain parameters versus buffer size. |
| 401 double bufferDuration = buffer()->duration(); | 405 double bufferDuration = buffer()->duration(); |
| 402 | 406 |
| 403 grainOffset = max(0.0, grainOffset); | 407 grainOffset = max(0.0, grainOffset); |
| 404 grainOffset = min(bufferDuration, grainOffset); | 408 grainOffset = min(bufferDuration, grainOffset); |
| 405 m_grainOffset = grainOffset; | 409 m_grainOffset = grainOffset; |
| 406 | 410 |
| 407 // Handle default/unspecified duration. | |
| 408 double maxDuration = bufferDuration - grainOffset; | 411 double maxDuration = bufferDuration - grainOffset; |
| 409 if (!grainDuration) | |
| 410 grainDuration = maxDuration; | |
| 411 | 412 |
| 412 grainDuration = max(0.0, grainDuration); | 413 grainDuration = max(0.0, grainDuration); |
| 413 grainDuration = min(maxDuration, grainDuration); | 414 grainDuration = min(maxDuration, grainDuration); |
| 414 m_grainDuration = grainDuration; | 415 m_grainDuration = grainDuration; |
| 415 | 416 |
| 416 m_isGrain = true; | 417 // Make this a grain if we're not playing the entire buffer. |
| 418 m_isGrain = m_grainOffset || m_grainDuration != bufferDuration; | |
|
Ken Russell (switch to Gerrit)
2013/10/28 21:32:30
The == comparison with bufferDuration seems like i
| |
| 417 m_startTime = when; | 419 m_startTime = when; |
| 418 | 420 |
| 419 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t o go through linear interpolation | 421 // 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. | 422 // 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. | 423 // 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. | 424 // Since playbackRate == 1 is very common, it's worth considering quality. |
| 423 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate()); | 425 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate()); |
| 424 | 426 |
| 425 m_playbackState = SCHEDULED_STATE; | 427 m_playbackState = SCHEDULED_STATE; |
| 426 } | 428 } |
| 427 | 429 |
| 428 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration) | 430 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration) |
| 429 { | 431 { |
| 430 startGrain(when, grainOffset, grainDuration); | 432 start(when, grainOffset, grainDuration); |
| 431 } | 433 } |
| 432 | 434 |
| 433 double AudioBufferSourceNode::totalPitchRate() | 435 double AudioBufferSourceNode::totalPitchRate() |
| 434 { | 436 { |
| 435 double dopplerRate = 1.0; | 437 double dopplerRate = 1.0; |
| 436 if (m_pannerNode) | 438 if (m_pannerNode) |
| 437 dopplerRate = m_pannerNode->dopplerRate(); | 439 dopplerRate = m_pannerNode->dopplerRate(); |
| 438 | 440 |
| 439 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 441 // 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. | 442 // 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() | 490 void AudioBufferSourceNode::finish() |
| 489 { | 491 { |
| 490 clearPannerNode(); | 492 clearPannerNode(); |
| 491 ASSERT(!m_pannerNode); | 493 ASSERT(!m_pannerNode); |
| 492 AudioScheduledSourceNode::finish(); | 494 AudioScheduledSourceNode::finish(); |
| 493 } | 495 } |
| 494 | 496 |
| 495 } // namespace WebCore | 497 } // namespace WebCore |
| 496 | 498 |
| 497 #endif // ENABLE(WEB_AUDIO) | 499 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |