Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: webrtc/modules/audio_coding/neteq/expand.cc

Issue 1290113002: NetEq: Implement logging of Delayed Packet Outage Events (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing windows build Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/expand.h" 11 #include "webrtc/modules/audio_coding/neteq/expand.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> // memset 14 #include <string.h> // memset
15 15
16 #include <algorithm> // min, max 16 #include <algorithm> // min, max
17 #include <limits> // numeric_limits<T> 17 #include <limits> // numeric_limits<T>
18 18
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
20 #include "webrtc/modules/audio_coding/neteq/background_noise.h" 20 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
21 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" 21 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h"
22 #include "webrtc/modules/audio_coding/neteq/random_vector.h" 22 #include "webrtc/modules/audio_coding/neteq/random_vector.h"
23 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
23 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 24 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
24 25
25 namespace webrtc { 26 namespace webrtc {
26 27
27 Expand::Expand(BackgroundNoise* background_noise, 28 Expand::Expand(BackgroundNoise* background_noise,
28 SyncBuffer* sync_buffer, 29 SyncBuffer* sync_buffer,
29 RandomVector* random_vector, 30 RandomVector* random_vector,
31 StatisticsCalculator* statistics,
30 int fs, 32 int fs,
31 size_t num_channels) 33 size_t num_channels)
32 : random_vector_(random_vector), 34 : random_vector_(random_vector),
33 sync_buffer_(sync_buffer), 35 sync_buffer_(sync_buffer),
34 first_expand_(true), 36 first_expand_(true),
35 fs_hz_(fs), 37 fs_hz_(fs),
36 num_channels_(num_channels), 38 num_channels_(num_channels),
37 consecutive_expands_(0), 39 consecutive_expands_(0),
38 background_noise_(background_noise), 40 background_noise_(background_noise),
41 statistics_(statistics),
39 overlap_length_(5 * fs / 8000), 42 overlap_length_(5 * fs / 8000),
40 lag_index_direction_(0), 43 lag_index_direction_(0),
41 current_lag_index_(0), 44 current_lag_index_(0),
42 stop_muting_(false), 45 stop_muting_(false),
43 channel_parameters_(new ChannelParameters[num_channels_]) { 46 channel_parameters_(new ChannelParameters[num_channels_]) {
44 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000); 47 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000);
45 assert(fs <= kMaxSampleRate); // Should not be possible. 48 assert(fs <= kMaxSampleRate); // Should not be possible.
46 assert(num_channels_ > 0); 49 assert(num_channels_ > 0);
47 memset(expand_lags_, 0, sizeof(expand_lags_)); 50 memset(expand_lags_, 0, sizeof(expand_lags_));
48 Reset(); 51 Reset();
(...skipping 22 matching lines...) Expand all
71 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125]; 74 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125];
72 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder; 75 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder;
73 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder; 76 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder;
74 77
75 int fs_mult = fs_hz_ / 8000; 78 int fs_mult = fs_hz_ / 8000;
76 79
77 if (first_expand_) { 80 if (first_expand_) {
78 // Perform initial setup if this is the first expansion since last reset. 81 // Perform initial setup if this is the first expansion since last reset.
79 AnalyzeSignal(random_vector); 82 AnalyzeSignal(random_vector);
80 first_expand_ = false; 83 first_expand_ = false;
84 expand_duration_samples_ = 0;
81 } else { 85 } else {
82 // This is not the first expansion, parameters are already estimated. 86 // This is not the first expansion, parameters are already estimated.
83 // Extract a noise segment. 87 // Extract a noise segment.
84 int16_t rand_length = max_lag_; 88 int16_t rand_length = max_lag_;
85 // This only applies to SWB where length could be larger than 256. 89 // This only applies to SWB where length could be larger than 256.
86 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30); 90 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30);
87 GenerateRandomVector(2, rand_length, random_vector); 91 GenerateRandomVector(2, rand_length, random_vector);
88 } 92 }
89 93
90 94
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } else { 295 } else {
292 assert(output->Size() == current_lag); 296 assert(output->Size() == current_lag);
293 } 297 }
294 memcpy(&(*output)[channel_ix][0], temp_data, 298 memcpy(&(*output)[channel_ix][0], temp_data,
295 sizeof(temp_data[0]) * current_lag); 299 sizeof(temp_data[0]) * current_lag);
296 } 300 }
297 301
298 // Increase call number and cap it. 302 // Increase call number and cap it.
299 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ? 303 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ?
300 kMaxConsecutiveExpands : consecutive_expands_ + 1; 304 kMaxConsecutiveExpands : consecutive_expands_ + 1;
305 expand_duration_samples_ += output->Size();
306 // Clamp the duration counter at 2 seconds.
307 expand_duration_samples_ = std::min(expand_duration_samples_, fs_hz_ * 2);
301 return 0; 308 return 0;
302 } 309 }
303 310
304 void Expand::SetParametersForNormalAfterExpand() { 311 void Expand::SetParametersForNormalAfterExpand() {
305 current_lag_index_ = 0; 312 current_lag_index_ = 0;
306 lag_index_direction_ = 0; 313 lag_index_direction_ = 0;
307 stop_muting_ = true; // Do not mute signal any more. 314 stop_muting_ = true; // Do not mute signal any more.
315 statistics_->LogDelayedPacketOutageEvent(expand_duration_samples_ /
316 (fs_hz_ / 1000));
308 } 317 }
309 318
310 void Expand::SetParametersForMergeAfterExpand() { 319 void Expand::SetParametersForMergeAfterExpand() {
311 current_lag_index_ = -1; /* out of the 3 possible ones */ 320 current_lag_index_ = -1; /* out of the 3 possible ones */
312 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */ 321 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */
313 stop_muting_ = true; 322 stop_muting_ = true;
314 } 323 }
315 324
316 size_t Expand::overlap_length() const { 325 size_t Expand::overlap_length() const {
317 return overlap_length_; 326 return overlap_length_;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 lag_index_direction_ = 1; 835 lag_index_direction_ = 1;
827 } 836 }
828 if (current_lag_index_ >= kNumLags - 1) { 837 if (current_lag_index_ >= kNumLags - 1) {
829 lag_index_direction_ = -1; 838 lag_index_direction_ = -1;
830 } 839 }
831 } 840 }
832 841
833 Expand* ExpandFactory::Create(BackgroundNoise* background_noise, 842 Expand* ExpandFactory::Create(BackgroundNoise* background_noise,
834 SyncBuffer* sync_buffer, 843 SyncBuffer* sync_buffer,
835 RandomVector* random_vector, 844 RandomVector* random_vector,
845 StatisticsCalculator* statistics,
836 int fs, 846 int fs,
837 size_t num_channels) const { 847 size_t num_channels) const {
838 return new Expand(background_noise, sync_buffer, random_vector, fs, 848 return new Expand(background_noise, sync_buffer, random_vector, statistics,
839 num_channels); 849 fs, num_channels);
840 } 850 }
841 851
842 // TODO(turajs): This can be moved to BackgroundNoise class. 852 // TODO(turajs): This can be moved to BackgroundNoise class.
843 void Expand::GenerateBackgroundNoise(int16_t* random_vector, 853 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
844 size_t channel, 854 size_t channel,
845 int mute_slope, 855 int mute_slope,
846 bool too_many_expands, 856 bool too_many_expands,
847 size_t num_noise_samples, 857 size_t num_noise_samples,
848 int16_t* buffer) { 858 int16_t* buffer) {
849 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 859 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 const size_t kMaxRandSamples = RandomVector::kRandomTableSize; 948 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
939 while (samples_generated < length) { 949 while (samples_generated < length) {
940 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 950 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
941 random_vector_->IncreaseSeedIncrement(seed_increment); 951 random_vector_->IncreaseSeedIncrement(seed_increment);
942 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 952 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
943 samples_generated += rand_length; 953 samples_generated += rand_length;
944 } 954 }
945 } 955 }
946 956
947 } // namespace webrtc 957 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698