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" |
11 #include "media/base/limits.h" | 11 #include "media/base/limits.h" |
12 | 12 |
13 #if defined(OS_MACOSX) | |
no longer working on chromium
2012/09/17 20:47:46
move this above #include <limits>
| |
14 #include <CoreAudio/CoreAudioTypes.h> | |
15 #endif | |
16 | |
13 namespace media { | 17 namespace media { |
14 | 18 |
15 static bool IsAligned(void* ptr) { | 19 static bool IsAligned(void* ptr) { |
16 return (reinterpret_cast<uintptr_t>(ptr) & | 20 return (reinterpret_cast<uintptr_t>(ptr) & |
17 (AudioBus::kChannelAlignment - 1)) == 0U; | 21 (AudioBus::kChannelAlignment - 1)) == 0U; |
18 } | 22 } |
19 | 23 |
20 // Calculates the required size for an AudioBus with the given params, sets | 24 // Calculates the required size for an AudioBus with the given params, sets |
21 // |aligned_frames| to the actual frame length of each channel array. | 25 // |aligned_frames| to the actual frame length of each channel array. |
22 static int CalculateMemorySizeInternal(int channels, int frames, | 26 static int CalculateMemorySizeInternal(int channels, int frames, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) | 134 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) |
131 : channel_data_(channel_data), | 135 : channel_data_(channel_data), |
132 frames_(frames) { | 136 frames_(frames) { |
133 ValidateConfig(channel_data_.size(), frames_); | 137 ValidateConfig(channel_data_.size(), frames_); |
134 | 138 |
135 // Sanity check wrapped vector for alignment and channel count. | 139 // Sanity check wrapped vector for alignment and channel count. |
136 for (size_t i = 0; i < channel_data_.size(); ++i) | 140 for (size_t i = 0; i < channel_data_.size(); ++i) |
137 DCHECK(IsAligned(channel_data_[i])); | 141 DCHECK(IsAligned(channel_data_[i])); |
138 } | 142 } |
139 | 143 |
144 #if defined(OS_MACOSX) | |
145 AudioBus::AudioBus(int channels, int frames, AudioBufferList* buffer_list) | |
146 : frames_(frames) { | |
147 ValidateConfig(channels, frames_); | |
148 | |
149 channel_data_.reserve(channels); | |
150 | |
151 // Copy pointers from AudioBufferList. | |
152 // It's ok to pass in a |buffer_list| with fewer channels, in which | |
153 // case we just duplicate the last channel. | |
154 int source_idx = 0; | |
155 for (int i = 0; i < channels; ++i) { | |
no longer working on chromium
2012/09/17 20:47:46
we should be able to use only either source_idx or
| |
156 channel_data_.push_back( | |
157 static_cast<float*>(buffer_list->mBuffers[source_idx].mData)); | |
scherkus (not reviewing)
2012/09/17 14:51:17
it does seem that we could have this bit of code a
| |
158 DCHECK(IsAligned(channel_data_[i])); | |
159 | |
160 if (source_idx < channels - 1) | |
161 ++source_idx; | |
162 } | |
163 } | |
164 #endif | |
165 | |
140 AudioBus::~AudioBus() {} | 166 AudioBus::~AudioBus() {} |
141 | 167 |
142 scoped_ptr<AudioBus> AudioBus::Create(int channels, int frames) { | 168 scoped_ptr<AudioBus> AudioBus::Create(int channels, int frames) { |
143 return scoped_ptr<AudioBus>(new AudioBus(channels, frames)); | 169 return scoped_ptr<AudioBus>(new AudioBus(channels, frames)); |
144 } | 170 } |
145 | 171 |
146 scoped_ptr<AudioBus> AudioBus::Create(const AudioParameters& params) { | 172 scoped_ptr<AudioBus> AudioBus::Create(const AudioParameters& params) { |
147 return scoped_ptr<AudioBus>(new AudioBus( | 173 return scoped_ptr<AudioBus>(new AudioBus( |
148 params.channels(), params.frames_per_buffer())); | 174 params.channels(), params.frames_per_buffer())); |
149 } | 175 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 DCHECK_EQ(channels(), dest->channels()); | 291 DCHECK_EQ(channels(), dest->channels()); |
266 DCHECK_EQ(frames(), dest->frames()); | 292 DCHECK_EQ(frames(), dest->frames()); |
267 | 293 |
268 // Since we don't know if the other AudioBus is wrapped or not (and we don't | 294 // 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. | 295 // want to care), just copy using the public channel() accessors. |
270 for (int i = 0; i < channels(); ++i) | 296 for (int i = 0; i < channels(); ++i) |
271 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); | 297 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); |
272 } | 298 } |
273 | 299 |
274 } // namespace media | 300 } // namespace media |
OLD | NEW |