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