xref: /aosp_15_r20/external/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 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_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_
12 #define MODULES_AUDIO_PROCESSING_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_
13 
14 #include <array>
15 
16 namespace webrtc {
17 
18 // Iteratively produces a sequence of delayed voice probability values given a
19 // fixed delay between 0 and 20 ms and given a sequence of voice probability
20 // values observed every 10 ms. Supports fractional delays, that are delays
21 // which are not a multiple integer of 10 ms. Applies interpolation with
22 // fractional delays; otherwise, returns a previously observed value according
23 // to the given fixed delay.
24 class VoiceProbabilityDelayUnit {
25  public:
26   // Ctor. `delay_num_samples` is the delay in number of samples and it must be
27   // non-negative and less than 20 ms.
28   VoiceProbabilityDelayUnit(int delay_num_samples, int sample_rate_hz);
29 
30   // Handles delay and sample rate changes and resets the delay unit.
31   void Initialize(int delay_num_samples, int sample_rate_hz);
32 
33   // Observes `voice_probability` and returns a delayed voice probability.
34   float Delay(float voice_probability);
35 
36  private:
37   std::array<float, 3> weights_;
38   std::array<float, 2> last_probabilities_;
39 };
40 
41 }  // namespace webrtc
42 
43 #endif  // MODULES_AUDIO_PROCESSING_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_
44