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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/safe_numerics.h" | 8 #include "base/numerics/safe_conversions.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
11 #include "media/base/vector_math.h" | 11 #include "media/base/vector_math.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 static const uint8 kUint8Bias = 128; | 15 static const uint8 kUint8Bias = 128; |
16 | 16 |
17 static bool IsAligned(void* ptr) { | 17 static bool IsAligned(void* ptr) { |
18 return (reinterpret_cast<uintptr_t>(ptr) & | 18 return (reinterpret_cast<uintptr_t>(ptr) & |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 CalculateMemorySizeInternal(channels, frames, &aligned_frames); | 123 CalculateMemorySizeInternal(channels, frames, &aligned_frames); |
124 | 124 |
125 BuildChannelData(channels, aligned_frames, data); | 125 BuildChannelData(channels, aligned_frames, data); |
126 } | 126 } |
127 | 127 |
128 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) | 128 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) |
129 : channel_data_(channel_data), | 129 : channel_data_(channel_data), |
130 frames_(frames), | 130 frames_(frames), |
131 can_set_channel_data_(false) { | 131 can_set_channel_data_(false) { |
132 ValidateConfig( | 132 ValidateConfig( |
133 base::checked_numeric_cast<int>(channel_data_.size()), frames_); | 133 base::checked_cast<int>(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) | 140 AudioBus::AudioBus(int channels) |
141 : channel_data_(channels), | 141 : channel_data_(channels), |
142 frames_(0), | 142 frames_(0), |
143 can_set_channel_data_(true) { | 143 can_set_channel_data_(true) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 void AudioBus::Scale(float volume) { | 327 void AudioBus::Scale(float volume) { |
328 if (volume > 0 && volume != 1) { | 328 if (volume > 0 && volume != 1) { |
329 for (int i = 0; i < channels(); ++i) | 329 for (int i = 0; i < channels(); ++i) |
330 vector_math::FMUL(channel(i), volume, frames(), channel(i)); | 330 vector_math::FMUL(channel(i), volume, frames(), channel(i)); |
331 } else if (volume == 0) { | 331 } else if (volume == 0) { |
332 Zero(); | 332 Zero(); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 } // namespace media | 336 } // namespace media |
OLD | NEW |