| 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  * | 7  * | 
| 8  * 1.  Redistributions of source code must retain the above copyright | 8  * 1.  Redistributions of source code must retain the above copyright | 
| 9  *     notice, this list of conditions and the following disclaimer. | 9  *     notice, this list of conditions and the following disclaimer. | 
| 10  * 2.  Redistributions in binary form must reproduce the above copyright | 10  * 2.  Redistributions in binary form must reproduce the above copyright | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 31 #include "modules/webaudio/AudioBuffer.h" | 31 #include "modules/webaudio/AudioBuffer.h" | 
| 32 | 32 | 
| 33 #include "bindings/core/v8/ExceptionMessages.h" | 33 #include "bindings/core/v8/ExceptionMessages.h" | 
| 34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" | 
| 35 #include "core/dom/DOMArrayBufferDeallocationObserver.h" | 35 #include "core/dom/DOMArrayBufferDeallocationObserver.h" | 
| 36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" | 
| 37 #include "modules/webaudio/AudioContext.h" | 37 #include "modules/webaudio/AudioContext.h" | 
| 38 #include "platform/audio/AudioBus.h" | 38 #include "platform/audio/AudioBus.h" | 
| 39 #include "platform/audio/AudioFileReader.h" | 39 #include "platform/audio/AudioFileReader.h" | 
| 40 #include "platform/audio/AudioUtilities.h" | 40 #include "platform/audio/AudioUtilities.h" | 
|  | 41 #include "wtf/Float32Array.h" | 
| 41 | 42 | 
| 42 namespace blink { | 43 namespace blink { | 
| 43 | 44 | 
| 44 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
     s, float sampleRate) | 45 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
     s, float sampleRate) | 
| 45 { | 46 { | 
| 46     if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate) || numberOfCha
     nnels > AudioContext::maxNumberOfChannels() || !numberOfChannels || !numberOfFra
     mes) | 47     if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate) || numberOfCha
     nnels > AudioContext::maxNumberOfChannels() || !numberOfChannels || !numberOfFra
     mes) | 
| 47         return nullptr; | 48         return nullptr; | 
| 48 | 49 | 
| 49     AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp
     leRate); | 50     AudioBuffer* buffer = new AudioBuffer(numberOfChannels, numberOfFrames, samp
     leRate); | 
| 50 | 51 | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 126     if (buffer->createdSuccessfully(bus->numberOfChannels())) | 127     if (buffer->createdSuccessfully(bus->numberOfChannels())) | 
| 127         return buffer; | 128         return buffer; | 
| 128     return nullptr; | 129     return nullptr; | 
| 129 } | 130 } | 
| 130 | 131 | 
| 131 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 132 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 
| 132 { | 133 { | 
| 133     return numberOfChannels() == desiredNumberOfChannels; | 134     return numberOfChannels() == desiredNumberOfChannels; | 
| 134 } | 135 } | 
| 135 | 136 | 
|  | 137 PassRefPtr<DOMFloat32Array> AudioBuffer::createFloat32Array(size_t length) | 
|  | 138 { | 
|  | 139     RefPtr<WTF::Float32Array> bufferView = WTF::Float32Array::createOrNull(lengt
     h); | 
|  | 140     if (!bufferView) | 
|  | 141         return nullptr; | 
|  | 142     return DOMFloat32Array::create(bufferView.release()); | 
|  | 143 } | 
|  | 144 | 
| 136 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
      sampleRate) | 145 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
      sampleRate) | 
| 137     : m_sampleRate(sampleRate) | 146     : m_sampleRate(sampleRate) | 
| 138     , m_length(numberOfFrames) | 147     , m_length(numberOfFrames) | 
| 139 { | 148 { | 
| 140     m_channels.reserveCapacity(numberOfChannels); | 149     m_channels.reserveCapacity(numberOfChannels); | 
| 141 | 150 | 
| 142     for (unsigned i = 0; i < numberOfChannels; ++i) { | 151     for (unsigned i = 0; i < numberOfChannels; ++i) { | 
| 143         RefPtr<DOMFloat32Array> channelDataArray = DOMFloat32Array::createOrNull
     (m_length); | 152         RefPtr<DOMFloat32Array> channelDataArray = createFloat32Array(m_length); | 
| 144         // If the channel data array could not be created, just return. The call
     er will need to | 153         // If the channel data array could not be created, just return. The call
     er will need to | 
| 145         // check that the desired number of channels were created. | 154         // check that the desired number of channels were created. | 
| 146         if (!channelDataArray) { | 155         if (!channelDataArray) { | 
| 147             return; | 156             return; | 
| 148         } | 157         } | 
| 149 | 158 | 
| 150         channelDataArray->setNeuterable(false); | 159         channelDataArray->setNeuterable(false); | 
| 151         m_channels.append(channelDataArray); | 160         m_channels.append(channelDataArray); | 
| 152     } | 161     } | 
| 153 } | 162 } | 
| 154 | 163 | 
| 155 AudioBuffer::AudioBuffer(AudioBus* bus) | 164 AudioBuffer::AudioBuffer(AudioBus* bus) | 
| 156     : m_sampleRate(bus->sampleRate()) | 165     : m_sampleRate(bus->sampleRate()) | 
| 157     , m_length(bus->length()) | 166     , m_length(bus->length()) | 
| 158 { | 167 { | 
| 159     // Copy audio data from the bus to the Float32Arrays we manage. | 168     // Copy audio data from the bus to the Float32Arrays we manage. | 
| 160     unsigned numberOfChannels = bus->numberOfChannels(); | 169     unsigned numberOfChannels = bus->numberOfChannels(); | 
| 161     m_channels.reserveCapacity(numberOfChannels); | 170     m_channels.reserveCapacity(numberOfChannels); | 
| 162     for (unsigned i = 0; i < numberOfChannels; ++i) { | 171     for (unsigned i = 0; i < numberOfChannels; ++i) { | 
| 163         RefPtr<DOMFloat32Array> channelDataArray = DOMFloat32Array::createOrNull
     (m_length); | 172         RefPtr<DOMFloat32Array> channelDataArray = createFloat32Array(m_length); | 
| 164         // If the channel data array could not be created, just return. The call
     er will need to | 173         // If the channel data array could not be created, just return. The call
     er will need to | 
| 165         // check that the desired number of channels were created. | 174         // check that the desired number of channels were created. | 
| 166         if (!channelDataArray) | 175         if (!channelDataArray) | 
| 167             return; | 176             return; | 
| 168 | 177 | 
| 169         channelDataArray->setNeuterable(false); | 178         channelDataArray->setNeuterable(false); | 
| 170         channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); | 179         channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); | 
| 171         m_channels.append(channelDataArray); | 180         m_channels.append(channelDataArray); | 
| 172     } | 181     } | 
| 173 } | 182 } | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 212         for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) { | 221         for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) { | 
| 213             getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD
     eallocationObserver::instance()); | 222             getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD
     eallocationObserver::instance()); | 
| 214         } | 223         } | 
| 215     } | 224     } | 
| 216     return wrapper; | 225     return wrapper; | 
| 217 } | 226 } | 
| 218 | 227 | 
| 219 } // namespace blink | 228 } // namespace blink | 
| 220 | 229 | 
| 221 #endif // ENABLE(WEB_AUDIO) | 230 #endif // ENABLE(WEB_AUDIO) | 
| OLD | NEW | 
|---|