blob: 6338b993fd11bc480e4e390fa9a169b1c97e47cd [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
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"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000018
19namespace webrtc {
20
Yves Gerey988cc082018-10-23 12:03:01 +020021class AudioMultiVector;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000022class BackgroundNoise;
23
24// This class implements the PreemptiveExpand operation. Most of the work is
25// done in the base class TimeStretch, which is shared with the Accelerate
26// operation. In the PreemptiveExpand class, the operations that are specific to
27// PreemptiveExpand are implemented.
28class PreemptiveExpand : public TimeStretch {
29 public:
turaj@webrtc.org8d1cdaa2014-04-11 18:47:55 +000030 PreemptiveExpand(int sample_rate_hz,
31 size_t num_channels,
32 const BackgroundNoise& background_noise,
Peter Kastingdce40cf2015-08-24 14:52:23 -070033 size_t overlap_samples)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000034 : TimeStretch(sample_rate_hz, num_channels, background_noise),
Peter Kastingdce40cf2015-08-24 14:52:23 -070035 old_data_length_per_channel_(0),
Yves Gerey665174f2018-06-19 15:03:05 +020036 overlap_samples_(overlap_samples) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000037
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090038 PreemptiveExpand(const PreemptiveExpand&) = delete;
39 PreemptiveExpand& operator=(const PreemptiveExpand&) = delete;
40
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000041 // This method performs the actual PreemptiveExpand operation. The samples are
Artem Titovd00ce742021-07-28 20:00:17 +020042 // 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
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000045 // the outcome of the operation as an enumerator value.
Yves Gerey665174f2018-06-19 15:03:05 +020046 ReturnCodes Process(const int16_t* pw16_decoded,
Peter Kastingdce40cf2015-08-24 14:52:23 -070047 size_t len,
48 size_t old_data_len,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000049 AudioMultiVector* output,
Peter Kastingdce40cf2015-08-24 14:52:23 -070050 size_t* length_change_samples);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000051
52 protected:
Artem Titovd00ce742021-07-28 20:00:17 +020053 // Sets the parameters `best_correlation` and `peak_index` to suitable
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000054 // values when the signal contains no active speech.
Peter Kasting728d9032015-06-11 14:31:38 -070055 void SetParametersForPassiveSpeech(size_t input_length,
56 int16_t* best_correlation,
Peter Kastingdce40cf2015-08-24 14:52:23 -070057 size_t* peak_index) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000058
59 // Checks the criteria for performing the time-stretching operation and,
60 // if possible, performs the time-stretching.
Henrik Lundincf808d22015-05-27 14:33:29 +020061 ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
62 size_t input_length,
63 size_t peak_index,
64 int16_t best_correlation,
65 bool active_speech,
66 bool /*fast_mode*/,
Karl Wiberg7f6c4d42015-04-09 15:44:22 +020067 AudioMultiVector* output) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000068
69 private:
Peter Kastingdce40cf2015-08-24 14:52:23 -070070 size_t old_data_length_per_channel_;
71 size_t overlap_samples_;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000072};
73
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000074struct PreemptiveExpandFactory {
75 PreemptiveExpandFactory() {}
76 virtual ~PreemptiveExpandFactory() {}
77
Yves Gerey665174f2018-06-19 15:03:05 +020078 virtual PreemptiveExpand* Create(int sample_rate_hz,
79 size_t num_channels,
80 const BackgroundNoise& background_noise,
81 size_t overlap_samples) const;
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000082};
83
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000084} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020085#endif // MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_