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 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (DOMFloat32Array* array = getChannelData(i)) { | 333 if (DOMFloat32Array* array = getChannelData(i)) { |
322 float* data = array->data(); | 334 float* data = array->data(); |
323 memset(data, 0, length() * sizeof(*data)); | 335 memset(data, 0, length() * sizeof(*data)); |
324 } | 336 } |
325 } | 337 } |
326 } | 338 } |
327 | 339 |
328 } // namespace blink | 340 } // namespace blink |
329 | 341 |
330 #endif // ENABLE(WEB_AUDIO) | 342 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |