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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return; | 176 return; |
177 | 177 |
178 channelDataArray->setNeuterable(false); | 178 channelDataArray->setNeuterable(false); |
179 const float* src = bus->channel(i)->data(); | 179 const float* src = bus->channel(i)->data(); |
180 float* dst = channelDataArray->data(); | 180 float* dst = channelDataArray->data(); |
181 memmove(dst, src, m_length * sizeof(*dst)); | 181 memmove(dst, src, m_length * sizeof(*dst)); |
182 m_channels.push_back(channelDataArray); | 182 m_channels.push_back(channelDataArray); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, | 186 NotShared<DOMFloat32Array> AudioBuffer::getChannelData( |
187 ExceptionState& exceptionState) { | 187 unsigned channelIndex, |
| 188 ExceptionState& exceptionState) { |
188 if (channelIndex >= m_channels.size()) { | 189 if (channelIndex >= m_channels.size()) { |
189 exceptionState.throwDOMException( | 190 exceptionState.throwDOMException( |
190 IndexSizeError, "channel index (" + String::number(channelIndex) + | 191 IndexSizeError, "channel index (" + String::number(channelIndex) + |
191 ") exceeds number of channels (" + | 192 ") exceeds number of channels (" + |
192 String::number(m_channels.size()) + ")"); | 193 String::number(m_channels.size()) + ")"); |
193 return nullptr; | 194 return NotShared<DOMFloat32Array>(nullptr); |
194 } | 195 } |
195 | 196 |
196 return getChannelData(channelIndex); | 197 return getChannelData(channelIndex); |
197 } | 198 } |
198 | 199 |
199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) { | 200 NotShared<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex) { |
200 if (channelIndex >= m_channels.size()) | 201 if (channelIndex >= m_channels.size()) |
201 return nullptr; | 202 return NotShared<DOMFloat32Array>(nullptr); |
202 | 203 |
203 return m_channels[channelIndex].get(); | 204 return NotShared<DOMFloat32Array>(m_channels[channelIndex].get()); |
204 } | 205 } |
205 | 206 |
206 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, | 207 void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination, |
207 long channelNumber, | 208 long channelNumber, |
208 ExceptionState& exceptionState) { | 209 ExceptionState& exceptionState) { |
209 return copyFromChannel(destination, channelNumber, 0, exceptionState); | 210 return copyFromChannel(destination, channelNumber, 0, exceptionState); |
210 } | 211 } |
211 | 212 |
212 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, | 213 void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination, |
213 long channelNumber, | 214 long channelNumber, |
214 unsigned long startInChannel, | 215 unsigned long startInChannel, |
215 ExceptionState& exceptionState) { | 216 ExceptionState& exceptionState) { |
216 if (channelNumber < 0 || | 217 if (channelNumber < 0 || |
217 channelNumber >= static_cast<long>(m_channels.size())) { | 218 channelNumber >= static_cast<long>(m_channels.size())) { |
218 exceptionState.throwDOMException( | 219 exceptionState.throwDOMException( |
219 IndexSizeError, ExceptionMessages::indexOutsideRange( | 220 IndexSizeError, ExceptionMessages::indexOutsideRange( |
220 "channelNumber", channelNumber, 0L, | 221 "channelNumber", channelNumber, 0L, |
221 ExceptionMessages::InclusiveBound, | 222 ExceptionMessages::InclusiveBound, |
222 static_cast<long>(m_channels.size() - 1), | 223 static_cast<long>(m_channels.size() - 1), |
223 ExceptionMessages::InclusiveBound)); | 224 ExceptionMessages::InclusiveBound)); |
224 return; | 225 return; |
225 } | 226 } |
226 | 227 |
227 DOMFloat32Array* channelData = m_channels[channelNumber].get(); | 228 DOMFloat32Array* channelData = m_channels[channelNumber].get(); |
228 | 229 |
229 if (startInChannel >= channelData->length()) { | 230 if (startInChannel >= channelData->length()) { |
230 exceptionState.throwDOMException( | 231 exceptionState.throwDOMException( |
231 IndexSizeError, ExceptionMessages::indexOutsideRange( | 232 IndexSizeError, ExceptionMessages::indexOutsideRange( |
232 "startInChannel", startInChannel, 0UL, | 233 "startInChannel", startInChannel, 0UL, |
233 ExceptionMessages::InclusiveBound, | 234 ExceptionMessages::InclusiveBound, |
234 static_cast<unsigned long>(channelData->length()), | 235 static_cast<unsigned long>(channelData->length()), |
235 ExceptionMessages::ExclusiveBound)); | 236 ExceptionMessages::ExclusiveBound)); |
236 | 237 |
237 return; | 238 return; |
238 } | 239 } |
239 | 240 |
240 unsigned count = channelData->length() - startInChannel; | 241 unsigned count = channelData->length() - startInChannel; |
241 count = std::min(destination->length(), count); | 242 count = std::min(destination.view()->length(), count); |
242 | 243 |
243 const float* src = channelData->data(); | 244 const float* src = channelData->data(); |
244 float* dst = destination->data(); | 245 float* dst = destination.view()->data(); |
245 | 246 |
246 DCHECK(src); | 247 DCHECK(src); |
247 DCHECK(dst); | 248 DCHECK(dst); |
248 | 249 |
249 memcpy(dst, src + startInChannel, count * sizeof(*src)); | 250 memcpy(dst, src + startInChannel, count * sizeof(*src)); |
250 } | 251 } |
251 | 252 |
252 void AudioBuffer::copyToChannel(DOMFloat32Array* source, | 253 void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source, |
253 long channelNumber, | 254 long channelNumber, |
254 ExceptionState& exceptionState) { | 255 ExceptionState& exceptionState) { |
255 return copyToChannel(source, channelNumber, 0, exceptionState); | 256 return copyToChannel(source, channelNumber, 0, exceptionState); |
256 } | 257 } |
257 | 258 |
258 void AudioBuffer::copyToChannel(DOMFloat32Array* source, | 259 void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source, |
259 long channelNumber, | 260 long channelNumber, |
260 unsigned long startInChannel, | 261 unsigned long startInChannel, |
261 ExceptionState& exceptionState) { | 262 ExceptionState& exceptionState) { |
262 if (channelNumber < 0 || | 263 if (channelNumber < 0 || |
263 channelNumber >= static_cast<long>(m_channels.size())) { | 264 channelNumber >= static_cast<long>(m_channels.size())) { |
264 exceptionState.throwDOMException( | 265 exceptionState.throwDOMException( |
265 IndexSizeError, ExceptionMessages::indexOutsideRange( | 266 IndexSizeError, ExceptionMessages::indexOutsideRange( |
266 "channelNumber", channelNumber, 0L, | 267 "channelNumber", channelNumber, 0L, |
267 ExceptionMessages::InclusiveBound, | 268 ExceptionMessages::InclusiveBound, |
268 static_cast<long>(m_channels.size() - 1), | 269 static_cast<long>(m_channels.size() - 1), |
269 ExceptionMessages::InclusiveBound)); | 270 ExceptionMessages::InclusiveBound)); |
270 return; | 271 return; |
271 } | 272 } |
272 | 273 |
273 DOMFloat32Array* channelData = m_channels[channelNumber].get(); | 274 DOMFloat32Array* channelData = m_channels[channelNumber].get(); |
274 | 275 |
275 if (startInChannel >= channelData->length()) { | 276 if (startInChannel >= channelData->length()) { |
276 exceptionState.throwDOMException( | 277 exceptionState.throwDOMException( |
277 IndexSizeError, ExceptionMessages::indexOutsideRange( | 278 IndexSizeError, ExceptionMessages::indexOutsideRange( |
278 "startInChannel", startInChannel, 0UL, | 279 "startInChannel", startInChannel, 0UL, |
279 ExceptionMessages::InclusiveBound, | 280 ExceptionMessages::InclusiveBound, |
280 static_cast<unsigned long>(channelData->length()), | 281 static_cast<unsigned long>(channelData->length()), |
281 ExceptionMessages::ExclusiveBound)); | 282 ExceptionMessages::ExclusiveBound)); |
282 | 283 |
283 return; | 284 return; |
284 } | 285 } |
285 | 286 |
286 unsigned count = channelData->length() - startInChannel; | 287 unsigned count = channelData->length() - startInChannel; |
287 count = std::min(source->length(), count); | 288 count = std::min(source.view()->length(), count); |
288 | 289 |
289 const float* src = source->data(); | 290 const float* src = source.view()->data(); |
290 float* dst = channelData->data(); | 291 float* dst = channelData->data(); |
291 | 292 |
292 DCHECK(src); | 293 DCHECK(src); |
293 DCHECK(dst); | 294 DCHECK(dst); |
294 | 295 |
295 memcpy(dst + startInChannel, src, count * sizeof(*dst)); | 296 memcpy(dst + startInChannel, src, count * sizeof(*dst)); |
296 } | 297 } |
297 | 298 |
298 void AudioBuffer::zero() { | 299 void AudioBuffer::zero() { |
299 for (unsigned i = 0; i < m_channels.size(); ++i) { | 300 for (unsigned i = 0; i < m_channels.size(); ++i) { |
300 if (DOMFloat32Array* array = getChannelData(i)) { | 301 if (NotShared<DOMFloat32Array> array = getChannelData(i)) { |
301 float* data = array->data(); | 302 float* data = array.view()->data(); |
302 memset(data, 0, length() * sizeof(*data)); | 303 memset(data, 0, length() * sizeof(*data)); |
303 } | 304 } |
304 } | 305 } |
305 } | 306 } |
306 | 307 |
307 } // namespace blink | 308 } // namespace blink |
OLD | NEW |