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

Unified Diff: webrtc/common_audio/channel_buffer.h

Issue 2053773002: Keep track of the user-facing number of channels in a ChannelBuffer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebasing Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_audio/BUILD.gn ('k') | webrtc/common_audio/channel_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d6661de4ff7ee8629e432f3f915cb99fe919e403 100644
--- a/webrtc/common_audio/channel_buffer.h
+++ b/webrtc/common_audio/channel_buffer.h
@@ -48,13 +48,14 @@ class ChannelBuffer {
bands_(new T*[num_channels * num_bands]),
num_frames_(num_frames),
num_frames_per_band_(num_frames / num_bands),
+ num_allocated_channels_(num_channels),
num_channels_(num_channels),
num_bands_(num_bands) {
- for (size_t i = 0; i < num_channels_; ++i) {
+ for (size_t i = 0; i < num_allocated_channels_; ++i) {
for (size_t j = 0; j < num_bands_; ++j) {
- channels_[j * num_channels_ + i] =
+ channels_[j * num_allocated_channels_ + i] =
&data_[i * num_frames_ + j * num_frames_per_band_];
- bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i];
+ bands_[i * num_bands_ + j] = channels_[j * num_allocated_channels_ + i];
}
}
}
@@ -63,7 +64,7 @@ class ChannelBuffer {
// Usage:
// channels()[channel][sample].
// Where:
- // 0 <= channel < |num_channels_|
+ // 0 <= channel < |num_allocated_channels_|
// 0 <= sample < |num_frames_|
T* const* channels() { return channels(0); }
const T* const* channels() const { return channels(0); }
@@ -73,11 +74,11 @@ class ChannelBuffer {
// channels(band)[channel][sample].
// Where:
// 0 <= band < |num_bands_|
- // 0 <= channel < |num_channels_|
+ // 0 <= channel < |num_allocated_channels_|
// 0 <= sample < |num_frames_per_band_|
const T* const* channels(size_t band) const {
RTC_DCHECK_LT(band, num_bands_);
- return &channels_[band * num_channels_];
+ return &channels_[band * num_allocated_channels_];
}
T* const* channels(size_t band) {
const ChannelBuffer<T>* t = this;
@@ -118,7 +119,12 @@ class ChannelBuffer {
size_t num_frames_per_band() const { return num_frames_per_band_; }
size_t num_channels() const { return num_channels_; }
size_t num_bands() const { return num_bands_; }
- size_t size() const {return num_frames_ * num_channels_; }
+ size_t size() const {return num_frames_ * num_allocated_channels_; }
+
+ void set_num_channels(size_t num_channels) {
+ RTC_DCHECK_LE(num_channels, num_allocated_channels_);
+ num_channels_ = num_channels;
+ }
void SetDataForTesting(const T* data, size_t size) {
RTC_CHECK_EQ(size, this->size());
@@ -131,7 +137,10 @@ class ChannelBuffer {
std::unique_ptr<T* []> bands_;
const size_t num_frames_;
const size_t num_frames_per_band_;
- const size_t num_channels_;
+ // Number of channels the internal buffer holds.
+ const size_t num_allocated_channels_;
+ // Number of channels the user sees.
+ size_t num_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 ivalid_ ? 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:
« no previous file with comments | « webrtc/common_audio/BUILD.gn ('k') | webrtc/common_audio/channel_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698