henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_coding/neteq/audio_multi_vector.h" |
| 15 | #include "modules/audio_coding/neteq/time_stretch.h" |
| 16 | #include "rtc_base/constructormagic.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Forward declarations. |
| 21 | class BackgroundNoise; |
| 22 | |
| 23 | // This class implements the Accelerate operation. Most of the work is done |
| 24 | // in the base class TimeStretch, which is shared with the PreemptiveExpand |
| 25 | // operation. In the Accelerate class, the operations that are specific to |
| 26 | // Accelerate are implemented. |
| 27 | class Accelerate : public TimeStretch { |
| 28 | public: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 29 | Accelerate(int sample_rate_hz, |
| 30 | size_t num_channels, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 31 | const BackgroundNoise& background_noise) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 32 | : TimeStretch(sample_rate_hz, num_channels, background_noise) {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 33 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 34 | // This method performs the actual Accelerate operation. The samples are |
| 35 | // read from |input|, of length |input_length| elements, and are written to |
| 36 | // |output|. The number of samples removed through time-stretching is |
| 37 | // is provided in the output |length_change_samples|. The method returns |
Henrik Lundin | cf808d2 | 2015-05-27 14:33:29 +0200 | [diff] [blame] | 38 | // the outcome of the operation as an enumerator value. If |fast_accelerate| |
| 39 | // is true, the algorithm will relax the requirements on finding strong |
| 40 | // correlations, and may remove multiple pitch periods if possible. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 41 | ReturnCodes Process(const int16_t* input, |
turaj@webrtc.org | 362a55e | 2013-09-20 16:25:28 +0000 | [diff] [blame] | 42 | size_t input_length, |
Henrik Lundin | cf808d2 | 2015-05-27 14:33:29 +0200 | [diff] [blame] | 43 | bool fast_accelerate, |
henrik.lundin@webrtc.org | fd11bbf | 2013-09-30 20:38:44 +0000 | [diff] [blame] | 44 | AudioMultiVector* output, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 45 | size_t* length_change_samples); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | // Sets the parameters |best_correlation| and |peak_index| to suitable |
| 49 | // values when the signal contains no active speech. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 50 | void SetParametersForPassiveSpeech(size_t len, |
| 51 | int16_t* best_correlation, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 52 | size_t* peak_index) const override; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 53 | |
| 54 | // Checks the criteria for performing the time-stretching operation and, |
| 55 | // if possible, performs the time-stretching. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 56 | ReturnCodes CheckCriteriaAndStretch(const int16_t* input, |
| 57 | size_t input_length, |
| 58 | size_t peak_index, |
| 59 | int16_t best_correlation, |
| 60 | bool active_speech, |
Henrik Lundin | cf808d2 | 2015-05-27 14:33:29 +0200 | [diff] [blame] | 61 | bool fast_mode, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 62 | AudioMultiVector* output) const override; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 63 | |
| 64 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 65 | RTC_DISALLOW_COPY_AND_ASSIGN(Accelerate); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
henrik.lundin@webrtc.org | d9faa46 | 2014-01-14 10:18:45 +0000 | [diff] [blame] | 68 | struct AccelerateFactory { |
| 69 | AccelerateFactory() {} |
| 70 | virtual ~AccelerateFactory() {} |
| 71 | |
| 72 | virtual Accelerate* Create(int sample_rate_hz, |
| 73 | size_t num_channels, |
| 74 | const BackgroundNoise& background_noise) const; |
| 75 | }; |
| 76 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 77 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 78 | #endif // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ |