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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 return getChannelData(channelIndex); | 196 return getChannelData(channelIndex); |
197 } | 197 } |
198 | 198 |
199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) { | 199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) { |
200 if (channelIndex >= m_channels.size()) | 200 if (channelIndex >= m_channels.size()) |
201 return nullptr; | 201 return nullptr; |
202 | 202 |
203 return m_channels[channelIndex].get(); | 203 return m_channels[channelIndex].get(); |
204 } | 204 } |
205 | 205 |
206 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, | 206 void AudioBuffer::copyFromChannel(const NotShared<DOMFloat32Array>& destination, |
haraken
2017/04/06 08:43:54
Would it be possible to make NotShared<> be passed
binji
2017/04/09 00:40:02
Done.
| |
207 long channelNumber, | 207 long channelNumber, |
208 ExceptionState& exceptionState) { | 208 ExceptionState& exceptionState) { |
209 return copyFromChannel(destination, channelNumber, 0, exceptionState); | 209 return copyFromChannel(destination, channelNumber, 0, exceptionState); |
210 } | 210 } |
211 | 211 |
212 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, | 212 void AudioBuffer::copyFromChannel(const NotShared<DOMFloat32Array>& destination, |
213 long channelNumber, | 213 long channelNumber, |
214 unsigned long startInChannel, | 214 unsigned long startInChannel, |
215 ExceptionState& exceptionState) { | 215 ExceptionState& exceptionState) { |
216 if (channelNumber < 0 || | 216 if (channelNumber < 0 || |
217 channelNumber >= static_cast<long>(m_channels.size())) { | 217 channelNumber >= static_cast<long>(m_channels.size())) { |
218 exceptionState.throwDOMException( | 218 exceptionState.throwDOMException( |
219 IndexSizeError, ExceptionMessages::indexOutsideRange( | 219 IndexSizeError, ExceptionMessages::indexOutsideRange( |
220 "channelNumber", channelNumber, 0L, | 220 "channelNumber", channelNumber, 0L, |
221 ExceptionMessages::InclusiveBound, | 221 ExceptionMessages::InclusiveBound, |
222 static_cast<long>(m_channels.size() - 1), | 222 static_cast<long>(m_channels.size() - 1), |
223 ExceptionMessages::InclusiveBound)); | 223 ExceptionMessages::InclusiveBound)); |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 DOMFloat32Array* channelData = m_channels[channelNumber].get(); | 227 DOMFloat32Array* channelData = m_channels[channelNumber].get(); |
228 | 228 |
229 if (startInChannel >= channelData->length()) { | 229 if (startInChannel >= channelData->length()) { |
230 exceptionState.throwDOMException( | 230 exceptionState.throwDOMException( |
231 IndexSizeError, ExceptionMessages::indexOutsideRange( | 231 IndexSizeError, ExceptionMessages::indexOutsideRange( |
232 "startInChannel", startInChannel, 0UL, | 232 "startInChannel", startInChannel, 0UL, |
233 ExceptionMessages::InclusiveBound, | 233 ExceptionMessages::InclusiveBound, |
234 static_cast<unsigned long>(channelData->length()), | 234 static_cast<unsigned long>(channelData->length()), |
235 ExceptionMessages::ExclusiveBound)); | 235 ExceptionMessages::ExclusiveBound)); |
236 | 236 |
237 return; | 237 return; |
238 } | 238 } |
239 | 239 |
240 unsigned count = channelData->length() - startInChannel; | 240 unsigned count = channelData->length() - startInChannel; |
241 count = std::min(destination->length(), count); | 241 count = std::min(destination.view()->length(), count); |
242 | 242 |
243 const float* src = channelData->data(); | 243 const float* src = channelData->data(); |
244 float* dst = destination->data(); | 244 float* dst = destination.view()->data(); |
245 | 245 |
246 DCHECK(src); | 246 DCHECK(src); |
247 DCHECK(dst); | 247 DCHECK(dst); |
248 | 248 |
249 memcpy(dst, src + startInChannel, count * sizeof(*src)); | 249 memcpy(dst, src + startInChannel, count * sizeof(*src)); |
250 } | 250 } |
251 | 251 |
252 void AudioBuffer::copyToChannel(DOMFloat32Array* source, | 252 void AudioBuffer::copyToChannel(const NotShared<DOMFloat32Array>& source, |
253 long channelNumber, | 253 long channelNumber, |
254 ExceptionState& exceptionState) { | 254 ExceptionState& exceptionState) { |
255 return copyToChannel(source, channelNumber, 0, exceptionState); | 255 return copyToChannel(source, channelNumber, 0, exceptionState); |
256 } | 256 } |
257 | 257 |
258 void AudioBuffer::copyToChannel(DOMFloat32Array* source, | 258 void AudioBuffer::copyToChannel(const NotShared<DOMFloat32Array>& source, |
259 long channelNumber, | 259 long channelNumber, |
260 unsigned long startInChannel, | 260 unsigned long startInChannel, |
261 ExceptionState& exceptionState) { | 261 ExceptionState& exceptionState) { |
262 if (channelNumber < 0 || | 262 if (channelNumber < 0 || |
263 channelNumber >= static_cast<long>(m_channels.size())) { | 263 channelNumber >= static_cast<long>(m_channels.size())) { |
264 exceptionState.throwDOMException( | 264 exceptionState.throwDOMException( |
265 IndexSizeError, ExceptionMessages::indexOutsideRange( | 265 IndexSizeError, ExceptionMessages::indexOutsideRange( |
266 "channelNumber", channelNumber, 0L, | 266 "channelNumber", channelNumber, 0L, |
267 ExceptionMessages::InclusiveBound, | 267 ExceptionMessages::InclusiveBound, |
268 static_cast<long>(m_channels.size() - 1), | 268 static_cast<long>(m_channels.size() - 1), |
269 ExceptionMessages::InclusiveBound)); | 269 ExceptionMessages::InclusiveBound)); |
270 return; | 270 return; |
271 } | 271 } |
272 | 272 |
273 DOMFloat32Array* channelData = m_channels[channelNumber].get(); | 273 DOMFloat32Array* channelData = m_channels[channelNumber].get(); |
274 | 274 |
275 if (startInChannel >= channelData->length()) { | 275 if (startInChannel >= channelData->length()) { |
276 exceptionState.throwDOMException( | 276 exceptionState.throwDOMException( |
277 IndexSizeError, ExceptionMessages::indexOutsideRange( | 277 IndexSizeError, ExceptionMessages::indexOutsideRange( |
278 "startInChannel", startInChannel, 0UL, | 278 "startInChannel", startInChannel, 0UL, |
279 ExceptionMessages::InclusiveBound, | 279 ExceptionMessages::InclusiveBound, |
280 static_cast<unsigned long>(channelData->length()), | 280 static_cast<unsigned long>(channelData->length()), |
281 ExceptionMessages::ExclusiveBound)); | 281 ExceptionMessages::ExclusiveBound)); |
282 | 282 |
283 return; | 283 return; |
284 } | 284 } |
285 | 285 |
286 unsigned count = channelData->length() - startInChannel; | 286 unsigned count = channelData->length() - startInChannel; |
287 count = std::min(source->length(), count); | 287 count = std::min(source.view()->length(), count); |
288 | 288 |
289 const float* src = source->data(); | 289 const float* src = source.view()->data(); |
290 float* dst = channelData->data(); | 290 float* dst = channelData->data(); |
291 | 291 |
292 DCHECK(src); | 292 DCHECK(src); |
293 DCHECK(dst); | 293 DCHECK(dst); |
294 | 294 |
295 memcpy(dst + startInChannel, src, count * sizeof(*dst)); | 295 memcpy(dst + startInChannel, src, count * sizeof(*dst)); |
296 } | 296 } |
297 | 297 |
298 void AudioBuffer::zero() { | 298 void AudioBuffer::zero() { |
299 for (unsigned i = 0; i < m_channels.size(); ++i) { | 299 for (unsigned i = 0; i < m_channels.size(); ++i) { |
300 if (DOMFloat32Array* array = getChannelData(i)) { | 300 if (DOMFloat32Array* array = getChannelData(i)) { |
301 float* data = array->data(); | 301 float* data = array->data(); |
302 memset(data, 0, length() * sizeof(*data)); | 302 memset(data, 0, length() * sizeof(*data)); |
303 } | 303 } |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 } // namespace blink | 307 } // namespace blink |
OLD | NEW |