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

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

Issue 1878463002: Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy Created 4 years, 8 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
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (buffer->createdSuccessfully(bus->numberOfChannels())) 123 if (buffer->createdSuccessfully(bus->numberOfChannels()))
124 return buffer; 124 return buffer;
125 return nullptr; 125 return nullptr;
126 } 126 }
127 127
128 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const 128 bool AudioBuffer::createdSuccessfully(unsigned desiredNumberOfChannels) const
129 { 129 {
130 return numberOfChannels() == desiredNumberOfChannels; 130 return numberOfChannels() == desiredNumberOfChannels;
131 } 131 }
132 132
133 PassRefPtr<DOMFloat32Array> AudioBuffer::createFloat32ArrayOrNull(size_t length) 133 DOMFloat32Array* AudioBuffer::createFloat32ArrayOrNull(size_t length)
134 { 134 {
135 RefPtr<WTF::Float32Array> bufferView = WTF::Float32Array::createOrNull(lengt h); 135 RefPtr<WTF::Float32Array> bufferView = WTF::Float32Array::createOrNull(lengt h);
136 if (!bufferView) 136 if (!bufferView)
137 return nullptr; 137 return nullptr;
138 return DOMFloat32Array::create(bufferView.release()); 138 return DOMFloat32Array::create(bufferView.release());
139 } 139 }
140 140
141 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate) 141 AudioBuffer::AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
142 : m_sampleRate(sampleRate) 142 : m_sampleRate(sampleRate)
143 , m_length(numberOfFrames) 143 , m_length(numberOfFrames)
144 { 144 {
145 m_channels.reserveCapacity(numberOfChannels); 145 m_channels.reserveCapacity(numberOfChannels);
146 146
147 for (unsigned i = 0; i < numberOfChannels; ++i) { 147 for (unsigned i = 0; i < numberOfChannels; ++i) {
148 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le ngth); 148 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length);
149 // If the channel data array could not be created, just return. The call er will need to 149 // If the channel data array could not be created, just return. The call er will need to
150 // check that the desired number of channels were created. 150 // check that the desired number of channels were created.
151 if (!channelDataArray) { 151 if (!channelDataArray)
152 return; 152 return;
153 }
154 153
155 channelDataArray->setNeuterable(false); 154 channelDataArray->setNeuterable(false);
156 m_channels.append(channelDataArray); 155 m_channels.append(channelDataArray);
157 } 156 }
158 } 157 }
159 158
160 AudioBuffer::AudioBuffer(AudioBus* bus) 159 AudioBuffer::AudioBuffer(AudioBus* bus)
161 : m_sampleRate(bus->sampleRate()) 160 : m_sampleRate(bus->sampleRate())
162 , m_length(bus->length()) 161 , m_length(bus->length())
163 { 162 {
164 // Copy audio data from the bus to the Float32Arrays we manage. 163 // Copy audio data from the bus to the Float32Arrays we manage.
165 unsigned numberOfChannels = bus->numberOfChannels(); 164 unsigned numberOfChannels = bus->numberOfChannels();
166 m_channels.reserveCapacity(numberOfChannels); 165 m_channels.reserveCapacity(numberOfChannels);
167 for (unsigned i = 0; i < numberOfChannels; ++i) { 166 for (unsigned i = 0; i < numberOfChannels; ++i) {
168 RefPtr<DOMFloat32Array> channelDataArray = createFloat32ArrayOrNull(m_le ngth); 167 DOMFloat32Array* channelDataArray = createFloat32ArrayOrNull(m_length);
169 // If the channel data array could not be created, just return. The call er will need to 168 // If the channel data array could not be created, just return. The call er will need to
170 // check that the desired number of channels were created. 169 // check that the desired number of channels were created.
171 if (!channelDataArray) 170 if (!channelDataArray)
172 return; 171 return;
173 172
174 channelDataArray->setNeuterable(false); 173 channelDataArray->setNeuterable(false);
175 const float* src = bus->channel(i)->data(); 174 const float* src = bus->channel(i)->data();
176 float* dst = channelDataArray->data(); 175 float* dst = channelDataArray->data();
177 memmove(dst, src, m_length * sizeof(*dst)); 176 memmove(dst, src, m_length * sizeof(*dst));
178 m_channels.append(channelDataArray); 177 m_channels.append(channelDataArray);
179 } 178 }
180 } 179 }
181 180
182 PassRefPtr<DOMFloat32Array> AudioBuffer::getChannelData(unsigned channelIndex, E xceptionState& exceptionState) 181 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, ExceptionSta te& exceptionState)
183 { 182 {
184 if (channelIndex >= m_channels.size()) { 183 if (channelIndex >= m_channels.size()) {
185 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")"); 184 exceptionState.throwDOMException(IndexSizeError, "channel index (" + Str ing::number(channelIndex) + ") exceeds number of channels (" + String::number(m_ channels.size()) + ")");
186 return nullptr; 185 return nullptr;
187 } 186 }
188 187
189 DOMFloat32Array* channelData = m_channels[channelIndex].get(); 188 DOMFloat32Array* channelData = m_channels[channelIndex].get();
190 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse t(), channelData->length()); 189 return DOMFloat32Array::create(channelData->buffer(), channelData->byteOffse t(), channelData->length());
191 } 190 }
192 191
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 for (unsigned i = 0; i < m_channels.size(); ++i) { 298 for (unsigned i = 0; i < m_channels.size(); ++i) {
300 if (DOMFloat32Array* array = getChannelData(i)) { 299 if (DOMFloat32Array* array = getChannelData(i)) {
301 float* data = array->data(); 300 float* data = array->data();
302 memset(data, 0, length() * sizeof(*data)); 301 memset(data, 0, length() * sizeof(*data));
303 } 302 }
304 } 303 }
305 } 304 }
306 305
307 } // namespace blink 306 } // namespace blink
308 307
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698