1 /* 2 * Copyright (c) 2014 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_SPLITTING_FILTER_H_ 12 #define MODULES_AUDIO_PROCESSING_SPLITTING_FILTER_H_ 13 14 #include <cstring> 15 #include <memory> 16 #include <vector> 17 18 #include "modules/audio_processing/three_band_filter_bank.h" 19 20 namespace webrtc { 21 22 class IFChannelBuffer; 23 24 struct TwoBandsStates { TwoBandsStatesTwoBandsStates25 TwoBandsStates() { 26 memset(analysis_state1, 0, sizeof(analysis_state1)); 27 memset(analysis_state2, 0, sizeof(analysis_state2)); 28 memset(synthesis_state1, 0, sizeof(synthesis_state1)); 29 memset(synthesis_state2, 0, sizeof(synthesis_state2)); 30 } 31 32 static const int kStateSize = 6; 33 int analysis_state1[kStateSize]; 34 int analysis_state2[kStateSize]; 35 int synthesis_state1[kStateSize]; 36 int synthesis_state2[kStateSize]; 37 }; 38 39 // Splitting filter which is able to split into and merge from 2 or 3 frequency 40 // bands. The number of channels needs to be provided at construction time. 41 // 42 // For each block, Analysis() is called to split into bands and then Synthesis() 43 // to merge these bands again. The input and output signals are contained in 44 // IFChannelBuffers and for the different bands an array of IFChannelBuffers is 45 // used. 46 class SplittingFilter { 47 public: 48 SplittingFilter(size_t num_channels, size_t num_bands, size_t num_frames); 49 ~SplittingFilter(); 50 51 void Analysis(const IFChannelBuffer* data, IFChannelBuffer* bands); 52 void Synthesis(const IFChannelBuffer* bands, IFChannelBuffer* data); 53 54 private: 55 // Two-band analysis and synthesis work for 640 samples or less. 56 void TwoBandsAnalysis(const IFChannelBuffer* data, IFChannelBuffer* bands); 57 void TwoBandsSynthesis(const IFChannelBuffer* bands, IFChannelBuffer* data); 58 void ThreeBandsAnalysis(const IFChannelBuffer* data, IFChannelBuffer* bands); 59 void ThreeBandsSynthesis(const IFChannelBuffer* bands, IFChannelBuffer* data); 60 void InitBuffers(); 61 62 const size_t num_bands_; 63 std::vector<TwoBandsStates> two_bands_states_; 64 std::vector<std::unique_ptr<ThreeBandFilterBank>> three_band_filter_banks_; 65 }; 66 67 } // namespace webrtc 68 69 #endif // MODULES_AUDIO_PROCESSING_SPLITTING_FILTER_H_ 70