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