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

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

Issue 54173005: Signal exceptions if start/stop is called out-of-order or too many times. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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
(...skipping 10 matching lines...) Expand all
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 "config.h" 25 #include "config.h"
26 26
27 #if ENABLE(WEB_AUDIO) 27 #if ENABLE(WEB_AUDIO)
28 28
29 #include "modules/webaudio/AudioBufferSourceNode.h" 29 #include "modules/webaudio/AudioBufferSourceNode.h"
30 30
31 #include "bindings/v8/ExceptionMessages.h"
31 #include "bindings/v8/ExceptionState.h" 32 #include "bindings/v8/ExceptionState.h"
33 #include "core/dom/ExceptionCode.h"
32 #include "core/page/PageConsole.h" 34 #include "core/page/PageConsole.h"
33 #include "platform/audio/AudioUtilities.h" 35 #include "platform/audio/AudioUtilities.h"
34 #include "modules/webaudio/AudioContext.h" 36 #include "modules/webaudio/AudioContext.h"
35 #include "modules/webaudio/AudioNodeOutput.h" 37 #include "modules/webaudio/AudioNodeOutput.h"
36 #include "platform/FloatConversion.h" 38 #include "platform/FloatConversion.h"
37 #include "wtf/MainThread.h" 39 #include "wtf/MainThread.h"
38 #include "wtf/MathExtras.h" 40 #include "wtf/MathExtras.h"
39 #include <algorithm> 41 #include <algorithm>
40 42
41 using namespace std; 43 using namespace std;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 376
375 m_virtualReadIndex = 0; 377 m_virtualReadIndex = 0;
376 m_buffer = buffer; 378 m_buffer = buffer;
377 } 379 }
378 380
379 unsigned AudioBufferSourceNode::numberOfChannels() 381 unsigned AudioBufferSourceNode::numberOfChannels()
380 { 382 {
381 return output(0)->numberOfChannels(); 383 return output(0)->numberOfChannels();
382 } 384 }
383 385
384 void AudioBufferSourceNode::start(double when) 386 void AudioBufferSourceNode::start(ExceptionState& es)
385 { 387 {
386 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0); 388 startPlaying(false, 0, 0, buffer() ? buffer()->duration() : 0, es);
387 } 389 }
388 390
389 void AudioBufferSourceNode::start(double when, double grainOffset) 391 void AudioBufferSourceNode::start(double when, ExceptionState& es)
390 { 392 {
391 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0); 393 startPlaying(false, when, 0, buffer() ? buffer()->duration() : 0, es);
392 } 394 }
393 395
394 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration) 396 void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionStat e& es)
395 { 397 {
396 startPlaying(true, when, grainOffset, grainDuration); 398 startPlaying(true, when, grainOffset, buffer() ? buffer()->duration() : 0, e s);
397 } 399 }
398 400
399 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain Offset, double grainDuration) 401 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& es)
402 {
403 startPlaying(true, when, grainOffset, grainDuration, es);
404 }
405
406 void AudioBufferSourceNode::startPlaying(bool isGrain, double when, double grain Offset, double grainDuration, ExceptionState& es)
400 { 407 {
401 ASSERT(isMainThread()); 408 ASSERT(isMainThread());
402 409
403 if (m_playbackState != UNSCHEDULED_STATE) 410 if (m_playbackState != UNSCHEDULED_STATE) {
411 es.throwDOMException(
412 InvalidStateError,
413 ExceptionMessages::failedToExecute(
414 "start",
415 nodeTypeName(),
416 "cannot call start more than once."));
404 return; 417 return;
418 }
405 419
406 if (!buffer()) 420 if (!buffer())
407 return; 421 return;
408 422
409 if (isGrain) { 423 if (isGrain) {
410 // Do sanity checking of grain parameters versus buffer size. 424 // Do sanity checking of grain parameters versus buffer size.
411 double bufferDuration = buffer()->duration(); 425 double bufferDuration = buffer()->duration();
412 426
413 grainOffset = max(0.0, grainOffset); 427 grainOffset = max(0.0, grainOffset);
414 grainOffset = min(bufferDuration, grainOffset); 428 grainOffset = min(bufferDuration, grainOffset);
415 m_grainOffset = grainOffset; 429 m_grainOffset = grainOffset;
416 430
417 double maxDuration = bufferDuration - grainOffset; 431 double maxDuration = bufferDuration - grainOffset;
418 432
419 grainDuration = max(0.0, grainDuration); 433 grainDuration = max(0.0, grainDuration);
420 grainDuration = min(maxDuration, grainDuration); 434 grainDuration = min(maxDuration, grainDuration);
421 m_grainDuration = grainDuration; 435 m_grainDuration = grainDuration;
422
423 } else {
424 // Until crbug.com/306139 is implemented, we initialize m_grainOffset an d m_grainDuration
425 // again.
426 m_grainOffset = 0.0;
427 m_grainDuration = DefaultGrainDuration;
428 } 436 }
429 437
430 m_isGrain = isGrain; 438 m_isGrain = isGrain;
431 m_startTime = when; 439 m_startTime = when;
432 440
433 // 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
434 // at a sub-sample position since it will degrade the quality. 442 // at a sub-sample position since it will degrade the quality.
435 // 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.
436 // Since playbackRate == 1 is very common, it's worth considering quality. 444 // Since playbackRate == 1 is very common, it's worth considering quality.
437 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate()); 445 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ()->sampleRate());
438 446
439 m_playbackState = SCHEDULED_STATE; 447 m_playbackState = SCHEDULED_STATE;
440 } 448 }
441 449
442 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration) 450 void AudioBufferSourceNode::noteGrainOn(double when, double grainOffset, double grainDuration, ExceptionState& es)
443 { 451 {
444 // Handle unspecified duration where 0 means the rest of the buffer. 452 // Handle unspecified duration where 0 means the rest of the buffer.
445 if (!grainDuration) 453 if (!grainDuration && buffer())
446 grainDuration = buffer()->duration(); 454 grainDuration = buffer()->duration();
447 startPlaying(true, when, grainOffset, grainDuration); 455 startPlaying(true, when, grainOffset, grainDuration, es);
448 } 456 }
449 457
450 double AudioBufferSourceNode::totalPitchRate() 458 double AudioBufferSourceNode::totalPitchRate()
451 { 459 {
452 double dopplerRate = 1.0; 460 double dopplerRate = 1.0;
453 if (m_pannerNode) 461 if (m_pannerNode)
454 dopplerRate = m_pannerNode->dopplerRate(); 462 dopplerRate = m_pannerNode->dopplerRate();
455 463
456 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. 464 // Incorporate buffer's sample-rate versus AudioContext's sample-rate.
457 // 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
505 void AudioBufferSourceNode::finish() 513 void AudioBufferSourceNode::finish()
506 { 514 {
507 clearPannerNode(); 515 clearPannerNode();
508 ASSERT(!m_pannerNode); 516 ASSERT(!m_pannerNode);
509 AudioScheduledSourceNode::finish(); 517 AudioScheduledSourceNode::finish();
510 } 518 }
511 519
512 } // namespace WebCore 520 } // namespace WebCore
513 521
514 #endif // ENABLE(WEB_AUDIO) 522 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioBufferSourceNode.h ('k') | Source/modules/webaudio/AudioBufferSourceNode.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698