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

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

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return buffer; 56 return buffer;
57 } 57 }
58 58
59 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels, 59 AudioBuffer* AudioBuffer::create(unsigned numberOfChannels,
60 size_t numberOfFrames, 60 size_t numberOfFrames,
61 float sampleRate, 61 float sampleRate,
62 ExceptionState& exceptionState) { 62 ExceptionState& exceptionState) {
63 if (!numberOfChannels || 63 if (!numberOfChannels ||
64 numberOfChannels > BaseAudioContext::maxNumberOfChannels()) { 64 numberOfChannels > BaseAudioContext::maxNumberOfChannels()) {
65 exceptionState.throwDOMException( 65 exceptionState.throwDOMException(
66 NotSupportedError, ExceptionMessages::indexOutsideRange( 66 NotSupportedError,
67 "number of channels", numberOfChannels, 1u, 67 ExceptionMessages::indexOutsideRange(
68 ExceptionMessages::InclusiveBound, 68 "number of channels", numberOfChannels, 1u,
69 BaseAudioContext::maxNumberOfChannels(), 69 ExceptionMessages::InclusiveBound,
70 ExceptionMessages::InclusiveBound)); 70 BaseAudioContext::maxNumberOfChannels(),
71 ExceptionMessages::InclusiveBound));
71 return nullptr; 72 return nullptr;
72 } 73 }
73 74
74 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { 75 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) {
75 exceptionState.throwDOMException( 76 exceptionState.throwDOMException(
76 NotSupportedError, ExceptionMessages::indexOutsideRange( 77 NotSupportedError,
77 "sample rate", sampleRate, 78 ExceptionMessages::indexOutsideRange(
78 AudioUtilities::minAudioBufferSampleRate(), 79 "sample rate", sampleRate,
79 ExceptionMessages::InclusiveBound, 80 AudioUtilities::minAudioBufferSampleRate(),
80 AudioUtilities::maxAudioBufferSampleRate(), 81 ExceptionMessages::InclusiveBound,
81 ExceptionMessages::InclusiveBound)); 82 AudioUtilities::maxAudioBufferSampleRate(),
83 ExceptionMessages::InclusiveBound));
82 return nullptr; 84 return nullptr;
83 } 85 }
84 86
85 if (!numberOfFrames) { 87 if (!numberOfFrames) {
86 exceptionState.throwDOMException( 88 exceptionState.throwDOMException(
87 NotSupportedError, 89 NotSupportedError,
88 ExceptionMessages::indexExceedsMinimumBound( 90 ExceptionMessages::indexExceedsMinimumBound(
89 "number of frames", numberOfFrames, static_cast<size_t>(0))); 91 "number of frames", numberOfFrames, static_cast<size_t>(0)));
90 return nullptr; 92 return nullptr;
91 } 93 }
92 94
93 AudioBuffer* audioBuffer = 95 AudioBuffer* audioBuffer =
94 create(numberOfChannels, numberOfFrames, sampleRate); 96 create(numberOfChannels, numberOfFrames, sampleRate);
95 97
96 if (!audioBuffer) { 98 if (!audioBuffer) {
97 exceptionState.throwDOMException( 99 exceptionState.throwDOMException(
98 NotSupportedError, "createBuffer(" + String::number(numberOfChannels) + 100 NotSupportedError,
99 ", " + String::number(numberOfFrames) + ", " + 101 "createBuffer(" + String::number(numberOfChannels) + ", " +
100 String::number(sampleRate) + ") failed."); 102 String::number(numberOfFrames) + ", " + String::number(sampleRate) +
103 ") failed.");
101 } 104 }
102 105
103 return audioBuffer; 106 return audioBuffer;
104 } 107 }
105 108
106 AudioBuffer* AudioBuffer::create(const AudioBufferOptions& options, 109 AudioBuffer* AudioBuffer::create(const AudioBufferOptions& options,
107 ExceptionState& exceptionState) { 110 ExceptionState& exceptionState) {
108 return create(options.numberOfChannels(), options.length(), 111 return create(options.numberOfChannels(), options.length(),
109 options.sampleRate(), exceptionState); 112 options.sampleRate(), exceptionState);
110 } 113 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 float* dst = channelDataArray->data(); 183 float* dst = channelDataArray->data();
181 memmove(dst, src, m_length * sizeof(*dst)); 184 memmove(dst, src, m_length * sizeof(*dst));
182 m_channels.push_back(channelDataArray); 185 m_channels.push_back(channelDataArray);
183 } 186 }
184 } 187 }
185 188
186 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex, 189 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex,
187 ExceptionState& exceptionState) { 190 ExceptionState& exceptionState) {
188 if (channelIndex >= m_channels.size()) { 191 if (channelIndex >= m_channels.size()) {
189 exceptionState.throwDOMException( 192 exceptionState.throwDOMException(
190 IndexSizeError, "channel index (" + String::number(channelIndex) + 193 IndexSizeError,
191 ") exceeds number of channels (" + 194 "channel index (" + String::number(channelIndex) +
192 String::number(m_channels.size()) + ")"); 195 ") exceeds number of channels (" +
196 String::number(m_channels.size()) + ")");
193 return nullptr; 197 return nullptr;
194 } 198 }
195 199
196 return getChannelData(channelIndex); 200 return getChannelData(channelIndex);
197 } 201 }
198 202
199 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) { 203 DOMFloat32Array* AudioBuffer::getChannelData(unsigned channelIndex) {
200 if (channelIndex >= m_channels.size()) 204 if (channelIndex >= m_channels.size())
201 return nullptr; 205 return nullptr;
202 206
203 return m_channels[channelIndex].get(); 207 return m_channels[channelIndex].get();
204 } 208 }
205 209
206 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, 210 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
207 long channelNumber, 211 long channelNumber,
208 ExceptionState& exceptionState) { 212 ExceptionState& exceptionState) {
209 return copyFromChannel(destination, channelNumber, 0, exceptionState); 213 return copyFromChannel(destination, channelNumber, 0, exceptionState);
210 } 214 }
211 215
212 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination, 216 void AudioBuffer::copyFromChannel(DOMFloat32Array* destination,
213 long channelNumber, 217 long channelNumber,
214 unsigned long startInChannel, 218 unsigned long startInChannel,
215 ExceptionState& exceptionState) { 219 ExceptionState& exceptionState) {
216 if (channelNumber < 0 || 220 if (channelNumber < 0 ||
217 channelNumber >= static_cast<long>(m_channels.size())) { 221 channelNumber >= static_cast<long>(m_channels.size())) {
218 exceptionState.throwDOMException( 222 exceptionState.throwDOMException(
219 IndexSizeError, ExceptionMessages::indexOutsideRange( 223 IndexSizeError,
220 "channelNumber", channelNumber, 0L, 224 ExceptionMessages::indexOutsideRange(
221 ExceptionMessages::InclusiveBound, 225 "channelNumber", channelNumber, 0L,
222 static_cast<long>(m_channels.size() - 1), 226 ExceptionMessages::InclusiveBound,
223 ExceptionMessages::InclusiveBound)); 227 static_cast<long>(m_channels.size() - 1),
228 ExceptionMessages::InclusiveBound));
224 return; 229 return;
225 } 230 }
226 231
227 DOMFloat32Array* channelData = m_channels[channelNumber].get(); 232 DOMFloat32Array* channelData = m_channels[channelNumber].get();
228 233
229 if (startInChannel >= channelData->length()) { 234 if (startInChannel >= channelData->length()) {
230 exceptionState.throwDOMException( 235 exceptionState.throwDOMException(
231 IndexSizeError, ExceptionMessages::indexOutsideRange( 236 IndexSizeError,
232 "startInChannel", startInChannel, 0UL, 237 ExceptionMessages::indexOutsideRange(
233 ExceptionMessages::InclusiveBound, 238 "startInChannel", startInChannel, 0UL,
234 static_cast<unsigned long>(channelData->length()), 239 ExceptionMessages::InclusiveBound,
235 ExceptionMessages::ExclusiveBound)); 240 static_cast<unsigned long>(channelData->length()),
241 ExceptionMessages::ExclusiveBound));
236 242
237 return; 243 return;
238 } 244 }
239 245
240 unsigned count = channelData->length() - startInChannel; 246 unsigned count = channelData->length() - startInChannel;
241 count = std::min(destination->length(), count); 247 count = std::min(destination->length(), count);
242 248
243 const float* src = channelData->data(); 249 const float* src = channelData->data();
244 float* dst = destination->data(); 250 float* dst = destination->data();
245 251
246 DCHECK(src); 252 DCHECK(src);
247 DCHECK(dst); 253 DCHECK(dst);
248 254
249 memcpy(dst, src + startInChannel, count * sizeof(*src)); 255 memcpy(dst, src + startInChannel, count * sizeof(*src));
250 } 256 }
251 257
252 void AudioBuffer::copyToChannel(DOMFloat32Array* source, 258 void AudioBuffer::copyToChannel(DOMFloat32Array* source,
253 long channelNumber, 259 long channelNumber,
254 ExceptionState& exceptionState) { 260 ExceptionState& exceptionState) {
255 return copyToChannel(source, channelNumber, 0, exceptionState); 261 return copyToChannel(source, channelNumber, 0, exceptionState);
256 } 262 }
257 263
258 void AudioBuffer::copyToChannel(DOMFloat32Array* source, 264 void AudioBuffer::copyToChannel(DOMFloat32Array* source,
259 long channelNumber, 265 long channelNumber,
260 unsigned long startInChannel, 266 unsigned long startInChannel,
261 ExceptionState& exceptionState) { 267 ExceptionState& exceptionState) {
262 if (channelNumber < 0 || 268 if (channelNumber < 0 ||
263 channelNumber >= static_cast<long>(m_channels.size())) { 269 channelNumber >= static_cast<long>(m_channels.size())) {
264 exceptionState.throwDOMException( 270 exceptionState.throwDOMException(
265 IndexSizeError, ExceptionMessages::indexOutsideRange( 271 IndexSizeError,
266 "channelNumber", channelNumber, 0L, 272 ExceptionMessages::indexOutsideRange(
267 ExceptionMessages::InclusiveBound, 273 "channelNumber", channelNumber, 0L,
268 static_cast<long>(m_channels.size() - 1), 274 ExceptionMessages::InclusiveBound,
269 ExceptionMessages::InclusiveBound)); 275 static_cast<long>(m_channels.size() - 1),
276 ExceptionMessages::InclusiveBound));
270 return; 277 return;
271 } 278 }
272 279
273 DOMFloat32Array* channelData = m_channels[channelNumber].get(); 280 DOMFloat32Array* channelData = m_channels[channelNumber].get();
274 281
275 if (startInChannel >= channelData->length()) { 282 if (startInChannel >= channelData->length()) {
276 exceptionState.throwDOMException( 283 exceptionState.throwDOMException(
277 IndexSizeError, ExceptionMessages::indexOutsideRange( 284 IndexSizeError,
278 "startInChannel", startInChannel, 0UL, 285 ExceptionMessages::indexOutsideRange(
279 ExceptionMessages::InclusiveBound, 286 "startInChannel", startInChannel, 0UL,
280 static_cast<unsigned long>(channelData->length()), 287 ExceptionMessages::InclusiveBound,
281 ExceptionMessages::ExclusiveBound)); 288 static_cast<unsigned long>(channelData->length()),
289 ExceptionMessages::ExclusiveBound));
282 290
283 return; 291 return;
284 } 292 }
285 293
286 unsigned count = channelData->length() - startInChannel; 294 unsigned count = channelData->length() - startInChannel;
287 count = std::min(source->length(), count); 295 count = std::min(source->length(), count);
288 296
289 const float* src = source->data(); 297 const float* src = source->data();
290 float* dst = channelData->data(); 298 float* dst = channelData->data();
291 299
292 DCHECK(src); 300 DCHECK(src);
293 DCHECK(dst); 301 DCHECK(dst);
294 302
295 memcpy(dst + startInChannel, src, count * sizeof(*dst)); 303 memcpy(dst + startInChannel, src, count * sizeof(*dst));
296 } 304 }
297 305
298 void AudioBuffer::zero() { 306 void AudioBuffer::zero() {
299 for (unsigned i = 0; i < m_channels.size(); ++i) { 307 for (unsigned i = 0; i < m_channels.size(); ++i) {
300 if (DOMFloat32Array* array = getChannelData(i)) { 308 if (DOMFloat32Array* array = getChannelData(i)) {
301 float* data = array->data(); 309 float* data = array->data();
302 memset(data, 0, length() * sizeof(*data)); 310 memset(data, 0, length() * sizeof(*data));
303 } 311 }
304 } 312 }
305 } 313 }
306 314
307 } // namespace blink 315 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698