Adds product operator for TimeDelta and Frequency
Also adding kHz factory function for Frequency class. Bug: webrtc:9883 Change-Id: Ide44910d50eb9616de2bb0c66b8c62493d2be92e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167725 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Ali Tofigh <alito@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30416}
This commit is contained in:

committed by
Commit Bot

parent
184ea66aed
commit
1cf15bfe55
@ -32,6 +32,11 @@ class Frequency final : public rtc_units_impl::RelativeUnit<Frequency> {
|
||||
return FromFraction(1000, hertz);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr Frequency kHz(T hertz) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction(1000000, hertz);
|
||||
}
|
||||
template <typename T>
|
||||
static constexpr Frequency hertz(T hertz) {
|
||||
static_assert(std::is_arithmetic<T>::value, "");
|
||||
return FromFraction(1000, hertz);
|
||||
@ -74,6 +79,13 @@ inline constexpr TimeDelta operator/(int64_t nominator,
|
||||
return TimeDelta::us(nominator * kMegaPerMilli / frequency.millihertz());
|
||||
}
|
||||
|
||||
inline constexpr double operator*(Frequency frequency, TimeDelta time_delta) {
|
||||
return frequency.hertz<double>() * time_delta.seconds<double>();
|
||||
}
|
||||
inline constexpr double operator*(TimeDelta time_delta, Frequency frequency) {
|
||||
return frequency * time_delta;
|
||||
}
|
||||
|
||||
std::string ToString(Frequency value);
|
||||
inline std::string ToLogString(Frequency value) {
|
||||
return ToString(value);
|
||||
|
@ -154,6 +154,7 @@ TEST(FrequencyTest, InfinityOperations) {
|
||||
TEST(UnitConversionTest, TimeDeltaAndFrequency) {
|
||||
EXPECT_EQ(1 / Frequency::hertz(50), TimeDelta::ms(20));
|
||||
EXPECT_EQ(1 / TimeDelta::ms(20), Frequency::hertz(50));
|
||||
EXPECT_EQ(Frequency::kHz(200) * TimeDelta::ms(2), 400.0);
|
||||
}
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
Reference in New Issue
Block a user