xref: /aosp_15_r20/external/webrtc/modules/audio_processing/agc2/rnn_vad/common.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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_COMMON_H_
12 #define MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_COMMON_H_
13 
14 #include <stddef.h>
15 
16 namespace webrtc {
17 namespace rnn_vad {
18 
19 constexpr double kPi = 3.14159265358979323846;
20 
21 constexpr int kSampleRate24kHz = 24000;
22 constexpr int kFrameSize10ms24kHz = kSampleRate24kHz / 100;
23 constexpr int kFrameSize20ms24kHz = kFrameSize10ms24kHz * 2;
24 
25 // Pitch buffer.
26 constexpr int kMinPitch24kHz = kSampleRate24kHz / 800;   // 0.00125 s.
27 constexpr int kMaxPitch24kHz = kSampleRate24kHz / 62.5;  // 0.016 s.
28 constexpr int kBufSize24kHz = kMaxPitch24kHz + kFrameSize20ms24kHz;
29 static_assert((kBufSize24kHz & 1) == 0, "The buffer size must be even.");
30 
31 // 24 kHz analysis.
32 // Define a higher minimum pitch period for the initial search. This is used to
33 // avoid searching for very short periods, for which a refinement step is
34 // responsible.
35 constexpr int kInitialMinPitch24kHz = 3 * kMinPitch24kHz;
36 static_assert(kMinPitch24kHz < kInitialMinPitch24kHz, "");
37 static_assert(kInitialMinPitch24kHz < kMaxPitch24kHz, "");
38 static_assert(kMaxPitch24kHz > kInitialMinPitch24kHz, "");
39 // Number of (inverted) lags during the initial pitch search phase at 24 kHz.
40 constexpr int kInitialNumLags24kHz = kMaxPitch24kHz - kInitialMinPitch24kHz;
41 // Number of (inverted) lags during the pitch search refinement phase at 24 kHz.
42 constexpr int kRefineNumLags24kHz = kMaxPitch24kHz + 1;
43 static_assert(
44     kRefineNumLags24kHz > kInitialNumLags24kHz,
45     "The refinement step must search the pitch in an extended pitch range.");
46 
47 // 12 kHz analysis.
48 constexpr int kSampleRate12kHz = 12000;
49 constexpr int kFrameSize10ms12kHz = kSampleRate12kHz / 100;
50 constexpr int kFrameSize20ms12kHz = kFrameSize10ms12kHz * 2;
51 constexpr int kBufSize12kHz = kBufSize24kHz / 2;
52 constexpr int kInitialMinPitch12kHz = kInitialMinPitch24kHz / 2;
53 constexpr int kMaxPitch12kHz = kMaxPitch24kHz / 2;
54 static_assert(kMaxPitch12kHz > kInitialMinPitch12kHz, "");
55 // The inverted lags for the pitch interval [`kInitialMinPitch12kHz`,
56 // `kMaxPitch12kHz`] are in the range [0, `kNumLags12kHz`].
57 constexpr int kNumLags12kHz = kMaxPitch12kHz - kInitialMinPitch12kHz;
58 
59 // 48 kHz constants.
60 constexpr int kMinPitch48kHz = kMinPitch24kHz * 2;
61 constexpr int kMaxPitch48kHz = kMaxPitch24kHz * 2;
62 
63 // Spectral features.
64 constexpr int kNumBands = 22;
65 constexpr int kNumLowerBands = 6;
66 static_assert((0 < kNumLowerBands) && (kNumLowerBands < kNumBands), "");
67 constexpr int kCepstralCoeffsHistorySize = 8;
68 static_assert(kCepstralCoeffsHistorySize > 2,
69               "The history size must at least be 3 to compute first and second "
70               "derivatives.");
71 
72 constexpr int kFeatureVectorSize = 42;
73 
74 }  // namespace rnn_vad
75 }  // namespace webrtc
76 
77 #endif  // MODULES_AUDIO_PROCESSING_AGC2_RNN_VAD_COMMON_H_
78