OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/audio_bus.h" | 5 #include "media/base/audio_bus.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) | 130 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) |
131 : channel_data_(channel_data), | 131 : channel_data_(channel_data), |
132 frames_(frames) { | 132 frames_(frames) { |
133 ValidateConfig(channel_data_.size(), frames_); | 133 ValidateConfig(channel_data_.size(), frames_); |
134 | 134 |
135 // Sanity check wrapped vector for alignment and channel count. | 135 // Sanity check wrapped vector for alignment and channel count. |
136 for (size_t i = 0; i < channel_data_.size(); ++i) | 136 for (size_t i = 0; i < channel_data_.size(); ++i) |
137 DCHECK(IsAligned(channel_data_[i])); | 137 DCHECK(IsAligned(channel_data_[i])); |
138 } | 138 } |
139 | 139 |
140 AudioBus::AudioBus(int channels) | |
141 : channel_data_(channels), | |
142 frames_(0) { | |
143 for (size_t i = 0; i < channel_data_.size(); ++i) | |
144 channel_data_[i] = NULL; | |
145 } | |
146 | |
140 AudioBus::~AudioBus() {} | 147 AudioBus::~AudioBus() {} |
141 | 148 |
142 scoped_ptr<AudioBus> AudioBus::Create(int channels, int frames) { | 149 scoped_ptr<AudioBus> AudioBus::Create(int channels, int frames) { |
143 return scoped_ptr<AudioBus>(new AudioBus(channels, frames)); | 150 return scoped_ptr<AudioBus>(new AudioBus(channels, frames)); |
144 } | 151 } |
145 | 152 |
146 scoped_ptr<AudioBus> AudioBus::Create(const AudioParameters& params) { | 153 scoped_ptr<AudioBus> AudioBus::Create(const AudioParameters& params) { |
147 return scoped_ptr<AudioBus>(new AudioBus( | 154 return scoped_ptr<AudioBus>(new AudioBus( |
148 params.channels(), params.frames_per_buffer())); | 155 params.channels(), params.frames_per_buffer())); |
149 } | 156 } |
150 | 157 |
158 scoped_ptr<AudioBus> AudioBus::Create(int channels) { | |
159 return scoped_ptr<AudioBus>(new AudioBus(channels)); | |
160 } | |
161 | |
151 scoped_ptr<AudioBus> AudioBus::WrapVector( | 162 scoped_ptr<AudioBus> AudioBus::WrapVector( |
152 int frames, const std::vector<float*>& channel_data) { | 163 int frames, const std::vector<float*>& channel_data) { |
153 return scoped_ptr<AudioBus>(new AudioBus(frames, channel_data)); | 164 return scoped_ptr<AudioBus>(new AudioBus(frames, channel_data)); |
154 } | 165 } |
155 | 166 |
156 scoped_ptr<AudioBus> AudioBus::WrapMemory(int channels, int frames, | 167 scoped_ptr<AudioBus> AudioBus::WrapMemory(int channels, int frames, |
157 void* data) { | 168 void* data) { |
158 // |data| must be aligned by AudioBus::kChannelAlignment. | 169 // |data| must be aligned by AudioBus::kChannelAlignment. |
159 CHECK(IsAligned(data)); | 170 CHECK(IsAligned(data)); |
160 return scoped_ptr<AudioBus>(new AudioBus( | 171 return scoped_ptr<AudioBus>(new AudioBus( |
161 channels, frames, static_cast<float*>(data))); | 172 channels, frames, static_cast<float*>(data))); |
162 } | 173 } |
163 | 174 |
164 scoped_ptr<AudioBus> AudioBus::WrapMemory(const AudioParameters& params, | 175 scoped_ptr<AudioBus> AudioBus::WrapMemory(const AudioParameters& params, |
165 void* data) { | 176 void* data) { |
166 // |data| must be aligned by AudioBus::kChannelAlignment. | 177 // |data| must be aligned by AudioBus::kChannelAlignment. |
167 CHECK(IsAligned(data)); | 178 CHECK(IsAligned(data)); |
168 return scoped_ptr<AudioBus>(new AudioBus( | 179 return scoped_ptr<AudioBus>(new AudioBus( |
169 params.channels(), params.frames_per_buffer(), | 180 params.channels(), params.frames_per_buffer(), |
170 static_cast<float*>(data))); | 181 static_cast<float*>(data))); |
171 } | 182 } |
172 | 183 |
184 void AudioBus::SetChannelData(int channel, float* data) { | |
DaleCurtis
2012/09/17 21:17:36
This can lead to some pretty confusing situations:
Chris Rogers
2012/09/17 22:00:42
We can discuss offline...
| |
185 CHECK_GE(channel, 0); | |
186 CHECK_LT(static_cast<size_t>(channel), channel_data_.size()); | |
187 DCHECK(IsAligned(data)); | |
188 channel_data_[channel] = data; | |
189 } | |
190 | |
173 void AudioBus::ZeroFramesPartial(int start_frame, int frames) { | 191 void AudioBus::ZeroFramesPartial(int start_frame, int frames) { |
174 CheckOverflow(start_frame, frames, frames_); | 192 CheckOverflow(start_frame, frames, frames_); |
175 | 193 |
176 if (frames <= 0) | 194 if (frames <= 0) |
177 return; | 195 return; |
178 | 196 |
179 for (size_t i = 0; i < channel_data_.size(); ++i) { | 197 for (size_t i = 0; i < channel_data_.size(); ++i) { |
180 memset(channel_data_[i] + start_frame, 0, | 198 memset(channel_data_[i] + start_frame, 0, |
181 frames * sizeof(*channel_data_[i])); | 199 frames * sizeof(*channel_data_[i])); |
182 } | 200 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 DCHECK_EQ(channels(), dest->channels()); | 283 DCHECK_EQ(channels(), dest->channels()); |
266 DCHECK_EQ(frames(), dest->frames()); | 284 DCHECK_EQ(frames(), dest->frames()); |
267 | 285 |
268 // Since we don't know if the other AudioBus is wrapped or not (and we don't | 286 // Since we don't know if the other AudioBus is wrapped or not (and we don't |
269 // want to care), just copy using the public channel() accessors. | 287 // want to care), just copy using the public channel() accessors. |
270 for (int i = 0; i < channels(); ++i) | 288 for (int i = 0; i < channels(); ++i) |
271 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); | 289 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); |
272 } | 290 } |
273 | 291 |
274 } // namespace media | 292 } // namespace media |
OLD | NEW |