| 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 13 matching lines...) Expand all Loading... |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/webaudio/AudioBuffer.h" | 29 #include "modules/webaudio/AudioBuffer.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ExceptionMessages.h" | 31 #include "bindings/core/v8/ExceptionMessages.h" |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 34 #include "modules/webaudio/AudioBufferOptions.h" |
| 34 #include "modules/webaudio/BaseAudioContext.h" | 35 #include "modules/webaudio/BaseAudioContext.h" |
| 35 #include "platform/audio/AudioBus.h" | 36 #include "platform/audio/AudioBus.h" |
| 36 #include "platform/audio/AudioFileReader.h" | 37 #include "platform/audio/AudioFileReader.h" |
| 37 #include "platform/audio/AudioUtilities.h" | 38 #include "platform/audio/AudioUtilities.h" |
| 38 #include "wtf/typed_arrays/Float32Array.h" | 39 #include "wtf/typed_arrays/Float32Array.h" |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate) | 43 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame
s, float sampleRate) |
| 43 { | 44 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 "createBuffer(" | 98 "createBuffer(" |
| 98 + String::number(numberOfChannels) + ", " | 99 + String::number(numberOfChannels) + ", " |
| 99 + String::number(numberOfFrames) + ", " | 100 + String::number(numberOfFrames) + ", " |
| 100 + String::number(sampleRate) | 101 + String::number(sampleRate) |
| 101 + ") failed."); | 102 + ") failed."); |
| 102 } | 103 } |
| 103 | 104 |
| 104 return audioBuffer; | 105 return audioBuffer; |
| 105 } | 106 } |
| 106 | 107 |
| 108 AudioBuffer* AudioBuffer::create(BaseAudioContext* context, const AudioBufferOpt
ions& options, ExceptionState& exceptionState) |
| 109 { |
| 110 unsigned numberOfChannels; |
| 111 size_t numberOfFrames; |
| 112 float sampleRate; |
| 113 |
| 114 if (!options.hasNumberOfChannels()) { |
| 115 exceptionState.throwDOMException( |
| 116 NotFoundError, |
| 117 "AudioBufferOptions: numberOfChannels is required."); |
| 118 return nullptr; |
| 119 } |
| 120 |
| 121 if (!options.hasLength()) { |
| 122 exceptionState.throwDOMException( |
| 123 NotFoundError, |
| 124 "AudioBufferOptions: length is required."); |
| 125 return nullptr; |
| 126 } |
| 127 |
| 128 numberOfChannels = options.numberOfChannels(); |
| 129 numberOfFrames = options.length(); |
| 130 |
| 131 if (options.hasSampleRate()) |
| 132 sampleRate = options.sampleRate(); |
| 133 else |
| 134 sampleRate = context->sampleRate(); |
| 135 |
| 136 return create(numberOfChannels, numberOfFrames, sampleRate, exceptionState); |
| 137 } |
| 138 |
| 107 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS
ize, bool mixToMono, float sampleRate) | 139 AudioBuffer* AudioBuffer::createFromAudioFileData(const void* data, size_t dataS
ize, bool mixToMono, float sampleRate) |
| 108 { | 140 { |
| 109 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM
ono, sampleRate); | 141 RefPtr<AudioBus> bus = createBusFromInMemoryAudioFile(data, dataSize, mixToM
ono, sampleRate); |
| 110 if (bus) { | 142 if (bus) { |
| 111 AudioBuffer* buffer = new AudioBuffer(bus.get()); | 143 AudioBuffer* buffer = new AudioBuffer(bus.get()); |
| 112 if (buffer->createdSuccessfully(bus->numberOfChannels())) | 144 if (buffer->createdSuccessfully(bus->numberOfChannels())) |
| 113 return buffer; | 145 return buffer; |
| 114 } | 146 } |
| 115 | 147 |
| 116 return nullptr; | 148 return nullptr; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 for (unsigned i = 0; i < m_channels.size(); ++i) { | 330 for (unsigned i = 0; i < m_channels.size(); ++i) { |
| 299 if (DOMFloat32Array* array = getChannelData(i)) { | 331 if (DOMFloat32Array* array = getChannelData(i)) { |
| 300 float* data = array->data(); | 332 float* data = array->data(); |
| 301 memset(data, 0, length() * sizeof(*data)); | 333 memset(data, 0, length() * sizeof(*data)); |
| 302 } | 334 } |
| 303 } | 335 } |
| 304 } | 336 } |
| 305 | 337 |
| 306 } // namespace blink | 338 } // namespace blink |
| 307 | 339 |
| OLD | NEW |