| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "platform/audio/StereoPanner.h" | 5 #include "platform/audio/StereoPanner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "platform/audio/AudioBus.h" | 8 #include "platform/audio/AudioBus.h" |
| 9 #include "platform/audio/AudioUtilities.h" | 9 #include "platform/audio/AudioUtilities.h" |
| 10 #include "platform/wtf/MathExtras.h" | 10 #include "platform/wtf/MathExtras.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 SmoothingTimeConstant, sampleRate); | 28 SmoothingTimeConstant, sampleRate); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void StereoPanner::panWithSampleAccurateValues(const AudioBus* inputBus, | 31 void StereoPanner::panWithSampleAccurateValues(const AudioBus* inputBus, |
| 32 AudioBus* outputBus, | 32 AudioBus* outputBus, |
| 33 const float* panValues, | 33 const float* panValues, |
| 34 size_t framesToProcess) { | 34 size_t framesToProcess) { |
| 35 bool isInputSafe = inputBus && (inputBus->numberOfChannels() == 1 || | 35 bool isInputSafe = inputBus && (inputBus->numberOfChannels() == 1 || |
| 36 inputBus->numberOfChannels() == 2) && | 36 inputBus->numberOfChannels() == 2) && |
| 37 framesToProcess <= inputBus->length(); | 37 framesToProcess <= inputBus->length(); |
| 38 ASSERT(isInputSafe); | 38 DCHECK(isInputSafe); |
| 39 if (!isInputSafe) | 39 if (!isInputSafe) |
| 40 return; | 40 return; |
| 41 | 41 |
| 42 unsigned numberOfInputChannels = inputBus->numberOfChannels(); | 42 unsigned numberOfInputChannels = inputBus->numberOfChannels(); |
| 43 | 43 |
| 44 bool isOutputSafe = outputBus && outputBus->numberOfChannels() == 2 && | 44 bool isOutputSafe = outputBus && outputBus->numberOfChannels() == 2 && |
| 45 framesToProcess <= outputBus->length(); | 45 framesToProcess <= outputBus->length(); |
| 46 ASSERT(isOutputSafe); | 46 DCHECK(isOutputSafe); |
| 47 if (!isOutputSafe) | 47 if (!isOutputSafe) |
| 48 return; | 48 return; |
| 49 | 49 |
| 50 const float* sourceL = inputBus->channel(0)->data(); | 50 const float* sourceL = inputBus->channel(0)->data(); |
| 51 const float* sourceR = | 51 const float* sourceR = |
| 52 numberOfInputChannels > 1 ? inputBus->channel(1)->data() : sourceL; | 52 numberOfInputChannels > 1 ? inputBus->channel(1)->data() : sourceL; |
| 53 float* destinationL = | 53 float* destinationL = |
| 54 outputBus->channelByType(AudioBus::ChannelLeft)->mutableData(); | 54 outputBus->channelByType(AudioBus::ChannelLeft)->mutableData(); |
| 55 float* destinationR = | 55 float* destinationR = |
| 56 outputBus->channelByType(AudioBus::ChannelRight)->mutableData(); | 56 outputBus->channelByType(AudioBus::ChannelRight)->mutableData(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void StereoPanner::panToTargetValue(const AudioBus* inputBus, | 96 void StereoPanner::panToTargetValue(const AudioBus* inputBus, |
| 97 AudioBus* outputBus, | 97 AudioBus* outputBus, |
| 98 float panValue, | 98 float panValue, |
| 99 size_t framesToProcess) { | 99 size_t framesToProcess) { |
| 100 bool isInputSafe = inputBus && (inputBus->numberOfChannels() == 1 || | 100 bool isInputSafe = inputBus && (inputBus->numberOfChannels() == 1 || |
| 101 inputBus->numberOfChannels() == 2) && | 101 inputBus->numberOfChannels() == 2) && |
| 102 framesToProcess <= inputBus->length(); | 102 framesToProcess <= inputBus->length(); |
| 103 ASSERT(isInputSafe); | 103 DCHECK(isInputSafe); |
| 104 if (!isInputSafe) | 104 if (!isInputSafe) |
| 105 return; | 105 return; |
| 106 | 106 |
| 107 unsigned numberOfInputChannels = inputBus->numberOfChannels(); | 107 unsigned numberOfInputChannels = inputBus->numberOfChannels(); |
| 108 | 108 |
| 109 bool isOutputSafe = outputBus && outputBus->numberOfChannels() == 2 && | 109 bool isOutputSafe = outputBus && outputBus->numberOfChannels() == 2 && |
| 110 framesToProcess <= outputBus->length(); | 110 framesToProcess <= outputBus->length(); |
| 111 ASSERT(isOutputSafe); | 111 DCHECK(isOutputSafe); |
| 112 if (!isOutputSafe) | 112 if (!isOutputSafe) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 const float* sourceL = inputBus->channel(0)->data(); | 115 const float* sourceL = inputBus->channel(0)->data(); |
| 116 const float* sourceR = | 116 const float* sourceR = |
| 117 numberOfInputChannels > 1 ? inputBus->channel(1)->data() : sourceL; | 117 numberOfInputChannels > 1 ? inputBus->channel(1)->data() : sourceL; |
| 118 float* destinationL = | 118 float* destinationL = |
| 119 outputBus->channelByType(AudioBus::ChannelLeft)->mutableData(); | 119 outputBus->channelByType(AudioBus::ChannelLeft)->mutableData(); |
| 120 float* destinationR = | 120 float* destinationR = |
| 121 outputBus->channelByType(AudioBus::ChannelRight)->mutableData(); | 121 outputBus->channelByType(AudioBus::ChannelRight)->mutableData(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // When [0; 1], keep right channel intact and equal-power pan the | 173 // When [0; 1], keep right channel intact and equal-power pan the |
| 174 // left channel only. | 174 // left channel only. |
| 175 *destinationL++ = static_cast<float>(inputL * gainL); | 175 *destinationL++ = static_cast<float>(inputL * gainL); |
| 176 *destinationR++ = static_cast<float>(inputR + inputL * gainR); | 176 *destinationR++ = static_cast<float>(inputR + inputL * gainR); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |