90 typedef std::vector<float, FloatAllocator> AlignedFloatVector;
93 typedef std::vector<int16, Int16Allocator> AlignedInt16Vector;
102 AudioBuffer(
size_t num_channels,
size_t num_frames);
115 size_t num_channels()
const {
return channel_views_.size(); }
118 size_t num_frames()
const {
return num_frames_; }
121 SourceId source_id()
const {
return source_id_; }
124 Channel& operator[](
size_t channel) {
125 DCHECK_LT(channel, channel_views_.size());
126 return channel_views_[channel];
130 const Channel& operator[](
size_t channel)
const {
131 DCHECK_LT(channel, channel_views_.size());
132 return channel_views_[channel];
136 AudioBuffer& operator=(
const std::vector<std::vector<float>>& other) {
137 DCHECK_EQ(other.size(), channel_views_.size());
138 for (
size_t channel = 0; channel < channel_views_.size(); ++channel) {
139 channel_views_[channel] = other[channel];
146 DCHECK_EQ(other.num_channels(), num_channels());
147 DCHECK_EQ(other.num_frames(), num_frames());
148 for (
size_t i = 0; i < channel_views_.size(); ++i)
149 channel_views_[i] += other[i];
156 DCHECK_EQ(other.num_channels(), num_channels());
157 DCHECK_EQ(other.num_frames(), num_frames());
158 for (
size_t i = 0; i < channel_views_.size(); ++i)
159 channel_views_[i] -= other[i];
165 std::vector<Channel>::iterator begin() {
return channel_views_.begin(); }
168 std::vector<Channel>::iterator end() {
return channel_views_.end(); }
171 std::vector<Channel>::const_iterator begin()
const {
172 return channel_views_.begin();
176 std::vector<Channel>::const_iterator end()
const {
177 return channel_views_.end();
182 for (
Channel& channel : channel_views_) {
183 channel.SetEnabled(
true);
191 size_t GetChannelStride()
const {
192 return FindNextAlignedArrayIndex(num_frames_,
sizeof(
float),
193 kMemoryAlignmentBytes);
197 void set_source_id(SourceId source_id) { source_id_ = source_id; }
201 void InitChannelViews(
size_t num_channels);
208 AlignedFloatVector data_;
214 std::vector<Channel> channel_views_;