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

Unified Diff: webrtc/common_audio/resampler/sinc_resampler.cc

Issue 1231713002: Update audio code to use size_t more correctly, webrtc/common_audio/resampler/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_audio/resampler/sinc_resampler.h ('k') | webrtc/common_audio/resampler/sinc_resampler_sse.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/resampler/sinc_resampler.cc
diff --git a/webrtc/common_audio/resampler/sinc_resampler.cc b/webrtc/common_audio/resampler/sinc_resampler.cc
index 81c789d00b73d18bada42bf08af646082c50def7..c4f1488b25bafc57956b2f40dd80d7f9fc96c062 100644
--- a/webrtc/common_audio/resampler/sinc_resampler.cc
+++ b/webrtc/common_audio/resampler/sinc_resampler.cc
@@ -149,7 +149,7 @@ void SincResampler::InitializeCPUSpecificFeatures() {}
#endif
SincResampler::SincResampler(double io_sample_rate_ratio,
- int request_frames,
+ size_t request_frames,
SincResamplerCallback* read_cb)
: io_sample_rate_ratio_(io_sample_rate_ratio),
read_cb_(read_cb),
@@ -215,14 +215,15 @@ void SincResampler::InitializeKernel() {
// Generates a set of windowed sinc() kernels.
// We generate a range of sub-sample offsets from 0.0 to 1.0.
const double sinc_scale_factor = SincScaleFactor(io_sample_rate_ratio_);
- for (int offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
+ for (size_t offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
const float subsample_offset =
static_cast<float>(offset_idx) / kKernelOffsetCount;
- for (int i = 0; i < kKernelSize; ++i) {
- const int idx = i + offset_idx * kKernelSize;
- const float pre_sinc =
- static_cast<float>(M_PI * (i - kKernelSize / 2 - subsample_offset));
+ for (size_t i = 0; i < kKernelSize; ++i) {
+ const size_t idx = i + offset_idx * kKernelSize;
+ const float pre_sinc = static_cast<float>(M_PI *
+ (static_cast<int>(i) - static_cast<int>(kKernelSize / 2) -
+ subsample_offset));
kernel_pre_sinc_storage_[idx] = pre_sinc;
// Compute Blackman window, matching the offset of the sinc().
@@ -252,9 +253,9 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) {
// Optimize reinitialization by reusing values which are independent of
// |sinc_scale_factor|. Provides a 3x speedup.
const double sinc_scale_factor = SincScaleFactor(io_sample_rate_ratio_);
- for (int offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
- for (int i = 0; i < kKernelSize; ++i) {
- const int idx = i + offset_idx * kKernelSize;
+ for (size_t offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
+ for (size_t i = 0; i < kKernelSize; ++i) {
+ const size_t idx = i + offset_idx * kKernelSize;
const float window = kernel_window_storage_[idx];
const float pre_sinc = kernel_pre_sinc_storage_[idx];
@@ -266,8 +267,8 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) {
}
}
-void SincResampler::Resample(int frames, float* destination) {
- int remaining_frames = frames;
+void SincResampler::Resample(size_t frames, float* destination) {
+ size_t remaining_frames = frames;
// Step (1) -- Prime the input buffer at the start of the input stream.
if (!buffer_primed_ && remaining_frames) {
@@ -343,8 +344,8 @@ void SincResampler::Resample(int frames, float* destination) {
#undef CONVOLVE_FUNC
-int SincResampler::ChunkSize() const {
- return static_cast<int>(block_size_ / io_sample_rate_ratio_);
+size_t SincResampler::ChunkSize() const {
+ return static_cast<size_t>(block_size_ / io_sample_rate_ratio_);
}
void SincResampler::Flush() {
@@ -363,7 +364,7 @@ float SincResampler::Convolve_C(const float* input_ptr, const float* k1,
// Generate a single output sample. Unrolling this loop hurt performance in
// local testing.
- int n = kKernelSize;
+ size_t n = kKernelSize;
while (n--) {
sum1 += *input_ptr * *k1++;
sum2 += *input_ptr++ * *k2++;
« no previous file with comments | « webrtc/common_audio/resampler/sinc_resampler.h ('k') | webrtc/common_audio/resampler/sinc_resampler_sse.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698