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 MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 12 #define MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 13 14 #include <array> 15 #include <cstring> 16 #include <memory> 17 #include <vector> 18 19 #include "api/array_view.h" 20 21 namespace webrtc { 22 23 constexpr int kSparsity = 4; 24 constexpr int kStrideLog2 = 2; 25 constexpr int kStride = 1 << kStrideLog2; 26 constexpr int kNumZeroFilters = 2; 27 constexpr int kFilterSize = 4; 28 constexpr int kMemorySize = kFilterSize * kStride - 1; 29 static_assert(kMemorySize == 15, 30 "The memory size must be sufficient to provide memory for the " 31 "shifted filters"); 32 33 // An implementation of a 3-band FIR filter-bank with DCT modulation, similar to 34 // the proposed in "Multirate Signal Processing for Communication Systems" by 35 // Fredric J Harris. 36 // The low-pass filter prototype has these characteristics: 37 // * Pass-band ripple = 0.3dB 38 // * Pass-band frequency = 0.147 (7kHz at 48kHz) 39 // * Stop-band attenuation = 40dB 40 // * Stop-band frequency = 0.192 (9.2kHz at 48kHz) 41 // * Delay = 24 samples (500us at 48kHz) 42 // * Linear phase 43 // This filter bank does not satisfy perfect reconstruction. The SNR after 44 // analysis and synthesis (with no processing in between) is approximately 9.5dB 45 // depending on the input signal after compensating for the delay. 46 class ThreeBandFilterBank final { 47 public: 48 static const int kNumBands = 3; 49 static const int kFullBandSize = 480; 50 static const int kSplitBandSize = 51 ThreeBandFilterBank::kFullBandSize / ThreeBandFilterBank::kNumBands; 52 static const int kNumNonZeroFilters = 53 kSparsity * ThreeBandFilterBank::kNumBands - kNumZeroFilters; 54 55 ThreeBandFilterBank(); 56 ~ThreeBandFilterBank(); 57 58 // Splits |in| of size kFullBandSize into 3 downsampled frequency bands in 59 // |out|, each of size 160. 60 void Analysis(rtc::ArrayView<const float, kFullBandSize> in, 61 rtc::ArrayView<const rtc::ArrayView<float>, kNumBands> out); 62 63 // Merges the 3 downsampled frequency bands in |in|, each of size 160, into 64 // |out|, which is of size kFullBandSize. 65 void Synthesis(rtc::ArrayView<const rtc::ArrayView<float>, kNumBands> in, 66 rtc::ArrayView<float, kFullBandSize> out); 67 68 private: 69 std::array<std::array<float, kMemorySize>, kNumNonZeroFilters> 70 state_analysis_; 71 std::array<std::array<float, kMemorySize>, kNumNonZeroFilters> 72 state_synthesis_; 73 }; 74 75 } // namespace webrtc 76 77 #endif // MODULES_AUDIO_PROCESSING_THREE_BAND_FILTER_BANK_H_ 78