Chromium Code Reviews| Index: webrtc/common_audio/channel_buffer.h |
| diff --git a/webrtc/common_audio/channel_buffer.h b/webrtc/common_audio/channel_buffer.h |
| index faecec9194ceb86be1d37104e24e7ad0a6915048..60ab0f4e6d9882d89e4dd1e9bdb3a9f500c334e5 100644 |
| --- a/webrtc/common_audio/channel_buffer.h |
| +++ b/webrtc/common_audio/channel_buffer.h |
| @@ -49,6 +49,7 @@ class ChannelBuffer { |
| num_frames_(num_frames), |
| num_frames_per_band_(num_frames / num_bands), |
| num_channels_(num_channels), |
| + num_official_channels_(num_channels), |
| num_bands_(num_bands) { |
| for (size_t i = 0; i < num_channels_; ++i) { |
| for (size_t j = 0; j < num_bands_; ++j) { |
| @@ -88,11 +89,11 @@ class ChannelBuffer { |
| // Usage: |
| // bands(channel)[band][sample]. |
| // Where: |
| - // 0 <= channel < |num_channels_| |
| + // 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.
|
| // 0 <= band < |num_bands_| |
| // 0 <= sample < |num_frames_per_band_| |
| const T* const* bands(size_t channel) const { |
| - RTC_DCHECK_LT(channel, num_channels_); |
| + RTC_DCHECK_LT(channel, num_official_channels_); |
| RTC_DCHECK_GE(channel, 0u); |
| return &bands_[channel * num_bands_]; |
| } |
| @@ -105,7 +106,7 @@ class ChannelBuffer { |
| // Returns |slice| for convenience. |
| const T* const* Slice(T** slice, size_t start_frame) const { |
| RTC_DCHECK_LT(start_frame, num_frames_); |
| - for (size_t i = 0; i < num_channels_; ++i) |
| + for (size_t i = 0; i < num_official_channels_; ++i) |
| slice[i] = &channels_[i][start_frame]; |
| return slice; |
| } |
| @@ -116,10 +117,15 @@ class ChannelBuffer { |
| size_t num_frames() const { return num_frames_; } |
| size_t num_frames_per_band() const { return num_frames_per_band_; } |
| - size_t num_channels() const { return num_channels_; } |
| + size_t num_channels() const { return num_official_channels_; } |
| size_t num_bands() const { return num_bands_; } |
| size_t size() const {return num_frames_ * num_channels_; } |
| + void set_num_channels(size_t num_channels) { |
| + RTC_DCHECK_LE(num_channels, num_channels_); |
| + num_official_channels_ = num_channels; |
| + } |
| + |
| void SetDataForTesting(const T* data, size_t size) { |
| RTC_CHECK_EQ(size, this->size()); |
| memcpy(data_.get(), data, size * sizeof(*data)); |
| @@ -131,7 +137,10 @@ class ChannelBuffer { |
| std::unique_ptr<T* []> bands_; |
| const size_t num_frames_; |
| const size_t num_frames_per_band_; |
| + // Number of channels the internal buffer holds. |
| const size_t num_channels_; |
| + // Number of channels the user sees. |
| + size_t num_official_channels_; |
| const size_t num_bands_; |
| }; |
| @@ -152,7 +161,13 @@ class IFChannelBuffer { |
| size_t num_frames() const { return ibuf_.num_frames(); } |
| size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); } |
| - size_t num_channels() const { return ibuf_.num_channels(); } |
| + size_t num_channels() const { |
| + return std::min(ibuf_.num_channels(), fbuf_.num_channels()); |
| + } |
| + void set_num_channels(size_t num_channels) { |
| + ibuf_.set_num_channels(num_channels); |
| + fbuf_.set_num_channels(num_channels); |
| + } |
| size_t num_bands() const { return ibuf_.num_bands(); } |
| private: |