OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 16 matching lines...) Expand all Loading... |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "platform/audio/HRTFPanner.h" | 29 #include "platform/audio/HRTFPanner.h" |
30 | 30 |
31 #include <algorithm> | 31 #include <algorithm> |
32 #include "platform/audio/AudioBus.h" | 32 #include "platform/audio/AudioBus.h" |
33 #include "platform/audio/HRTFDatabase.h" | 33 #include "platform/audio/HRTFDatabase.h" |
34 #include "wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
35 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
36 | 36 |
37 using namespace std; | |
38 | |
39 namespace blink { | 37 namespace blink { |
40 | 38 |
41 // The value of 2 milliseconds is larger than the largest delay which exists in
any HRTFKernel from the default HRTFDatabase (0.0136 seconds). | 39 // The value of 2 milliseconds is larger than the largest delay which exists in
any HRTFKernel from the default HRTFDatabase (0.0136 seconds). |
42 // We ASSERT the delay values used in process() with this value. | 40 // We ASSERT the delay values used in process() with this value. |
43 const double MaxDelayTimeSeconds = 0.002; | 41 const double MaxDelayTimeSeconds = 0.002; |
44 | 42 |
45 const int UninitializedAzimuth = -1; | 43 const int UninitializedAzimuth = -1; |
46 const unsigned RenderingQuantum = 128; | 44 const unsigned RenderingQuantum = 128; |
47 | 45 |
48 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) | 46 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 int numberOfAzimuths = database->numberOfAzimuths(); | 104 int numberOfAzimuths = database->numberOfAzimuths(); |
107 const double angleBetweenAzimuths = 360.0 / numberOfAzimuths; | 105 const double angleBetweenAzimuths = 360.0 / numberOfAzimuths; |
108 | 106 |
109 // Calculate the azimuth index and the blend (0 -> 1) for interpolation. | 107 // Calculate the azimuth index and the blend (0 -> 1) for interpolation. |
110 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; | 108 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; |
111 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat); | 109 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat); |
112 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth
Index); | 110 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth
Index); |
113 | 111 |
114 // We don't immediately start using this azimuth index, but instead approach
this index from the last index we rendered at. | 112 // We don't immediately start using this azimuth index, but instead approach
this index from the last index we rendered at. |
115 // This minimizes the clicks and graininess for moving sources which occur o
therwise. | 113 // This minimizes the clicks and graininess for moving sources which occur o
therwise. |
116 desiredAzimuthIndex = max(0, desiredAzimuthIndex); | 114 desiredAzimuthIndex = std::max(0, desiredAzimuthIndex); |
117 desiredAzimuthIndex = min(numberOfAzimuths - 1, desiredAzimuthIndex); | 115 desiredAzimuthIndex = std::min(numberOfAzimuths - 1, desiredAzimuthIndex); |
118 return desiredAzimuthIndex; | 116 return desiredAzimuthIndex; |
119 } | 117 } |
120 | 118 |
121 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in
putBus, AudioBus* outputBus, size_t framesToProcess) | 119 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in
putBus, AudioBus* outputBus, size_t framesToProcess) |
122 { | 120 { |
123 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; | 121 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; |
124 | 122 |
125 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <=
2; | 123 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <=
2; |
126 ASSERT(isInputGood); | 124 ASSERT(isInputGood); |
127 | 125 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 double HRTFPanner::latencyTime() const | 302 double HRTFPanner::latencyTime() const |
305 { | 303 { |
306 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t
o its tailTime of the | 304 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t
o its tailTime of the |
307 // same value. | 305 // same value. |
308 return (fftSize() / 2) / static_cast<double>(sampleRate()); | 306 return (fftSize() / 2) / static_cast<double>(sampleRate()); |
309 } | 307 } |
310 | 308 |
311 } // namespace blink | 309 } // namespace blink |
312 | 310 |
313 #endif // ENABLE(WEB_AUDIO) | 311 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |