1 /* 2 * Copyright (c) 2015 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 13 14 #include <cstring> 15 #include <memory> 16 #include <vector> 17 18 #include "webrtc/common_audio/sparse_fir_filter.h" 19 20 namespace webrtc { 21 22 // An implementation of a 3-band FIR filter-bank with DCT modulation, similar to 23 // the proposed in "Multirate Signal Processing for Communication Systems" by 24 // Fredric J Harris. 25 // The low-pass filter prototype has these characteristics: 26 // * Pass-band ripple = 0.3dB 27 // * Pass-band frequency = 0.147 (7kHz at 48kHz) 28 // * Stop-band attenuation = 40dB 29 // * Stop-band frequency = 0.192 (9.2kHz at 48kHz) 30 // * Delay = 24 samples (500us at 48kHz) 31 // * Linear phase 32 // This filter bank does not satisfy perfect reconstruction. The SNR after 33 // analysis and synthesis (with no processing in between) is approximately 9.5dB 34 // depending on the input signal after compensating for the delay. 35 class ThreeBandFilterBank final { 36 public: 37 explicit ThreeBandFilterBank(size_t length); 38 ~ThreeBandFilterBank(); 39 40 // Splits |in| into 3 downsampled frequency bands in |out|. 41 // |length| is the |in| length. Each of the 3 bands of |out| has to have a 42 // length of |length| / 3. 43 void Analysis(const float* in, size_t length, float* const* out); 44 45 // Merges the 3 downsampled frequency bands in |in| into |out|. 46 // |split_length| is the length of each band of |in|. |out| has to have at 47 // least a length of 3 * |split_length|. 48 void Synthesis(const float* const* in, size_t split_length, float* out); 49 50 private: 51 void DownModulate(const float* in, 52 size_t split_length, 53 size_t offset, 54 float* const* out); 55 void UpModulate(const float* const* in, 56 size_t split_length, 57 size_t offset, 58 float* out); 59 60 std::vector<float> in_buffer_; 61 std::vector<float> out_buffer_; 62 std::vector<std::unique_ptr<SparseFIRFilter>> analysis_filters_; 63 std::vector<std::unique_ptr<SparseFIRFilter>> synthesis_filters_; 64 std::vector<std::vector<float>> dct_modulation_; 65 }; 66 67 } // namespace webrtc 68 69 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 70