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 #include "platform/audio/AudioBus.h" | 6 #include "platform/audio/AudioBus.h" |
7 #include "platform/audio/AudioUtilities.h" | 7 #include "platform/audio/AudioUtilities.h" |
8 #include "wtf/MathExtras.h" | 8 #include "wtf/MathExtras.h" |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 // Use a 50ms smoothing / de-zippering time-constant. | 11 // Use a 50ms smoothing / de-zippering time-constant. |
12 const float SmoothingTimeConstant = 0.050f; | 12 const float SmoothingTimeConstant = 0.050f; |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 // Implement equal-power panning algorithm for mono or stereo input. | 16 std::unique_ptr<StereoPanner> StereoPanner::create(float sampleRate) |
17 // See: http://webaudio.github.io/web-audio-api/#panning-algorithm | 17 { |
18 return wrapUnique(new StereoPanner(sampleRate)); | |
19 } | |
18 | 20 |
19 StereoPanner::StereoPanner(float sampleRate) : Spatializer(PanningModelEqualPowe r) | 21 StereoPanner::StereoPanner(float sampleRate) |
20 , m_isFirstRender(true) | 22 : m_isFirstRender(true) |
23 , m_smoothingConstant(AudioUtilities::discreteTimeConstantForSampleRate(Smoo thingTimeConstant, sampleRate)) | |
21 , m_pan(0.0) | 24 , m_pan(0.0) |
22 { | 25 { |
23 // Convert smoothing time (50ms) to a per-sample time value. | |
24 m_smoothingConstant = AudioUtilities::discreteTimeConstantForSampleRate(Smoo thingTimeConstant, sampleRate); | |
Raymond Toy
2016/08/24 18:30:29
I'd prefer not changing these lines.
hongchan
2016/08/24 21:52:33
Done.
| |
25 } | 26 } |
26 | 27 |
27 void StereoPanner::panWithSampleAccurateValues(const AudioBus* inputBus, AudioBu s* outputBus, const float* panValues, size_t framesToProcess) | 28 void StereoPanner::panWithSampleAccurateValues(const AudioBus* inputBus, AudioBu s* outputBus, const float* panValues, size_t framesToProcess) |
28 { | 29 { |
29 bool isInputSafe = inputBus | 30 bool isInputSafe = inputBus |
30 && (inputBus->numberOfChannels() == 1 || inputBus->numberOfChannels() == 2) | 31 && (inputBus->numberOfChannels() == 1 || inputBus->numberOfChannels() == 2) |
31 && framesToProcess <= inputBus->length(); | 32 && framesToProcess <= inputBus->length(); |
32 ASSERT(isInputSafe); | 33 ASSERT(isInputSafe); |
33 if (!isInputSafe) | 34 if (!isInputSafe) |
34 return; | 35 return; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 // When [0; 1], keep right channel intact and equal-power pan th e | 162 // When [0; 1], keep right channel intact and equal-power pan th e |
162 // left channel only. | 163 // left channel only. |
163 *destinationL++ = static_cast<float>(inputL * gainL); | 164 *destinationL++ = static_cast<float>(inputL * gainL); |
164 *destinationR++ = static_cast<float>(inputR + inputL * gainR); | 165 *destinationR++ = static_cast<float>(inputR + inputL * gainR); |
165 } | 166 } |
166 } | 167 } |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 } // namespace blink | 171 } // namespace blink |
171 | |
OLD | NEW |