OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS_H_ |
13 | 13 |
14 #include <complex> | 14 #include <complex> |
15 | 15 #include <memory> |
16 #include "webrtc/base/scoped_ptr.h" | |
17 | 16 |
18 namespace webrtc { | 17 namespace webrtc { |
19 | 18 |
20 namespace intelligibility { | 19 namespace intelligibility { |
21 | 20 |
22 // Internal helper for computing the power of a stream of arrays. | 21 // Internal helper for computing the power of a stream of arrays. |
23 // The result is an array of power per position: the i-th power is the power of | 22 // The result is an array of power per position: the i-th power is the power of |
24 // the stream of data on the i-th positions in the input arrays. | 23 // the stream of data on the i-th positions in the input arrays. |
25 class PowerEstimator { | 24 class PowerEstimator { |
26 public: | 25 public: |
27 // Construct an instance for the given input array length (|freqs|), with the | 26 // Construct an instance for the given input array length (|freqs|), with the |
28 // appropriate parameters. |decay| is the forgetting factor. | 27 // appropriate parameters. |decay| is the forgetting factor. |
29 PowerEstimator(size_t freqs, float decay); | 28 PowerEstimator(size_t freqs, float decay); |
30 | 29 |
31 // Add a new data point to the series. | 30 // Add a new data point to the series. |
32 void Step(const std::complex<float>* data); | 31 void Step(const std::complex<float>* data); |
33 | 32 |
34 // The current power array. | 33 // The current power array. |
35 const float* Power(); | 34 const float* Power(); |
36 | 35 |
37 private: | 36 private: |
38 // TODO(ekmeyerson): Switch the following running means | 37 // TODO(ekmeyerson): Switch the following running means |
39 // and histories from rtc::scoped_ptr to std::vector. | 38 // and histories from std::unique_ptr to std::vector. |
40 rtc::scoped_ptr<std::complex<float>[]> running_mean_sq_; | 39 std::unique_ptr<std::complex<float>[]> running_mean_sq_; |
41 | 40 |
42 // The current magnitude array. | 41 // The current magnitude array. |
43 rtc::scoped_ptr<float[]> magnitude_; | 42 std::unique_ptr<float[]> magnitude_; |
44 // The current power array. | 43 // The current power array. |
45 rtc::scoped_ptr<float[]> power_; | 44 std::unique_ptr<float[]> power_; |
46 | 45 |
47 const size_t num_freqs_; | 46 const size_t num_freqs_; |
48 const float decay_; | 47 const float decay_; |
49 }; | 48 }; |
50 | 49 |
51 // Helper class for smoothing gain changes. On each application step, the | 50 // Helper class for smoothing gain changes. On each application step, the |
52 // currently used gains are changed towards a set of settable target gains, | 51 // currently used gains are changed towards a set of settable target gains, |
53 // constrained by a limit on the magnitude of the changes. | 52 // constrained by a limit on the magnitude of the changes. |
54 class GainApplier { | 53 class GainApplier { |
55 public: | 54 public: |
56 GainApplier(size_t freqs, float change_limit); | 55 GainApplier(size_t freqs, float change_limit); |
57 | 56 |
58 // Copy |in_block| to |out_block|, multiplied by the current set of gains, | 57 // Copy |in_block| to |out_block|, multiplied by the current set of gains, |
59 // and step the current set of gains towards the target set. | 58 // and step the current set of gains towards the target set. |
60 void Apply(const std::complex<float>* in_block, | 59 void Apply(const std::complex<float>* in_block, |
61 std::complex<float>* out_block); | 60 std::complex<float>* out_block); |
62 | 61 |
63 // Return the current target gain set. Modify this array to set the targets. | 62 // Return the current target gain set. Modify this array to set the targets. |
64 float* target() const { return target_.get(); } | 63 float* target() const { return target_.get(); } |
65 | 64 |
66 private: | 65 private: |
67 const size_t num_freqs_; | 66 const size_t num_freqs_; |
68 const float change_limit_; | 67 const float change_limit_; |
69 rtc::scoped_ptr<float[]> target_; | 68 std::unique_ptr<float[]> target_; |
70 rtc::scoped_ptr<float[]> current_; | 69 std::unique_ptr<float[]> current_; |
71 }; | 70 }; |
72 | 71 |
73 } // namespace intelligibility | 72 } // namespace intelligibility |
74 | 73 |
75 } // namespace webrtc | 74 } // namespace webrtc |
76 | 75 |
77 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ | 76 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_INTELLIGIBILITY_INTELLIGIBILITY_UTILS
_H_ |
OLD | NEW |