mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 16:47:50 +01:00
Qualify cmath function calls.
Bug: webrtc:10433 Change-Id: I5c31010a99be8ae93b3a85c3bce09292268007cd Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128612 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Minyue Li <minyue@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27262}
This commit is contained in:
parent
2cdc6117b0
commit
b00dec57fe
2 changed files with 14 additions and 10 deletions
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "common_audio/smoothing_filter.h"
|
#include "common_audio/smoothing_filter.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
@ -71,7 +72,7 @@ bool SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmoothingFilterImpl::UpdateAlpha(int time_constant_ms) {
|
void SmoothingFilterImpl::UpdateAlpha(int time_constant_ms) {
|
||||||
alpha_ = time_constant_ms == 0 ? 0.0f : exp(-1.0f / time_constant_ms);
|
alpha_ = time_constant_ms == 0 ? 0.0f : std::exp(-1.0f / time_constant_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmoothingFilterImpl::ExtrapolateLastSample(int64_t time_ms) {
|
void SmoothingFilterImpl::ExtrapolateLastSample(int64_t time_ms) {
|
||||||
|
@ -93,12 +94,12 @@ void SmoothingFilterImpl::ExtrapolateLastSample(int64_t time_ms) {
|
||||||
multiplier = 0.0f;
|
multiplier = 0.0f;
|
||||||
} else if (init_time_ms_ == 1) {
|
} else if (init_time_ms_ == 1) {
|
||||||
// This means |init_factor_| = 1.
|
// This means |init_factor_| = 1.
|
||||||
multiplier = exp(last_state_time_ms_ - time_ms);
|
multiplier = std::exp(last_state_time_ms_ - time_ms);
|
||||||
} else {
|
} else {
|
||||||
multiplier =
|
multiplier = std::exp(
|
||||||
exp(-(powf(init_factor_, last_state_time_ms_ - *init_end_time_ms_) -
|
-(powf(init_factor_, last_state_time_ms_ - *init_end_time_ms_) -
|
||||||
powf(init_factor_, time_ms - *init_end_time_ms_)) /
|
powf(init_factor_, time_ms - *init_end_time_ms_)) /
|
||||||
init_const_);
|
init_const_);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (last_state_time_ms_ < *init_end_time_ms_) {
|
if (last_state_time_ms_ < *init_end_time_ms_) {
|
||||||
|
|
|
@ -122,7 +122,8 @@ TEST(SmoothingFilterTest, InitTimeEqualsOne) {
|
||||||
constexpr int kInitTimeMs = 1;
|
constexpr int kInitTimeMs = 1;
|
||||||
SmoothingFilterStates states(kInitTimeMs);
|
SmoothingFilterStates states(kInitTimeMs);
|
||||||
CheckOutput(&states, 1.0f, 1, 1.0f);
|
CheckOutput(&states, 1.0f, 1, 1.0f);
|
||||||
CheckOutput(&states, 0.5f, 1, 1.0f * exp(-1.0f) + (1.0f - exp(-1.0f)) * 0.5f);
|
CheckOutput(&states, 0.5f, 1,
|
||||||
|
1.0f * std::exp(-1.0f) + (1.0f - std::exp(-1.0f)) * 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SmoothingFilterTest, GetAverageOutputsEmptyBeforeFirstSample) {
|
TEST(SmoothingFilterTest, GetAverageOutputsEmptyBeforeFirstSample) {
|
||||||
|
@ -144,17 +145,19 @@ TEST(SmoothingFilterTest, CannotChangeTimeConstantDuringInitialization) {
|
||||||
states.smoothing_filter.AddSample(0.0);
|
states.smoothing_filter.AddSample(0.0);
|
||||||
|
|
||||||
EXPECT_FALSE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
|
EXPECT_FALSE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
|
||||||
EXPECT_NE(exp(-1.0f / (kInitTimeMs * 2)), states.smoothing_filter.alpha());
|
EXPECT_NE(std::exp(-1.0f / (kInitTimeMs * 2)),
|
||||||
|
states.smoothing_filter.alpha());
|
||||||
|
|
||||||
states.fake_clock.AdvanceTime(TimeDelta::ms(1));
|
states.fake_clock.AdvanceTime(TimeDelta::ms(1));
|
||||||
states.smoothing_filter.AddSample(0.0);
|
states.smoothing_filter.AddSample(0.0);
|
||||||
// When initialization finishes, the time constant should be come
|
// When initialization finishes, the time constant should be come
|
||||||
// |kInitTimeConstantMs|.
|
// |kInitTimeConstantMs|.
|
||||||
EXPECT_FLOAT_EQ(exp(-1.0f / kInitTimeMs), states.smoothing_filter.alpha());
|
EXPECT_FLOAT_EQ(std::exp(-1.0f / kInitTimeMs),
|
||||||
|
states.smoothing_filter.alpha());
|
||||||
|
|
||||||
// After initialization, |SetTimeConstantMs| takes effect.
|
// After initialization, |SetTimeConstantMs| takes effect.
|
||||||
EXPECT_TRUE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
|
EXPECT_TRUE(states.smoothing_filter.SetTimeConstantMs(kInitTimeMs * 2));
|
||||||
EXPECT_FLOAT_EQ(exp(-1.0f / (kInitTimeMs * 2)),
|
EXPECT_FLOAT_EQ(std::exp(-1.0f / (kInitTimeMs * 2)),
|
||||||
states.smoothing_filter.alpha());
|
states.smoothing_filter.alpha());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue