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/common_audio/resampler/push_resampler.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
(...skipping 29 matching lines...) Expand all
40 return 0; 40 return 0;
41 41
42 if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 || 42 if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 ||
43 num_channels <= 0 || num_channels > 2) 43 num_channels <= 0 || num_channels > 2)
44 return -1; 44 return -1;
45 45
46 src_sample_rate_hz_ = src_sample_rate_hz; 46 src_sample_rate_hz_ = src_sample_rate_hz;
47 dst_sample_rate_hz_ = dst_sample_rate_hz; 47 dst_sample_rate_hz_ = dst_sample_rate_hz;
48 num_channels_ = num_channels; 48 num_channels_ = num_channels;
49 49
50 const int src_size_10ms_mono = src_sample_rate_hz / 100; 50 const size_t src_size_10ms_mono =
51 const int dst_size_10ms_mono = dst_sample_rate_hz / 100; 51 static_cast<size_t>(src_sample_rate_hz / 100);
52 const size_t dst_size_10ms_mono =
53 static_cast<size_t>(dst_sample_rate_hz / 100);
52 sinc_resampler_.reset(new PushSincResampler(src_size_10ms_mono, 54 sinc_resampler_.reset(new PushSincResampler(src_size_10ms_mono,
53 dst_size_10ms_mono)); 55 dst_size_10ms_mono));
54 if (num_channels_ == 2) { 56 if (num_channels_ == 2) {
55 src_left_.reset(new T[src_size_10ms_mono]); 57 src_left_.reset(new T[src_size_10ms_mono]);
56 src_right_.reset(new T[src_size_10ms_mono]); 58 src_right_.reset(new T[src_size_10ms_mono]);
57 dst_left_.reset(new T[dst_size_10ms_mono]); 59 dst_left_.reset(new T[dst_size_10ms_mono]);
58 dst_right_.reset(new T[dst_size_10ms_mono]); 60 dst_right_.reset(new T[dst_size_10ms_mono]);
59 sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono, 61 sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono,
60 dst_size_10ms_mono)); 62 dst_size_10ms_mono));
61 } 63 }
62 64
63 return 0; 65 return 0;
64 } 66 }
65 67
66 template <typename T> 68 template <typename T>
67 int PushResampler<T>::Resample(const T* src, int src_length, T* dst, 69 int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst,
68 int dst_capacity) { 70 size_t dst_capacity) {
69 const int src_size_10ms = src_sample_rate_hz_ * num_channels_ / 100; 71 const size_t src_size_10ms =
70 const int dst_size_10ms = dst_sample_rate_hz_ * num_channels_ / 100; 72 static_cast<size_t>(src_sample_rate_hz_ * num_channels_ / 100);
73 const size_t dst_size_10ms =
74 static_cast<size_t>(dst_sample_rate_hz_ * num_channels_ / 100);
71 if (src_length != src_size_10ms || dst_capacity < dst_size_10ms) 75 if (src_length != src_size_10ms || dst_capacity < dst_size_10ms)
72 return -1; 76 return -1;
73 77
74 if (src_sample_rate_hz_ == dst_sample_rate_hz_) { 78 if (src_sample_rate_hz_ == dst_sample_rate_hz_) {
75 // The old resampler provides this memcpy facility in the case of matching 79 // The old resampler provides this memcpy facility in the case of matching
76 // sample rates, so reproduce it here for the sinc resampler. 80 // sample rates, so reproduce it here for the sinc resampler.
77 memcpy(dst, src, src_length * sizeof(T)); 81 memcpy(dst, src, src_length * sizeof(T));
78 return src_length; 82 return static_cast<int>(src_length);
79 } 83 }
80 if (num_channels_ == 2) { 84 if (num_channels_ == 2) {
81 const int src_length_mono = src_length / num_channels_; 85 const size_t src_length_mono = src_length / num_channels_;
82 const int dst_capacity_mono = dst_capacity / num_channels_; 86 const size_t dst_capacity_mono = dst_capacity / num_channels_;
83 T* deinterleaved[] = {src_left_.get(), src_right_.get()}; 87 T* deinterleaved[] = {src_left_.get(), src_right_.get()};
84 Deinterleave(src, src_length_mono, num_channels_, deinterleaved); 88 Deinterleave(src, src_length_mono, num_channels_, deinterleaved);
85 89
86 int dst_length_mono = 90 size_t dst_length_mono =
87 sinc_resampler_->Resample(src_left_.get(), src_length_mono, 91 sinc_resampler_->Resample(src_left_.get(), src_length_mono,
88 dst_left_.get(), dst_capacity_mono); 92 dst_left_.get(), dst_capacity_mono);
89 sinc_resampler_right_->Resample(src_right_.get(), src_length_mono, 93 sinc_resampler_right_->Resample(src_right_.get(), src_length_mono,
90 dst_right_.get(), dst_capacity_mono); 94 dst_right_.get(), dst_capacity_mono);
91 95
92 deinterleaved[0] = dst_left_.get(); 96 deinterleaved[0] = dst_left_.get();
93 deinterleaved[1] = dst_right_.get(); 97 deinterleaved[1] = dst_right_.get();
94 Interleave(deinterleaved, dst_length_mono, num_channels_, dst); 98 Interleave(deinterleaved, dst_length_mono, num_channels_, dst);
95 return dst_length_mono * num_channels_; 99 return static_cast<int>(dst_length_mono * num_channels_);
96 } else { 100 } else {
97 return sinc_resampler_->Resample(src, src_length, dst, dst_capacity); 101 return static_cast<int>(
102 sinc_resampler_->Resample(src, src_length, dst, dst_capacity));
98 } 103 }
99 } 104 }
100 105
101 // Explictly generate required instantiations. 106 // Explictly generate required instantiations.
102 template class PushResampler<int16_t>; 107 template class PushResampler<int16_t>;
103 template class PushResampler<float>; 108 template class PushResampler<float>;
104 109
105 } // namespace webrtc 110 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/resampler/include/resampler.h ('k') | webrtc/common_audio/resampler/push_sinc_resampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698