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 12 matching lines...) Expand all Loading... |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #if ENABLE(WEB_AUDIO) | 26 #if ENABLE(WEB_AUDIO) |
27 #include "modules/webaudio/AudioBufferSourceNode.h" | 27 #include "modules/webaudio/AudioBufferSourceNode.h" |
28 | 28 |
29 #include "bindings/core/v8/ExceptionMessages.h" | 29 #include "bindings/core/v8/ExceptionMessages.h" |
30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
32 #include "core/frame/UseCounter.h" | 32 #include "core/frame/UseCounter.h" |
33 #include "modules/webaudio/AudioContext.h" | 33 #include "modules/webaudio/AbstractAudioContext.h" |
34 #include "modules/webaudio/AudioNodeOutput.h" | 34 #include "modules/webaudio/AudioNodeOutput.h" |
35 #include "platform/FloatConversion.h" | 35 #include "platform/FloatConversion.h" |
36 #include "platform/audio/AudioUtilities.h" | 36 #include "platform/audio/AudioUtilities.h" |
37 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
38 #include "wtf/MathExtras.h" | 38 #include "wtf/MathExtras.h" |
39 #include <algorithm> | 39 #include <algorithm> |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 const double DefaultGrainDuration = 0.020; // 20ms | 43 const double DefaultGrainDuration = 0.020; // 20ms |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 ASSERT(isMainThread()); | 340 ASSERT(isMainThread()); |
341 | 341 |
342 if (m_buffer) { | 342 if (m_buffer) { |
343 exceptionState.throwDOMException( | 343 exceptionState.throwDOMException( |
344 InvalidStateError, | 344 InvalidStateError, |
345 "Cannot set buffer after it has been already been set"); | 345 "Cannot set buffer after it has been already been set"); |
346 return; | 346 return; |
347 } | 347 } |
348 | 348 |
349 // The context must be locked since changing the buffer can re-configure the
number of channels that are output. | 349 // The context must be locked since changing the buffer can re-configure the
number of channels that are output. |
350 AudioContext::AutoLocker contextLocker(context()); | 350 AbstractAudioContext::AutoLocker contextLocker(context()); |
351 | 351 |
352 // This synchronizes with process(). | 352 // This synchronizes with process(). |
353 MutexLocker processLocker(m_processLock); | 353 MutexLocker processLocker(m_processLock); |
354 | 354 |
355 if (buffer) { | 355 if (buffer) { |
356 // Do any necesssary re-configuration to the buffer's number of channels
. | 356 // Do any necesssary re-configuration to the buffer's number of channels
. |
357 unsigned numberOfChannels = buffer->numberOfChannels(); | 357 unsigned numberOfChannels = buffer->numberOfChannels(); |
358 | 358 |
359 // This should not be possible since AudioBuffers can't be created with
too many channels | 359 // This should not be possible since AudioBuffers can't be created with
too many channels |
360 // either. | 360 // either. |
361 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | 361 if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { |
362 exceptionState.throwDOMException( | 362 exceptionState.throwDOMException( |
363 NotSupportedError, | 363 NotSupportedError, |
364 ExceptionMessages::indexOutsideRange( | 364 ExceptionMessages::indexOutsideRange( |
365 "number of input channels", | 365 "number of input channels", |
366 numberOfChannels, | 366 numberOfChannels, |
367 1u, | 367 1u, |
368 ExceptionMessages::InclusiveBound, | 368 ExceptionMessages::InclusiveBound, |
369 AudioContext::maxNumberOfChannels(), | 369 AbstractAudioContext::maxNumberOfChannels(), |
370 ExceptionMessages::InclusiveBound)); | 370 ExceptionMessages::InclusiveBound)); |
371 return; | 371 return; |
372 } | 372 } |
373 | 373 |
374 output(0).setNumberOfChannels(numberOfChannels); | 374 output(0).setNumberOfChannels(numberOfChannels); |
375 | 375 |
376 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); | 376 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); |
377 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); | 377 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); |
378 | 378 |
379 for (unsigned i = 0; i < numberOfChannels; ++i) | 379 for (unsigned i = 0; i < numberOfChannels; ++i) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 502 |
503 m_playbackState = SCHEDULED_STATE; | 503 m_playbackState = SCHEDULED_STATE; |
504 } | 504 } |
505 | 505 |
506 double AudioBufferSourceHandler::computePlaybackRate() | 506 double AudioBufferSourceHandler::computePlaybackRate() |
507 { | 507 { |
508 double dopplerRate = 1; | 508 double dopplerRate = 1; |
509 if (m_pannerNode) | 509 if (m_pannerNode) |
510 dopplerRate = m_pannerNode->dopplerRate(); | 510 dopplerRate = m_pannerNode->dopplerRate(); |
511 | 511 |
512 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. | 512 // Incorporate buffer's sample-rate versus AbstractAudioContext's sample-rat
e. |
513 // Normally it's not an issue because buffers are loaded at the | 513 // Normally it's not an issue because buffers are loaded at the |
514 // AudioContext's sample-rate, but we can handle it in any case. | 514 // AbstractAudioContext's sample-rate, but we can handle it in any case. |
515 double sampleRateFactor = 1.0; | 515 double sampleRateFactor = 1.0; |
516 if (buffer()) { | 516 if (buffer()) { |
517 // Use doubles to compute this to full accuracy. | 517 // Use doubles to compute this to full accuracy. |
518 sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRa
te()); | 518 sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRa
te()); |
519 } | 519 } |
520 | 520 |
521 // Use finalValue() to incorporate changes of AudioParamTimeline and | 521 // Use finalValue() to incorporate changes of AudioParamTimeline and |
522 // AudioSummingJunction from m_playbackRate AudioParam. | 522 // AudioSummingJunction from m_playbackRate AudioParam. |
523 double basePlaybackRate = m_playbackRate->finalValue(); | 523 double basePlaybackRate = m_playbackRate->finalValue(); |
524 | 524 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 } | 601 } |
602 | 602 |
603 void AudioBufferSourceHandler::finish() | 603 void AudioBufferSourceHandler::finish() |
604 { | 604 { |
605 clearPannerNode(); | 605 clearPannerNode(); |
606 ASSERT(!m_pannerNode); | 606 ASSERT(!m_pannerNode); |
607 AudioScheduledSourceHandler::finish(); | 607 AudioScheduledSourceHandler::finish(); |
608 } | 608 } |
609 | 609 |
610 // ---------------------------------------------------------------- | 610 // ---------------------------------------------------------------- |
611 AudioBufferSourceNode::AudioBufferSourceNode(AudioContext& context, float sample
Rate) | 611 AudioBufferSourceNode::AudioBufferSourceNode(AbstractAudioContext& context, floa
t sampleRate) |
612 : AudioScheduledSourceNode(context) | 612 : AudioScheduledSourceNode(context) |
613 , m_playbackRate(AudioParam::create(context, 1.0)) | 613 , m_playbackRate(AudioParam::create(context, 1.0)) |
614 , m_detune(AudioParam::create(context, 0.0)) | 614 , m_detune(AudioParam::create(context, 0.0)) |
615 { | 615 { |
616 setHandler(AudioBufferSourceHandler::create(*this, sampleRate, m_playbackRat
e->handler(), m_detune->handler())); | 616 setHandler(AudioBufferSourceHandler::create(*this, sampleRate, m_playbackRat
e->handler(), m_detune->handler())); |
617 } | 617 } |
618 | 618 |
619 AudioBufferSourceNode* AudioBufferSourceNode::create(AudioContext& context, floa
t sampleRate) | 619 AudioBufferSourceNode* AudioBufferSourceNode::create(AbstractAudioContext& conte
xt, float sampleRate) |
620 { | 620 { |
621 return new AudioBufferSourceNode(context, sampleRate); | 621 return new AudioBufferSourceNode(context, sampleRate); |
622 } | 622 } |
623 | 623 |
624 DEFINE_TRACE(AudioBufferSourceNode) | 624 DEFINE_TRACE(AudioBufferSourceNode) |
625 { | 625 { |
626 visitor->trace(m_playbackRate); | 626 visitor->trace(m_playbackRate); |
627 visitor->trace(m_detune); | 627 visitor->trace(m_detune); |
628 AudioScheduledSourceNode::trace(visitor); | 628 AudioScheduledSourceNode::trace(visitor); |
629 } | 629 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 699 } |
700 | 700 |
701 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) | 701 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) |
702 { | 702 { |
703 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); | 703 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); |
704 } | 704 } |
705 | 705 |
706 } // namespace blink | 706 } // namespace blink |
707 | 707 |
708 #endif // ENABLE(WEB_AUDIO) | 708 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |