Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1876)

Side by Side Diff: Source/modules/webaudio/AudioBuffer.cpp

Issue 1180023002: Inline the only callers of TypedArrayBase::{setRange,zeroRange} (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/DOMTypedArray.h ('k') | Source/wtf/ArrayBufferView.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 unsigned numberOfChannels = bus->numberOfChannels(); 169 unsigned numberOfChannels = bus->numberOfChannels();
170 m_channels.reserveCapacity(numberOfChannels); 170 m_channels.reserveCapacity(numberOfChannels);
171 for (unsigned i = 0; i < numberOfChannels; ++i) { 171 for (unsigned i = 0; i < numberOfChannels; ++i) {
172 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le ngth); 172 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le ngth);
173 // If the channel data array could not be created, just return. The call er will need to 173 // If the channel data array could not be created, just return. The call er will need to
174 // check that the desired number of channels were created. 174 // check that the desired number of channels were created.
175 if (!channelDataArray) 175 if (!channelDataArray)
176 return; 176 return;
177 177
178 channelDataArray->setNeuterable(false); 178 channelDataArray->setNeuterable(false);
179 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); 179 const float* src = bus->channel(i)->data();
180 float* dst = channelDataArray->data();
181 memmove(dst, src, m_length * sizeof(*dst));
adamk 2015/06/12 17:59:25 For WebAudio reviewers: this memmove is from the o
Raymond Toy 2015/06/12 18:05:50 If the original did this, I'm happy with leaving i
adamk 2015/06/12 18:14:28 The destination of this memmove was just created w
180 m_channels.append(channelDataArray); 182 m_channels.append(channelDataArray);
181 } 183 }
182 } 184 }
183 185
184 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E xceptionState& exceptionState) 186 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E xceptionState& exceptionState)
185 { 187 {
186 if (channelIndex >= m_channels.size()) { 188 if (channelIndex >= m_channels.size()) {
187 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")"); 189 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")");
188 return nullptr; 190 return nullptr;
189 } 191 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 312
311 ASSERT(src); 313 ASSERT(src);
312 ASSERT(dst); 314 ASSERT(dst);
313 315
314 memcpy(dst + startInChannel, src, count * sizeof(*dst)); 316 memcpy(dst + startInChannel, src, count * sizeof(*dst));
315 } 317 }
316 318
317 void AudioBuffer::zero() 319 void AudioBuffer::zero()
318 { 320 {
319 for (unsigned i = 0; i < m_channels.size(); ++i) { 321 for (unsigned i = 0; i < m_channels.size(); ++i) {
320 if (getChannelData(i)) 322 if (DOMFloat32Array* array = getChannelData(i)) {
321 getChannelData(i)->zeroRange(0, length()); 323 float* data = array->data();
324 memset(data, 0, length() * sizeof(*data));
Raymond Toy 2015/06/12 18:05:50 The original had some checks on the parameters. Ar
adamk 2015/06/12 18:14:28 Same as above, all the channel data arrays have th
325 }
322 } 326 }
323 } 327 }
324 328
325 v8::Local<v8::Object> AudioBuffer::associateWithWrapper(v8::Isolate* isolate, co nst WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) 329 v8::Local<v8::Object> AudioBuffer::associateWithWrapper(v8::Isolate* isolate, co nst WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper)
326 { 330 {
327 ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper); 331 ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper);
328 332
329 if (!wrapper.IsEmpty()) { 333 if (!wrapper.IsEmpty()) {
330 // We only setDeallocationObservers on array buffers that are held by 334 // We only setDeallocationObservers on array buffers that are held by
331 // some object in the V8 heap, not in the ArrayBuffer constructor 335 // some object in the V8 heap, not in the ArrayBuffer constructor
332 // itself. This is because V8 GC only cares about memory it can free on 336 // itself. This is because V8 GC only cares about memory it can free on
333 // GC, and until the object is exposed to JavaScript, V8 GC doesn't 337 // GC, and until the object is exposed to JavaScript, V8 GC doesn't
334 // affect it. 338 // affect it.
335 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) { 339 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) {
336 getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD eallocationObserver::instance()); 340 getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD eallocationObserver::instance());
337 } 341 }
338 } 342 }
339 return wrapper; 343 return wrapper;
340 } 344 }
341 345
342 } // namespace blink 346 } // namespace blink
343 347
344 #endif // ENABLE(WEB_AUDIO) 348 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/core/dom/DOMTypedArray.h ('k') | Source/wtf/ArrayBufferView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698