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

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

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 Resample(nullptr, source_length, float_buffer_.get(), destination_frames_); 43 Resample(nullptr, source_length, float_buffer_.get(), destination_frames_);
44 FloatS16ToS16(float_buffer_.get(), destination_frames_, destination); 44 FloatS16ToS16(float_buffer_.get(), destination_frames_, destination);
45 source_ptr_int_ = nullptr; 45 source_ptr_int_ = nullptr;
46 return destination_frames_; 46 return destination_frames_;
47 } 47 }
48 48
49 size_t PushSincResampler::Resample(const float* source, 49 size_t PushSincResampler::Resample(const float* source,
50 size_t source_length, 50 size_t source_length,
51 float* destination, 51 float* destination,
52 size_t destination_capacity) { 52 size_t destination_capacity) {
53 CHECK_EQ(source_length, resampler_->request_frames()); 53 RTC_CHECK_EQ(source_length, resampler_->request_frames());
54 CHECK_GE(destination_capacity, destination_frames_); 54 RTC_CHECK_GE(destination_capacity, destination_frames_);
55 // Cache the source pointer. Calling Resample() will immediately trigger 55 // Cache the source pointer. Calling Resample() will immediately trigger
56 // the Run() callback whereupon we provide the cached value. 56 // the Run() callback whereupon we provide the cached value.
57 source_ptr_ = source; 57 source_ptr_ = source;
58 source_available_ = source_length; 58 source_available_ = source_length;
59 59
60 // On the first pass, we call Resample() twice. During the first call, we 60 // On the first pass, we call Resample() twice. During the first call, we
61 // provide dummy input and discard the output. This is done to prime the 61 // provide dummy input and discard the output. This is done to prime the
62 // SincResampler buffer with the correct delay (half the kernel size), thereby 62 // SincResampler buffer with the correct delay (half the kernel size), thereby
63 // ensuring that all later Resample() calls will only result in one input 63 // ensuring that all later Resample() calls will only result in one input
64 // request through Run(). 64 // request through Run().
65 // 65 //
66 // If this wasn't done, SincResampler would call Run() twice on the first 66 // If this wasn't done, SincResampler would call Run() twice on the first
67 // pass, and we'd have to introduce an entire |source_frames| of delay, rather 67 // pass, and we'd have to introduce an entire |source_frames| of delay, rather
68 // than the minimum half kernel. 68 // than the minimum half kernel.
69 // 69 //
70 // It works out that ChunkSize() is exactly the amount of output we need to 70 // It works out that ChunkSize() is exactly the amount of output we need to
71 // request in order to prime the buffer with a single Run() request for 71 // request in order to prime the buffer with a single Run() request for
72 // |source_frames|. 72 // |source_frames|.
73 if (first_pass_) 73 if (first_pass_)
74 resampler_->Resample(resampler_->ChunkSize(), destination); 74 resampler_->Resample(resampler_->ChunkSize(), destination);
75 75
76 resampler_->Resample(destination_frames_, destination); 76 resampler_->Resample(destination_frames_, destination);
77 source_ptr_ = nullptr; 77 source_ptr_ = nullptr;
78 return destination_frames_; 78 return destination_frames_;
79 } 79 }
80 80
81 void PushSincResampler::Run(size_t frames, float* destination) { 81 void PushSincResampler::Run(size_t frames, float* destination) {
82 // Ensure we are only asked for the available samples. This would fail if 82 // Ensure we are only asked for the available samples. This would fail if
83 // Run() was triggered more than once per Resample() call. 83 // Run() was triggered more than once per Resample() call.
84 CHECK_EQ(source_available_, frames); 84 RTC_CHECK_EQ(source_available_, frames);
85 85
86 if (first_pass_) { 86 if (first_pass_) {
87 // Provide dummy input on the first pass, the output of which will be 87 // Provide dummy input on the first pass, the output of which will be
88 // discarded, as described in Resample(). 88 // discarded, as described in Resample().
89 std::memset(destination, 0, frames * sizeof(*destination)); 89 std::memset(destination, 0, frames * sizeof(*destination));
90 first_pass_ = false; 90 first_pass_ = false;
91 return; 91 return;
92 } 92 }
93 93
94 if (source_ptr_) { 94 if (source_ptr_) {
95 std::memcpy(destination, source_ptr_, frames * sizeof(*destination)); 95 std::memcpy(destination, source_ptr_, frames * sizeof(*destination));
96 } else { 96 } else {
97 for (size_t i = 0; i < frames; ++i) 97 for (size_t i = 0; i < frames; ++i)
98 destination[i] = static_cast<float>(source_ptr_int_[i]); 98 destination[i] = static_cast<float>(source_ptr_int_[i]);
99 } 99 }
100 source_available_ -= frames; 100 source_available_ -= frames;
101 } 101 }
102 102
103 } // namespace webrtc 103 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/real_fourier_openmax.cc ('k') | webrtc/common_audio/resampler/sinc_resampler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698