blob: ace648f15cce257109976bbec88dc87b0a125f53 [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_PREEMPTIVE_EXPAND_H_
12#define MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_coding/neteq/audio_multi_vector.h"
15#include "modules/audio_coding/neteq/time_stretch.h"
16#include "rtc_base/constructormagic.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000017
18namespace webrtc {
19
20// Forward declarations.
21class BackgroundNoise;
22
23// This class implements the PreemptiveExpand operation. Most of the work is
24// done in the base class TimeStretch, which is shared with the Accelerate
25// operation. In the PreemptiveExpand class, the operations that are specific to
26// PreemptiveExpand are implemented.
27class PreemptiveExpand : public TimeStretch {
28 public:
turaj@webrtc.org8d1cdaa2014-04-11 18:47:55 +000029 PreemptiveExpand(int sample_rate_hz,
30 size_t num_channels,
31 const BackgroundNoise& background_noise,
Peter Kastingdce40cf2015-08-24 14:52:23 -070032 size_t overlap_samples)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000033 : TimeStretch(sample_rate_hz, num_channels, background_noise),
Peter Kastingdce40cf2015-08-24 14:52:23 -070034 old_data_length_per_channel_(0),
Yves Gerey665174f2018-06-19 15:03:05 +020035 overlap_samples_(overlap_samples) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000036
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000037 // This method performs the actual PreemptiveExpand operation. The samples are
38 // read from |input|, of length |input_length| elements, and are written to
39 // |output|. The number of samples added through time-stretching is
40 // is provided in the output |length_change_samples|. The method returns
41 // the outcome of the operation as an enumerator value.
Yves Gerey665174f2018-06-19 15:03:05 +020042 ReturnCodes Process(const int16_t* pw16_decoded,
Peter Kastingdce40cf2015-08-24 14:52:23 -070043 size_t len,
44 size_t old_data_len,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000045 AudioMultiVector* output,
Peter Kastingdce40cf2015-08-24 14:52:23 -070046 size_t* length_change_samples);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000047
48 protected:
49 // Sets the parameters |best_correlation| and |peak_index| to suitable
50 // values when the signal contains no active speech.
Peter Kasting728d9032015-06-11 14:31:38 -070051 void SetParametersForPassiveSpeech(size_t input_length,
52 int16_t* best_correlation,
Peter Kastingdce40cf2015-08-24 14:52:23 -070053 size_t* peak_index) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000054
55 // Checks the criteria for performing the time-stretching operation and,
56 // if possible, performs the time-stretching.
Henrik Lundincf808d22015-05-27 14:33:29 +020057 ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
58 size_t input_length,
59 size_t peak_index,
60 int16_t best_correlation,
61 bool active_speech,
62 bool /*fast_mode*/,
Karl Wiberg7f6c4d42015-04-09 15:44:22 +020063 AudioMultiVector* output) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000064
65 private:
Peter Kastingdce40cf2015-08-24 14:52:23 -070066 size_t old_data_length_per_channel_;
67 size_t overlap_samples_;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000068
henrikg3c089d72015-09-16 05:37:44 -070069 RTC_DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000070};
71
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000072struct PreemptiveExpandFactory {
73 PreemptiveExpandFactory() {}
74 virtual ~PreemptiveExpandFactory() {}
75
Yves Gerey665174f2018-06-19 15:03:05 +020076 virtual PreemptiveExpand* Create(int sample_rate_hz,
77 size_t num_channels,
78 const BackgroundNoise& background_noise,
79 size_t overlap_samples) const;
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000080};
81
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000082} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020083#endif // MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_