OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_mixer/gain_change_calculator.h" | |
12 | |
13 #include <cmath> | |
hlundin-webrtc
2017/03/29 07:22:56
math.h
We tend to use the C-version of a header th
aleloi
2017/03/29 10:56:11
Done. Consequence: cmath seems to put a 'fabs' in
| |
14 #include <vector> | |
15 | |
16 namespace webrtc { | |
17 | |
18 namespace { | |
19 constexpr int16_t kReliabilityThreshold = 100; | |
20 } // namespace | |
21 | |
22 float GainChangeCalculator::CalculateGainChange( | |
23 rtc::ArrayView<const int16_t> in, | |
24 rtc::ArrayView<const int16_t> out) { | |
25 RTC_DCHECK_EQ(in.size(), out.size()); | |
26 | |
27 std::vector<float> gain(in.size()); | |
28 auto gain_view = rtc::ArrayView<float>(gain.data(), gain.size()); | |
29 CalculateGain(in, out, gain_view); | |
hlundin-webrtc
2017/03/29 07:22:56
std::vector should implicitly convert to rtc::Arra
aleloi
2017/03/29 10:56:11
Done.
| |
30 return CalculateDifferences(gain_view); | |
hlundin-webrtc
2017/03/29 07:22:55
... and here.
aleloi
2017/03/29 10:56:11
Done.
| |
31 } | |
32 | |
33 void GainChangeCalculator::CalculateGain(rtc::ArrayView<const int16_t> in, | |
34 rtc::ArrayView<const int16_t> out, | |
35 rtc::ArrayView<float> gain) { | |
36 RTC_DCHECK_EQ(in.size(), out.size()); | |
37 RTC_DCHECK_EQ(in.size(), gain.size()); | |
38 | |
39 for (size_t i = 0; i < in.size(); ++i) { | |
40 if (std::abs(in[i]) >= kReliabilityThreshold) { | |
41 last_reliable_gain_ = out[i] / static_cast<float>(in[i]); | |
42 } | |
43 gain[i] = last_reliable_gain_; | |
44 } | |
45 } | |
46 | |
47 float GainChangeCalculator::CalculateDifferences( | |
48 rtc::ArrayView<const float> values) { | |
49 float res = 0; | |
50 for (float f : values) { | |
51 res += std::fabs(f - last_value_); | |
52 last_value_ = f; | |
53 } | |
54 return res; | |
55 } | |
56 } // namespace webrtc | |
OLD | NEW |