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