| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 m_channels.reserveCapacity(numberOfChannels); | 170 m_channels.reserveCapacity(numberOfChannels); |
| 171 | 171 |
| 172 for (unsigned i = 0; i < numberOfChannels; ++i) { | 172 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 173 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); | 173 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); |
| 174 // If the channel data array could not be created, just return. The caller | 174 // If the channel data array could not be created, just return. The caller |
| 175 // will need to check that the desired number of channels were created. | 175 // will need to check that the desired number of channels were created. |
| 176 if (!channelDataArray) | 176 if (!channelDataArray) |
| 177 return; | 177 return; |
| 178 | 178 |
| 179 channelDataArray->setNeuterable(false); | 179 channelDataArray->setNeuterable(false); |
| 180 m_channels.append(channelDataArray); | 180 m_channels.push_back(channelDataArray); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 AudioBuffer::AudioBuffer(AudioBus* bus) | 184 AudioBuffer::AudioBuffer(AudioBus* bus) |
| 185 : m_sampleRate(bus->sampleRate()), m_length(bus->length()) { | 185 : m_sampleRate(bus->sampleRate()), m_length(bus->length()) { |
| 186 // Copy audio data from the bus to the Float32Arrays we manage. | 186 // Copy audio data from the bus to the Float32Arrays we manage. |
| 187 unsigned numberOfChannels = bus->numberOfChannels(); | 187 unsigned numberOfChannels = bus->numberOfChannels(); |
| 188 m_channels.reserveCapacity(numberOfChannels); | 188 m_channels.reserveCapacity(numberOfChannels); |
| 189 for (unsigned i = 0; i < numberOfChannels; ++i) { | 189 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 190 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); | 190 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); |
| 191 // If the channel data array could not be created, just return. The caller | 191 // If the channel data array could not be created, just return. The caller |
| 192 // will need to check that the desired number of channels were created. | 192 // will need to check that the desired number of channels were created. |
| 193 if (!channelDataArray) | 193 if (!channelDataArray) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 channelDataArray->setNeuterable(false); | 196 channelDataArray->setNeuterable(false); |
| 197 const float* src = bus->channel(i)->data(); | 197 const float* src = bus->channel(i)->data(); |
| 198 float* dst = channelDataArray->data(); | 198 float* dst = channelDataArray->data(); |
| 199 memmove(dst, src, m_length * sizeof(*dst)); | 199 memmove(dst, src, m_length * sizeof(*dst)); |
| 200 m_channels.append(channelDataArray); | 200 m_channels.push_back(channelDataArray); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, | 204 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, |
| 205 ExceptionState& exceptionState) { | 205 ExceptionState& exceptionState) { |
| 206 if (channelIndex >= m_channels.size()) { | 206 if (channelIndex >= m_channels.size()) { |
| 207 exceptionState.throwDOMException( | 207 exceptionState.throwDOMException( |
| 208 IndexSizeError, "channel index (" + String::number(channelIndex) + | 208 IndexSizeError, "channel index (" + String::number(channelIndex) + |
| 209 ") exceeds number of channels (" + | 209 ") exceeds number of channels (" + |
| 210 String::number(m_channels.size()) + ")"); | 210 String::number(m_channels.size()) + ")"); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 void AudioBuffer::zero() { | 316 void AudioBuffer::zero() { |
| 317 for (unsigned i = 0; i < m_channels.size(); ++i) { | 317 for (unsigned i = 0; i < m_channels.size(); ++i) { |
| 318 if (DOMFloat32Array* array = getChannelData(i)) { | 318 if (DOMFloat32Array* array = getChannelData(i)) { |
| 319 float* data = array->data(); | 319 float* data = array->data(); |
| 320 memset(data, 0, length() * sizeof(*data)); | 320 memset(data, 0, length() * sizeof(*data)); |
| 321 } | 321 } |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace blink | 325 } // namespace blink |
| OLD | NEW |