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

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

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 2 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/modules/webaudio/AudioBuffer.h ('k') | Source/modules/webaudio/AudioContext.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 16 matching lines...) Expand all
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 32
33 #include "modules/webaudio/AudioBuffer.h" 33 #include "modules/webaudio/AudioBuffer.h"
34 34
35 #include "bindings/core/v8/ExceptionMessages.h" 35 #include "bindings/core/v8/ExceptionMessages.h"
36 #include "bindings/core/v8/ExceptionState.h" 36 #include "bindings/core/v8/ExceptionState.h"
37 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" 37 #include "core/dom/DOMArrayBufferDeallocationObserver.h"
38 #include "core/dom/ExceptionCode.h" 38 #include "core/dom/ExceptionCode.h"
39 #include "modules/webaudio/AudioContext.h" 39 #include "modules/webaudio/AudioContext.h"
40 #include "platform/audio/AudioBus.h" 40 #include "platform/audio/AudioBus.h"
41 #include "platform/audio/AudioFileReader.h" 41 #include "platform/audio/AudioFileReader.h"
42 #include "platform/audio/AudioUtilities.h" 42 #include "platform/audio/AudioUtilities.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate) 46 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, size_t numberOfFrame s, float sampleRate)
47 { 47 {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // check that the desired number of channels were created. 167 // check that the desired number of channels were created.
168 if (!channelDataArray) 168 if (!channelDataArray)
169 return; 169 return;
170 170
171 channelDataArray->setNeuterable(false); 171 channelDataArray->setNeuterable(false);
172 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0); 172 channelDataArray->setRange(bus->channel(i)->data(), m_length, 0);
173 m_channels.append(channelDataArray); 173 m_channels.append(channelDataArray);
174 } 174 }
175 } 175 }
176 176
177 PassRefPtr<Float32Array> AudioBuffer::getChannelData(unsigned channelIndex, Exce ptionState& exceptionState) 177 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E xceptionState& exceptionState)
178 { 178 {
179 if (channelIndex >= m_channels.size()) { 179 if (channelIndex >= m_channels.size()) {
180 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")"); 180 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")");
181 return nullptr; 181 return nullptr;
182 } 182 }
183 183
184 Float32Array* channelData = m_channels[channelIndex].get(); 184 Float32Array* channelData = m_channels[channelIndex].get();
185 return Float32Array::create(channelData->buffer(), channelData->byteOffset() , channelData->length()); 185 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse t(), channelData->length());
186 } 186 }
187 187
188 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex) 188 Float32Array* AudioBuffer::getChannelData(unsigned channelIndex)
189 { 189 {
190 if (channelIndex >= m_channels.size()) 190 if (channelIndex >= m_channels.size())
191 return 0; 191 return 0;
192 192
193 return m_channels[channelIndex].get(); 193 return m_channels[channelIndex].get();
194 } 194 }
195 195
196 void AudioBuffer::zero() 196 void AudioBuffer::zero()
197 { 197 {
198 for (unsigned i = 0; i < m_channels.size(); ++i) { 198 for (unsigned i = 0; i < m_channels.size(); ++i) {
199 if (getChannelData(i)) 199 if (getChannelData(i))
200 getChannelData(i)->zeroRange(0, length()); 200 getChannelData(i)->zeroRange(0, length());
201 } 201 }
202 } 202 }
203 203
204 v8::Handle<v8::Object> AudioBuffer::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) 204 v8::Handle<v8::Object> AudioBuffer::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
205 { 205 {
206 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); 206 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate);
207 207
208 if (!wrapper.IsEmpty()) { 208 if (!wrapper.IsEmpty()) {
209 // We only setDeallocationObservers on array buffers that are held by 209 // We only setDeallocationObservers on array buffers that are held by
210 // some object in the V8 heap, not in the ArrayBuffer constructor 210 // some object in the V8 heap, not in the ArrayBuffer constructor
211 // itself. This is because V8 GC only cares about memory it can free on 211 // itself. This is because V8 GC only cares about memory it can free on
212 // GC, and until the object is exposed to JavaScript, V8 GC doesn't 212 // GC, and until the object is exposed to JavaScript, V8 GC doesn't
213 // affect it. 213 // affect it.
214 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) { 214 for (unsigned i = 0, n = numberOfChannels(); i < n; ++i) {
215 getChannelData(i)->buffer()->setDeallocationObserver(V8ArrayBufferDe allocationObserver::instanceTemplate()); 215 getChannelData(i)->buffer()->setDeallocationObserver(DOMArrayBufferD eallocationObserver::instance());
216 } 216 }
217 } 217 }
218 return wrapper; 218 return wrapper;
219 } 219 }
220 220
221 } // namespace blink 221 } // namespace blink
222 222
223 #endif // ENABLE(WEB_AUDIO) 223 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioBuffer.h ('k') | Source/modules/webaudio/AudioContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698