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_PREEMPTIVE_EXPAND_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
| 14 | #include <assert.h> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_coding/neteq/audio_multi_vector.h" |
| 17 | #include "modules/audio_coding/neteq/time_stretch.h" |
| 18 | #include "rtc_base/constructormagic.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 19 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // Forward declarations. |
| 24 | class BackgroundNoise; |
| 25 | |
| 26 | // This class implements the PreemptiveExpand operation. Most of the work is |
| 27 | // done in the base class TimeStretch, which is shared with the Accelerate |
| 28 | // operation. In the PreemptiveExpand class, the operations that are specific to |
| 29 | // PreemptiveExpand are implemented. |
| 30 | class PreemptiveExpand : public TimeStretch { |
| 31 | public: |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 32 | PreemptiveExpand(int sample_rate_hz, |
| 33 | size_t num_channels, |
| 34 | const BackgroundNoise& background_noise, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 35 | size_t overlap_samples) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 36 | : TimeStretch(sample_rate_hz, num_channels, background_noise), |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 37 | old_data_length_per_channel_(0), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 38 | overlap_samples_(overlap_samples) {} |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 39 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 40 | // This method performs the actual PreemptiveExpand operation. The samples are |
| 41 | // read from |input|, of length |input_length| elements, and are written to |
| 42 | // |output|. The number of samples added through time-stretching is |
| 43 | // is provided in the output |length_change_samples|. The method returns |
| 44 | // the outcome of the operation as an enumerator value. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 45 | ReturnCodes Process(const int16_t* pw16_decoded, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 46 | size_t len, |
| 47 | size_t old_data_len, |
henrik.lundin@webrtc.org | fd11bbf | 2013-09-30 20:38:44 +0000 | [diff] [blame] | 48 | AudioMultiVector* output, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 49 | size_t* length_change_samples); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | // Sets the parameters |best_correlation| and |peak_index| to suitable |
| 53 | // values when the signal contains no active speech. |
Peter Kasting | 728d903 | 2015-06-11 14:31:38 -0700 | [diff] [blame] | 54 | void SetParametersForPassiveSpeech(size_t input_length, |
| 55 | int16_t* best_correlation, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 56 | size_t* peak_index) const override; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 57 | |
| 58 | // Checks the criteria for performing the time-stretching operation and, |
| 59 | // if possible, performs the time-stretching. |
Henrik Lundin | cf808d2 | 2015-05-27 14:33:29 +0200 | [diff] [blame] | 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*/, |
Karl Wiberg | 7f6c4d4 | 2015-04-09 15:44:22 +0200 | [diff] [blame] | 66 | AudioMultiVector* output) const override; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 67 | |
| 68 | private: |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 69 | size_t old_data_length_per_channel_; |
| 70 | size_t overlap_samples_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 71 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 72 | RTC_DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
henrik.lundin@webrtc.org | d9faa46 | 2014-01-14 10:18:45 +0000 | [diff] [blame] | 75 | struct PreemptiveExpandFactory { |
| 76 | PreemptiveExpandFactory() {} |
| 77 | virtual ~PreemptiveExpandFactory() {} |
| 78 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 79 | virtual PreemptiveExpand* Create(int sample_rate_hz, |
| 80 | size_t num_channels, |
| 81 | const BackgroundNoise& background_noise, |
| 82 | size_t overlap_samples) const; |
henrik.lundin@webrtc.org | d9faa46 | 2014-01-14 10:18:45 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 85 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 86 | #endif // MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ |