| 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("number of input channels (" + String::number(numb
     erOfChannels) | 
 |  361                 + ") exceeds maximum (" | 
 |  362                 + String::number(AudioContext::maxNumberOfChannels()) + ")."); | 
 |  363             return; | 
 |  364         } | 
|  354  |  365  | 
|  355         output(0)->setNumberOfChannels(numberOfChannels); |  366         output(0)->setNumberOfChannels(numberOfChannels); | 
|  356  |  367  | 
|  357         m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); |  368         m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); | 
|  358         m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); |  369         m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); | 
|  359  |  370  | 
|  360         for (unsigned i = 0; i < numberOfChannels; ++i) |  371         for (unsigned i = 0; i < numberOfChannels; ++i) | 
|  361             m_sourceChannels[i] = buffer->getChannelData(i)->data(); |  372             m_sourceChannels[i] = buffer->getChannelData(i)->data(); | 
|  362     } |  373     } | 
|  363  |  374  | 
|  364     m_virtualReadIndex = 0; |  375     m_virtualReadIndex = 0; | 
|  365     m_buffer = buffer; |  376     m_buffer = buffer; | 
|  366  |  | 
|  367     return true; |  | 
|  368 } |  377 } | 
|  369  |  378  | 
|  370 unsigned AudioBufferSourceNode::numberOfChannels() |  379 unsigned AudioBufferSourceNode::numberOfChannels() | 
|  371 { |  380 { | 
|  372     return output(0)->numberOfChannels(); |  381     return output(0)->numberOfChannels(); | 
|  373 } |  382 } | 
|  374  |  383  | 
|  375 void AudioBufferSourceNode::startGrain(double when, double grainOffset) |  384 void AudioBufferSourceNode::startGrain(double when, double grainOffset) | 
|  376 { |  385 { | 
|  377     // Duration of 0 has special value, meaning calculate based on the entire bu
     ffer's duration. |  386     // 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() |  488 void AudioBufferSourceNode::finish() | 
|  480 { |  489 { | 
|  481     clearPannerNode(); |  490     clearPannerNode(); | 
|  482     ASSERT(!m_pannerNode); |  491     ASSERT(!m_pannerNode); | 
|  483     AudioScheduledSourceNode::finish(); |  492     AudioScheduledSourceNode::finish(); | 
|  484 } |  493 } | 
|  485  |  494  | 
|  486 } // namespace WebCore |  495 } // namespace WebCore | 
|  487  |  496  | 
|  488 #endif // ENABLE(WEB_AUDIO) |  497 #endif // ENABLE(WEB_AUDIO) | 
| OLD | NEW |