| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 | 333 |
| 334 | 334 |
| 335 void AudioBufferSourceNode::reset() | 335 void AudioBufferSourceNode::reset() |
| 336 { | 336 { |
| 337 m_virtualReadIndex = 0; | 337 m_virtualReadIndex = 0; |
| 338 m_lastGain = gain()->value(); | 338 m_lastGain = gain()->value(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void AudioBufferSourceNode::setBuffer(AudioBuffer* buffer, ExceptionState& es) | 341 void AudioBufferSourceNode::setBuffer(AudioBuffer* buffer, ExceptionState& excep
tionState) |
| 342 { | 342 { |
| 343 ASSERT(isMainThread()); | 343 ASSERT(isMainThread()); |
| 344 // FIXME: It does not look like we should throw if the buffer is null as | 344 // FIXME: It does not look like we should throw if the buffer is null as |
| 345 // the attribute is nullable in the specification. | 345 // the attribute is nullable in the specification. |
| 346 if (!buffer) { | 346 if (!buffer) { |
| 347 es.throwTypeError("buffer cannot be null"); | 347 exceptionState.throwTypeError("buffer cannot be null"); |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 | 350 |
| 351 // The context must be locked since changing the buffer can re-configure the
number of channels that are output. | 351 // The context must be locked since changing the buffer can re-configure the
number of channels that are output. |
| 352 AudioContext::AutoLocker contextLocker(context()); | 352 AudioContext::AutoLocker contextLocker(context()); |
| 353 | 353 |
| 354 // This synchronizes with process(). | 354 // This synchronizes with process(). |
| 355 MutexLocker processLocker(m_processLock); | 355 MutexLocker processLocker(m_processLock); |
| 356 | 356 |
| 357 if (buffer) { | 357 if (buffer) { |
| 358 // Do any necesssary re-configuration to the buffer's number of channels
. | 358 // Do any necesssary re-configuration to the buffer's number of channels
. |
| 359 unsigned numberOfChannels = buffer->numberOfChannels(); | 359 unsigned numberOfChannels = buffer->numberOfChannels(); |
| 360 | 360 |
| 361 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | 361 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { |
| 362 es.throwTypeError("number of input channels (" + String::number(numb
erOfChannels) | 362 exceptionState.throwTypeError("number of input channels (" + String:
:number(numberOfChannels) |
| 363 + ") exceeds maximum (" | 363 + ") exceeds maximum (" |
| 364 + String::number(AudioContext::maxNumberOfChannels()) + ")."); | 364 + String::number(AudioContext::maxNumberOfChannels()) + ")."); |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 | 367 |
| 368 output(0)->setNumberOfChannels(numberOfChannels); | 368 output(0)->setNumberOfChannels(numberOfChannels); |
| 369 | 369 |
| 370 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); | 370 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); |
| 371 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); | 371 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); |
| 372 | 372 |
| 373 for (unsigned i = 0; i < numberOfChannels; ++i) | 373 for (unsigned i = 0; i < numberOfChannels; ++i) |
| 374 m_sourceChannels[i] = buffer->getChannelData(i)->data(); | 374 m_sourceChannels[i] = buffer->getChannelData(i)->data(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 m_virtualReadIndex = 0; | 377 m_virtualReadIndex = 0; |
| 378 m_buffer = buffer; | 378 m_buffer = buffer; |
| 379 } | 379 } |
| 380 | 380 |
| 381 unsigned AudioBufferSourceNode::numberOfChannels() | 381 unsigned AudioBufferSourceNode::numberOfChannels() |
| 382 { | 382 { |
| 383 return output(0)->numberOfChannels(); | 383 return output(0)->numberOfChannels(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void AudioBufferSourceNode::start(ExceptionState& es) | 386 void AudioBufferSourceNode::start(ExceptionState& exceptionState) |
| 387 { | 387 { |
| 388 startPlaying(false, 0, 0, buffer() ? buffer()->duration() : 0, es); | 388 startPlaying(false, 0, 0, buffer() ? buffer()->duration() : 0, exceptionStat
e); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void AudioBufferSourceNode::start(double when, ExceptionState& es) | 391 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) |
| 392 { | 392 { |
| 393 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0, es); | 393 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0, exceptionS
tate); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat
e& es) | 396 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat
e& exceptionState) |
| 397 { | 397 { |
| 398 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0, e
s); | 398 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0, e
xceptionState); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& es) | 401 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) |
| 402 { | 402 { |
| 403 startPlaying(true, when, grainOffset, grainDuration, es); | 403 startPlaying(true, when, grainOffset, grainDuration, exceptionState); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration, ExceptionState& es) | 406 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain
Offset, double grainDuration, ExceptionState& exceptionState) |
| 407 { | 407 { |
| 408 ASSERT(isMainThread()); | 408 ASSERT(isMainThread()); |
| 409 | 409 |
| 410 if (m_playbackState != UNSCHEDULED_STATE) { | 410 if (m_playbackState != UNSCHEDULED_STATE) { |
| 411 es.throwDOMException( | 411 exceptionState.throwDOMException( |
| 412 InvalidStateError, | 412 InvalidStateError, |
| 413 ExceptionMessages::failedToExecute( | 413 ExceptionMessages::failedToExecute( |
| 414 "start", | 414 "start", |
| 415 nodeTypeName(), | 415 nodeTypeName(), |
| 416 "cannot call start more than once.")); | 416 "cannot call start more than once.")); |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 | 419 |
| 420 if (!buffer()) | 420 if (!buffer()) |
| 421 return; | 421 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 440 | 440 |
| 441 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation | 441 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t
o go through linear interpolation |
| 442 // at a sub-sample position since it will degrade the quality. | 442 // at a sub-sample position since it will degrade the quality. |
| 443 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. | 443 // When aligned to the sample-frame the playback will be identical to the PC
M data stored in the buffer. |
| 444 // Since playbackRate == 1 is very common, it's worth considering quality. | 444 // Since playbackRate == 1 is very common, it's worth considering quality. |
| 445 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); | 445 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer
()->sampleRate()); |
| 446 | 446 |
| 447 m_playbackState = SCHEDULED_STATE; | 447 m_playbackState = SCHEDULED_STATE; |
| 448 } | 448 } |
| 449 | 449 |
| 450 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double
grainDuration, ExceptionState& es) | 450 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double
grainDuration, ExceptionState& exceptionState) |
| 451 { | 451 { |
| 452 // Handle unspecified duration where 0 means the rest of the buffer. | 452 // Handle unspecified duration where 0 means the rest of the buffer. |
| 453 if (!grainDuration && buffer()) | 453 if (!grainDuration && buffer()) |
| 454 grainDuration = buffer()->duration(); | 454 grainDuration = buffer()->duration(); |
| 455 startPlaying(true, when, grainOffset, grainDuration, es); | 455 startPlaying(true, when, grainOffset, grainDuration, exceptionState); |
| 456 } | 456 } |
| 457 | 457 |
| 458 double AudioBufferSourceNode::totalPitchRate() | 458 double AudioBufferSourceNode::totalPitchRate() |
| 459 { | 459 { |
| 460 double dopplerRate = 1.0; | 460 double dopplerRate = 1.0; |
| 461 if (m_pannerNode) | 461 if (m_pannerNode) |
| 462 dopplerRate = m_pannerNode->dopplerRate(); | 462 dopplerRate = m_pannerNode->dopplerRate(); |
| 463 | 463 |
| 464 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 464 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. |
| 465 // Normally it's not an issue because buffers are loaded at the AudioContext
's sample-rate, but we can handle it in any case. | 465 // 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... |
| 513 void AudioBufferSourceNode::finish() | 513 void AudioBufferSourceNode::finish() |
| 514 { | 514 { |
| 515 clearPannerNode(); | 515 clearPannerNode(); |
| 516 ASSERT(!m_pannerNode); | 516 ASSERT(!m_pannerNode); |
| 517 AudioScheduledSourceNode::finish(); | 517 AudioScheduledSourceNode::finish(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 } // namespace WebCore | 520 } // namespace WebCore |
| 521 | 521 |
| 522 #endif // ENABLE(WEB_AUDIO) | 522 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |