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 21namespace webrtc { 22 23// Forward declarations. 24class 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. 30class PreemptiveExpand : public TimeStretch { 31 public: 32 PreemptiveExpand(int sample_rate_hz, 33 size_t num_channels, 34 const BackgroundNoise& background_noise, 35 int overlap_samples) 36 : TimeStretch(sample_rate_hz, num_channels, background_noise), 37 old_data_length_per_channel_(-1), 38 overlap_samples_(overlap_samples) { 39 } 40 41 virtual ~PreemptiveExpand() {} 42 43 // This method performs the actual PreemptiveExpand operation. The samples are 44 // read from |input|, of length |input_length| elements, and are written to 45 // |output|. The number of samples added through time-stretching is 46 // is provided in the output |length_change_samples|. The method returns 47 // the outcome of the operation as an enumerator value. 48 ReturnCodes Process(const int16_t *pw16_decoded, 49 int len, 50 int old_data_len, 51 AudioMultiVector* output, 52 int16_t* length_change_samples); 53 54 protected: 55 // Sets the parameters |best_correlation| and |peak_index| to suitable 56 // values when the signal contains no active speech. 57 virtual void SetParametersForPassiveSpeech(size_t len, 58 int16_t* w16_bestCorr, 59 int* w16_bestIndex) const; 60 61 // Checks the criteria for performing the time-stretching operation and, 62 // if possible, performs the time-stretching. 63 virtual ReturnCodes CheckCriteriaAndStretch( 64 const int16_t *pw16_decoded, size_t len, size_t w16_bestIndex, 65 int16_t w16_bestCorr, bool w16_VAD, 66 AudioMultiVector* output) const; 67 68 private: 69 int old_data_length_per_channel_; 70 int overlap_samples_; 71 72 DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand); 73}; 74 75struct PreemptiveExpandFactory { 76 PreemptiveExpandFactory() {} 77 virtual ~PreemptiveExpandFactory() {} 78 79 virtual PreemptiveExpand* Create( 80 int sample_rate_hz, 81 size_t num_channels, 82 const BackgroundNoise& background_noise, 83 int overlap_samples) const; 84}; 85 86} // namespace webrtc 87#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_ 88