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

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: Rename InputAudioFile::Move to InputAudioFile::Seek 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/base/safe_conversions.h"
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 20 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
20 #include "webrtc/modules/audio_coding/neteq/background_noise.h" 21 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
21 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h" 22 #include "webrtc/modules/audio_coding/neteq/dsp_helper.h"
22 #include "webrtc/modules/audio_coding/neteq/random_vector.h" 23 #include "webrtc/modules/audio_coding/neteq/random_vector.h"
24 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
23 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 25 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
24 26
25 namespace webrtc { 27 namespace webrtc {
26 28
27 Expand::Expand(BackgroundNoise* background_noise, 29 Expand::Expand(BackgroundNoise* background_noise,
28 SyncBuffer* sync_buffer, 30 SyncBuffer* sync_buffer,
29 RandomVector* random_vector, 31 RandomVector* random_vector,
32 StatisticsCalculator* statistics,
30 int fs, 33 int fs,
31 size_t num_channels) 34 size_t num_channels)
32 : random_vector_(random_vector), 35 : random_vector_(random_vector),
33 sync_buffer_(sync_buffer), 36 sync_buffer_(sync_buffer),
34 first_expand_(true), 37 first_expand_(true),
35 fs_hz_(fs), 38 fs_hz_(fs),
36 num_channels_(num_channels), 39 num_channels_(num_channels),
37 consecutive_expands_(0), 40 consecutive_expands_(0),
38 background_noise_(background_noise), 41 background_noise_(background_noise),
42 statistics_(statistics),
39 overlap_length_(5 * fs / 8000), 43 overlap_length_(5 * fs / 8000),
40 lag_index_direction_(0), 44 lag_index_direction_(0),
41 current_lag_index_(0), 45 current_lag_index_(0),
42 stop_muting_(false), 46 stop_muting_(false),
47 expand_duration_samples_(0),
43 channel_parameters_(new ChannelParameters[num_channels_]) { 48 channel_parameters_(new ChannelParameters[num_channels_]) {
44 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000); 49 assert(fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000);
45 assert(fs <= kMaxSampleRate); // Should not be possible. 50 assert(fs <= kMaxSampleRate); // Should not be possible.
46 assert(num_channels_ > 0); 51 assert(num_channels_ > 0);
47 memset(expand_lags_, 0, sizeof(expand_lags_)); 52 memset(expand_lags_, 0, sizeof(expand_lags_));
48 Reset(); 53 Reset();
49 } 54 }
50 55
51 Expand::~Expand() = default; 56 Expand::~Expand() = default;
52 57
(...skipping 18 matching lines...) Expand all
71 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125]; 76 int16_t unvoiced_array_memory[kNoiseLpcOrder + kMaxSampleRate / 8000 * 125];
72 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder; 77 int16_t* unvoiced_vector = unvoiced_array_memory + kUnvoicedLpcOrder;
73 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder; 78 int16_t* noise_vector = unvoiced_array_memory + kNoiseLpcOrder;
74 79
75 int fs_mult = fs_hz_ / 8000; 80 int fs_mult = fs_hz_ / 8000;
76 81
77 if (first_expand_) { 82 if (first_expand_) {
78 // Perform initial setup if this is the first expansion since last reset. 83 // Perform initial setup if this is the first expansion since last reset.
79 AnalyzeSignal(random_vector); 84 AnalyzeSignal(random_vector);
80 first_expand_ = false; 85 first_expand_ = false;
86 expand_duration_samples_ = 0;
81 } else { 87 } else {
82 // This is not the first expansion, parameters are already estimated. 88 // This is not the first expansion, parameters are already estimated.
83 // Extract a noise segment. 89 // Extract a noise segment.
84 int16_t rand_length = max_lag_; 90 int16_t rand_length = max_lag_;
85 // This only applies to SWB where length could be larger than 256. 91 // This only applies to SWB where length could be larger than 256.
86 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30); 92 assert(rand_length <= kMaxSampleRate / 8000 * 120 + 30);
87 GenerateRandomVector(2, rand_length, random_vector); 93 GenerateRandomVector(2, rand_length, random_vector);
88 } 94 }
89 95
90 96
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } else { 297 } else {
292 assert(output->Size() == current_lag); 298 assert(output->Size() == current_lag);
293 } 299 }
294 memcpy(&(*output)[channel_ix][0], temp_data, 300 memcpy(&(*output)[channel_ix][0], temp_data,
295 sizeof(temp_data[0]) * current_lag); 301 sizeof(temp_data[0]) * current_lag);
296 } 302 }
297 303
298 // Increase call number and cap it. 304 // Increase call number and cap it.
299 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ? 305 consecutive_expands_ = consecutive_expands_ >= kMaxConsecutiveExpands ?
300 kMaxConsecutiveExpands : consecutive_expands_ + 1; 306 kMaxConsecutiveExpands : consecutive_expands_ + 1;
307 expand_duration_samples_ += output->Size();
308 // Clamp the duration counter at 2 seconds.
309 expand_duration_samples_ =
310 std::min(expand_duration_samples_, rtc::checked_cast<size_t>(fs_hz_ * 2));
301 return 0; 311 return 0;
302 } 312 }
303 313
304 void Expand::SetParametersForNormalAfterExpand() { 314 void Expand::SetParametersForNormalAfterExpand() {
305 current_lag_index_ = 0; 315 current_lag_index_ = 0;
306 lag_index_direction_ = 0; 316 lag_index_direction_ = 0;
307 stop_muting_ = true; // Do not mute signal any more. 317 stop_muting_ = true; // Do not mute signal any more.
318 statistics_->LogDelayedPacketOutageEvent(
319 rtc::checked_cast<int>(expand_duration_samples_) / (fs_hz_ / 1000));
308 } 320 }
309 321
310 void Expand::SetParametersForMergeAfterExpand() { 322 void Expand::SetParametersForMergeAfterExpand() {
311 current_lag_index_ = -1; /* out of the 3 possible ones */ 323 current_lag_index_ = -1; /* out of the 3 possible ones */
312 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */ 324 lag_index_direction_ = 1; /* make sure we get the "optimal" lag */
313 stop_muting_ = true; 325 stop_muting_ = true;
314 } 326 }
315 327
316 size_t Expand::overlap_length() const { 328 size_t Expand::overlap_length() const {
317 return overlap_length_; 329 return overlap_length_;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 lag_index_direction_ = 1; 838 lag_index_direction_ = 1;
827 } 839 }
828 if (current_lag_index_ >= kNumLags - 1) { 840 if (current_lag_index_ >= kNumLags - 1) {
829 lag_index_direction_ = -1; 841 lag_index_direction_ = -1;
830 } 842 }
831 } 843 }
832 844
833 Expand* ExpandFactory::Create(BackgroundNoise* background_noise, 845 Expand* ExpandFactory::Create(BackgroundNoise* background_noise,
834 SyncBuffer* sync_buffer, 846 SyncBuffer* sync_buffer,
835 RandomVector* random_vector, 847 RandomVector* random_vector,
848 StatisticsCalculator* statistics,
836 int fs, 849 int fs,
837 size_t num_channels) const { 850 size_t num_channels) const {
838 return new Expand(background_noise, sync_buffer, random_vector, fs, 851 return new Expand(background_noise, sync_buffer, random_vector, statistics,
839 num_channels); 852 fs, num_channels);
840 } 853 }
841 854
842 // TODO(turajs): This can be moved to BackgroundNoise class. 855 // TODO(turajs): This can be moved to BackgroundNoise class.
843 void Expand::GenerateBackgroundNoise(int16_t* random_vector, 856 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
844 size_t channel, 857 size_t channel,
845 int mute_slope, 858 int mute_slope,
846 bool too_many_expands, 859 bool too_many_expands,
847 size_t num_noise_samples, 860 size_t num_noise_samples,
848 int16_t* buffer) { 861 int16_t* buffer) {
849 static const int kNoiseLpcOrder = BackgroundNoise::kMaxLpcOrder; 862 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; 951 const size_t kMaxRandSamples = RandomVector::kRandomTableSize;
939 while (samples_generated < length) { 952 while (samples_generated < length) {
940 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples); 953 size_t rand_length = std::min(length - samples_generated, kMaxRandSamples);
941 random_vector_->IncreaseSeedIncrement(seed_increment); 954 random_vector_->IncreaseSeedIncrement(seed_increment);
942 random_vector_->Generate(rand_length, &random_vector[samples_generated]); 955 random_vector_->Generate(rand_length, &random_vector[samples_generated]);
943 samples_generated += rand_length; 956 samples_generated += rand_length;
944 } 957 }
945 } 958 }
946 959
947 } // namespace webrtc 960 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/expand.h ('k') | webrtc/modules/audio_coding/neteq/expand_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698