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

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

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 10 matching lines...) Expand all
21 #include "webrtc/typedefs.h" 21 #include "webrtc/typedefs.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 24
25 // Callback class for providing more data into the resampler. Expects |frames| 25 // Callback class for providing more data into the resampler. Expects |frames|
26 // of data to be rendered into |destination|; zero padded if not enough frames 26 // of data to be rendered into |destination|; zero padded if not enough frames
27 // are available to satisfy the request. 27 // are available to satisfy the request.
28 class SincResamplerCallback { 28 class SincResamplerCallback {
29 public: 29 public:
30 virtual ~SincResamplerCallback() {} 30 virtual ~SincResamplerCallback() {}
31 virtual void Run(int frames, float* destination) = 0; 31 virtual void Run(size_t frames, float* destination) = 0;
32 }; 32 };
33 33
34 // SincResampler is a high-quality single-channel sample-rate converter. 34 // SincResampler is a high-quality single-channel sample-rate converter.
35 class SincResampler { 35 class SincResampler {
36 public: 36 public:
37 // The kernel size can be adjusted for quality (higher is better) at the 37 // The kernel size can be adjusted for quality (higher is better) at the
38 // expense of performance. Must be a multiple of 32. 38 // expense of performance. Must be a multiple of 32.
39 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. 39 // TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
40 static const int kKernelSize = 32; 40 static const size_t kKernelSize = 32;
41 41
42 // Default request size. Affects how often and for how much SincResampler 42 // Default request size. Affects how often and for how much SincResampler
43 // calls back for input. Must be greater than kKernelSize. 43 // calls back for input. Must be greater than kKernelSize.
44 static const int kDefaultRequestSize = 512; 44 static const size_t kDefaultRequestSize = 512;
45 45
46 // The kernel offset count is used for interpolation and is the number of 46 // The kernel offset count is used for interpolation and is the number of
47 // sub-sample kernel shifts. Can be adjusted for quality (higher is better) 47 // sub-sample kernel shifts. Can be adjusted for quality (higher is better)
48 // at the expense of allocating more memory. 48 // at the expense of allocating more memory.
49 static const int kKernelOffsetCount = 32; 49 static const size_t kKernelOffsetCount = 32;
50 static const int kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1); 50 static const size_t kKernelStorageSize =
51 kKernelSize * (kKernelOffsetCount + 1);
51 52
52 // Constructs a SincResampler with the specified |read_cb|, which is used to 53 // Constructs a SincResampler with the specified |read_cb|, which is used to
53 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio 54 // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio
54 // of input / output sample rates. |request_frames| controls the size in 55 // of input / output sample rates. |request_frames| controls the size in
55 // frames of the buffer requested by each |read_cb| call. The value must be 56 // frames of the buffer requested by each |read_cb| call. The value must be
56 // greater than kKernelSize. Specify kDefaultRequestSize if there are no 57 // greater than kKernelSize. Specify kDefaultRequestSize if there are no
57 // request size constraints. 58 // request size constraints.
58 SincResampler(double io_sample_rate_ratio, 59 SincResampler(double io_sample_rate_ratio,
59 int request_frames, 60 size_t request_frames,
60 SincResamplerCallback* read_cb); 61 SincResamplerCallback* read_cb);
61 virtual ~SincResampler(); 62 virtual ~SincResampler();
62 63
63 // Resample |frames| of data from |read_cb_| into |destination|. 64 // Resample |frames| of data from |read_cb_| into |destination|.
64 void Resample(int frames, float* destination); 65 void Resample(size_t frames, float* destination);
65 66
66 // The maximum size in frames that guarantees Resample() will only make a 67 // The maximum size in frames that guarantees Resample() will only make a
67 // single call to |read_cb_| for more data. 68 // single call to |read_cb_| for more data.
68 int ChunkSize() const; 69 size_t ChunkSize() const;
69 70
70 int request_frames() const { return request_frames_; } 71 size_t request_frames() const { return request_frames_; }
71 72
72 // Flush all buffered data and reset internal indices. Not thread safe, do 73 // Flush all buffered data and reset internal indices. Not thread safe, do
73 // not call while Resample() is in progress. 74 // not call while Resample() is in progress.
74 void Flush(); 75 void Flush();
75 76
76 // Update |io_sample_rate_ratio_|. SetRatio() will cause a reconstruction of 77 // Update |io_sample_rate_ratio_|. SetRatio() will cause a reconstruction of
77 // the kernels used for resampling. Not thread safe, do not call while 78 // the kernels used for resampling. Not thread safe, do not call while
78 // Resample() is in progress. 79 // Resample() is in progress.
79 // 80 //
80 // TODO(ajm): Use this in PushSincResampler rather than reconstructing 81 // TODO(ajm): Use this in PushSincResampler rather than reconstructing
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // double precision to avoid drift. 119 // double precision to avoid drift.
119 double virtual_source_idx_; 120 double virtual_source_idx_;
120 121
121 // The buffer is primed once at the very beginning of processing. 122 // The buffer is primed once at the very beginning of processing.
122 bool buffer_primed_; 123 bool buffer_primed_;
123 124
124 // Source of data for resampling. 125 // Source of data for resampling.
125 SincResamplerCallback* read_cb_; 126 SincResamplerCallback* read_cb_;
126 127
127 // The size (in samples) to request from each |read_cb_| execution. 128 // The size (in samples) to request from each |read_cb_| execution.
128 const int request_frames_; 129 const size_t request_frames_;
129 130
130 // The number of source frames processed per pass. 131 // The number of source frames processed per pass.
131 int block_size_; 132 size_t block_size_;
132 133
133 // The size (in samples) of the internal buffer used by the resampler. 134 // The size (in samples) of the internal buffer used by the resampler.
134 const int input_buffer_size_; 135 const size_t input_buffer_size_;
135 136
136 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize. 137 // Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
137 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from 138 // The kernel offsets are sub-sample shifts of a windowed sinc shifted from
138 // 0.0 to 1.0 sample. 139 // 0.0 to 1.0 sample.
139 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_storage_; 140 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_storage_;
140 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_pre_sinc_storage_; 141 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_pre_sinc_storage_;
141 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_window_storage_; 142 rtc::scoped_ptr<float[], AlignedFreeDeleter> kernel_window_storage_;
142 143
143 // Data from the source is copied into this buffer for each processing pass. 144 // Data from the source is copied into this buffer for each processing pass.
144 rtc::scoped_ptr<float[], AlignedFreeDeleter> input_buffer_; 145 rtc::scoped_ptr<float[], AlignedFreeDeleter> input_buffer_;
(...skipping 15 matching lines...) Expand all
160 float* const r2_; 161 float* const r2_;
161 float* r3_; 162 float* r3_;
162 float* r4_; 163 float* r4_;
163 164
164 DISALLOW_COPY_AND_ASSIGN(SincResampler); 165 DISALLOW_COPY_AND_ASSIGN(SincResampler);
165 }; 166 };
166 167
167 } // namespace webrtc 168 } // namespace webrtc
168 169
169 #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_SINC_RESAMPLER_H_ 170 #endif // WEBRTC_COMMON_AUDIO_RESAMPLER_SINC_RESAMPLER_H_
OLDNEW
« no previous file with comments | « webrtc/common_audio/resampler/resampler_unittest.cc ('k') | webrtc/common_audio/resampler/sinc_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698