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 10 matching lines...) Expand all Loading... | |
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/ExceptionState.h" | |
31 #include "core/page/PageConsole.h" | 32 #include "core/page/PageConsole.h" |
32 #include "platform/audio/AudioUtilities.h" | 33 #include "platform/audio/AudioUtilities.h" |
33 #include "modules/webaudio/AudioContext.h" | 34 #include "modules/webaudio/AudioContext.h" |
34 #include "modules/webaudio/AudioNodeOutput.h" | 35 #include "modules/webaudio/AudioNodeOutput.h" |
35 #include "platform/FloatConversion.h" | 36 #include "platform/FloatConversion.h" |
36 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
37 #include "wtf/MathExtras.h" | 38 #include "wtf/MathExtras.h" |
38 #include <algorithm> | 39 #include <algorithm> |
39 | 40 |
40 using namespace std; | 41 using namespace std; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 return true; | 329 return true; |
329 } | 330 } |
330 | 331 |
331 | 332 |
332 void AudioBufferSourceNode::reset() | 333 void AudioBufferSourceNode::reset() |
333 { | 334 { |
334 m_virtualReadIndex = 0; | 335 m_virtualReadIndex = 0; |
335 m_lastGain = gain()->value(); | 336 m_lastGain = gain()->value(); |
336 } | 337 } |
337 | 338 |
338 bool AudioBufferSourceNode::setBuffer(AudioBuffer* buffer) | 339 void AudioBufferSourceNode::setBuffer(AudioBuffer* buffer, ExceptionState& es) |
339 { | 340 { |
340 ASSERT(isMainThread()); | 341 ASSERT(isMainThread()); |
342 // FIXME: It does not look like we should throw if the buffer is null as | |
343 // the attribute is nullable in the specification. | |
344 if (!buffer) { | |
345 es.throwTypeError("buffer cannot be null"); | |
346 return; | |
347 } | |
341 | 348 |
342 // 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. |
343 AudioContext::AutoLocker contextLocker(context()); | 350 AudioContext::AutoLocker contextLocker(context()); |
344 | 351 |
345 // This synchronizes with process(). | 352 // This synchronizes with process(). |
346 MutexLocker processLocker(m_processLock); | 353 MutexLocker processLocker(m_processLock); |
347 | 354 |
348 if (buffer) { | 355 if (buffer) { |
349 // 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 . |
350 unsigned numberOfChannels = buffer->numberOfChannels(); | 357 unsigned numberOfChannels = buffer->numberOfChannels(); |
351 | 358 |
352 if (numberOfChannels > AudioContext::maxNumberOfChannels()) | 359 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { |
353 return false; | 360 es.throwTypeError("AudioBuffer unsupported number of channels"); |
Raymond Toy (Google)
2013/10/10 22:40:57
Should this be a DOMException? And if so, can we
| |
361 return; | |
362 } | |
354 | 363 |
355 output(0)->setNumberOfChannels(numberOfChannels); | 364 output(0)->setNumberOfChannels(numberOfChannels); |
356 | 365 |
357 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); | 366 m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); |
358 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); | 367 m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); |
359 | 368 |
360 for (unsigned i = 0; i < numberOfChannels; ++i) | 369 for (unsigned i = 0; i < numberOfChannels; ++i) |
361 m_sourceChannels[i] = buffer->getChannelData(i)->data(); | 370 m_sourceChannels[i] = buffer->getChannelData(i)->data(); |
362 } | 371 } |
363 | 372 |
364 m_virtualReadIndex = 0; | 373 m_virtualReadIndex = 0; |
365 m_buffer = buffer; | 374 m_buffer = buffer; |
366 | |
367 return true; | |
368 } | 375 } |
369 | 376 |
370 unsigned AudioBufferSourceNode::numberOfChannels() | 377 unsigned AudioBufferSourceNode::numberOfChannels() |
371 { | 378 { |
372 return output(0)->numberOfChannels(); | 379 return output(0)->numberOfChannels(); |
373 } | 380 } |
374 | 381 |
375 void AudioBufferSourceNode::startGrain(double when, double grainOffset) | 382 void AudioBufferSourceNode::startGrain(double when, double grainOffset) |
376 { | 383 { |
377 // Duration of 0 has special value, meaning calculate based on the entire bu ffer's duration. | 384 // Duration of 0 has special value, meaning calculate based on the entire bu ffer's duration. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 void AudioBufferSourceNode::finish() | 486 void AudioBufferSourceNode::finish() |
480 { | 487 { |
481 clearPannerNode(); | 488 clearPannerNode(); |
482 ASSERT(!m_pannerNode); | 489 ASSERT(!m_pannerNode); |
483 AudioScheduledSourceNode::finish(); | 490 AudioScheduledSourceNode::finish(); |
484 } | 491 } |
485 | 492 |
486 } // namespace WebCore | 493 } // namespace WebCore |
487 | 494 |
488 #endif // ENABLE(WEB_AUDIO) | 495 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |