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