henrik.lundin@webrtc.org | 9a40081 | 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 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_H_ |
| 13 | |
| 14 | #include <assert.h> |
| 15 | |
| 16 | #include "webrtc/modules/audio_coding/neteq4/audio_multi_vector.h" |
| 17 | #include "webrtc/modules/audio_coding/neteq4/time_stretch.h" |
| 18 | #include "webrtc/system_wrappers/interface/constructor_magic.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, size_t num_channels, |
| 33 | const BackgroundNoise& background_noise) |
| 34 | : TimeStretch(sample_rate_hz, num_channels, background_noise), |
| 35 | old_data_length_per_channel_(-1), |
| 36 | overlap_samples_(5 * sample_rate_hz / 8000) { |
| 37 | } |
| 38 | |
| 39 | virtual ~PreemptiveExpand() {} |
| 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. |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 46 | ReturnCodes Process(const int16_t *pw16_decoded, |
henrik.lundin@webrtc.org | 9a40081 | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 47 | int len, |
| 48 | int oldDataLen, |
| 49 | AudioMultiVector<int16_t>* output, |
| 50 | int16_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 | virtual void SetParametersForPassiveSpeech(int len, |
| 56 | int16_t* w16_bestCorr, |
| 57 | int* w16_bestIndex) const; |
| 58 | |
| 59 | // Checks the criteria for performing the time-stretching operation and, |
| 60 | // if possible, performs the time-stretching. |
| 61 | virtual ReturnCodes CheckCriteriaAndStretch( |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 62 | const int16_t *pw16_decoded, int len, size_t w16_bestIndex, |
henrik.lundin@webrtc.org | 9a40081 | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 63 | int16_t w16_bestCorr, bool w16_VAD, |
| 64 | AudioMultiVector<int16_t>* output) const; |
| 65 | |
| 66 | private: |
| 67 | int old_data_length_per_channel_; |
| 68 | int overlap_samples_; |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand); |
| 71 | }; |
| 72 | |
| 73 | } // namespace webrtc |
| 74 | #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_H_ |