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 #include "media/base/vector_math.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 static bool IsAligned(void* ptr) { | 16 static bool IsAligned(void* ptr) { |
16 return (reinterpret_cast<uintptr_t>(ptr) & | 17 return (reinterpret_cast<uintptr_t>(ptr) & |
17 (AudioBus::kChannelAlignment - 1)) == 0U; | 18 (AudioBus::kChannelAlignment - 1)) == 0U; |
18 } | 19 } |
19 | 20 |
20 // Calculates the required size for an AudioBus with the given params, sets | 21 // Calculates the required size for an AudioBus with the given params, sets |
21 // |aligned_frames| to the actual frame length of each channel array. | 22 // |aligned_frames| to the actual frame length of each channel array. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 void AudioBus::CopyTo(AudioBus* dest) const { | 301 void AudioBus::CopyTo(AudioBus* dest) const { |
301 CHECK_EQ(channels(), dest->channels()); | 302 CHECK_EQ(channels(), dest->channels()); |
302 CHECK_EQ(frames(), dest->frames()); | 303 CHECK_EQ(frames(), dest->frames()); |
303 | 304 |
304 // Since we don't know if the other AudioBus is wrapped or not (and we don't | 305 // Since we don't know if the other AudioBus is wrapped or not (and we don't |
305 // want to care), just copy using the public channel() accessors. | 306 // want to care), just copy using the public channel() accessors. |
306 for (int i = 0; i < channels(); ++i) | 307 for (int i = 0; i < channels(); ++i) |
307 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); | 308 memcpy(dest->channel(i), channel(i), sizeof(*channel(i)) * frames()); |
308 } | 309 } |
309 | 310 |
| 311 void AudioBus::Scale(float volume) { |
| 312 if (volume > 0 && volume != 1) { |
| 313 for (int i = 0; i < channels(); ++i) |
| 314 vector_math::FMUL(channel(i), volume, frames(), channel(i)); |
| 315 } else if (volume == 0) { |
| 316 Zero(); |
| 317 } |
| 318 } |
| 319 |
310 } // namespace media | 320 } // namespace media |
OLD | NEW |