Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioBufferSourceNode.cpp

Issue 2103043007: Rename AbstractAudioContext to BaseAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ASSERT(isGraphOwner()) instead of DCHECK Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "bindings/core/v8/ExceptionMessages.h" 25 #include "bindings/core/v8/ExceptionMessages.h"
26 #include "bindings/core/v8/ExceptionState.h" 26 #include "bindings/core/v8/ExceptionState.h"
27 #include "core/dom/ExceptionCode.h" 27 #include "core/dom/ExceptionCode.h"
28 #include "core/frame/UseCounter.h" 28 #include "core/frame/UseCounter.h"
29 #include "modules/webaudio/AbstractAudioContext.h"
30 #include "modules/webaudio/AudioBufferSourceNode.h" 29 #include "modules/webaudio/AudioBufferSourceNode.h"
31 #include "modules/webaudio/AudioNodeOutput.h" 30 #include "modules/webaudio/AudioNodeOutput.h"
31 #include "modules/webaudio/BaseAudioContext.h"
32 #include "platform/FloatConversion.h" 32 #include "platform/FloatConversion.h"
33 #include "platform/audio/AudioUtilities.h" 33 #include "platform/audio/AudioUtilities.h"
34 #include "wtf/MathExtras.h" 34 #include "wtf/MathExtras.h"
35 #include "wtf/PtrUtil.h" 35 #include "wtf/PtrUtil.h"
36 #include <algorithm> 36 #include <algorithm>
37 37
38 namespace blink { 38 namespace blink {
39 39
40 const double DefaultGrainDuration = 0.020; // 20ms 40 const double DefaultGrainDuration = 0.020; // 20ms
41 41
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ASSERT(isMainThread()); 337 ASSERT(isMainThread());
338 338
339 if (m_buffer) { 339 if (m_buffer) {
340 exceptionState.throwDOMException( 340 exceptionState.throwDOMException(
341 InvalidStateError, 341 InvalidStateError,
342 "Cannot set buffer after it has been already been set"); 342 "Cannot set buffer after it has been already been set");
343 return; 343 return;
344 } 344 }
345 345
346 // The context must be locked since changing the buffer can re-configure the number of channels that are output. 346 // The context must be locked since changing the buffer can re-configure the number of channels that are output.
347 AbstractAudioContext::AutoLocker contextLocker(context()); 347 BaseAudioContext::AutoLocker contextLocker(context());
348 348
349 // This synchronizes with process(). 349 // This synchronizes with process().
350 MutexLocker processLocker(m_processLock); 350 MutexLocker processLocker(m_processLock);
351 351
352 if (buffer) { 352 if (buffer) {
353 // Do any necesssary re-configuration to the buffer's number of channels . 353 // Do any necesssary re-configuration to the buffer's number of channels .
354 unsigned numberOfChannels = buffer->numberOfChannels(); 354 unsigned numberOfChannels = buffer->numberOfChannels();
355 355
356 // This should not be possible since AudioBuffers can't be created with too many channels 356 // This should not be possible since AudioBuffers can't be created with too many channels
357 // either. 357 // either.
358 if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { 358 if (numberOfChannels > BaseAudioContext::maxNumberOfChannels()) {
359 exceptionState.throwDOMException( 359 exceptionState.throwDOMException(
360 NotSupportedError, 360 NotSupportedError,
361 ExceptionMessages::indexOutsideRange( 361 ExceptionMessages::indexOutsideRange(
362 "number of input channels", 362 "number of input channels",
363 numberOfChannels, 363 numberOfChannels,
364 1u, 364 1u,
365 ExceptionMessages::InclusiveBound, 365 ExceptionMessages::InclusiveBound,
366 AbstractAudioContext::maxNumberOfChannels(), 366 BaseAudioContext::maxNumberOfChannels(),
367 ExceptionMessages::InclusiveBound)); 367 ExceptionMessages::InclusiveBound));
368 return; 368 return;
369 } 369 }
370 370
371 output(0).setNumberOfChannels(numberOfChannels); 371 output(0).setNumberOfChannels(numberOfChannels);
372 372
373 m_sourceChannels = wrapArrayUnique(new const float* [numberOfChannels]); 373 m_sourceChannels = wrapArrayUnique(new const float* [numberOfChannels]);
374 m_destinationChannels = wrapArrayUnique(new float* [numberOfChannels]); 374 m_destinationChannels = wrapArrayUnique(new float* [numberOfChannels]);
375 375
376 for (unsigned i = 0; i < numberOfChannels; ++i) 376 for (unsigned i = 0; i < numberOfChannels; ++i)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 m_startTime = std::max(when, context()->currentTime()); 501 m_startTime = std::max(when, context()->currentTime());
502 502
503 if (buffer()) 503 if (buffer())
504 clampGrainParameters(buffer()); 504 clampGrainParameters(buffer());
505 505
506 setPlaybackState(SCHEDULED_STATE); 506 setPlaybackState(SCHEDULED_STATE);
507 } 507 }
508 508
509 double AudioBufferSourceHandler::computePlaybackRate() 509 double AudioBufferSourceHandler::computePlaybackRate()
510 { 510 {
511 // Incorporate buffer's sample-rate versus AbstractAudioContext's sample-rat e. 511 // Incorporate buffer's sample-rate versus BaseAudioContext's sample-rate.
512 // Normally it's not an issue because buffers are loaded at the 512 // Normally it's not an issue because buffers are loaded at the
513 // AbstractAudioContext's sample-rate, but we can handle it in any case. 513 // BaseAudioContext's sample-rate, but we can handle it in any case.
514 double sampleRateFactor = 1.0; 514 double sampleRateFactor = 1.0;
515 if (buffer()) { 515 if (buffer()) {
516 // Use doubles to compute this to full accuracy. 516 // Use doubles to compute this to full accuracy.
517 sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRa te()); 517 sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRa te());
518 } 518 }
519 519
520 // Use finalValue() to incorporate changes of AudioParamTimeline and 520 // Use finalValue() to incorporate changes of AudioParamTimeline and
521 // AudioSummingJunction from m_playbackRate AudioParam. 521 // AudioSummingJunction from m_playbackRate AudioParam.
522 double basePlaybackRate = m_playbackRate->finalValue(); 522 double basePlaybackRate = m_playbackRate->finalValue();
523 523
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 if (context()->currentTime() > stopTime) { 577 if (context()->currentTime() > stopTime) {
578 // The context time has passed the time when the source nodes should have stopped 578 // The context time has passed the time when the source nodes should have stopped
579 // playing. Stop the node now and deref it. (But don't run the onEnd ed event because the 579 // playing. Stop the node now and deref it. (But don't run the onEnd ed event because the
580 // source never actually played.) 580 // source never actually played.)
581 finishWithoutOnEnded(); 581 finishWithoutOnEnded();
582 } 582 }
583 } 583 }
584 } 584 }
585 585
586 // ---------------------------------------------------------------- 586 // ----------------------------------------------------------------
587 AudioBufferSourceNode::AudioBufferSourceNode(AbstractAudioContext& context) 587 AudioBufferSourceNode::AudioBufferSourceNode(BaseAudioContext& context)
588 : AudioScheduledSourceNode(context) 588 : AudioScheduledSourceNode(context)
589 , m_playbackRate(AudioParam::create(context, ParamTypeAudioBufferSourcePlayb ackRate, 1.0)) 589 , m_playbackRate(AudioParam::create(context, ParamTypeAudioBufferSourcePlayb ackRate, 1.0))
590 , m_detune(AudioParam::create(context, ParamTypeAudioBufferSourceDetune, 0.0 )) 590 , m_detune(AudioParam::create(context, ParamTypeAudioBufferSourceDetune, 0.0 ))
591 { 591 {
592 setHandler(AudioBufferSourceHandler::create( 592 setHandler(AudioBufferSourceHandler::create(
593 *this, 593 *this,
594 context.sampleRate(), 594 context.sampleRate(),
595 m_playbackRate->handler(), 595 m_playbackRate->handler(),
596 m_detune->handler())); 596 m_detune->handler()));
597 } 597 }
598 598
599 AudioBufferSourceNode* AudioBufferSourceNode::create(AbstractAudioContext& conte xt, ExceptionState& exceptionState) 599 AudioBufferSourceNode* AudioBufferSourceNode::create(BaseAudioContext& context, ExceptionState& exceptionState)
600 { 600 {
601 DCHECK(isMainThread()); 601 DCHECK(isMainThread());
602 602
603 if (context.isContextClosed()) { 603 if (context.isContextClosed()) {
604 context.throwExceptionForClosedState(exceptionState); 604 context.throwExceptionForClosedState(exceptionState);
605 return nullptr; 605 return nullptr;
606 } 606 }
607 607
608 return new AudioBufferSourceNode(context); 608 return new AudioBufferSourceNode(context);
609 } 609 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 { 684 {
685 audioBufferSourceHandler().start(when, grainOffset, exceptionState); 685 audioBufferSourceHandler().start(when, grainOffset, exceptionState);
686 } 686 }
687 687
688 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState) 688 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState)
689 { 689 {
690 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State); 690 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State);
691 } 691 }
692 692
693 } // namespace blink 693 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698