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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 144 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
145 : m_sampleRate(sampleRate) | 145 : m_sampleRate(sampleRate) |
146 , m_length(numberOfFrames) | 146 , m_length(numberOfFrames) |
147 { | 147 { |
148 m_channels.reserveCapacity(numberOfChannels); | 148 m_channels.reserveCapacity(numberOfChannels); |
149 | 149 |
150 for (unsigned i = 0; i < numberOfChannels; ++i) { | 150 for (unsigned i = 0; i < numberOfChannels; ++i) { |
151 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); | 151 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); |
152 // If the channel data array could not be created, just return. The call
er will need to | 152 // If the channel data array could not be created, just return. The call
er will need to |
153 // check that the desired number of channels were created. | 153 // check that the desired number of channels were created. |
| 154 |
| 155 // TODO(junov) crbug.com/536816 |
| 156 // According to ECMAScript spec, failure to allocate should result in a |
| 157 // RangeError exception being thrown: |
| 158 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock |
| 159 // The spec for createBuffer does not specify whether such an exception |
| 160 // should be re-thrown. |
154 if (!channelDataArray) { | 161 if (!channelDataArray) { |
155 return; | 162 return; |
156 } | 163 } |
157 | 164 |
158 channelDataArray->setNeuterable(false); | 165 channelDataArray->setNeuterable(false); |
159 m_channels.append(channelDataArray); | 166 m_channels.append(channelDataArray); |
160 } | 167 } |
161 } | 168 } |
162 | 169 |
163 AudioBuffer::AudioBuffer(AudioBus* bus) | 170 AudioBuffer::AudioBuffer(AudioBus* bus) |
164 : m_sampleRate(bus->sampleRate()) | 171 : m_sampleRate(bus->sampleRate()) |
165 , m_length(bus->length()) | 172 , m_length(bus->length()) |
166 { | 173 { |
167 // Copy audio data from the bus to the Float32Arrays we manage. | 174 // Copy audio data from the bus to the Float32Arrays we manage. |
168 unsigned numberOfChannels = bus->numberOfChannels(); | 175 unsigned numberOfChannels = bus->numberOfChannels(); |
169 m_channels.reserveCapacity(numberOfChannels); | 176 m_channels.reserveCapacity(numberOfChannels); |
170 for (unsigned i = 0; i < numberOfChannels; ++i) { | 177 for (unsigned i = 0; i < numberOfChannels; ++i) { |
171 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); | 178 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); |
172 // If the channel data array could not be created, just return. The call
er will need to | 179 // If the channel data array could not be created, just return. The call
er will need to |
173 // check that the desired number of channels were created. | 180 // check that the desired number of channels were created. |
| 181 |
| 182 // TODO(junov): crbug.com/536816 |
| 183 // According to ECMAScript spec, failure to allocate should result in a |
| 184 // RangeError exception being thrown: |
| 185 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock |
174 if (!channelDataArray) | 186 if (!channelDataArray) |
175 return; | 187 return; |
176 | 188 |
177 channelDataArray->setNeuterable(false); | 189 channelDataArray->setNeuterable(false); |
178 const float* src = bus->channel(i)->data(); | 190 const float* src = bus->channel(i)->data(); |
179 float* dst = channelDataArray->data(); | 191 float* dst = channelDataArray->data(); |
180 memmove(dst, src, m_length * sizeof(*dst)); | 192 memmove(dst, src, m_length * sizeof(*dst)); |
181 m_channels.append(channelDataArray); | 193 m_channels.append(channelDataArray); |
182 } | 194 } |
183 } | 195 } |
184 | 196 |
185 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E
xceptionState& exceptionState) | 197 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E
xceptionState& exceptionState) |
186 { | 198 { |
187 if (channelIndex >= m_channels.size()) { | 199 if (channelIndex >= m_channels.size()) { |
188 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); | 200 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); |
189 return nullptr; | 201 return nullptr; |
190 } | 202 } |
191 | 203 |
192 DOMFloat32Array* channelData = m_channels[channelIndex].get(); | 204 DOMFloat32Array* channelData = m_channels[channelIndex].get(); |
193 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse
t(), channelData->length()); | 205 RefPtr<DOMArrayBuffer> buffer = channelData->bufferOrNull(); |
| 206 RELEASE_ASSERT(buffer); // crbug.com/536816 |
| 207 return DOMFloat32Array::create(buffer.release(), channelData->byteOffset(),
channelData->length()); |
194 } | 208 } |
195 | 209 |
196 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) | 210 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) |
197 { | 211 { |
198 if (channelIndex >= m_channels.size()) | 212 if (channelIndex >= m_channels.size()) |
199 return nullptr; | 213 return nullptr; |
200 | 214 |
201 return m_channels[channelIndex].get(); | 215 return m_channels[channelIndex].get(); |
202 } | 216 } |
203 | 217 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (DOMFloat32Array* array = getChannelData(i)) { | 335 if (DOMFloat32Array* array = getChannelData(i)) { |
322 float* data = array->data(); | 336 float* data = array->data(); |
323 memset(data, 0, length() * sizeof(*data)); | 337 memset(data, 0, length() * sizeof(*data)); |
324 } | 338 } |
325 } | 339 } |
326 } | 340 } |
327 | 341 |
328 } // namespace blink | 342 } // namespace blink |
329 | 343 |
330 #endif // ENABLE(WEB_AUDIO) | 344 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |