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