Chromium Code Reviews| 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" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 10 #include "media/base/audio_bus.h" | 9 #include "media/base/audio_bus.h" |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 // Calculates the maximum absolute amplitude of the audio data. | 15 // Calculates the maximum absolute amplitude of the audio data. |
| 17 float MaxAmplitude(const float* audio_data, int length) { | 16 float MaxAmplitude(const float* audio_data, int length) { |
| 18 float max = 0.0f; | 17 float max = 0.0f; |
| 19 for (int i = 0; i < length; ++i) { | 18 for (int i = 0; i < length; ++i) { |
| 20 const float absolute = fabsf(audio_data[i]); | 19 const float absolute = fabsf(audio_data[i]); |
| 21 if (absolute > max) | 20 if (absolute > max) |
| 22 max = absolute; | 21 max = absolute; |
| 23 } | 22 } |
| 24 DCHECK(base::IsFinite(max)); | 23 DCHECK(std::isfinite(max)); |
|
Mark Mentovai
2015/04/09 12:46:37
#include <cmath>. I asked you to self-review to fi
Mateusz Szymański
2015/04/09 15:32:29
Done.
| |
| 25 return max; | 24 return max; |
| 26 } | 25 } |
| 27 | 26 |
| 28 } // namespace | 27 } // namespace |
| 29 | 28 |
| 30 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator() | 29 MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator() |
| 31 : counter_(0), | 30 : counter_(0), |
| 32 max_amplitude_(0.0f), | 31 max_amplitude_(0.0f), |
| 33 level_(0.0f) { | 32 level_(0.0f) { |
| 34 } | 33 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 59 max_amplitude_ /= 4.0f; | 58 max_amplitude_ /= 4.0f; |
| 60 | 59 |
| 61 // Reset the counter. | 60 // Reset the counter. |
| 62 counter_ = 0; | 61 counter_ = 0; |
| 63 } | 62 } |
| 64 | 63 |
| 65 return level_; | 64 return level_; |
| 66 } | 65 } |
| 67 | 66 |
| 68 } // namespace content | 67 } // namespace content |
| OLD | NEW |