Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 public: | 42 public: |
| 43 ChannelBuffer(size_t num_frames, | 43 ChannelBuffer(size_t num_frames, |
| 44 size_t num_channels, | 44 size_t num_channels, |
| 45 size_t num_bands = 1) | 45 size_t num_bands = 1) |
| 46 : data_(new T[num_frames * num_channels]()), | 46 : data_(new T[num_frames * num_channels]()), |
| 47 channels_(new T*[num_channels * num_bands]), | 47 channels_(new T*[num_channels * num_bands]), |
| 48 bands_(new T*[num_channels * num_bands]), | 48 bands_(new T*[num_channels * num_bands]), |
| 49 num_frames_(num_frames), | 49 num_frames_(num_frames), |
| 50 num_frames_per_band_(num_frames / num_bands), | 50 num_frames_per_band_(num_frames / num_bands), |
| 51 num_channels_(num_channels), | 51 num_channels_(num_channels), |
| 52 num_official_channels_(num_channels), | |
| 52 num_bands_(num_bands) { | 53 num_bands_(num_bands) { |
| 53 for (size_t i = 0; i < num_channels_; ++i) { | 54 for (size_t i = 0; i < num_channels_; ++i) { |
| 54 for (size_t j = 0; j < num_bands_; ++j) { | 55 for (size_t j = 0; j < num_bands_; ++j) { |
| 55 channels_[j * num_channels_ + i] = | 56 channels_[j * num_channels_ + i] = |
| 56 &data_[i * num_frames_ + j * num_frames_per_band_]; | 57 &data_[i * num_frames_ + j * num_frames_per_band_]; |
| 57 bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i]; | 58 bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i]; |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 81 } | 82 } |
| 82 T* const* channels(size_t band) { | 83 T* const* channels(size_t band) { |
| 83 const ChannelBuffer<T>* t = this; | 84 const ChannelBuffer<T>* t = this; |
| 84 return const_cast<T* const*>(t->channels(band)); | 85 return const_cast<T* const*>(t->channels(band)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 // Returns a pointer array to the bands for a specific channel. | 88 // Returns a pointer array to the bands for a specific channel. |
| 88 // Usage: | 89 // Usage: |
| 89 // bands(channel)[band][sample]. | 90 // bands(channel)[band][sample]. |
| 90 // Where: | 91 // Where: |
| 91 // 0 <= channel < |num_channels_| | 92 // 0 <= channel < |num_official_channels_| |
|
peah-webrtc
2016/06/01 14:51:01
This seems very confusing to me. What is the diffe
aluebs-webrtc
2016/06/01 22:13:20
It is needed to change the number of channels of a
peah-webrtc
2016/06/08 12:04:55
I still don't see why this change is here. But I'l
aluebs-webrtc
2016/06/09 02:11:46
Acknowledged.
| |
| 92 // 0 <= band < |num_bands_| | 93 // 0 <= band < |num_bands_| |
| 93 // 0 <= sample < |num_frames_per_band_| | 94 // 0 <= sample < |num_frames_per_band_| |
| 94 const T* const* bands(size_t channel) const { | 95 const T* const* bands(size_t channel) const { |
| 95 RTC_DCHECK_LT(channel, num_channels_); | 96 RTC_DCHECK_LT(channel, num_official_channels_); |
| 96 RTC_DCHECK_GE(channel, 0u); | 97 RTC_DCHECK_GE(channel, 0u); |
| 97 return &bands_[channel * num_bands_]; | 98 return &bands_[channel * num_bands_]; |
| 98 } | 99 } |
| 99 T* const* bands(size_t channel) { | 100 T* const* bands(size_t channel) { |
| 100 const ChannelBuffer<T>* t = this; | 101 const ChannelBuffer<T>* t = this; |
| 101 return const_cast<T* const*>(t->bands(channel)); | 102 return const_cast<T* const*>(t->bands(channel)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 // Sets the |slice| pointers to the |start_frame| position for each channel. | 105 // Sets the |slice| pointers to the |start_frame| position for each channel. |
| 105 // Returns |slice| for convenience. | 106 // Returns |slice| for convenience. |
| 106 const T* const* Slice(T** slice, size_t start_frame) const { | 107 const T* const* Slice(T** slice, size_t start_frame) const { |
| 107 RTC_DCHECK_LT(start_frame, num_frames_); | 108 RTC_DCHECK_LT(start_frame, num_frames_); |
| 108 for (size_t i = 0; i < num_channels_; ++i) | 109 for (size_t i = 0; i < num_official_channels_; ++i) |
| 109 slice[i] = &channels_[i][start_frame]; | 110 slice[i] = &channels_[i][start_frame]; |
| 110 return slice; | 111 return slice; |
| 111 } | 112 } |
| 112 T** Slice(T** slice, size_t start_frame) { | 113 T** Slice(T** slice, size_t start_frame) { |
| 113 const ChannelBuffer<T>* t = this; | 114 const ChannelBuffer<T>* t = this; |
| 114 return const_cast<T**>(t->Slice(slice, start_frame)); | 115 return const_cast<T**>(t->Slice(slice, start_frame)); |
| 115 } | 116 } |
| 116 | 117 |
| 117 size_t num_frames() const { return num_frames_; } | 118 size_t num_frames() const { return num_frames_; } |
| 118 size_t num_frames_per_band() const { return num_frames_per_band_; } | 119 size_t num_frames_per_band() const { return num_frames_per_band_; } |
| 119 size_t num_channels() const { return num_channels_; } | 120 size_t num_channels() const { return num_official_channels_; } |
| 120 size_t num_bands() const { return num_bands_; } | 121 size_t num_bands() const { return num_bands_; } |
| 121 size_t size() const {return num_frames_ * num_channels_; } | 122 size_t size() const {return num_frames_ * num_channels_; } |
| 122 | 123 |
| 124 void set_num_channels(size_t num_channels) { | |
| 125 RTC_DCHECK_LE(num_channels, num_channels_); | |
| 126 num_official_channels_ = num_channels; | |
| 127 } | |
| 128 | |
| 123 void SetDataForTesting(const T* data, size_t size) { | 129 void SetDataForTesting(const T* data, size_t size) { |
| 124 RTC_CHECK_EQ(size, this->size()); | 130 RTC_CHECK_EQ(size, this->size()); |
| 125 memcpy(data_.get(), data, size * sizeof(*data)); | 131 memcpy(data_.get(), data, size * sizeof(*data)); |
| 126 } | 132 } |
| 127 | 133 |
| 128 private: | 134 private: |
| 129 std::unique_ptr<T[]> data_; | 135 std::unique_ptr<T[]> data_; |
| 130 std::unique_ptr<T* []> channels_; | 136 std::unique_ptr<T* []> channels_; |
| 131 std::unique_ptr<T* []> bands_; | 137 std::unique_ptr<T* []> bands_; |
| 132 const size_t num_frames_; | 138 const size_t num_frames_; |
| 133 const size_t num_frames_per_band_; | 139 const size_t num_frames_per_band_; |
| 140 // Number of channels the internal buffer holds. | |
| 134 const size_t num_channels_; | 141 const size_t num_channels_; |
| 142 // Number of channels the user sees. | |
| 143 size_t num_official_channels_; | |
| 135 const size_t num_bands_; | 144 const size_t num_bands_; |
| 136 }; | 145 }; |
| 137 | 146 |
| 138 // One int16_t and one float ChannelBuffer that are kept in sync. The sync is | 147 // One int16_t and one float ChannelBuffer that are kept in sync. The sync is |
| 139 // broken when someone requests write access to either ChannelBuffer, and | 148 // broken when someone requests write access to either ChannelBuffer, and |
| 140 // reestablished when someone requests the outdated ChannelBuffer. It is | 149 // reestablished when someone requests the outdated ChannelBuffer. It is |
| 141 // therefore safe to use the return value of ibuf_const() and fbuf_const() | 150 // therefore safe to use the return value of ibuf_const() and fbuf_const() |
| 142 // until the next call to ibuf() or fbuf(), and the return value of ibuf() and | 151 // until the next call to ibuf() or fbuf(), and the return value of ibuf() and |
| 143 // fbuf() until the next call to any of the other functions. | 152 // fbuf() until the next call to any of the other functions. |
| 144 class IFChannelBuffer { | 153 class IFChannelBuffer { |
| 145 public: | 154 public: |
| 146 IFChannelBuffer(size_t num_frames, size_t num_channels, size_t num_bands = 1); | 155 IFChannelBuffer(size_t num_frames, size_t num_channels, size_t num_bands = 1); |
| 147 | 156 |
| 148 ChannelBuffer<int16_t>* ibuf(); | 157 ChannelBuffer<int16_t>* ibuf(); |
| 149 ChannelBuffer<float>* fbuf(); | 158 ChannelBuffer<float>* fbuf(); |
| 150 const ChannelBuffer<int16_t>* ibuf_const() const; | 159 const ChannelBuffer<int16_t>* ibuf_const() const; |
| 151 const ChannelBuffer<float>* fbuf_const() const; | 160 const ChannelBuffer<float>* fbuf_const() const; |
| 152 | 161 |
| 153 size_t num_frames() const { return ibuf_.num_frames(); } | 162 size_t num_frames() const { return ibuf_.num_frames(); } |
| 154 size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); } | 163 size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); } |
| 155 size_t num_channels() const { return ibuf_.num_channels(); } | 164 size_t num_channels() const { |
| 165 return std::min(ibuf_.num_channels(), fbuf_.num_channels()); | |
| 166 } | |
| 167 void set_num_channels(size_t num_channels) { | |
| 168 ibuf_.set_num_channels(num_channels); | |
| 169 fbuf_.set_num_channels(num_channels); | |
| 170 } | |
| 156 size_t num_bands() const { return ibuf_.num_bands(); } | 171 size_t num_bands() const { return ibuf_.num_bands(); } |
| 157 | 172 |
| 158 private: | 173 private: |
| 159 void RefreshF() const; | 174 void RefreshF() const; |
| 160 void RefreshI() const; | 175 void RefreshI() const; |
| 161 | 176 |
| 162 mutable bool ivalid_; | 177 mutable bool ivalid_; |
| 163 mutable ChannelBuffer<int16_t> ibuf_; | 178 mutable ChannelBuffer<int16_t> ibuf_; |
| 164 mutable bool fvalid_; | 179 mutable bool fvalid_; |
| 165 mutable ChannelBuffer<float> fbuf_; | 180 mutable ChannelBuffer<float> fbuf_; |
| 166 }; | 181 }; |
| 167 | 182 |
| 168 } // namespace webrtc | 183 } // namespace webrtc |
| 169 | 184 |
| 170 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ | 185 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ |
| OLD | NEW |