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

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

Issue 1493753003: Drop [LegacyInterfaceTypeChecking] for the Web Audio API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update tests Created 5 years 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 for (size_t i = 0; i < n; ++i) { 183 for (size_t i = 0; i < n; ++i) {
184 std::complex<double> c(realP[i], imagP[i]); 184 std::complex<double> c(realP[i], imagP[i]);
185 double scalarMagnitude = abs(c) * magnitudeScale; 185 double scalarMagnitude = abs(c) * magnitudeScale;
186 destination[i] = float(k * destination[i] + (1 - k) * scalarMagnitude); 186 destination[i] = float(k * destination[i] + (1 - k) * scalarMagnitude);
187 } 187 }
188 } 188 }
189 189
190 void RealtimeAnalyser::getFloatFrequencyData(DOMFloat32Array* destinationArray) 190 void RealtimeAnalyser::getFloatFrequencyData(DOMFloat32Array* destinationArray)
191 { 191 {
192 ASSERT(isMainThread()); 192 ASSERT(isMainThread());
193 193 ASSERT(destinationArray);
194 if (!destinationArray)
195 return;
196 194
197 doFFTAnalysis(); 195 doFFTAnalysis();
198 196
199 // Convert from linear magnitude to floating-point decibels. 197 // Convert from linear magnitude to floating-point decibels.
200 const double minDecibels = m_minDecibels; 198 const double minDecibels = m_minDecibels;
201 unsigned sourceLength = magnitudeBuffer().size(); 199 unsigned sourceLength = magnitudeBuffer().size();
202 size_t len = std::min(sourceLength, destinationArray->length()); 200 size_t len = std::min(sourceLength, destinationArray->length());
203 if (len > 0) { 201 if (len > 0) {
204 const float* source = magnitudeBuffer().data(); 202 const float* source = magnitudeBuffer().data();
205 float* destination = destinationArray->data(); 203 float* destination = destinationArray->data();
206 204
207 for (unsigned i = 0; i < len; ++i) { 205 for (unsigned i = 0; i < len; ++i) {
208 float linearValue = source[i]; 206 float linearValue = source[i];
209 double dbMag = !linearValue ? minDecibels : AudioUtilities::linearTo Decibels(linearValue); 207 double dbMag = !linearValue ? minDecibels : AudioUtilities::linearTo Decibels(linearValue);
210 destination[i] = float(dbMag); 208 destination[i] = float(dbMag);
211 } 209 }
212 } 210 }
213 } 211 }
214 212
215 void RealtimeAnalyser::getByteFrequencyData(DOMUint8Array* destinationArray) 213 void RealtimeAnalyser::getByteFrequencyData(DOMUint8Array* destinationArray)
216 { 214 {
217 ASSERT(isMainThread()); 215 ASSERT(isMainThread());
218 216 ASSERT(destinationArray);
219 if (!destinationArray)
220 return;
221 217
222 doFFTAnalysis(); 218 doFFTAnalysis();
223 219
224 // Convert from linear magnitude to unsigned-byte decibels. 220 // Convert from linear magnitude to unsigned-byte decibels.
225 unsigned sourceLength = magnitudeBuffer().size(); 221 unsigned sourceLength = magnitudeBuffer().size();
226 size_t len = std::min(sourceLength, destinationArray->length()); 222 size_t len = std::min(sourceLength, destinationArray->length());
227 if (len > 0) { 223 if (len > 0) {
228 const double rangeScaleFactor = m_maxDecibels == m_minDecibels ? 1 : 1 / (m_maxDecibels - m_minDecibels); 224 const double rangeScaleFactor = m_maxDecibels == m_minDecibels ? 1 : 1 / (m_maxDecibels - m_minDecibels);
229 const double minDecibels = m_minDecibels; 225 const double minDecibels = m_minDecibels;
230 226
(...skipping 14 matching lines...) Expand all
245 scaledValue = UCHAR_MAX; 241 scaledValue = UCHAR_MAX;
246 242
247 destination[i] = static_cast<unsigned char>(scaledValue); 243 destination[i] = static_cast<unsigned char>(scaledValue);
248 } 244 }
249 } 245 }
250 } 246 }
251 247
252 void RealtimeAnalyser::getFloatTimeDomainData(DOMFloat32Array* destinationArray) 248 void RealtimeAnalyser::getFloatTimeDomainData(DOMFloat32Array* destinationArray)
253 { 249 {
254 ASSERT(isMainThread()); 250 ASSERT(isMainThread());
255 251 ASSERT(destinationArray);
256 if (!destinationArray)
257 return;
258 252
259 unsigned fftSize = this->fftSize(); 253 unsigned fftSize = this->fftSize();
260 size_t len = std::min(fftSize, destinationArray->length()); 254 size_t len = std::min(fftSize, destinationArray->length());
261 if (len > 0) { 255 if (len > 0) {
262 bool isInputBufferGood = m_inputBuffer.size() == InputBufferSize && m_in putBuffer.size() > fftSize; 256 bool isInputBufferGood = m_inputBuffer.size() == InputBufferSize && m_in putBuffer.size() > fftSize;
263 ASSERT(isInputBufferGood); 257 ASSERT(isInputBufferGood);
264 if (!isInputBufferGood) 258 if (!isInputBufferGood)
265 return; 259 return;
266 260
267 float* inputBuffer = m_inputBuffer.data(); 261 float* inputBuffer = m_inputBuffer.data();
268 float* destination = destinationArray->data(); 262 float* destination = destinationArray->data();
269 263
270 unsigned writeIndex = m_writeIndex; 264 unsigned writeIndex = m_writeIndex;
271 265
272 for (unsigned i = 0; i < len; ++i) { 266 for (unsigned i = 0; i < len; ++i) {
273 // Buffer access is protected due to modulo operation. 267 // Buffer access is protected due to modulo operation.
274 float value = inputBuffer[(i + writeIndex - fftSize + InputBufferSiz e) % InputBufferSize]; 268 float value = inputBuffer[(i + writeIndex - fftSize + InputBufferSiz e) % InputBufferSize];
275 269
276 destination[i] = value; 270 destination[i] = value;
277 } 271 }
278 } 272 }
279 } 273 }
280 274
281 void RealtimeAnalyser::getByteTimeDomainData(DOMUint8Array* destinationArray) 275 void RealtimeAnalyser::getByteTimeDomainData(DOMUint8Array* destinationArray)
282 { 276 {
283 ASSERT(isMainThread()); 277 ASSERT(isMainThread());
284 278 ASSERT(destinationArray);
285 if (!destinationArray)
286 return;
287 279
288 unsigned fftSize = this->fftSize(); 280 unsigned fftSize = this->fftSize();
289 size_t len = std::min(fftSize, destinationArray->length()); 281 size_t len = std::min(fftSize, destinationArray->length());
290 if (len > 0) { 282 if (len > 0) {
291 bool isInputBufferGood = m_inputBuffer.size() == InputBufferSize && m_in putBuffer.size() > fftSize; 283 bool isInputBufferGood = m_inputBuffer.size() == InputBufferSize && m_in putBuffer.size() > fftSize;
292 ASSERT(isInputBufferGood); 284 ASSERT(isInputBufferGood);
293 if (!isInputBufferGood) 285 if (!isInputBufferGood)
294 return; 286 return;
295 287
296 float* inputBuffer = m_inputBuffer.data(); 288 float* inputBuffer = m_inputBuffer.data();
(...skipping 15 matching lines...) Expand all
312 scaledValue = UCHAR_MAX; 304 scaledValue = UCHAR_MAX;
313 305
314 destination[i] = static_cast<unsigned char>(scaledValue); 306 destination[i] = static_cast<unsigned char>(scaledValue);
315 } 307 }
316 } 308 }
317 } 309 }
318 310
319 } // namespace blink 311 } // namespace blink
320 312
321 #endif // ENABLE(WEB_AUDIO) 313 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698