OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" | 11 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" |
12 | 12 |
13 #include <algorithm> // min, max | 13 #include <algorithm> // min, max |
14 | 14 |
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 PreemptiveExpand::ReturnCodes PreemptiveExpand::Process( | 19 PreemptiveExpand::ReturnCodes PreemptiveExpand::Process( |
20 const int16_t* input, | 20 const int16_t* input, |
21 int input_length, | 21 size_t input_length, |
22 int old_data_length, | 22 size_t old_data_length, |
23 AudioMultiVector* output, | 23 AudioMultiVector* output, |
24 int16_t* length_change_samples) { | 24 size_t* length_change_samples) { |
25 old_data_length_per_channel_ = old_data_length; | 25 old_data_length_per_channel_ = old_data_length; |
26 // Input length must be (almost) 30 ms. | 26 // Input length must be (almost) 30 ms. |
27 // Also, the new part must be at least |overlap_samples_| elements. | 27 // Also, the new part must be at least |overlap_samples_| elements. |
28 static const int k15ms = 120; // 15 ms = 120 samples at 8 kHz sample rate. | 28 static const int k15ms = 120; // 15 ms = 120 samples at 8 kHz sample rate. |
29 if (num_channels_ == 0 || | 29 if (num_channels_ == 0 || |
30 input_length / num_channels_ < (2 * k15ms - 1) * fs_mult_ || | 30 input_length / num_channels_ < (2 * k15ms - 1) * fs_mult_ || |
31 old_data_length >= input_length / num_channels_ - overlap_samples_) { | 31 old_data_length >= input_length / num_channels_ - overlap_samples_) { |
32 // Length of input data too short to do preemptive expand. Simply move all | 32 // Length of input data too short to do preemptive expand. Simply move all |
33 // data from input to output. | 33 // data from input to output. |
34 output->PushBackInterleaved(input, input_length); | 34 output->PushBackInterleaved(input, input_length); |
35 return kError; | 35 return kError; |
36 } | 36 } |
37 const bool kFastMode = false; // Fast mode is not available for PE Expand. | 37 const bool kFastMode = false; // Fast mode is not available for PE Expand. |
38 return TimeStretch::Process(input, input_length, kFastMode, output, | 38 return TimeStretch::Process(input, input_length, kFastMode, output, |
39 length_change_samples); | 39 length_change_samples); |
40 } | 40 } |
41 | 41 |
42 void PreemptiveExpand::SetParametersForPassiveSpeech(size_t len, | 42 void PreemptiveExpand::SetParametersForPassiveSpeech(size_t len, |
43 int16_t* best_correlation, | 43 int16_t* best_correlation, |
44 int* peak_index) const { | 44 size_t* peak_index) const { |
45 // When the signal does not contain any active speech, the correlation does | 45 // When the signal does not contain any active speech, the correlation does |
46 // not matter. Simply set it to zero. | 46 // not matter. Simply set it to zero. |
47 *best_correlation = 0; | 47 *best_correlation = 0; |
48 | 48 |
49 // For low energy expansion, the new data can be less than 15 ms, | 49 // For low energy expansion, the new data can be less than 15 ms, |
50 // but we must ensure that best_correlation is not larger than the length of | 50 // but we must ensure that best_correlation is not larger than the length of |
51 // the new data. | 51 // the new data. |
52 // but we must ensure that best_correlation is not larger than the new data. | 52 // but we must ensure that best_correlation is not larger than the new data. |
53 *peak_index = std::min(*peak_index, | 53 *peak_index = std::min(*peak_index, |
54 static_cast<int>(len - old_data_length_per_channel_)); | 54 len - old_data_length_per_channel_); |
55 } | 55 } |
56 | 56 |
57 PreemptiveExpand::ReturnCodes PreemptiveExpand::CheckCriteriaAndStretch( | 57 PreemptiveExpand::ReturnCodes PreemptiveExpand::CheckCriteriaAndStretch( |
58 const int16_t* input, | 58 const int16_t* input, |
59 size_t input_length, | 59 size_t input_length, |
60 size_t peak_index, | 60 size_t peak_index, |
61 int16_t best_correlation, | 61 int16_t best_correlation, |
62 bool active_speech, | 62 bool active_speech, |
63 bool /*fast_mode*/, | 63 bool /*fast_mode*/, |
64 AudioMultiVector* output) const { | 64 AudioMultiVector* output) const { |
65 // Pre-calculate common multiplication with |fs_mult_|. | 65 // Pre-calculate common multiplication with |fs_mult_|. |
66 // 120 corresponds to 15 ms. | 66 // 120 corresponds to 15 ms. |
67 int fs_mult_120 = fs_mult_ * 120; | 67 size_t fs_mult_120 = fs_mult_ * 120; |
hlundin-webrtc
2015/08/10 11:30:01
Keep the int.
Peter Kasting
2015/08/17 22:49:47
This is an example of a place where I left |fs_mul
hlundin-webrtc
2015/08/18 07:19:18
Acknowledged.
| |
68 assert(old_data_length_per_channel_ >= 0); // Make sure it's been set. | |
69 // Check for strong correlation (>0.9 in Q14) and at least 15 ms new data, | 68 // Check for strong correlation (>0.9 in Q14) and at least 15 ms new data, |
70 // or passive speech. | 69 // or passive speech. |
71 if (((best_correlation > kCorrelationThreshold) && | 70 if (((best_correlation > kCorrelationThreshold) && |
72 (old_data_length_per_channel_ <= fs_mult_120)) || | 71 (old_data_length_per_channel_ <= fs_mult_120)) || |
73 !active_speech) { | 72 !active_speech) { |
74 // Do accelerate operation by overlap add. | 73 // Do accelerate operation by overlap add. |
75 | 74 |
76 // Set length of the first part, not to be modified. | 75 // Set length of the first part, not to be modified. |
77 size_t unmodified_length = std::max(old_data_length_per_channel_, | 76 size_t unmodified_length = std::max(old_data_length_per_channel_, |
78 fs_mult_120); | 77 fs_mult_120); |
(...skipping 21 matching lines...) Expand all Loading... | |
100 // Accelerate not allowed. Simply move all data from decoded to outData. | 99 // Accelerate not allowed. Simply move all data from decoded to outData. |
101 output->PushBackInterleaved(input, input_length); | 100 output->PushBackInterleaved(input, input_length); |
102 return kNoStretch; | 101 return kNoStretch; |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
106 PreemptiveExpand* PreemptiveExpandFactory::Create( | 105 PreemptiveExpand* PreemptiveExpandFactory::Create( |
107 int sample_rate_hz, | 106 int sample_rate_hz, |
108 size_t num_channels, | 107 size_t num_channels, |
109 const BackgroundNoise& background_noise, | 108 const BackgroundNoise& background_noise, |
110 int overlap_samples) const { | 109 size_t overlap_samples) const { |
111 return new PreemptiveExpand( | 110 return new PreemptiveExpand( |
112 sample_rate_hz, num_channels, background_noise, overlap_samples); | 111 sample_rate_hz, num_channels, background_noise, overlap_samples); |
113 } | 112 } |
114 | 113 |
115 } // namespace webrtc | 114 } // namespace webrtc |
OLD | NEW |