Skip to content

Commit

Permalink
Qualify cmath function calls
Browse files Browse the repository at this point in the history
Use the C++-style stdlib headers, add `std::` prefix, in order to avoid implicit casts to double.

Bug: None
Change-Id: I78d9caaee715be341d2480c6d5e769068966d577
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133625
Reviewed-by: Karl Wiberg <[email protected]>
Commit-Queue: Oleh Prypin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#27905}
  • Loading branch information
oprypin authored and Commit Bot committed May 10, 2019
1 parent fb08781 commit 1992958
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/audio_processing/agc2/vad_with_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ float ProcessForRms(AudioFrameView<const float> frame) {
for (const auto& x : frame.channel(0)) {
rms += x * x;
}
return sqrt(rms / frame.samples_per_channel());
return std::sqrt(rms / frame.samples_per_channel());
}
} // namespace

Expand Down
4 changes: 2 additions & 2 deletions modules/audio_processing/rms_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "modules/audio_processing/rms_level.h"

#include <math.h>
#include <algorithm>
#include <cmath>
#include <numeric>

#include "rtc_base/checks.h"
Expand All @@ -36,7 +36,7 @@ int ComputeRms(float mean_square) {
const float mean_square_norm = mean_square / kMaxSquaredLevel;
RTC_DCHECK_GT(mean_square_norm, kMinLevel);
// 20log_10(x^0.5) = 10log_10(x)
const float rms = 10.f * log10(mean_square_norm);
const float rms = 10.f * std::log10(mean_square_norm);
RTC_DCHECK_LE(rms, 0.f);
RTC_DCHECK_GT(rms, -RmsLevel::kMinLevelDb);
// Return the negated value.
Expand Down
15 changes: 8 additions & 7 deletions modules/audio_processing/transient/transient_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "modules/audio_processing/transient/transient_detector.h"

#include <float.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <cmath>

#include "modules/audio_processing/transient/common.h"
#include "modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h"
Expand Down Expand Up @@ -125,9 +125,9 @@ float TransientDetector::Detect(const float* data,
const float kVerticalScaling = 0.5f;
const float kVerticalShift = 1.f;

result =
(cos(result * horizontal_scaling + kHorizontalShift) + kVerticalShift) *
kVerticalScaling;
result = (std::cos(result * horizontal_scaling + kHorizontalShift) +
kVerticalShift) *
kVerticalScaling;
result *= result;
}

Expand Down Expand Up @@ -161,9 +161,10 @@ float TransientDetector::ReferenceDetectionValue(const float* data,
return 1.f;
}
RTC_DCHECK_NE(0, reference_energy_);
float result = 1.f / (1.f + exp(kReferenceNonLinearity *
(kEnergyRatioThreshold -
reference_energy / reference_energy_)));
float result =
1.f / (1.f + std::exp(kReferenceNonLinearity *
(kEnergyRatioThreshold -
reference_energy / reference_energy_)));
reference_energy_ =
kMemory * reference_energy_ + (1.f - kMemory) * reference_energy;

Expand Down
8 changes: 4 additions & 4 deletions modules/audio_processing/transient/transient_suppressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "modules/audio_processing/transient/transient_suppressor.h"

#include <math.h>
#include <string.h>
#include <cmath>
#include <complex>
Expand Down Expand Up @@ -139,9 +138,9 @@ int TransientSuppressor::Initialize(int sample_rate_hz,
for (size_t i = 0; i < complex_analysis_length_; ++i) {
mean_factor_[i] =
kFactorHeight /
(1.f + exp(kLowSlope * static_cast<int>(i - kMinVoiceBin))) +
(1.f + std::exp(kLowSlope * static_cast<int>(i - kMinVoiceBin))) +
kFactorHeight /
(1.f + exp(kHighSlope * static_cast<int>(kMaxVoiceBin - i)));
(1.f + std::exp(kHighSlope * static_cast<int>(kMaxVoiceBin - i)));
}
detector_smoothed_ = 0.f;
keypress_counter_ = 0;
Expand Down Expand Up @@ -352,7 +351,8 @@ void TransientSuppressor::UpdateBuffers(float* data) {
// If a restoration takes place, the |magnitudes_| are updated to the new value.
void TransientSuppressor::HardRestoration(float* spectral_mean) {
const float detector_result =
1.f - pow(1.f - detector_smoothed_, using_reference_ ? 200.f : 50.f);
1.f -
std::pow(1.f - detector_smoothed_, using_reference_ ? 200.f : 50.f);
// To restore, we get the peaks in the spectrum. If higher than the previous
// spectral mean we adjust them.
for (size_t i = 0; i < complex_analysis_length_; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions modules/rtp_rtcp/source/receive_statistics_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "modules/rtp_rtcp/source/receive_statistics_impl.h"

#include <math.h>
#include <cmath>
#include <cstdlib>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -329,7 +329,7 @@ bool StreamStatisticianImpl::IsRetransmitOfOldPacket(
int64_t max_delay_ms = 0;

// Jitter standard deviation in samples.
float jitter_std = sqrt(static_cast<float>(jitter_q4_ >> 4));
float jitter_std = std::sqrt(static_cast<float>(jitter_q4_ >> 4));

// 2 times the standard deviation => 95% confidence.
// And transform to milliseconds by dividing by the frequency in kHz.
Expand Down
2 changes: 1 addition & 1 deletion video/send_statistics_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ void SendStatisticsProxy::OnEncodedFrameTimeMeasured(int encode_time_ms,
rtc::CritScope lock(&crit_);
uma_container_->encode_time_counter_.Add(encode_time_ms);
encode_time_.Apply(1.0f, encode_time_ms);
stats_.avg_encode_time_ms = round(encode_time_.filtered());
stats_.avg_encode_time_ms = std::round(encode_time_.filtered());
stats_.total_encode_time_ms += encode_time_ms;
stats_.encode_usage_percent = encode_usage_percent;
}
Expand Down

0 comments on commit 1992958

Please sign in to comment.