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 12 matching lines...) Expand all Loading... |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
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/AudioUtilities.h" |
33 #include "platform/audio/HRTFDatabase.h" | 34 #include "platform/audio/HRTFDatabase.h" |
34 #include "wtf/MathExtras.h" | 35 #include "wtf/MathExtras.h" |
35 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 // The value of 2 milliseconds is larger than the largest delay which exists in
any HRTFKernel from the default HRTFDatabase (0.0136 seconds). | 40 // The value of 2 milliseconds is larger than the largest delay which exists in
any HRTFKernel from the default HRTFDatabase (0.0136 seconds). |
40 // We ASSERT the delay values used in process() with this value. | 41 // We ASSERT the delay values used in process() with this value. |
41 const double MaxDelayTimeSeconds = 0.002; | 42 const double MaxDelayTimeSeconds = 0.002; |
42 | 43 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) | 76 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) |
76 { | 77 { |
77 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra
mes @44.1KHz. | 78 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra
mes @44.1KHz. |
78 // Currently, we truncate the impulse responses to half this size, | 79 // Currently, we truncate the impulse responses to half this size, |
79 // but an FFT-size of twice impulse response size is needed (for convolution
). | 80 // but an FFT-size of twice impulse response size is needed (for convolution
). |
80 // So for sample rates around 44.1KHz an FFT size of 512 is good. | 81 // So for sample rates around 44.1KHz an FFT size of 512 is good. |
81 // For different sample rates, the truncated response is resampled. | 82 // For different sample rates, the truncated response is resampled. |
82 // The resampled length is used to compute the FFT size by choosing a power
of two that is | 83 // The resampled length is used to compute the FFT size by choosing a power
of two that is |
83 // greater than or equal the resampled length. This power of two is doubled
to get the actual FFT size. | 84 // greater than or equal the resampled length. This power of two is doubled
to get the actual FFT size. |
84 | 85 |
85 ASSERT(sampleRate >= 3000 && sampleRate <= 192000); | 86 ASSERT(AudioUtilities::isValidAudioBufferSampleRate(sampleRate)); |
86 | 87 |
87 int truncatedImpulseLength = 256; | 88 int truncatedImpulseLength = 256; |
88 double sampleRateRatio = sampleRate / 44100; | 89 double sampleRateRatio = sampleRate / 44100; |
89 double resampledLength = truncatedImpulseLength * sampleRateRatio; | 90 double resampledLength = truncatedImpulseLength * sampleRateRatio; |
90 | 91 |
91 return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); | 92 return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); |
92 } | 93 } |
93 | 94 |
94 void HRTFPanner::reset() | 95 void HRTFPanner::reset() |
95 { | 96 { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 319 |
319 void HRTFPanner::trace(Visitor* visitor) | 320 void HRTFPanner::trace(Visitor* visitor) |
320 { | 321 { |
321 visitor->trace(m_databaseLoader); | 322 visitor->trace(m_databaseLoader); |
322 Panner::trace(visitor); | 323 Panner::trace(visitor); |
323 } | 324 } |
324 | 325 |
325 } // namespace blink | 326 } // namespace blink |
326 | 327 |
327 #endif // ENABLE(WEB_AUDIO) | 328 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |