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

Side by Side Diff: webrtc/common_audio/channel_buffer.h

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix compile Created 4 years, 11 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
« no previous file with comments | « webrtc/common_audio/blocker_unittest.cc ('k') | webrtc/common_audio/channel_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 22 matching lines...) Expand all
33 // 33 //
34 // |channels_|: 34 // |channels_|:
35 // { [ b1ch1* ] [ b1ch2* ] [ b2ch1* ] [ b2ch2* ] } 35 // { [ b1ch1* ] [ b1ch2* ] [ b2ch1* ] [ b2ch2* ] }
36 // 36 //
37 // |bands_|: 37 // |bands_|:
38 // { [ b1ch1* ] [ b2ch1* ] [ b1ch2* ] [ b2ch2* ] } 38 // { [ b1ch1* ] [ b2ch1* ] [ b1ch2* ] [ b2ch2* ] }
39 template <typename T> 39 template <typename T>
40 class ChannelBuffer { 40 class ChannelBuffer {
41 public: 41 public:
42 ChannelBuffer(size_t num_frames, 42 ChannelBuffer(size_t num_frames,
43 int num_channels, 43 size_t num_channels,
44 size_t num_bands = 1) 44 size_t num_bands = 1)
45 : data_(new T[num_frames * num_channels]()), 45 : data_(new T[num_frames * num_channels]()),
46 channels_(new T*[num_channels * num_bands]), 46 channels_(new T*[num_channels * num_bands]),
47 bands_(new T*[num_channels * num_bands]), 47 bands_(new T*[num_channels * num_bands]),
48 num_frames_(num_frames), 48 num_frames_(num_frames),
49 num_frames_per_band_(num_frames / num_bands), 49 num_frames_per_band_(num_frames / num_bands),
50 num_channels_(num_channels), 50 num_channels_(num_channels),
51 num_bands_(num_bands) { 51 num_bands_(num_bands) {
52 for (int i = 0; i < num_channels_; ++i) { 52 for (size_t i = 0; i < num_channels_; ++i) {
53 for (size_t j = 0; j < num_bands_; ++j) { 53 for (size_t j = 0; j < num_bands_; ++j) {
54 channels_[j * num_channels_ + i] = 54 channels_[j * num_channels_ + i] =
55 &data_[i * num_frames_ + j * num_frames_per_band_]; 55 &data_[i * num_frames_ + j * num_frames_per_band_];
56 bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i]; 56 bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i];
57 } 57 }
58 } 58 }
59 } 59 }
60 60
61 // Returns a pointer array to the full-band channels (or lower band channels). 61 // Returns a pointer array to the full-band channels (or lower band channels).
62 // Usage: 62 // Usage:
(...skipping 20 matching lines...) Expand all
83 return const_cast<T* const*>(t->channels(band)); 83 return const_cast<T* const*>(t->channels(band));
84 } 84 }
85 85
86 // Returns a pointer array to the bands for a specific channel. 86 // Returns a pointer array to the bands for a specific channel.
87 // Usage: 87 // Usage:
88 // bands(channel)[band][sample]. 88 // bands(channel)[band][sample].
89 // Where: 89 // Where:
90 // 0 <= channel < |num_channels_| 90 // 0 <= channel < |num_channels_|
91 // 0 <= band < |num_bands_| 91 // 0 <= band < |num_bands_|
92 // 0 <= sample < |num_frames_per_band_| 92 // 0 <= sample < |num_frames_per_band_|
93 const T* const* bands(int channel) const { 93 const T* const* bands(size_t channel) const {
94 RTC_DCHECK_LT(channel, num_channels_); 94 RTC_DCHECK_LT(channel, num_channels_);
95 RTC_DCHECK_GE(channel, 0); 95 RTC_DCHECK_GE(channel, 0u);
96 return &bands_[channel * num_bands_]; 96 return &bands_[channel * num_bands_];
97 } 97 }
98 T* const* bands(int channel) { 98 T* const* bands(size_t channel) {
99 const ChannelBuffer<T>* t = this; 99 const ChannelBuffer<T>* t = this;
100 return const_cast<T* const*>(t->bands(channel)); 100 return const_cast<T* const*>(t->bands(channel));
101 } 101 }
102 102
103 // Sets the |slice| pointers to the |start_frame| position for each channel. 103 // Sets the |slice| pointers to the |start_frame| position for each channel.
104 // Returns |slice| for convenience. 104 // Returns |slice| for convenience.
105 const T* const* Slice(T** slice, size_t start_frame) const { 105 const T* const* Slice(T** slice, size_t start_frame) const {
106 RTC_DCHECK_LT(start_frame, num_frames_); 106 RTC_DCHECK_LT(start_frame, num_frames_);
107 for (int i = 0; i < num_channels_; ++i) 107 for (size_t i = 0; i < num_channels_; ++i)
108 slice[i] = &channels_[i][start_frame]; 108 slice[i] = &channels_[i][start_frame];
109 return slice; 109 return slice;
110 } 110 }
111 T** Slice(T** slice, size_t start_frame) { 111 T** Slice(T** slice, size_t start_frame) {
112 const ChannelBuffer<T>* t = this; 112 const ChannelBuffer<T>* t = this;
113 return const_cast<T**>(t->Slice(slice, start_frame)); 113 return const_cast<T**>(t->Slice(slice, start_frame));
114 } 114 }
115 115
116 size_t num_frames() const { return num_frames_; } 116 size_t num_frames() const { return num_frames_; }
117 size_t num_frames_per_band() const { return num_frames_per_band_; } 117 size_t num_frames_per_band() const { return num_frames_per_band_; }
118 int num_channels() const { return num_channels_; } 118 size_t num_channels() const { return num_channels_; }
119 size_t num_bands() const { return num_bands_; } 119 size_t num_bands() const { return num_bands_; }
120 size_t size() const {return num_frames_ * num_channels_; } 120 size_t size() const {return num_frames_ * num_channels_; }
121 121
122 void SetDataForTesting(const T* data, size_t size) { 122 void SetDataForTesting(const T* data, size_t size) {
123 RTC_CHECK_EQ(size, this->size()); 123 RTC_CHECK_EQ(size, this->size());
124 memcpy(data_.get(), data, size * sizeof(*data)); 124 memcpy(data_.get(), data, size * sizeof(*data));
125 } 125 }
126 126
127 private: 127 private:
128 rtc::scoped_ptr<T[]> data_; 128 rtc::scoped_ptr<T[]> data_;
129 rtc::scoped_ptr<T* []> channels_; 129 rtc::scoped_ptr<T* []> channels_;
130 rtc::scoped_ptr<T* []> bands_; 130 rtc::scoped_ptr<T* []> bands_;
131 const size_t num_frames_; 131 const size_t num_frames_;
132 const size_t num_frames_per_band_; 132 const size_t num_frames_per_band_;
133 const int num_channels_; 133 const size_t num_channels_;
134 const size_t num_bands_; 134 const size_t num_bands_;
135 }; 135 };
136 136
137 // One int16_t and one float ChannelBuffer that are kept in sync. The sync is 137 // One int16_t and one float ChannelBuffer that are kept in sync. The sync is
138 // broken when someone requests write access to either ChannelBuffer, and 138 // broken when someone requests write access to either ChannelBuffer, and
139 // reestablished when someone requests the outdated ChannelBuffer. It is 139 // reestablished when someone requests the outdated ChannelBuffer. It is
140 // therefore safe to use the return value of ibuf_const() and fbuf_const() 140 // therefore safe to use the return value of ibuf_const() and fbuf_const()
141 // until the next call to ibuf() or fbuf(), and the return value of ibuf() and 141 // until the next call to ibuf() or fbuf(), and the return value of ibuf() and
142 // fbuf() until the next call to any of the other functions. 142 // fbuf() until the next call to any of the other functions.
143 class IFChannelBuffer { 143 class IFChannelBuffer {
144 public: 144 public:
145 IFChannelBuffer(size_t num_frames, int num_channels, size_t num_bands = 1); 145 IFChannelBuffer(size_t num_frames, size_t num_channels, size_t num_bands = 1);
146 146
147 ChannelBuffer<int16_t>* ibuf(); 147 ChannelBuffer<int16_t>* ibuf();
148 ChannelBuffer<float>* fbuf(); 148 ChannelBuffer<float>* fbuf();
149 const ChannelBuffer<int16_t>* ibuf_const() const; 149 const ChannelBuffer<int16_t>* ibuf_const() const;
150 const ChannelBuffer<float>* fbuf_const() const; 150 const ChannelBuffer<float>* fbuf_const() const;
151 151
152 size_t num_frames() const { return ibuf_.num_frames(); } 152 size_t num_frames() const { return ibuf_.num_frames(); }
153 size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); } 153 size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); }
154 int num_channels() const { return ibuf_.num_channels(); } 154 size_t num_channels() const { return ibuf_.num_channels(); }
155 size_t num_bands() const { return ibuf_.num_bands(); } 155 size_t num_bands() const { return ibuf_.num_bands(); }
156 156
157 private: 157 private:
158 void RefreshF() const; 158 void RefreshF() const;
159 void RefreshI() const; 159 void RefreshI() const;
160 160
161 mutable bool ivalid_; 161 mutable bool ivalid_;
162 mutable ChannelBuffer<int16_t> ibuf_; 162 mutable ChannelBuffer<int16_t> ibuf_;
163 mutable bool fvalid_; 163 mutable bool fvalid_;
164 mutable ChannelBuffer<float> fbuf_; 164 mutable ChannelBuffer<float> fbuf_;
165 }; 165 };
166 166
167 } // namespace webrtc 167 } // namespace webrtc
168 168
169 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ 169 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/common_audio/blocker_unittest.cc ('k') | webrtc/common_audio/channel_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698