• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PREEMPTIVE_EXPAND_H_
12 #define MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include "modules/audio_coding/neteq/time_stretch.h"
18 #include "rtc_base/constructor_magic.h"
19 
20 namespace webrtc {
21 
22 class AudioMultiVector;
23 class BackgroundNoise;
24 
25 // This class implements the PreemptiveExpand operation. Most of the work is
26 // done in the base class TimeStretch, which is shared with the Accelerate
27 // operation. In the PreemptiveExpand class, the operations that are specific to
28 // PreemptiveExpand are implemented.
29 class PreemptiveExpand : public TimeStretch {
30  public:
PreemptiveExpand(int sample_rate_hz,size_t num_channels,const BackgroundNoise & background_noise,size_t overlap_samples)31   PreemptiveExpand(int sample_rate_hz,
32                    size_t num_channels,
33                    const BackgroundNoise& background_noise,
34                    size_t overlap_samples)
35       : TimeStretch(sample_rate_hz, num_channels, background_noise),
36         old_data_length_per_channel_(0),
37         overlap_samples_(overlap_samples) {}
38 
39   // This method performs the actual PreemptiveExpand operation. The samples are
40   // read from |input|, of length |input_length| elements, and are written to
41   // |output|. The number of samples added through time-stretching is
42   // is provided in the output |length_change_samples|. The method returns
43   // the outcome of the operation as an enumerator value.
44   ReturnCodes Process(const int16_t* pw16_decoded,
45                       size_t len,
46                       size_t old_data_len,
47                       AudioMultiVector* output,
48                       size_t* length_change_samples);
49 
50  protected:
51   // Sets the parameters |best_correlation| and |peak_index| to suitable
52   // values when the signal contains no active speech.
53   void SetParametersForPassiveSpeech(size_t input_length,
54                                      int16_t* best_correlation,
55                                      size_t* peak_index) const override;
56 
57   // Checks the criteria for performing the time-stretching operation and,
58   // if possible, performs the time-stretching.
59   ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
60                                       size_t input_length,
61                                       size_t peak_index,
62                                       int16_t best_correlation,
63                                       bool active_speech,
64                                       bool /*fast_mode*/,
65                                       AudioMultiVector* output) const override;
66 
67  private:
68   size_t old_data_length_per_channel_;
69   size_t overlap_samples_;
70 
71   RTC_DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
72 };
73 
74 struct PreemptiveExpandFactory {
PreemptiveExpandFactoryPreemptiveExpandFactory75   PreemptiveExpandFactory() {}
~PreemptiveExpandFactoryPreemptiveExpandFactory76   virtual ~PreemptiveExpandFactory() {}
77 
78   virtual PreemptiveExpand* Create(int sample_rate_hz,
79                                    size_t num_channels,
80                                    const BackgroundNoise& background_noise,
81                                    size_t overlap_samples) const;
82 };
83 
84 }  // namespace webrtc
85 #endif  // MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_
86