| OLD | NEW |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 m_smoothingTimeConstant(DefaultSmoothingTimeConstant), | 56 m_smoothingTimeConstant(DefaultSmoothingTimeConstant), |
| 57 m_minDecibels(DefaultMinDecibels), | 57 m_minDecibels(DefaultMinDecibels), |
| 58 m_maxDecibels(DefaultMaxDecibels), | 58 m_maxDecibels(DefaultMaxDecibels), |
| 59 m_lastAnalysisTime(-1) { | 59 m_lastAnalysisTime(-1) { |
| 60 m_analysisFrame = WTF::makeUnique<FFTFrame>(DefaultFFTSize); | 60 m_analysisFrame = WTF::makeUnique<FFTFrame>(DefaultFFTSize); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool RealtimeAnalyser::setFftSize(size_t size) { | 63 bool RealtimeAnalyser::setFftSize(size_t size) { |
| 64 DCHECK(isMainThread()); | 64 DCHECK(isMainThread()); |
| 65 | 65 |
| 66 // Only allow powers of two. | 66 // Only allow powers of two within the allowed range. |
| 67 unsigned log2size = static_cast<unsigned>(log2(size)); | 67 if (size > MaxFFTSize || size < MinFFTSize || |
| 68 bool isPOT(1UL << log2size == size); | 68 !AudioUtilities::isPowerOfTwo(size)) |
| 69 | |
| 70 if (!isPOT || size > MaxFFTSize || size < MinFFTSize) | |
| 71 return false; | 69 return false; |
| 72 | 70 |
| 73 if (m_fftSize != size) { | 71 if (m_fftSize != size) { |
| 74 m_analysisFrame = WTF::makeUnique<FFTFrame>(size); | 72 m_analysisFrame = WTF::makeUnique<FFTFrame>(size); |
| 75 // m_magnitudeBuffer has size = fftSize / 2 because it contains floats | 73 // m_magnitudeBuffer has size = fftSize / 2 because it contains floats |
| 76 // reduced from complex values in m_analysisFrame. | 74 // reduced from complex values in m_analysisFrame. |
| 77 m_magnitudeBuffer.allocate(size / 2); | 75 m_magnitudeBuffer.allocate(size / 2); |
| 78 m_fftSize = size; | 76 m_fftSize = size; |
| 79 } | 77 } |
| 80 | 78 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 scaledValue = 0; | 331 scaledValue = 0; |
| 334 if (scaledValue > UCHAR_MAX) | 332 if (scaledValue > UCHAR_MAX) |
| 335 scaledValue = UCHAR_MAX; | 333 scaledValue = UCHAR_MAX; |
| 336 | 334 |
| 337 destination[i] = static_cast<unsigned char>(scaledValue); | 335 destination[i] = static_cast<unsigned char>(scaledValue); |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 } | 338 } |
| 341 | 339 |
| 342 } // namespace blink | 340 } // namespace blink |
| OLD | NEW |