Index: webrtc/modules/audio_processing/biquad_high_pass_filter.cc |
diff --git a/webrtc/modules/audio_processing/high_pass_filter_impl.cc b/webrtc/modules/audio_processing/biquad_high_pass_filter.cc |
similarity index 63% |
copy from webrtc/modules/audio_processing/high_pass_filter_impl.cc |
copy to webrtc/modules/audio_processing/biquad_high_pass_filter.cc |
index d33ec78dcbca29b7214d338600864812a0d05e03..6b0677e200ad6a67138443c88ca4207378a1d5f4 100644 |
--- a/webrtc/modules/audio_processing/high_pass_filter_impl.cc |
+++ b/webrtc/modules/audio_processing/biquad_high_pass_filter.cc |
@@ -8,7 +8,7 @@ |
* be found in the AUTHORS file in the root of the source tree. |
*/ |
-#include "webrtc/modules/audio_processing/high_pass_filter_impl.h" |
+#include "webrtc/modules/audio_processing/biquad_high_pass_filter.h" |
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
#include "webrtc/modules/audio_processing/audio_buffer.h" |
@@ -20,16 +20,12 @@ const int16_t kFilterCoefficients8kHz[5] = {3798, -7596, 3798, 7807, -3733}; |
const int16_t kFilterCoefficients[5] = {4012, -8024, 4012, 8002, -3913}; |
} // namespace |
-class HighPassFilterImpl::BiquadFilter { |
+class BiquadHighPassFilter::BiquadFilter { |
the sun
2016/10/28 10:52:53
What do we do about the name? Should we use LowCut
peah-webrtc
2016/10/28 12:19:52
Let's go with that. That name is awesome!
Done.
|
public: |
- explicit BiquadFilter(int sample_rate_hz) : |
- ba_(sample_rate_hz == AudioProcessing::kSampleRate8kHz ? |
- kFilterCoefficients8kHz : kFilterCoefficients) |
- { |
- Reset(); |
- } |
- |
- void Reset() { |
+ explicit BiquadFilter(int sample_rate_hz) |
+ : ba_(sample_rate_hz == AudioProcessing::kSampleRate8kHz |
+ ? kFilterCoefficients8kHz |
+ : kFilterCoefficients) { |
std::memset(x_, 0, sizeof(x_)); |
std::memset(y_, 0, sizeof(y_)); |
} |
@@ -44,11 +40,11 @@ class HighPassFilterImpl::BiquadFilter { |
// y[i] = b[0] * x[i] + b[1] * x[i-1] + b[2] * x[i-2] |
// + -a[1] * y[i-1] + -a[2] * y[i-2]; |
- tmp_int32 = y[1] * ba[3]; // -a[1] * y[i-1] (low part) |
- tmp_int32 += y[3] * ba[4]; // -a[2] * y[i-2] (low part) |
+ tmp_int32 = y[1] * ba[3]; // -a[1] * y[i-1] (low part) |
+ tmp_int32 += y[3] * ba[4]; // -a[2] * y[i-2] (low part) |
tmp_int32 = (tmp_int32 >> 15); |
- tmp_int32 += y[0] * ba[3]; // -a[1] * y[i-1] (high part) |
- tmp_int32 += y[2] * ba[4]; // -a[2] * y[i-2] (high part) |
+ tmp_int32 += y[0] * ba[3]; // -a[1] * y[i-1] (high part) |
+ tmp_int32 += y[2] * ba[4]; // -a[2] * y[i-2] (high part) |
tmp_int32 = (tmp_int32 << 1); |
tmp_int32 += data[i] * ba[0]; // b[0] * x[0] |
@@ -70,8 +66,7 @@ class HighPassFilterImpl::BiquadFilter { |
tmp_int32 += 2048; |
// Saturate (to 2^27) so that the HP filtered signal does not overflow. |
- tmp_int32 = WEBRTC_SPL_SAT(static_cast<int32_t>(134217727), |
- tmp_int32, |
+ tmp_int32 = WEBRTC_SPL_SAT(static_cast<int32_t>(134217727), tmp_int32, |
static_cast<int32_t>(-134217728)); |
// Convert back to Q0 and use rounding. |
@@ -85,29 +80,18 @@ class HighPassFilterImpl::BiquadFilter { |
int16_t y_[4]; |
}; |
-HighPassFilterImpl::HighPassFilterImpl(rtc::CriticalSection* crit) |
- : crit_(crit) { |
- RTC_DCHECK(crit_); |
-} |
- |
-HighPassFilterImpl::~HighPassFilterImpl() {} |
- |
-void HighPassFilterImpl::Initialize(size_t channels, int sample_rate_hz) { |
- std::vector<std::unique_ptr<BiquadFilter>> new_filters(channels); |
+BiquadHighPassFilter::BiquadHighPassFilter(size_t channels, |
+ int sample_rate_hz) { |
+ filters_.resize(channels); |
for (size_t i = 0; i < channels; i++) { |
- new_filters[i].reset(new BiquadFilter(sample_rate_hz)); |
+ filters_[i].reset(new BiquadFilter(sample_rate_hz)); |
} |
- rtc::CritScope cs(crit_); |
- filters_.swap(new_filters); |
} |
-void HighPassFilterImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
- RTC_DCHECK(audio); |
- rtc::CritScope cs(crit_); |
- if (!enabled_) { |
- return; |
- } |
+BiquadHighPassFilter::~BiquadHighPassFilter() {} |
+void BiquadHighPassFilter::Process(AudioBuffer* audio) { |
+ RTC_DCHECK(audio); |
RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
RTC_DCHECK_EQ(filters_.size(), audio->num_channels()); |
for (size_t i = 0; i < filters_.size(); i++) { |
@@ -116,19 +100,4 @@ void HighPassFilterImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
} |
} |
-int HighPassFilterImpl::Enable(bool enable) { |
- rtc::CritScope cs(crit_); |
- if (!enabled_ && enable) { |
- for (auto& filter : filters_) { |
- filter->Reset(); |
- } |
- } |
- enabled_ = enable; |
- return AudioProcessing::kNoError; |
-} |
- |
-bool HighPassFilterImpl::is_enabled() const { |
- rtc::CritScope cs(crit_); |
- return enabled_; |
-} |
} // namespace webrtc |