| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (buffer->createdSuccessfully(bus->numberOfChannels())) | 123 if (buffer->createdSuccessfully(bus->numberOfChannels())) |
| 124 return buffer; | 124 return buffer; |
| 125 return nullptr; | 125 return nullptr; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const | 128 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const |
| 129 { | 129 { |
| 130 return numberOfChannels() == desiredNumberOfChannels; | 130 return numberOfChannels() == desiredNumberOfChannels; |
| 131 } | 131 } |
| 132 | 132 |
| 133 DOMFloat32Array* AudioBuffer::createFloat32ArrayOrNull(size_t length) | 133 PassRefPtr<DOMFloat32Array> AudioBuffer::createFloat32ArrayOrNull(size_t length) |
| 134 { | 134 { |
| 135 RefPtr<WTF::Float32Array> bufferView = WTF::Float32Array::createOrNull(lengt
h); | 135 RefPtr<WTF::Float32Array> bufferView = WTF::Float32Array::createOrNull(lengt
h); |
| 136 if (!bufferView) | 136 if (!bufferView) |
| 137 return nullptr; | 137 return nullptr; |
| 138 return DOMFloat32Array::create(bufferView.release()); | 138 return DOMFloat32Array::create(bufferView.release()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) | 141 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float
sampleRate) |
| 142 : m_sampleRate(sampleRate) | 142 : m_sampleRate(sampleRate) |
| 143 , m_length(numberOfFrames) | 143 , m_length(numberOfFrames) |
| 144 { | 144 { |
| 145 m_channels.reserveCapacity(numberOfChannels); | 145 m_channels.reserveCapacity(numberOfChannels); |
| 146 | 146 |
| 147 for (unsigned i = 0; i < numberOfChannels; ++i) { | 147 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 148 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); | 148 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); |
| 149 // If the channel data array could not be created, just return. The call
er will need to | 149 // If the channel data array could not be created, just return. The call
er will need to |
| 150 // check that the desired number of channels were created. | 150 // check that the desired number of channels were created. |
| 151 if (!channelDataArray) | 151 if (!channelDataArray) { |
| 152 return; | 152 return; |
| 153 } |
| 153 | 154 |
| 154 channelDataArray->setNeuterable(false); | 155 channelDataArray->setNeuterable(false); |
| 155 m_channels.append(channelDataArray); | 156 m_channels.append(channelDataArray); |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 159 AudioBuffer::AudioBuffer(AudioBus* bus) | 160 AudioBuffer::AudioBuffer(AudioBus* bus) |
| 160 : m_sampleRate(bus->sampleRate()) | 161 : m_sampleRate(bus->sampleRate()) |
| 161 , m_length(bus->length()) | 162 , m_length(bus->length()) |
| 162 { | 163 { |
| 163 // Copy audio data from the bus to the Float32Arrays we manage. | 164 // Copy audio data from the bus to the Float32Arrays we manage. |
| 164 unsigned numberOfChannels = bus->numberOfChannels(); | 165 unsigned numberOfChannels = bus->numberOfChannels(); |
| 165 m_channels.reserveCapacity(numberOfChannels); | 166 m_channels.reserveCapacity(numberOfChannels); |
| 166 for (unsigned i = 0; i < numberOfChannels; ++i) { | 167 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 167 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length); | 168 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le
ngth); |
| 168 // If the channel data array could not be created, just return. The call
er will need to | 169 // If the channel data array could not be created, just return. The call
er will need to |
| 169 // check that the desired number of channels were created. | 170 // check that the desired number of channels were created. |
| 170 if (!channelDataArray) | 171 if (!channelDataArray) |
| 171 return; | 172 return; |
| 172 | 173 |
| 173 channelDataArray->setNeuterable(false); | 174 channelDataArray->setNeuterable(false); |
| 174 const float* src = bus->channel(i)->data(); | 175 const float* src = bus->channel(i)->data(); |
| 175 float* dst = channelDataArray->data(); | 176 float* dst = channelDataArray->data(); |
| 176 memmove(dst, src, m_length * sizeof(*dst)); | 177 memmove(dst, src, m_length * sizeof(*dst)); |
| 177 m_channels.append(channelDataArray); | 178 m_channels.append(channelDataArray); |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, ExceptionSta
te& exceptionState) | 182 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E
xceptionState& exceptionState) |
| 182 { | 183 { |
| 183 if (channelIndex >= m_channels.size()) { | 184 if (channelIndex >= m_channels.size()) { |
| 184 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); | 185 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str
ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_
channels.size()) + ")"); |
| 185 return nullptr; | 186 return nullptr; |
| 186 } | 187 } |
| 187 | 188 |
| 188 DOMFloat32Array* channelData = m_channels[channelIndex].get(); | 189 DOMFloat32Array* channelData = m_channels[channelIndex].get(); |
| 189 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse
t(), channelData->length()); | 190 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse
t(), channelData->length()); |
| 190 } | 191 } |
| 191 | 192 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 for (unsigned i = 0; i < m_channels.size(); ++i) { | 299 for (unsigned i = 0; i < m_channels.size(); ++i) { |
| 299 if (DOMFloat32Array* array = getChannelData(i)) { | 300 if (DOMFloat32Array* array = getChannelData(i)) { |
| 300 float* data = array->data(); | 301 float* data = array->data(); |
| 301 memset(data, 0, length() * sizeof(*data)); | 302 memset(data, 0, length() * sizeof(*data)); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 | 306 |
| 306 } // namespace blink | 307 } // namespace blink |
| 307 | 308 |
| OLD | NEW |