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 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) { |
|
Ken Russell (switch to Gerrit)
2013/10/28 23:06:31
It looks like an else clause is needed initializin
Raymond Toy (Google)
2013/10/28 23:20:38
m_grainOffset and m_grainDuration are initialized
Raymond Toy (Google)
2013/10/28 23:38:00
Done.
| |
| 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 // Make this a grain if we're not playing the entire buffer. |
| 424 m_isGrain = isGrain; | |
|
Ken Russell (switch to Gerrit)
2013/10/28 23:06:31
I don't think this should be inside the conditiona
Raymond Toy (Google)
2013/10/28 23:38:00
Done.
| |
| 425 } | |
| 417 m_startTime = when; | 426 m_startTime = when; |
| 418 | 427 |
| 419 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t o go through linear interpolation | 428 // 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. | 429 // 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. | 430 // 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. | 431 // Since playbackRate == 1 is very common, it's worth considering quality. |
| 423 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate()); | 432 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate()); |
| 424 | 433 |
| 425 m_playbackState = SCHEDULED_STATE; | 434 m_playbackState = SCHEDULED_STATE; |
| 426 } | 435 } |
| 427 | 436 |
| 428 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration) | 437 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration) |
| 429 { | 438 { |
| 430 startGrain(when, grainOffset, grainDuration); | 439 // Handle unspecified duration where 0 means the rest of the buffer. |
| 440 if (!grainDuration) | |
| 441 grainDuration = buffer()->duration(); | |
| 442 startPlaying(true, when, grainOffset, grainDuration); | |
| 431 } | 443 } |
| 432 | 444 |
| 433 double AudioBufferSourceNode::totalPitchRate() | 445 double AudioBufferSourceNode::totalPitchRate() |
| 434 { | 446 { |
| 435 double dopplerRate = 1.0; | 447 double dopplerRate = 1.0; |
| 436 if (m_pannerNode) | 448 if (m_pannerNode) |
| 437 dopplerRate = m_pannerNode->dopplerRate(); | 449 dopplerRate = m_pannerNode->dopplerRate(); |
| 438 | 450 |
| 439 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 451 // 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. | 452 // 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() | 500 void AudioBufferSourceNode::finish() |
| 489 { | 501 { |
| 490 clearPannerNode(); | 502 clearPannerNode(); |
| 491 ASSERT(!m_pannerNode); | 503 ASSERT(!m_pannerNode); |
| 492 AudioScheduledSourceNode::finish(); | 504 AudioScheduledSourceNode::finish(); |
| 493 } | 505 } |
| 494 | 506 |
| 495 } // namespace WebCore | 507 } // namespace WebCore |
| 496 | 508 |
| 497 #endif // ENABLE(WEB_AUDIO) | 509 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |