| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Convert from seconds to sample-frames. | 219 // Convert from seconds to sample-frames. |
| 220 double loopStartFrame = m_loopStart * buffer()->sampleRate(); | 220 double loopStartFrame = m_loopStart * buffer()->sampleRate(); |
| 221 double loopEndFrame = m_loopEnd * buffer()->sampleRate(); | 221 double loopEndFrame = m_loopEnd * buffer()->sampleRate(); |
| 222 | 222 |
| 223 virtualEndFrame = std::min(loopEndFrame, virtualEndFrame); | 223 virtualEndFrame = std::min(loopEndFrame, virtualEndFrame); |
| 224 virtualDeltaFrames = virtualEndFrame - loopStartFrame; | 224 virtualDeltaFrames = virtualEndFrame - loopStartFrame; |
| 225 } | 225 } |
| 226 | 226 |
| 227 // If we're looping and the offset (virtualReadIndex) is past the end of the
loop, wrap back to | 227 // If we're looping and the offset (virtualReadIndex) is past the end of the
loop, wrap back to |
| 228 // the beginning of the loop. For other cases, nothing needs to be done. | 228 // the beginning of the loop. For other cases, nothing needs to be done. |
| 229 if (loop() && m_virtualReadIndex >= virtualEndFrame) | 229 if (loop() && m_virtualReadIndex >= virtualEndFrame) { |
| 230 m_virtualReadIndex = (m_loopStart < 0) ? 0 : (m_loopStart * buffer()->sa
mpleRate()); | 230 m_virtualReadIndex = (m_loopStart < 0) ? 0 : (m_loopStart * buffer()->sa
mpleRate()); |
| 231 m_virtualReadIndex = std::min(m_virtualReadIndex, static_cast<double>(bu
fferLength - 1)); |
| 232 } |
| 231 | 233 |
| 232 double computedPlaybackRate = computePlaybackRate(); | 234 double computedPlaybackRate = computePlaybackRate(); |
| 233 | 235 |
| 234 // Sanity check that our playback rate isn't larger than the loop size. | 236 // Sanity check that our playback rate isn't larger than the loop size. |
| 235 if (computedPlaybackRate > virtualDeltaFrames) | 237 if (computedPlaybackRate > virtualDeltaFrames) |
| 236 return false; | 238 return false; |
| 237 | 239 |
| 238 // Get local copy. | 240 // Get local copy. |
| 239 double virtualReadIndex = m_virtualReadIndex; | 241 double virtualReadIndex = m_virtualReadIndex; |
| 240 | 242 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 254 && virtualDeltaFrames == floor(virtualDeltaFrames) | 256 && virtualDeltaFrames == floor(virtualDeltaFrames) |
| 255 && virtualEndFrame == floor(virtualEndFrame)) { | 257 && virtualEndFrame == floor(virtualEndFrame)) { |
| 256 unsigned readIndex = static_cast<unsigned>(virtualReadIndex); | 258 unsigned readIndex = static_cast<unsigned>(virtualReadIndex); |
| 257 unsigned deltaFrames = static_cast<unsigned>(virtualDeltaFrames); | 259 unsigned deltaFrames = static_cast<unsigned>(virtualDeltaFrames); |
| 258 endFrame = static_cast<unsigned>(virtualEndFrame); | 260 endFrame = static_cast<unsigned>(virtualEndFrame); |
| 259 while (framesToProcess > 0) { | 261 while (framesToProcess > 0) { |
| 260 int framesToEnd = endFrame - readIndex; | 262 int framesToEnd = endFrame - readIndex; |
| 261 int framesThisTime = std::min(framesToProcess, framesToEnd); | 263 int framesThisTime = std::min(framesToProcess, framesToEnd); |
| 262 framesThisTime = std::max(0, framesThisTime); | 264 framesThisTime = std::max(0, framesThisTime); |
| 263 | 265 |
| 266 DCHECK_LE(writeIndex + framesThisTime, destinationLength); |
| 267 DCHECK_LE(readIndex + framesThisTime, bufferLength); |
| 268 |
| 264 for (unsigned i = 0; i < numberOfChannels; ++i) | 269 for (unsigned i = 0; i < numberOfChannels; ++i) |
| 265 memcpy(destinationChannels[i] + writeIndex, sourceChannels[i] +
readIndex, sizeof(float) * framesThisTime); | 270 memcpy(destinationChannels[i] + writeIndex, sourceChannels[i] +
readIndex, sizeof(float) * framesThisTime); |
| 266 | 271 |
| 267 writeIndex += framesThisTime; | 272 writeIndex += framesThisTime; |
| 268 readIndex += framesThisTime; | 273 readIndex += framesThisTime; |
| 269 framesToProcess -= framesThisTime; | 274 framesToProcess -= framesThisTime; |
| 270 | 275 |
| 271 // It can happen that framesThisTime is 0. DCHECK that we will actua
lly exit the loop in | 276 // It can happen that framesThisTime is 0. DCHECK that we will actua
lly exit the loop in |
| 272 // this case. framesThisTime is 0 only if readIndex >= endFrame; | 277 // this case. framesThisTime is 0 only if readIndex >= endFrame; |
| 273 DCHECK(framesThisTime ? true : readIndex >= endFrame); | 278 DCHECK(framesThisTime ? true : readIndex >= endFrame); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 { | 690 { |
| 686 audioBufferSourceHandler().start(when, grainOffset, exceptionState); | 691 audioBufferSourceHandler().start(when, grainOffset, exceptionState); |
| 687 } | 692 } |
| 688 | 693 |
| 689 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) | 694 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
uration, ExceptionState& exceptionState) |
| 690 { | 695 { |
| 691 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); | 696 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception
State); |
| 692 } | 697 } |
| 693 | 698 |
| 694 } // namespace blink | 699 } // namespace blink |
| OLD | NEW |