1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ 12*d9f75844SAndroid Build Coastguard Worker #define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <stddef.h> 15*d9f75844SAndroid Build Coastguard Worker #include <stdint.h> 16*d9f75844SAndroid Build Coastguard Worker 17*d9f75844SAndroid Build Coastguard Worker #include "modules/audio_coding/neteq/time_stretch.h" 18*d9f75844SAndroid Build Coastguard Worker 19*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 20*d9f75844SAndroid Build Coastguard Worker 21*d9f75844SAndroid Build Coastguard Worker class AudioMultiVector; 22*d9f75844SAndroid Build Coastguard Worker class BackgroundNoise; 23*d9f75844SAndroid Build Coastguard Worker 24*d9f75844SAndroid Build Coastguard Worker // This class implements the Accelerate operation. Most of the work is done 25*d9f75844SAndroid Build Coastguard Worker // in the base class TimeStretch, which is shared with the PreemptiveExpand 26*d9f75844SAndroid Build Coastguard Worker // operation. In the Accelerate class, the operations that are specific to 27*d9f75844SAndroid Build Coastguard Worker // Accelerate are implemented. 28*d9f75844SAndroid Build Coastguard Worker class Accelerate : public TimeStretch { 29*d9f75844SAndroid Build Coastguard Worker public: Accelerate(int sample_rate_hz,size_t num_channels,const BackgroundNoise & background_noise)30*d9f75844SAndroid Build Coastguard Worker Accelerate(int sample_rate_hz, 31*d9f75844SAndroid Build Coastguard Worker size_t num_channels, 32*d9f75844SAndroid Build Coastguard Worker const BackgroundNoise& background_noise) 33*d9f75844SAndroid Build Coastguard Worker : TimeStretch(sample_rate_hz, num_channels, background_noise) {} 34*d9f75844SAndroid Build Coastguard Worker 35*d9f75844SAndroid Build Coastguard Worker Accelerate(const Accelerate&) = delete; 36*d9f75844SAndroid Build Coastguard Worker Accelerate& operator=(const Accelerate&) = delete; 37*d9f75844SAndroid Build Coastguard Worker 38*d9f75844SAndroid Build Coastguard Worker // This method performs the actual Accelerate operation. The samples are 39*d9f75844SAndroid Build Coastguard Worker // read from `input`, of length `input_length` elements, and are written to 40*d9f75844SAndroid Build Coastguard Worker // `output`. The number of samples removed through time-stretching is 41*d9f75844SAndroid Build Coastguard Worker // is provided in the output `length_change_samples`. The method returns 42*d9f75844SAndroid Build Coastguard Worker // the outcome of the operation as an enumerator value. If `fast_accelerate` 43*d9f75844SAndroid Build Coastguard Worker // is true, the algorithm will relax the requirements on finding strong 44*d9f75844SAndroid Build Coastguard Worker // correlations, and may remove multiple pitch periods if possible. 45*d9f75844SAndroid Build Coastguard Worker ReturnCodes Process(const int16_t* input, 46*d9f75844SAndroid Build Coastguard Worker size_t input_length, 47*d9f75844SAndroid Build Coastguard Worker bool fast_accelerate, 48*d9f75844SAndroid Build Coastguard Worker AudioMultiVector* output, 49*d9f75844SAndroid Build Coastguard Worker size_t* length_change_samples); 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker protected: 52*d9f75844SAndroid Build Coastguard Worker // Sets the parameters `best_correlation` and `peak_index` to suitable 53*d9f75844SAndroid Build Coastguard Worker // values when the signal contains no active speech. 54*d9f75844SAndroid Build Coastguard Worker void SetParametersForPassiveSpeech(size_t len, 55*d9f75844SAndroid Build Coastguard Worker int16_t* best_correlation, 56*d9f75844SAndroid Build Coastguard Worker size_t* peak_index) const override; 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker // Checks the criteria for performing the time-stretching operation and, 59*d9f75844SAndroid Build Coastguard Worker // if possible, performs the time-stretching. 60*d9f75844SAndroid Build Coastguard Worker ReturnCodes CheckCriteriaAndStretch(const int16_t* input, 61*d9f75844SAndroid Build Coastguard Worker size_t input_length, 62*d9f75844SAndroid Build Coastguard Worker size_t peak_index, 63*d9f75844SAndroid Build Coastguard Worker int16_t best_correlation, 64*d9f75844SAndroid Build Coastguard Worker bool active_speech, 65*d9f75844SAndroid Build Coastguard Worker bool fast_mode, 66*d9f75844SAndroid Build Coastguard Worker AudioMultiVector* output) const override; 67*d9f75844SAndroid Build Coastguard Worker }; 68*d9f75844SAndroid Build Coastguard Worker 69*d9f75844SAndroid Build Coastguard Worker struct AccelerateFactory { AccelerateFactoryAccelerateFactory70*d9f75844SAndroid Build Coastguard Worker AccelerateFactory() {} ~AccelerateFactoryAccelerateFactory71*d9f75844SAndroid Build Coastguard Worker virtual ~AccelerateFactory() {} 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker virtual Accelerate* Create(int sample_rate_hz, 74*d9f75844SAndroid Build Coastguard Worker size_t num_channels, 75*d9f75844SAndroid Build Coastguard Worker const BackgroundNoise& background_noise) const; 76*d9f75844SAndroid Build Coastguard Worker }; 77*d9f75844SAndroid Build Coastguard Worker 78*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 79*d9f75844SAndroid Build Coastguard Worker #endif // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_ 80