blob: 1aa613301451cda2eb7ac7f727032dcae943792a [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_PREEMPTIVE_EXPAND_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_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 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:
turaj@webrtc.org8d1cdaa2014-04-11 18:47:55 +000032 PreemptiveExpand(int sample_rate_hz,
33 size_t num_channels,
34 const BackgroundNoise& background_noise,
35 int overlap_samples)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000036 : TimeStretch(sample_rate_hz, num_channels, background_noise),
37 old_data_length_per_channel_(-1),
turaj@webrtc.org8d1cdaa2014-04-11 18:47:55 +000038 overlap_samples_(overlap_samples) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000039 }
40
41 virtual ~PreemptiveExpand() {}
42
43 // This method performs the actual PreemptiveExpand operation. The samples are
44 // read from |input|, of length |input_length| elements, and are written to
45 // |output|. The number of samples added through time-stretching is
46 // is provided in the output |length_change_samples|. The method returns
47 // the outcome of the operation as an enumerator value.
pbos@webrtc.org0946a562013-04-09 00:28:06 +000048 ReturnCodes Process(const int16_t *pw16_decoded,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000049 int len,
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000050 int old_data_len,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000051 AudioMultiVector* output,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000052 int16_t* length_change_samples);
53
54 protected:
55 // Sets the parameters |best_correlation| and |peak_index| to suitable
56 // values when the signal contains no active speech.
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000057 virtual void SetParametersForPassiveSpeech(size_t len,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000058 int16_t* w16_bestCorr,
59 int* w16_bestIndex) const;
60
61 // Checks the criteria for performing the time-stretching operation and,
62 // if possible, performs the time-stretching.
63 virtual ReturnCodes CheckCriteriaAndStretch(
turaj@webrtc.org362a55e2013-09-20 16:25:28 +000064 const int16_t *pw16_decoded, size_t len, size_t w16_bestIndex,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000065 int16_t w16_bestCorr, bool w16_VAD,
henrik.lundin@webrtc.orgfd11bbf2013-09-30 20:38:44 +000066 AudioMultiVector* output) const;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000067
68 private:
69 int old_data_length_per_channel_;
70 int overlap_samples_;
71
72 DISALLOW_COPY_AND_ASSIGN(PreemptiveExpand);
73};
74
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000075struct PreemptiveExpandFactory {
76 PreemptiveExpandFactory() {}
77 virtual ~PreemptiveExpandFactory() {}
78
79 virtual PreemptiveExpand* Create(
80 int sample_rate_hz,
81 size_t num_channels,
turaj@webrtc.org8d1cdaa2014-04-11 18:47:55 +000082 const BackgroundNoise& background_noise,
83 int overlap_samples) const;
henrik.lundin@webrtc.orgd9faa462014-01-14 10:18:45 +000084};
85
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000086} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000087#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PREEMPTIVE_EXPAND_H_