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

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

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 3 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 initialized_ = true; 142 initialized_ = true;
143 return 0; 143 return 0;
144 } 144 }
145 145
146 // Reset tone generator to uninitialized state. 146 // Reset tone generator to uninitialized state.
147 void DtmfToneGenerator::Reset() { 147 void DtmfToneGenerator::Reset() {
148 initialized_ = false; 148 initialized_ = false;
149 } 149 }
150 150
151 // Generate num_samples of DTMF signal and write to |output|. 151 // Generate num_samples of DTMF signal and write to |output|.
152 int DtmfToneGenerator::Generate(int num_samples, 152 int DtmfToneGenerator::Generate(size_t num_samples,
153 AudioMultiVector* output) { 153 AudioMultiVector* output) {
154 if (!initialized_) { 154 if (!initialized_) {
155 return kNotInitialized; 155 return kNotInitialized;
156 } 156 }
157 157
158 if (num_samples < 0 || !output) { 158 if (!output) {
159 return kParameterError; 159 return kParameterError;
160 } 160 }
161 161
162 output->AssertSize(num_samples); 162 output->AssertSize(num_samples);
163 for (int i = 0; i < num_samples; ++i) { 163 for (size_t i = 0; i < num_samples; ++i) {
164 // Use recursion formula y[n] = a * y[n - 1] - y[n - 2]. 164 // Use recursion formula y[n] = a * y[n - 1] - y[n - 2].
165 int16_t temp_val_low = ((coeff1_ * sample_history1_[1] + 8192) >> 14) 165 int16_t temp_val_low = ((coeff1_ * sample_history1_[1] + 8192) >> 14)
166 - sample_history1_[0]; 166 - sample_history1_[0];
167 int16_t temp_val_high = ((coeff2_ * sample_history2_[1] + 8192) >> 14) 167 int16_t temp_val_high = ((coeff2_ * sample_history2_[1] + 8192) >> 14)
168 - sample_history2_[0]; 168 - sample_history2_[0];
169 169
170 // Update recursion memory. 170 // Update recursion memory.
171 sample_history1_[0] = sample_history1_[1]; 171 sample_history1_[0] = sample_history1_[1];
172 sample_history1_[1] = temp_val_low; 172 sample_history1_[1] = temp_val_low;
173 sample_history2_[0] = sample_history2_[1]; 173 sample_history2_[0] = sample_history2_[1];
174 sample_history2_[1] = temp_val_high; 174 sample_history2_[1] = temp_val_high;
175 175
176 // Attenuate the low frequency tone 3 dB. 176 // Attenuate the low frequency tone 3 dB.
177 int32_t temp_val = kAmpMultiplier * temp_val_low + (temp_val_high << 15); 177 int32_t temp_val = kAmpMultiplier * temp_val_low + (temp_val_high << 15);
178 // Normalize the signal to Q14 with proper rounding. 178 // Normalize the signal to Q14 with proper rounding.
179 temp_val = (temp_val + 16384) >> 15; 179 temp_val = (temp_val + 16384) >> 15;
180 // Scale the signal to correct volume. 180 // Scale the signal to correct volume.
181 (*output)[0][i] = 181 (*output)[0][i] =
182 static_cast<int16_t>((temp_val * amplitude_ + 8192) >> 14); 182 static_cast<int16_t>((temp_val * amplitude_ + 8192) >> 14);
183 } 183 }
184 // Copy first channel to all other channels. 184 // Copy first channel to all other channels.
185 for (size_t channel = 1; channel < output->Channels(); ++channel) { 185 for (size_t channel = 1; channel < output->Channels(); ++channel) {
186 output->CopyChannel(0, channel); 186 output->CopyChannel(0, channel);
187 } 187 }
188 188
189 return num_samples; 189 return static_cast<int>(num_samples);
190 } 190 }
191 191
192 bool DtmfToneGenerator::initialized() const { 192 bool DtmfToneGenerator::initialized() const {
193 return initialized_; 193 return initialized_;
194 } 194 }
195 195
196 } // namespace webrtc 196 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698