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

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

Issue 723823002: AudioBufferSourceNode loop duration should be the actual duration (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: One item per line Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/webaudio/resources/audiobuffersource-testing.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 397 }
398 398
399 void AudioBufferSourceNode::clampGrainParameters(const AudioBuffer* buffer) 399 void AudioBufferSourceNode::clampGrainParameters(const AudioBuffer* buffer)
400 { 400 {
401 ASSERT(buffer); 401 ASSERT(buffer);
402 402
403 // We have a buffer so we can clip the offset and duration to lie within the buffer. 403 // We have a buffer so we can clip the offset and duration to lie within the buffer.
404 double bufferDuration = buffer->duration(); 404 double bufferDuration = buffer->duration();
405 405
406 m_grainOffset = clampTo(m_grainOffset, 0.0, bufferDuration); 406 m_grainOffset = clampTo(m_grainOffset, 0.0, bufferDuration);
407 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grainOffs et); 407
408 if (loop()) {
409 // We're looping a grain with a grain duration specified. Schedule the l oop to stop after
410 // grainDuration seconds after starting, possibly running the loop multi ple times if
411 // grainDuration is larger than the buffer duration. The net effect is a s if the user called
412 // stop(when + grainDuration).
413 m_grainDuration = clampTo(m_grainDuration, 0.0, std::numeric_limits<doub le>::infinity());
414 m_endTime = m_startTime + m_grainDuration;
415 } else {
416 m_grainDuration = clampTo(m_grainDuration, 0.0, bufferDuration - m_grain Offset);
417 }
408 418
409 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t o go through 419 // We call timeToSampleFrame here since at playbackRate == 1 we don't want t o go through
410 // linear interpolation at a sub-sample position since it will degrade the q uality. When 420 // linear interpolation at a sub-sample position since it will degrade the q uality. When
411 // aligned to the sample-frame the playback will be identical to the PCM dat a stored in the 421 // aligned to the sample-frame the playback will be identical to the PCM dat a stored in the
412 // buffer. Since playbackRate == 1 is very common, it's worth considering qu ality. 422 // buffer. Since playbackRate == 1 is very common, it's worth considering qu ality.
413 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ->sampleRate()); 423 m_virtualReadIndex = AudioUtilities::timeToSampleFrame(m_grainOffset, buffer ->sampleRate());
414 } 424 }
415 425
416 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState) 426 void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState)
417 { 427 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 exceptionState.throwDOMException( 462 exceptionState.throwDOMException(
453 InvalidStateError, 463 InvalidStateError,
454 "Duration must be a finite non-negative number: " + String::number(g rainDuration)); 464 "Duration must be a finite non-negative number: " + String::number(g rainDuration));
455 return; 465 return;
456 } 466 }
457 467
458 m_isGrain = true; 468 m_isGrain = true;
459 m_grainOffset = grainOffset; 469 m_grainOffset = grainOffset;
460 m_grainDuration = grainDuration; 470 m_grainDuration = grainDuration;
461 471
472 m_startTime = when;
473
462 if (buffer()) 474 if (buffer())
463 clampGrainParameters(buffer()); 475 clampGrainParameters(buffer());
464 476
465 m_startTime = when;
466 m_playbackState = SCHEDULED_STATE; 477 m_playbackState = SCHEDULED_STATE;
467 } 478 }
468 479
469 double AudioBufferSourceNode::totalPitchRate() 480 double AudioBufferSourceNode::totalPitchRate()
470 { 481 {
471 double dopplerRate = 1.0; 482 double dopplerRate = 1.0;
472 if (m_pannerNode) 483 if (m_pannerNode)
473 dopplerRate = m_pannerNode->dopplerRate(); 484 dopplerRate = m_pannerNode->dopplerRate();
474 485
475 // Incorporate buffer's sample-rate versus AudioContext's sample-rate. 486 // Incorporate buffer's sample-rate versus AudioContext's sample-rate.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 { 558 {
548 visitor->trace(m_buffer); 559 visitor->trace(m_buffer);
549 visitor->trace(m_playbackRate); 560 visitor->trace(m_playbackRate);
550 visitor->trace(m_pannerNode); 561 visitor->trace(m_pannerNode);
551 AudioScheduledSourceNode::trace(visitor); 562 AudioScheduledSourceNode::trace(visitor);
552 } 563 }
553 564
554 } // namespace blink 565 } // namespace blink
555 566
556 #endif // ENABLE(WEB_AUDIO) 567 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « LayoutTests/webaudio/resources/audiobuffersource-testing.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698