tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
 
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_SPLITTING_FILTER_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_SPLITTING_FILTER_H_
 
#include <cstring>
#include <vector>
 
#include "webrtc/modules/audio_processing/three_band_filter_bank.h"
#include "webrtc/system_wrappers/include/scoped_vector.h"
 
namespace webrtc {
 
class IFChannelBuffer;
 
struct TwoBandsStates {
  TwoBandsStates() {
    memset(analysis_state1, 0, sizeof(analysis_state1));
    memset(analysis_state2, 0, sizeof(analysis_state2));
    memset(synthesis_state1, 0, sizeof(synthesis_state1));
    memset(synthesis_state2, 0, sizeof(synthesis_state2));
  }
 
  static const int kStateSize = 6;
  int analysis_state1[kStateSize];
  int analysis_state2[kStateSize];
  int synthesis_state1[kStateSize];
  int synthesis_state2[kStateSize];
};
 
// Splitting filter which is able to split into and merge from 2 or 3 frequency
// bands. The number of channels needs to be provided at construction time.
//
// For each block, Analysis() is called to split into bands and then Synthesis()
// to merge these bands again. The input and output signals are contained in
// IFChannelBuffers and for the different bands an array of IFChannelBuffers is
// used.
class SplittingFilter {
 public:
  SplittingFilter(size_t num_channels, size_t num_bands, size_t num_frames);
 
  void Analysis(const IFChannelBuffer* data, IFChannelBuffer* bands);
  void Synthesis(const IFChannelBuffer* bands, IFChannelBuffer* data);
 
 private:
  // Two-band analysis and synthesis work for 640 samples or less.
  void TwoBandsAnalysis(const IFChannelBuffer* data, IFChannelBuffer* bands);
  void TwoBandsSynthesis(const IFChannelBuffer* bands, IFChannelBuffer* data);
  void ThreeBandsAnalysis(const IFChannelBuffer* data, IFChannelBuffer* bands);
  void ThreeBandsSynthesis(const IFChannelBuffer* bands, IFChannelBuffer* data);
  void InitBuffers();
 
  const size_t num_bands_;
  std::vector<TwoBandsStates> two_bands_states_;
  ScopedVector<ThreeBandFilterBank> three_band_filter_banks_;
};
 
}  // namespace webrtc
 
#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_SPLITTING_FILTER_H_