blob: 124b63384ca2ce7087318b1bc4397cdcb1d4c2d2 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
12#define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/neteq/time_stretch.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/constructor_magic.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000019
20namespace webrtc {
21
Yves Gerey988cc082018-10-23 12:03:01 +020022class AudioMultiVector;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000023class BackgroundNoise;
24
25// This class implements the Accelerate operation. Most of the work is done
26// in the base class TimeStretch, which is shared with the PreemptiveExpand
27// operation. In the Accelerate class, the operations that are specific to
28// Accelerate are implemented.
29class Accelerate : public TimeStretch {
30 public:
Yves Gerey665174f2018-06-19 15:03:05 +020031 Accelerate(int sample_rate_hz,
32 size_t num_channels,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000033 const BackgroundNoise& background_noise)
Yves Gerey665174f2018-06-19 15:03:05 +020034 : TimeStretch(sample_rate_hz, num_channels, background_noise) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000035
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000036 // This method performs the actual Accelerate operation. The samples are
37 // read from |input|, of length |input_length| elements, and are written to
38 // |output|. The number of samples removed through time-stretching is
39 // is provided in the output |length_change_samples|. The method returns
Henrik Lundincf808d22015-05-27 14:33:29 +020040 // the outcome of the operation as an enumerator value. If |fast_accelerate|
41 // is true, the algorithm will relax the requirements on finding strong
42 // correlations, and may remove multiple pitch periods if possible.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000043 ReturnCodes Process(const int16_t* input,
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000044 size_t input_length,
Henrik Lundincf808d22015-05-27 14:33:29 +020045 bool fast_accelerate,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000046 AudioMultiVector* output,
Peter Kastingdce40cf2015-08-24 14:52:23 -070047 size_t* length_change_samples);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000048
49 protected:
50 // Sets the parameters |best_correlation| and |peak_index| to suitable
51 // values when the signal contains no active speech.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000052 void SetParametersForPassiveSpeech(size_t len,
53 int16_t* best_correlation,
Peter Kastingdce40cf2015-08-24 14:52:23 -070054 size_t* peak_index) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000055
56 // Checks the criteria for performing the time-stretching operation and,
57 // if possible, performs the time-stretching.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000058 ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
59 size_t input_length,
60 size_t peak_index,
61 int16_t best_correlation,
62 bool active_speech,
Henrik Lundincf808d22015-05-27 14:33:29 +020063 bool fast_mode,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000064 AudioMultiVector* output) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000065
66 private:
henrikg3c089d72015-09-16 05:37:44 -070067 RTC_DISALLOW_COPY_AND_ASSIGN(Accelerate);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000068};
69
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000070struct AccelerateFactory {
71 AccelerateFactory() {}
72 virtual ~AccelerateFactory() {}
73
74 virtual Accelerate* Create(int sample_rate_hz,
75 size_t num_channels,
76 const BackgroundNoise& background_noise) const;
77};
78
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000079} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#endif // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_