xref: /aosp_15_r20/external/webrtc/modules/audio_processing/agc2/rnn_vad/auto_correlation.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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_AGC2_RNN_VAD_AUTO_CORRELATION_H_
12 #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_AUTO_CORRELATION_H_
13 
14 #include <memory>
15 
16 #include "api/array_view.h"
17 #include "modules/audio_processing/agc2/rnn_vad/common.h"
18 #include "modules/audio_processing/utility/pffft_wrapper.h"
19 
20 namespace webrtc {
21 namespace rnn_vad {
22 
23 // Class to compute the auto correlation on the pitch buffer for a target pitch
24 // interval.
25 class AutoCorrelationCalculator {
26  public:
27   AutoCorrelationCalculator();
28   AutoCorrelationCalculator(const AutoCorrelationCalculator&) = delete;
29   AutoCorrelationCalculator& operator=(const AutoCorrelationCalculator&) =
30       delete;
31   ~AutoCorrelationCalculator();
32 
33   // Computes the auto-correlation coefficients for a target pitch interval.
34   // `auto_corr` indexes are inverted lags.
35   void ComputeOnPitchBuffer(
36       rtc::ArrayView<const float, kBufSize12kHz> pitch_buf,
37       rtc::ArrayView<float, kNumLags12kHz> auto_corr);
38 
39  private:
40   Pffft fft_;
41   std::unique_ptr<Pffft::FloatBuffer> tmp_;
42   std::unique_ptr<Pffft::FloatBuffer> X_;
43   std::unique_ptr<Pffft::FloatBuffer> H_;
44 };
45 
46 }  // namespace rnn_vad
47 }  // namespace webrtc
48 
49 #endif  // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_AUTO_CORRELATION_H_
50