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 WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ 13 14 #include <assert.h> 15 16 #include "webrtc/base/constructormagic.h" 17 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" 18 #include "webrtc/modules/audio_coding/neteq/time_stretch.h" 19 #include "webrtc/typedefs.h" 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: 32 PreemptiveExpand(int sample_rate_hz, 33 size_t num_channels, 34 const BackgroundNoise& background_noise, 35 size_t overlap_samples) 36 : TimeStretch(sample_rate_hz, num_channels, background_noise), 37 old_data_length_per_channel_(0), 38 overlap_samples_(overlap_samples) { 39 } 40 41 // This method performs the actual PreemptiveExpand operation. The samples are 42 // read from |input|, of length |input_length| elements, and are written to 43 // |output|. The number of samples added through time-stretching is 44 // is provided in the output |length_change_samples|. The method returns 45 // the outcome of the operation as an enumerator value. 46 ReturnCodes Process(const int16_t *pw16_decoded, 47 size_t len, 48 size_t old_data_len, 49 AudioMultiVector* output, 50 size_t* length_change_samples); 51 52 protected: 53 // Sets the parameters |best_correlation| and |peak_index| to suitable 54 // values when the signal contains no active speech. 55 void SetParametersForPassiveSpeech(size_t input_length, 56 int16_t* best_correlation, 57 size_t* peak_index) const override; 58 59 // Checks the criteria for performing the time-stretching operation and, 60 // if possible, performs the time-stretching. 61 ReturnCodes CheckCriteriaAndStretch(const int16_t* input, 62 size_t input_length, 63 size_t peak_index, 64 int16_t best_correlation, 65 bool active_speech, 66 bool /*fast_mode*/, 67 AudioMultiVector* output) const override; 68 69 private: 70 size_t old_data_length_per_channel_; 71 size_t overlap_samples_; 72 73 RTC_DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand); 74 }; 75 76 struct PreemptiveExpandFactory { 77 PreemptiveExpandFactory() {} 78 virtual ~PreemptiveExpandFactory() {} 79 80 virtual PreemptiveExpand* Create( 81 int sample_rate_hz, 82 size_t num_channels, 83 const BackgroundNoise& background_noise, 84 size_t overlap_samples) const; 85 }; 86 87 } // namespace webrtc 88 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ 89