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

Side by Side Diff: webrtc/modules/audio_coding/neteq/time_stretch.h

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments 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
(...skipping 21 matching lines...) Expand all
32 kSuccess = 0, 32 kSuccess = 0,
33 kSuccessLowEnergy = 1, 33 kSuccessLowEnergy = 1,
34 kNoStretch = 2, 34 kNoStretch = 2,
35 kError = -1 35 kError = -1
36 }; 36 };
37 37
38 TimeStretch(int sample_rate_hz, size_t num_channels, 38 TimeStretch(int sample_rate_hz, size_t num_channels,
39 const BackgroundNoise& background_noise) 39 const BackgroundNoise& background_noise)
40 : sample_rate_hz_(sample_rate_hz), 40 : sample_rate_hz_(sample_rate_hz),
41 fs_mult_(sample_rate_hz / 8000), 41 fs_mult_(sample_rate_hz / 8000),
42 num_channels_(static_cast<int>(num_channels)), 42 num_channels_(num_channels),
43 master_channel_(0), // First channel is master. 43 master_channel_(0), // First channel is master.
44 background_noise_(background_noise), 44 background_noise_(background_noise),
45 max_input_value_(0) { 45 max_input_value_(0) {
46 assert(sample_rate_hz_ == 8000 || 46 assert(sample_rate_hz_ == 8000 ||
47 sample_rate_hz_ == 16000 || 47 sample_rate_hz_ == 16000 ||
48 sample_rate_hz_ == 32000 || 48 sample_rate_hz_ == 32000 ||
49 sample_rate_hz_ == 48000); 49 sample_rate_hz_ == 48000);
50 assert(num_channels_ > 0); 50 assert(num_channels_ > 0);
51 assert(static_cast<int>(master_channel_) < num_channels_); 51 assert(master_channel_ < num_channels_);
52 memset(auto_correlation_, 0, sizeof(auto_correlation_)); 52 memset(auto_correlation_, 0, sizeof(auto_correlation_));
53 } 53 }
54 54
55 virtual ~TimeStretch() {} 55 virtual ~TimeStretch() {}
56 56
57 // This method performs the processing common to both Accelerate and 57 // This method performs the processing common to both Accelerate and
58 // PreemptiveExpand. 58 // PreemptiveExpand.
59 ReturnCodes Process(const int16_t* input, 59 ReturnCodes Process(const int16_t* input,
60 size_t input_len, 60 size_t input_len,
61 bool fast_mode, 61 bool fast_mode,
62 AudioMultiVector* output, 62 AudioMultiVector* output,
63 int16_t* length_change_samples); 63 size_t* length_change_samples);
64 64
65 protected: 65 protected:
66 // Sets the parameters |best_correlation| and |peak_index| to suitable 66 // Sets the parameters |best_correlation| and |peak_index| to suitable
67 // values when the signal contains no active speech. This method must be 67 // values when the signal contains no active speech. This method must be
68 // implemented by the sub-classes. 68 // implemented by the sub-classes.
69 virtual void SetParametersForPassiveSpeech(size_t input_length, 69 virtual void SetParametersForPassiveSpeech(size_t input_length,
70 int16_t* best_correlation, 70 int16_t* best_correlation,
71 int* peak_index) const = 0; 71 size_t* peak_index) const = 0;
72 72
73 // Checks the criteria for performing the time-stretching operation and, 73 // Checks the criteria for performing the time-stretching operation and,
74 // if possible, performs the time-stretching. This method must be implemented 74 // if possible, performs the time-stretching. This method must be implemented
75 // by the sub-classes. 75 // by the sub-classes.
76 virtual ReturnCodes CheckCriteriaAndStretch( 76 virtual ReturnCodes CheckCriteriaAndStretch(
77 const int16_t* input, 77 const int16_t* input,
78 size_t input_length, 78 size_t input_length,
79 size_t peak_index, 79 size_t peak_index,
80 int16_t best_correlation, 80 int16_t best_correlation,
81 bool active_speech, 81 bool active_speech,
82 bool fast_mode, 82 bool fast_mode,
83 AudioMultiVector* output) const = 0; 83 AudioMultiVector* output) const = 0;
84 84
85 static const int kCorrelationLen = 50; 85 static const size_t kCorrelationLen = 50;
86 static const int kLogCorrelationLen = 6; // >= log2(kCorrelationLen). 86 static const size_t kLogCorrelationLen = 6; // >= log2(kCorrelationLen).
87 static const int kMinLag = 10; 87 static const size_t kMinLag = 10;
88 static const int kMaxLag = 60; 88 static const size_t kMaxLag = 60;
89 static const int kDownsampledLen = kCorrelationLen + kMaxLag; 89 static const size_t kDownsampledLen = kCorrelationLen + kMaxLag;
90 static const int kCorrelationThreshold = 14746; // 0.9 in Q14. 90 static const int kCorrelationThreshold = 14746; // 0.9 in Q14.
91 91
92 const int sample_rate_hz_; 92 const int sample_rate_hz_;
93 const int fs_mult_; // Sample rate multiplier = sample_rate_hz_ / 8000. 93 const int fs_mult_; // Sample rate multiplier = sample_rate_hz_ / 8000.
94 const int num_channels_; 94 const size_t num_channels_;
95 const size_t master_channel_; 95 const size_t master_channel_;
96 const BackgroundNoise& background_noise_; 96 const BackgroundNoise& background_noise_;
97 int16_t max_input_value_; 97 int16_t max_input_value_;
98 int16_t downsampled_input_[kDownsampledLen]; 98 int16_t downsampled_input_[kDownsampledLen];
99 // Adding 1 to the size of |auto_correlation_| because of how it is used 99 // Adding 1 to the size of |auto_correlation_| because of how it is used
100 // by the peak-detection algorithm. 100 // by the peak-detection algorithm.
101 int16_t auto_correlation_[kCorrelationLen + 1]; 101 int16_t auto_correlation_[kCorrelationLen + 1];
102 102
103 private: 103 private:
104 // Calculates the auto-correlation of |downsampled_input_| and writes the 104 // Calculates the auto-correlation of |downsampled_input_| and writes the
105 // result to |auto_correlation_|. 105 // result to |auto_correlation_|.
106 void AutoCorrelation(); 106 void AutoCorrelation();
107 107
108 // Performs a simple voice-activity detection based on the input parameters. 108 // Performs a simple voice-activity detection based on the input parameters.
109 bool SpeechDetection(int32_t vec1_energy, int32_t vec2_energy, 109 bool SpeechDetection(int32_t vec1_energy, int32_t vec2_energy,
110 int peak_index, int scaling) const; 110 size_t peak_index, int scaling) const;
111 111
112 DISALLOW_COPY_AND_ASSIGN(TimeStretch); 112 DISALLOW_COPY_AND_ASSIGN(TimeStretch);
113 }; 113 };
114 114
115 } // namespace webrtc 115 } // namespace webrtc
116 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TIME_STRETCH_H_ 116 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TIME_STRETCH_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/test/neteq_pcmu_quality_test.cc ('k') | webrtc/modules/audio_coding/neteq/time_stretch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698