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

Side by Side Diff: webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.cc

Issue 1174813003: Prepare to convert various types to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix MSVC warning Created 5 years, 6 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 18 matching lines...) Expand all
29 k_ = (max_frequency_ - kMinFrequency) / duration; 29 k_ = (max_frequency_ - kMinFrequency) / duration;
30 } 30 }
31 31
32 void SinusoidalLinearChirpSource::Run(int frames, float* destination) { 32 void SinusoidalLinearChirpSource::Run(int frames, float* destination) {
33 for (int i = 0; i < frames; ++i, ++current_index_) { 33 for (int i = 0; i < frames; ++i, ++current_index_) {
34 // Filter out frequencies higher than Nyquist. 34 // Filter out frequencies higher than Nyquist.
35 if (Frequency(current_index_) > 0.5 * sample_rate_) { 35 if (Frequency(current_index_) > 0.5 * sample_rate_) {
36 destination[i] = 0; 36 destination[i] = 0;
37 } else { 37 } else {
38 // Calculate time in seconds. 38 // Calculate time in seconds.
39 double t = (static_cast<double>(current_index_) - delay_samples_) / 39 if (current_index_ < delay_samples_) {
40 sample_rate_;
41 if (t < 0) {
42 destination[i] = 0; 40 destination[i] = 0;
43 } else { 41 } else {
44 // Sinusoidal linear chirp. 42 // Sinusoidal linear chirp.
43 double t = (current_index_ - delay_samples_) / sample_rate_;
45 destination[i] = 44 destination[i] =
46 sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t)); 45 sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t));
47 } 46 }
48 } 47 }
49 } 48 }
50 } 49 }
51 50
52 double SinusoidalLinearChirpSource::Frequency(int position) { 51 double SinusoidalLinearChirpSource::Frequency(int position) {
53 return kMinFrequency + (position - delay_samples_) * 52 return kMinFrequency + (position - delay_samples_) *
54 (max_frequency_ - kMinFrequency) / total_samples_; 53 (max_frequency_ - kMinFrequency) / total_samples_;
55 } 54 }
56 55
57 } // namespace webrtc 56 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698