blob: 4cd92cc0bb6a96fc5612639266903bbe755d8492 [file] [log] [blame]
henrik.lundin@webrtc.org9a400812013-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_PREEMPTIVE_EXPAND_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_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"
18#include "webrtc/system_wrappers/interface/constructor_magic.h"
19#include "webrtc/typedefs.h"
20
21namespace webrtc {
22
23// Forward declarations.
24class BackgroundNoise;
25
26// This class implements the PreemptiveExpand operation. Most of the work is
27// done in the base class TimeStretch, which is shared with the Accelerate
28// operation. In the PreemptiveExpand class, the operations that are specific to
29// PreemptiveExpand are implemented.
30class PreemptiveExpand : public TimeStretch {
31 public:
32 PreemptiveExpand(int sample_rate_hz, size_t num_channels,
33 const BackgroundNoise& background_noise)
34 : TimeStretch(sample_rate_hz, num_channels, background_noise),
35 old_data_length_per_channel_(-1),
36 overlap_samples_(5 * sample_rate_hz / 8000) {
37 }
38
39 virtual ~PreemptiveExpand() {}
40
41 // This method performs the actual PreemptiveExpand operation. The samples are
42 // 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
45 // the outcome of the operation as an enumerator value.
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06 +000046 ReturnCodes Process(const int16_t *pw16_decoded,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000047 int len,
turaj@webrtc.org045e45e2013-09-20 16:25:28 +000048 int old_data_len,
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000049 AudioMultiVector* output,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000050 int16_t* length_change_samples);
51
52 protected:
53 // Sets the parameters |best_correlation| and |peak_index| to suitable
54 // values when the signal contains no active speech.
turaj@webrtc.org045e45e2013-09-20 16:25:28 +000055 virtual void SetParametersForPassiveSpeech(size_t len,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000056 int16_t* w16_bestCorr,
57 int* w16_bestIndex) const;
58
59 // Checks the criteria for performing the time-stretching operation and,
60 // if possible, performs the time-stretching.
61 virtual ReturnCodes CheckCriteriaAndStretch(
turaj@webrtc.org045e45e2013-09-20 16:25:28 +000062 const int16_t *pw16_decoded, size_t len, size_t w16_bestIndex,
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000063 int16_t w16_bestCorr, bool w16_VAD,
henrik.lundin@webrtc.org0e9c3992013-09-30 20:38:44 +000064 AudioMultiVector* output) const;
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +000065
66 private:
67 int old_data_length_per_channel_;
68 int overlap_samples_;
69
70 DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
71};
72
73} // namespace webrtc
74#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PREEMPTIVE_EXPAND_H_