xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/accelerate.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2012 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_CODING_NETEQ_ACCELERATE_H_
12 #define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include "modules/audio_coding/neteq/time_stretch.h"
18 
19 namespace webrtc {
20 
21 class AudioMultiVector;
22 class BackgroundNoise;
23 
24 // This class implements the Accelerate operation. Most of the work is done
25 // in the base class TimeStretch, which is shared with the PreemptiveExpand
26 // operation. In the Accelerate class, the operations that are specific to
27 // Accelerate are implemented.
28 class Accelerate : public TimeStretch {
29  public:
Accelerate(int sample_rate_hz,size_t num_channels,const BackgroundNoise & background_noise)30   Accelerate(int sample_rate_hz,
31              size_t num_channels,
32              const BackgroundNoise& background_noise)
33       : TimeStretch(sample_rate_hz, num_channels, background_noise) {}
34 
35   Accelerate(const Accelerate&) = delete;
36   Accelerate& operator=(const Accelerate&) = delete;
37 
38   // This method performs the actual Accelerate operation. The samples are
39   // read from `input`, of length `input_length` elements, and are written to
40   // `output`. The number of samples removed through time-stretching is
41   // is provided in the output `length_change_samples`. The method returns
42   // the outcome of the operation as an enumerator value. If `fast_accelerate`
43   // is true, the algorithm will relax the requirements on finding strong
44   // correlations, and may remove multiple pitch periods if possible.
45   ReturnCodes Process(const int16_t* input,
46                       size_t input_length,
47                       bool fast_accelerate,
48                       AudioMultiVector* output,
49                       size_t* length_change_samples);
50 
51  protected:
52   // Sets the parameters `best_correlation` and `peak_index` to suitable
53   // values when the signal contains no active speech.
54   void SetParametersForPassiveSpeech(size_t len,
55                                      int16_t* best_correlation,
56                                      size_t* peak_index) const override;
57 
58   // Checks the criteria for performing the time-stretching operation and,
59   // if possible, performs the time-stretching.
60   ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
61                                       size_t input_length,
62                                       size_t peak_index,
63                                       int16_t best_correlation,
64                                       bool active_speech,
65                                       bool fast_mode,
66                                       AudioMultiVector* output) const override;
67 };
68 
69 struct AccelerateFactory {
AccelerateFactoryAccelerateFactory70   AccelerateFactory() {}
~AccelerateFactoryAccelerateFactory71   virtual ~AccelerateFactory() {}
72 
73   virtual Accelerate* Create(int sample_rate_hz,
74                              size_t num_channels,
75                              const BackgroundNoise& background_noise) const;
76 };
77 
78 }  // namespace webrtc
79 #endif  // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
80