blob: 684f74bb8c3ac949ff1c8b1b97d476fad264eb37 [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
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
14#include <assert.h>
15
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000016#include "webrtc/base/constructormagic.h"
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000017#include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h"
18#include "webrtc/modules/audio_coding/neteq/time_stretch.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000019#include "webrtc/typedefs.h"
20
21namespace webrtc {
22
23// Forward declarations.
24class BackgroundNoise;
25
26// This class implements the Accelerate operation. Most of the work is done
27// in the base class TimeStretch, which is shared with the PreemptiveExpand
28// operation. In the Accelerate class, the operations that are specific to
29// Accelerate are implemented.
30class Accelerate : public TimeStretch {
31 public:
32 Accelerate(int sample_rate_hz, size_t num_channels,
33 const BackgroundNoise& background_noise)
34 : TimeStretch(sample_rate_hz, num_channels, background_noise) {
35 }
36
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000037 // This method performs the actual Accelerate operation. The samples are
38 // read from |input|, of length |input_length| elements, and are written to
39 // |output|. The number of samples removed through time-stretching is
40 // is provided in the output |length_change_samples|. The method returns
Henrik Lundincf808d22015-05-27 14:33:29 +020041 // the outcome of the operation as an enumerator value. If |fast_accelerate|
42 // is true, the algorithm will relax the requirements on finding strong
43 // correlations, and may remove multiple pitch periods if possible.
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000044 ReturnCodes Process(const int16_t* input,
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000045 size_t input_length,
Henrik Lundincf808d22015-05-27 14:33:29 +020046 bool fast_accelerate,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000047 AudioMultiVector* output,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000048 int16_t* length_change_samples);
49
50 protected:
51 // Sets the parameters |best_correlation| and |peak_index| to suitable
52 // values when the signal contains no active speech.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000053 void SetParametersForPassiveSpeech(size_t len,
54 int16_t* best_correlation,
55 int* peak_index) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000056
57 // Checks the criteria for performing the time-stretching operation and,
58 // if possible, performs the time-stretching.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 ReturnCodes CheckCriteriaAndStretch(const int16_t* input,
60 size_t input_length,
61 size_t peak_index,
62 int16_t best_correlation,
63 bool active_speech,
Henrik Lundincf808d22015-05-27 14:33:29 +020064 bool fast_mode,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 AudioMultiVector* output) const override;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000066
67 private:
68 DISALLOW_COPY_AND_ASSIGN(Accelerate);
69};
70
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000071struct AccelerateFactory {
72 AccelerateFactory() {}
73 virtual ~AccelerateFactory() {}
74
75 virtual Accelerate* Create(int sample_rate_hz,
76 size_t num_channels,
77 const BackgroundNoise& background_noise) const;
78};
79
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000080} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000081#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_ACCELERATE_H_