This change adds a Block class to reduce the need for std::vector<std::vector<std::vector<float>>>. This make the code easier to read and less error prone. It also enables future changes to the underlying data structure of a block. For instance, the data of all bands and channels could be stored in a single vector. The change has been verified to be bit-exact. Bug: webrtc:14089 Change-Id: Ied9a78124c0bbafe0e912017aef91f7c311de2ae Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262252 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36968}
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AEC3_BLOCK_H_
|
|
#define MODULES_AUDIO_PROCESSING_AEC3_BLOCK_H_
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
|
|
#include "api/array_view.h"
|
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class Block {
|
|
public:
|
|
Block(int num_bands, int num_channels, float default_value = 0.0f)
|
|
: data_(num_bands,
|
|
std::vector<std::array<float, kBlockSize>>(
|
|
num_channels,
|
|
std::array<float, kBlockSize>({default_value}))) {}
|
|
|
|
// Returns the number of bands.
|
|
int NumBands() const { return data_.size(); }
|
|
|
|
// Returns the number of channels.
|
|
int NumChannels() const { return data_[0].size(); }
|
|
|
|
// Modifies the number of channels.
|
|
void SetNumChannels(int num_channels) {
|
|
for (std::vector<std::array<float, kBlockSize>>& block_band : data_) {
|
|
block_band.resize(num_channels, std::array<float, kBlockSize>({0.0f}));
|
|
}
|
|
}
|
|
|
|
// Iterators for accessing the data.
|
|
auto begin(int band, int channel) { return data_[band][channel].begin(); }
|
|
|
|
auto begin(int band, int channel) const {
|
|
return data_[band][channel].begin();
|
|
}
|
|
|
|
auto end(int band, int channel) { return data_[band][channel].end(); }
|
|
|
|
auto end(int band, int channel) const { return data_[band][channel].end(); }
|
|
|
|
// Access data via ArrayView.
|
|
rtc::ArrayView<float, kBlockSize> View(int band, int channel) {
|
|
return rtc::ArrayView<float, kBlockSize>(data_[band][channel].data(),
|
|
kBlockSize);
|
|
}
|
|
|
|
rtc::ArrayView<const float, kBlockSize> View(int band, int channel) const {
|
|
return rtc::ArrayView<const float, kBlockSize>(data_[band][channel].data(),
|
|
kBlockSize);
|
|
}
|
|
|
|
// Lets two Blocks swap audio data.
|
|
void Swap(Block& b) { data_.swap(b.data_); }
|
|
|
|
private:
|
|
std::vector<std::vector<std::array<float, kBlockSize>>> data_;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
#endif // MODULES_AUDIO_PROCESSING_AEC3_BLOCK_H_
|