blob: 81f1abb53c081ea28b7f6cf0cd96dbf663f5dd18 [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
11#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_ACCELERATE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_ACCELERATE_H_
13
14#include <assert.h>
15
16#include "webrtc/modules/audio_coding/neteq4/audio_multi_vector.h"
17#include "webrtc/modules/audio_coding/neteq4/time_stretch.h"
mcasas@webrtc.org2fa7f792014-05-21 11:07:29 +000018#include "webrtc/system_wrappers/interface/constructor_magic.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
37 virtual ~Accelerate() {}
38
39 // This method performs the actual Accelerate operation. The samples are
40 // read from |input|, of length |input_length| elements, and are written to
41 // |output|. The number of samples removed through time-stretching is
42 // is provided in the output |length_change_samples|. The method returns
43 // the outcome of the operation as an enumerator value.
44 ReturnCodes Process(const int16_t* input,
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000045 size_t input_length,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000046 AudioMultiVector* output,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000047 int16_t* length_change_samples);
48
49 protected:
50 // Sets the parameters |best_correlation| and |peak_index| to suitable
51 // values when the signal contains no active speech.
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000052 virtual void SetParametersForPassiveSpeech(size_t len,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000053 int16_t* best_correlation,
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000054 int* 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.
58 virtual ReturnCodes CheckCriteriaAndStretch(
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000059 const int16_t* input, size_t input_length, size_t peak_index,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000060 int16_t best_correlation, bool active_speech,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000061 AudioMultiVector* output) const OVERRIDE;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000062
63 private:
64 DISALLOW_COPY_AND_ASSIGN(Accelerate);
65};
66
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000067struct AccelerateFactory {
68 AccelerateFactory() {}
69 virtual ~AccelerateFactory() {}
70
71 virtual Accelerate* Create(int sample_rate_hz,
72 size_t num_channels,
73 const BackgroundNoise& background_noise) const;
74};
75
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000076} // namespace webrtc
77#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_ACCELERATE_H_