blob: 01fe874d549294e5098fb6da80deaef34fbd949e [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:211/*
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 04:47:3111#ifndef MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
12#define MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2113
Yves Gerey988cc082018-10-23 10:03:0114#include <stddef.h>
15#include <stdint.h>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/audio_coding/neteq/time_stretch.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2118
19namespace webrtc {
20
Yves Gerey988cc082018-10-23 10:03:0121class AudioMultiVector;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2122class BackgroundNoise;
23
24// This class implements the Accelerate operation. Most of the work is done
25// in the base class TimeStretch, which is shared with the PreemptiveExpand
26// operation. In the Accelerate class, the operations that are specific to
27// Accelerate are implemented.
28class Accelerate : public TimeStretch {
29 public:
Yves Gerey665174f2018-06-19 13:03:0530 Accelerate(int sample_rate_hz,
31 size_t num_channels,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2132 const BackgroundNoise& background_noise)
Yves Gerey665174f2018-06-19 13:03:0533 : TimeStretch(sample_rate_hz, num_channels, background_noise) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2134
Byoungchan Lee604fd2f2022-01-21 00:49:3935 Accelerate(const Accelerate&) = delete;
36 Accelerate& operator=(const Accelerate&) = delete;
37
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2138 // This method performs the actual Accelerate operation. The samples are
Artem Titovd00ce742021-07-28 18:00:1739 // read from `input`, of length `input_length` elements, and are written to
40 // `output`. The number of samples removed through time-stretching is
41 // is provided in the output `length_change_samples`. The method returns
42 // the outcome of the operation as an enumerator value. If `fast_accelerate`
Henrik Lundincf808d22015-05-27 12:33:2943 // is true, the algorithm will relax the requirements on finding strong
44 // correlations, and may remove multiple pitch periods if possible.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2145 ReturnCodes Process(const int16_t* input,
turaj@webrtc.org362a55e2013-09-20 16:25:2846 size_t input_length,
Henrik Lundincf808d22015-05-27 12:33:2947 bool fast_accelerate,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:4448 AudioMultiVector* output,
Peter Kastingdce40cf2015-08-24 21:52:2349 size_t* length_change_samples);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2150
51 protected:
Artem Titovd00ce742021-07-28 18:00:1752 // Sets the parameters `best_correlation` and `peak_index` to suitable
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2153 // values when the signal contains no active speech.
kjellander@webrtc.org14665ff2015-03-04 12:58:3554 void SetParametersForPassiveSpeech(size_t len,
55 int16_t* best_correlation,
Peter Kastingdce40cf2015-08-24 21:52:2356 size_t* peak_index) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2157
58 // Checks the criteria for performing the time-stretching operation and,
59 // if possible, performs the time-stretching.
kjellander@webrtc.org14665ff2015-03-04 12:58:3560 ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
61 size_t input_length,
62 size_t peak_index,
63 int16_t best_correlation,
64 bool active_speech,
Henrik Lundincf808d22015-05-27 12:33:2965 bool fast_mode,
kjellander@webrtc.org14665ff2015-03-04 12:58:3566 AudioMultiVector* output) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2167};
68
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:4569struct AccelerateFactory {
70 AccelerateFactory() {}
71 virtual ~AccelerateFactory() {}
72
73 virtual Accelerate* Create(int sample_rate_hz,
74 size_t num_channels,
75 const BackgroundNoise& background_noise) const;
76};
77
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:2178} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 04:47:3179#endif // MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_