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

Side by Side Diff: webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.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) 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
11 // MSVC++ requires this to be set before any other includes to get M_PI. 11 // MSVC++ requires this to be set before any other includes to get M_PI.
12 #define _USE_MATH_DEFINES 12 #define _USE_MATH_DEFINES
13 13
14 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h" 14 #include "webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h"
15 15
16 #include <math.h> 16 #include <math.h>
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 SinusoidalLinearChirpSource::SinusoidalLinearChirpSource(int sample_rate, 20 SinusoidalLinearChirpSource::SinusoidalLinearChirpSource(int sample_rate,
21 int samples, double max_frequency, double delay_samples) 21 size_t samples,
22 double max_frequency,
23 double delay_samples)
22 : sample_rate_(sample_rate), 24 : sample_rate_(sample_rate),
23 total_samples_(samples), 25 total_samples_(samples),
24 max_frequency_(max_frequency), 26 max_frequency_(max_frequency),
25 current_index_(0), 27 current_index_(0),
26 delay_samples_(delay_samples) { 28 delay_samples_(delay_samples) {
27 // Chirp rate. 29 // Chirp rate.
28 double duration = static_cast<double>(total_samples_) / sample_rate_; 30 double duration = static_cast<double>(total_samples_) / sample_rate_;
29 k_ = (max_frequency_ - kMinFrequency) / duration; 31 k_ = (max_frequency_ - kMinFrequency) / duration;
30 } 32 }
31 33
32 void SinusoidalLinearChirpSource::Run(int frames, float* destination) { 34 void SinusoidalLinearChirpSource::Run(size_t frames, float* destination) {
33 for (int i = 0; i < frames; ++i, ++current_index_) { 35 for (size_t i = 0; i < frames; ++i, ++current_index_) {
34 // Filter out frequencies higher than Nyquist. 36 // Filter out frequencies higher than Nyquist.
35 if (Frequency(current_index_) > 0.5 * sample_rate_) { 37 if (Frequency(current_index_) > 0.5 * sample_rate_) {
36 destination[i] = 0; 38 destination[i] = 0;
37 } else { 39 } else {
38 // Calculate time in seconds. 40 // Calculate time in seconds.
39 if (current_index_ < delay_samples_) { 41 if (current_index_ < delay_samples_) {
40 destination[i] = 0; 42 destination[i] = 0;
41 } else { 43 } else {
42 // Sinusoidal linear chirp. 44 // Sinusoidal linear chirp.
43 double t = (current_index_ - delay_samples_) / sample_rate_; 45 double t = (current_index_ - delay_samples_) / sample_rate_;
44 destination[i] = 46 destination[i] =
45 sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t)); 47 sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t));
46 } 48 }
47 } 49 }
48 } 50 }
49 } 51 }
50 52
51 double SinusoidalLinearChirpSource::Frequency(int position) { 53 double SinusoidalLinearChirpSource::Frequency(size_t position) {
52 return kMinFrequency + (position - delay_samples_) * 54 return kMinFrequency + (position - delay_samples_) *
53 (max_frequency_ - kMinFrequency) / total_samples_; 55 (max_frequency_ - kMinFrequency) / total_samples_;
54 } 56 }
55 57
56 } // namespace webrtc 58 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698