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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // target signal es present and to false otherwise. This methods can be called | 54 // target signal es present and to false otherwise. This methods can be called |
55 // to know if the data is target signal or interference and process it | 55 // to know if the data is target signal or interference and process it |
56 // accordingly. | 56 // accordingly. |
57 bool is_target_present() override { return is_target_present_; } | 57 bool is_target_present() override { return is_target_present_; } |
58 | 58 |
59 protected: | 59 protected: |
60 // Process one frequency-domain block of audio. This is where the fun | 60 // Process one frequency-domain block of audio. This is where the fun |
61 // happens. Implements LappedTransform::Callback. | 61 // happens. Implements LappedTransform::Callback. |
62 void ProcessAudioBlock(const complex<float>* const* input, | 62 void ProcessAudioBlock(const complex<float>* const* input, |
63 int num_input_channels, | 63 int num_input_channels, |
64 int num_freq_bins, | 64 size_t num_freq_bins, |
65 int num_output_channels, | 65 int num_output_channels, |
66 complex<float>* const* output) override; | 66 complex<float>* const* output) override; |
67 | 67 |
68 private: | 68 private: |
69 typedef Matrix<float> MatrixF; | 69 typedef Matrix<float> MatrixF; |
70 typedef ComplexMatrix<float> ComplexMatrixF; | 70 typedef ComplexMatrix<float> ComplexMatrixF; |
71 typedef complex<float> complex_f; | 71 typedef complex<float> complex_f; |
72 | 72 |
73 void InitDelaySumMasks(); | 73 void InitDelaySumMasks(); |
74 void InitTargetCovMats(); // TODO(aluebs): Make this depend on target angle. | 74 void InitTargetCovMats(); // TODO(aluebs): Make this depend on target angle. |
(...skipping 19 matching lines...) Expand all Loading... |
94 void ApplyLowFrequencyCorrection(); | 94 void ApplyLowFrequencyCorrection(); |
95 | 95 |
96 // Postfilter masks are also unreliable at high frequencies. Average mid-high | 96 // Postfilter masks are also unreliable at high frequencies. Average mid-high |
97 // frequency masks to calculate a single mask per block which can be applied | 97 // frequency masks to calculate a single mask per block which can be applied |
98 // in the time-domain. Further, we average these block-masks over a chunk, | 98 // in the time-domain. Further, we average these block-masks over a chunk, |
99 // resulting in one postfilter mask per audio chunk. This allows us to skip | 99 // resulting in one postfilter mask per audio chunk. This allows us to skip |
100 // both transforming and blocking the high-frequency signal. | 100 // both transforming and blocking the high-frequency signal. |
101 void ApplyHighFrequencyCorrection(); | 101 void ApplyHighFrequencyCorrection(); |
102 | 102 |
103 // Compute the means needed for the above frequency correction. | 103 // Compute the means needed for the above frequency correction. |
104 float MaskRangeMean(int start_bin, int end_bin); | 104 float MaskRangeMean(size_t start_bin, size_t end_bin); |
105 | 105 |
106 // Applies both sets of masks to |input| and store in |output|. | 106 // Applies both sets of masks to |input| and store in |output|. |
107 void ApplyMasks(const complex_f* const* input, complex_f* const* output); | 107 void ApplyMasks(const complex_f* const* input, complex_f* const* output); |
108 | 108 |
109 void EstimateTargetPresence(); | 109 void EstimateTargetPresence(); |
110 | 110 |
111 static const int kFftSize = 256; | 111 static const size_t kFftSize = 256; |
112 static const int kNumFreqBins = kFftSize / 2 + 1; | 112 static const size_t kNumFreqBins = kFftSize / 2 + 1; |
113 | 113 |
114 // Deals with the fft transform and blocking. | 114 // Deals with the fft transform and blocking. |
115 int chunk_length_; | 115 size_t chunk_length_; |
116 rtc::scoped_ptr<LappedTransform> lapped_transform_; | 116 rtc::scoped_ptr<LappedTransform> lapped_transform_; |
117 float window_[kFftSize]; | 117 float window_[kFftSize]; |
118 | 118 |
119 // Parameters exposed to the user. | 119 // Parameters exposed to the user. |
120 const int num_input_channels_; | 120 const int num_input_channels_; |
121 int sample_rate_hz_; | 121 int sample_rate_hz_; |
122 | 122 |
123 const std::vector<Point> array_geometry_; | 123 const std::vector<Point> array_geometry_; |
124 | 124 |
125 // Calculated based on user-input and constants in the .cc file. | 125 // Calculated based on user-input and constants in the .cc file. |
126 int low_mean_start_bin_; | 126 size_t low_mean_start_bin_; |
127 int low_mean_end_bin_; | 127 size_t low_mean_end_bin_; |
128 int high_mean_start_bin_; | 128 size_t high_mean_start_bin_; |
129 int high_mean_end_bin_; | 129 size_t high_mean_end_bin_; |
130 | 130 |
131 // Quickly varying mask updated every block. | 131 // Quickly varying mask updated every block. |
132 float new_mask_[kNumFreqBins]; | 132 float new_mask_[kNumFreqBins]; |
133 // Time smoothed mask. | 133 // Time smoothed mask. |
134 float time_smooth_mask_[kNumFreqBins]; | 134 float time_smooth_mask_[kNumFreqBins]; |
135 // Time and frequency smoothed mask. | 135 // Time and frequency smoothed mask. |
136 float final_mask_[kNumFreqBins]; | 136 float final_mask_[kNumFreqBins]; |
137 | 137 |
138 // Array of length |kNumFreqBins|, Matrix of size |1| x |num_channels_|. | 138 // Array of length |kNumFreqBins|, Matrix of size |1| x |num_channels_|. |
139 ComplexMatrixF delay_sum_masks_[kNumFreqBins]; | 139 ComplexMatrixF delay_sum_masks_[kNumFreqBins]; |
(...skipping 21 matching lines...) Expand all Loading... |
161 // The microphone normalization factor. | 161 // The microphone normalization factor. |
162 ComplexMatrixF eig_m_; | 162 ComplexMatrixF eig_m_; |
163 | 163 |
164 // For processing the high-frequency input signal. | 164 // For processing the high-frequency input signal. |
165 float high_pass_postfilter_mask_; | 165 float high_pass_postfilter_mask_; |
166 | 166 |
167 // True when the target signal is present. | 167 // True when the target signal is present. |
168 bool is_target_present_; | 168 bool is_target_present_; |
169 // Number of blocks after which the data is considered interference if the | 169 // Number of blocks after which the data is considered interference if the |
170 // mask does not pass |kMaskSignalThreshold|. | 170 // mask does not pass |kMaskSignalThreshold|. |
171 int hold_target_blocks_; | 171 size_t hold_target_blocks_; |
172 // Number of blocks since the last mask that passed |kMaskSignalThreshold|. | 172 // Number of blocks since the last mask that passed |kMaskSignalThreshold|. |
173 int interference_blocks_count_; | 173 size_t interference_blocks_count_; |
174 }; | 174 }; |
175 | 175 |
176 } // namespace webrtc | 176 } // namespace webrtc |
177 | 177 |
178 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_NONLINEAR_BEAMFORMER_H_ | 178 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_NONLINEAR_BEAMFORMER_H_ |
OLD | NEW |