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

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

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, 4 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 #ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_ 11 #ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_
12 #define WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_ 12 #define WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_
13 13
14 #include "webrtc/base/constructormagic.h" 14 #include "webrtc/base/constructormagic.h"
15 #include "webrtc/base/scoped_ptr.h" 15 #include "webrtc/base/scoped_ptr.h"
16 #include "webrtc/common_audio/resampler/sinc_resampler.h" 16 #include "webrtc/common_audio/resampler/sinc_resampler.h"
17 #include "webrtc/typedefs.h" 17 #include "webrtc/typedefs.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 // A thin wrapper over SincResampler to provide a push-based interface as 21 // A thin wrapper over SincResampler to provide a push-based interface as
22 // required by WebRTC. SincResampler uses a pull-based interface, and will 22 // required by WebRTC. SincResampler uses a pull-based interface, and will
23 // use SincResamplerCallback::Run() to request data upon a call to Resample(). 23 // use SincResamplerCallback::Run() to request data upon a call to Resample().
24 // These Run() calls will happen on the same thread Resample() is called on. 24 // These Run() calls will happen on the same thread Resample() is called on.
25 class PushSincResampler : public SincResamplerCallback { 25 class PushSincResampler : public SincResamplerCallback {
26 public: 26 public:
27 // Provide the size of the source and destination blocks in samples. These 27 // Provide the size of the source and destination blocks in samples. These
28 // must correspond to the same time duration (typically 10 ms) as the sample 28 // must correspond to the same time duration (typically 10 ms) as the sample
29 // ratio is inferred from them. 29 // ratio is inferred from them.
30 PushSincResampler(int source_frames, int destination_frames); 30 PushSincResampler(size_t source_frames, size_t destination_frames);
31 ~PushSincResampler() override; 31 ~PushSincResampler() override;
32 32
33 // Perform the resampling. |source_frames| must always equal the 33 // Perform the resampling. |source_frames| must always equal the
34 // |source_frames| provided at construction. |destination_capacity| must be 34 // |source_frames| provided at construction. |destination_capacity| must be
35 // at least as large as |destination_frames|. Returns the number of samples 35 // at least as large as |destination_frames|. Returns the number of samples
36 // provided in destination (for convenience, since this will always be equal 36 // provided in destination (for convenience, since this will always be equal
37 // to |destination_frames|). 37 // to |destination_frames|).
38 int Resample(const int16_t* source, int source_frames, 38 size_t Resample(const int16_t* source, size_t source_frames,
39 int16_t* destination, int destination_capacity); 39 int16_t* destination, size_t destination_capacity);
40 int Resample(const float* source, 40 size_t Resample(const float* source,
41 int source_frames, 41 size_t source_frames,
42 float* destination, 42 float* destination,
43 int destination_capacity); 43 size_t destination_capacity);
44 44
45 // Delay due to the filter kernel. Essentially, the time after which an input 45 // Delay due to the filter kernel. Essentially, the time after which an input
46 // sample will appear in the resampled output. 46 // sample will appear in the resampled output.
47 static float AlgorithmicDelaySeconds(int source_rate_hz) { 47 static float AlgorithmicDelaySeconds(int source_rate_hz) {
48 return 1.f / source_rate_hz * SincResampler::kKernelSize / 2; 48 return 1.f / source_rate_hz * SincResampler::kKernelSize / 2;
49 } 49 }
50 50
51 protected: 51 protected:
52 // Implements SincResamplerCallback. 52 // Implements SincResamplerCallback.
53 void Run(int frames, float* destination) override; 53 void Run(size_t frames, float* destination) override;
54 54
55 private: 55 private:
56 friend class PushSincResamplerTest; 56 friend class PushSincResamplerTest;
57 SincResampler* get_resampler_for_testing() { return resampler_.get(); } 57 SincResampler* get_resampler_for_testing() { return resampler_.get(); }
58 58
59 rtc::scoped_ptr<SincResampler> resampler_; 59 rtc::scoped_ptr<SincResampler> resampler_;
60 rtc::scoped_ptr<float[]> float_buffer_; 60 rtc::scoped_ptr<float[]> float_buffer_;
61 const float* source_ptr_; 61 const float* source_ptr_;
62 const int16_t* source_ptr_int_; 62 const int16_t* source_ptr_int_;
63 const int destination_frames_; 63 const size_t destination_frames_;
64 64
65 // True on the first call to Resample(), to prime the SincResampler buffer. 65 // True on the first call to Resample(), to prime the SincResampler buffer.
66 bool first_pass_; 66 bool first_pass_;
67 67
68 // Used to assert we are only requested for as much data as is available. 68 // Used to assert we are only requested for as much data as is available.
69 int source_available_; 69 size_t source_available_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(PushSincResampler); 71 DISALLOW_COPY_AND_ASSIGN(PushSincResampler);
72 }; 72 };
73 73
74 } // namespace webrtc 74 } // namespace webrtc
75 75
76 #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_ 76 #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_PUSH_SINC_RESAMPLER_H_
OLDNEW
« no previous file with comments | « webrtc/common_audio/resampler/push_resampler.cc ('k') | webrtc/common_audio/resampler/push_sinc_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698