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

Side by Side Diff: webrtc/modules/audio_device/include/audio_device_defines.h

Issue 1305983003: Convert some more things to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Support Android's C89 mode 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) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 }; 136 };
137 137
138 // Helper class for storage of fundamental audio parameters such as sample rate, 138 // Helper class for storage of fundamental audio parameters such as sample rate,
139 // number of channels, native buffer size etc. 139 // number of channels, native buffer size etc.
140 // Note that one audio frame can contain more than one channel sample and each 140 // Note that one audio frame can contain more than one channel sample and each
141 // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in 141 // sample is assumed to be a 16-bit PCM sample. Hence, one audio frame in
142 // stereo contains 2 * (16/8) = 4 bytes of data. 142 // stereo contains 2 * (16/8) = 4 bytes of data.
143 class AudioParameters { 143 class AudioParameters {
144 public: 144 public:
145 // This implementation does only support 16-bit PCM samples. 145 // This implementation does only support 16-bit PCM samples.
146 enum { kBitsPerSample = 16 }; 146 static const size_t kBitsPerSample = 16;
147 AudioParameters() 147 AudioParameters()
148 : sample_rate_(0), 148 : sample_rate_(0),
149 channels_(0), 149 channels_(0),
150 frames_per_buffer_(0), 150 frames_per_buffer_(0),
151 frames_per_10ms_buffer_(0) {} 151 frames_per_10ms_buffer_(0) {}
152 AudioParameters(int sample_rate, int channels, int frames_per_buffer) 152 AudioParameters(int sample_rate, int channels, size_t frames_per_buffer)
153 : sample_rate_(sample_rate), 153 : sample_rate_(sample_rate),
154 channels_(channels), 154 channels_(channels),
155 frames_per_buffer_(frames_per_buffer), 155 frames_per_buffer_(frames_per_buffer),
156 frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {} 156 frames_per_10ms_buffer_(static_cast<size_t>(sample_rate / 100)) {}
157 void reset(int sample_rate, int channels, int frames_per_buffer) { 157 void reset(int sample_rate, int channels, size_t frames_per_buffer) {
158 sample_rate_ = sample_rate; 158 sample_rate_ = sample_rate;
159 channels_ = channels; 159 channels_ = channels;
160 frames_per_buffer_ = frames_per_buffer; 160 frames_per_buffer_ = frames_per_buffer;
161 frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100); 161 frames_per_10ms_buffer_ = static_cast<size_t>(sample_rate / 100);
162 } 162 }
163 int bits_per_sample() const { return kBitsPerSample; } 163 size_t bits_per_sample() const { return kBitsPerSample; }
164 int sample_rate() const { return sample_rate_; } 164 int sample_rate() const { return sample_rate_; }
165 int channels() const { return channels_; } 165 int channels() const { return channels_; }
166 int frames_per_buffer() const { return frames_per_buffer_; } 166 size_t frames_per_buffer() const { return frames_per_buffer_; }
167 size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; } 167 size_t frames_per_10ms_buffer() const { return frames_per_10ms_buffer_; }
168 bool is_valid() const { 168 bool is_valid() const {
169 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0)); 169 return ((sample_rate_ > 0) && (channels_ > 0) && (frames_per_buffer_ > 0));
170 } 170 }
171 int GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; } 171 size_t GetBytesPerFrame() const { return channels_ * kBitsPerSample / 8; }
172 int GetBytesPerBuffer() const { 172 size_t GetBytesPerBuffer() const {
173 return frames_per_buffer_ * GetBytesPerFrame(); 173 return frames_per_buffer_ * GetBytesPerFrame();
174 } 174 }
175 size_t GetBytesPer10msBuffer() const { 175 size_t GetBytesPer10msBuffer() const {
176 return frames_per_10ms_buffer_ * GetBytesPerFrame(); 176 return frames_per_10ms_buffer_ * GetBytesPerFrame();
177 } 177 }
178 float GetBufferSizeInMilliseconds() const { 178 float GetBufferSizeInMilliseconds() const {
179 if (sample_rate_ == 0) 179 if (sample_rate_ == 0)
180 return 0.0f; 180 return 0.0f;
181 return frames_per_buffer_ / (sample_rate_ / 1000.0f); 181 return frames_per_buffer_ / (sample_rate_ / 1000.0f);
182 } 182 }
183 183
184 private: 184 private:
185 int sample_rate_; 185 int sample_rate_;
186 int channels_; 186 int channels_;
187 int frames_per_buffer_; 187 size_t frames_per_buffer_;
188 size_t frames_per_10ms_buffer_; 188 size_t frames_per_10ms_buffer_;
189 }; 189 };
190 190
191 } // namespace webrtc 191 } // namespace webrtc
192 192
193 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H 193 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_DEFINES_H
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/opensles_player.cc ('k') | webrtc/modules/audio_device/ios/audio_device_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698