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

Side by Side Diff: media/audio/audio_power_monitor.cc

Issue 1076443002: Removed obsolete float_util.h as VS2013 supports standards well enough. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Added missing includes everywhere. Created 5 years, 8 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/audio/audio_power_monitor.h" 5 #include "media/audio/audio_power_monitor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/float_util.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "media/base/audio_bus.h" 12 #include "media/base/audio_bus.h"
14 #include "media/base/vector_math.h" 13 #include "media/base/vector_math.h"
15 14
16 namespace media { 15 namespace media {
17 16
18 AudioPowerMonitor::AudioPowerMonitor( 17 AudioPowerMonitor::AudioPowerMonitor(
19 int sample_rate, const base::TimeDelta& time_constant) 18 int sample_rate, const base::TimeDelta& time_constant)
20 : sample_weight_( 19 : sample_weight_(
(...skipping 25 matching lines...) Expand all
46 return; 45 return;
47 46
48 // Calculate a new average power by applying a first-order low-pass filter 47 // Calculate a new average power by applying a first-order low-pass filter
49 // (a.k.a. an exponentially-weighted moving average) over the audio samples in 48 // (a.k.a. an exponentially-weighted moving average) over the audio samples in
50 // each channel in |buffer|. 49 // each channel in |buffer|.
51 float sum_power = 0.0f; 50 float sum_power = 0.0f;
52 for (int i = 0; i < num_channels; ++i) { 51 for (int i = 0; i < num_channels; ++i) {
53 const std::pair<float, float> ewma_and_max = vector_math::EWMAAndMaxPower( 52 const std::pair<float, float> ewma_and_max = vector_math::EWMAAndMaxPower(
54 average_power_, buffer.channel(i), num_frames, sample_weight_); 53 average_power_, buffer.channel(i), num_frames, sample_weight_);
55 // If data in audio buffer is garbage, ignore its effect on the result. 54 // If data in audio buffer is garbage, ignore its effect on the result.
56 if (!base::IsFinite(ewma_and_max.first)) { 55 if (!std::isfinite(ewma_and_max.first)) {
57 sum_power += average_power_; 56 sum_power += average_power_;
58 } else { 57 } else {
59 sum_power += ewma_and_max.first; 58 sum_power += ewma_and_max.first;
60 has_clipped_ |= (ewma_and_max.second > 1.0f); 59 has_clipped_ |= (ewma_and_max.second > 1.0f);
61 } 60 }
62 } 61 }
63 62
64 // Update accumulated results, with clamping for sanity. 63 // Update accumulated results, with clamping for sanity.
65 average_power_ = std::max(0.0f, std::min(1.0f, sum_power / num_channels)); 64 average_power_ = std::max(0.0f, std::min(1.0f, sum_power / num_channels));
66 65
(...skipping 17 matching lines...) Expand all
84 const float power_dbfs = power_reading_ < kInsignificantPower ? zero_power() : 83 const float power_dbfs = power_reading_ < kInsignificantPower ? zero_power() :
85 10.0f * log10f(power_reading_); 84 10.0f * log10f(power_reading_);
86 85
87 const bool clipped = clipped_reading_; 86 const bool clipped = clipped_reading_;
88 clipped_reading_ = false; 87 clipped_reading_ = false;
89 88
90 return std::make_pair(power_dbfs, clipped); 89 return std::make_pair(power_dbfs, clipped);
91 } 90 }
92 91
93 } // namespace media 92 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698