| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/media_stream_audio_level_calculator.h" | 5 #include "content/renderer/media/media_stream_audio_level_calculator.h" |
| 6 | 6 |
| 7 #include "base/float_util.h" | 7 #include <cmath> |
| 8 |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "media/base/audio_bus.h" | 11 #include "media/base/audio_bus.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Calculates the maximum absolute amplitude of the audio data. | 17 // Calculates the maximum absolute amplitude of the audio data. |
| 17 float MaxAmplitude(const float* audio_data, int length) { | 18 float MaxAmplitude(const float* audio_data, int length) { |
| 18 float max = 0.0f; | 19 float max = 0.0f; |
| 19 for (int i = 0; i < length; ++i) { | 20 for (int i = 0; i < length; ++i) { |
| 20 const float absolute = fabsf(audio_data[i]); | 21 const float absolute = fabsf(audio_data[i]); |
| 21 if (absolute > max) | 22 if (absolute > max) |
| 22 max = absolute; | 23 max = absolute; |
| 23 } | 24 } |
| 24 DCHECK(base::IsFinite(max)); | 25 DCHECK(std::isfinite(max)); |
| 25 return max; | 26 return max; |
| 26 } | 27 } |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator() | 31 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator() |
| 31 : counter_(0), | 32 : counter_(0), |
| 32 max_amplitude_(0.0f), | 33 max_amplitude_(0.0f), |
| 33 level_(0.0f) { | 34 level_(0.0f) { |
| 34 } | 35 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 max_amplitude_ /= 4.0f; | 60 max_amplitude_ /= 4.0f; |
| 60 | 61 |
| 61 // Reset the counter. | 62 // Reset the counter. |
| 62 counter_ = 0; | 63 counter_ = 0; |
| 63 } | 64 } |
| 64 | 65 |
| 65 return level_; | 66 return level_; |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace content | 69 } // namespace content |
| OLD | NEW |