| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ASSERT(databaseLoader); | 68 ASSERT(databaseLoader); |
| 69 } | 69 } |
| 70 | 70 |
| 71 HRTFPanner::~HRTFPanner() | 71 HRTFPanner::~HRTFPanner() |
| 72 { | 72 { |
| 73 } | 73 } |
| 74 | 74 |
| 75 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) | 75 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) |
| 76 { | 76 { |
| 77 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra
mes @44.1KHz. | 77 // 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, but an FF
T-size of twice impulse response size is needed (for convolution). | 78 // Currently, we truncate the impulse responses to half this size, |
| 79 // So for sample rates around 44.1KHz an FFT size of 512 is good. We double
the FFT-size only for sample rates at least double this. | 79 // but an FFT-size of twice impulse response size is needed (for convolution
). |
| 80 ASSERT(sampleRate >= 44100 && sampleRate <= 96000.0); | 80 // So for sample rates around 44.1KHz an FFT size of 512 is good. |
| 81 return (sampleRate < 88200.0) ? 512 : 1024; | 81 // 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 // greater than or equal the resampled length. This power of two is doubled
to get the actual FFT size. |
| 84 |
| 85 ASSERT(sampleRate >= 3000 && sampleRate <= 192000); |
| 86 |
| 87 int truncatedImpulseLength = 256; |
| 88 double sampleRateRatio = sampleRate / 44100; |
| 89 double resampledLength = truncatedImpulseLength * sampleRateRatio; |
| 90 |
| 91 return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); |
| 82 } | 92 } |
| 83 | 93 |
| 84 void HRTFPanner::reset() | 94 void HRTFPanner::reset() |
| 85 { | 95 { |
| 86 m_convolverL1.reset(); | 96 m_convolverL1.reset(); |
| 87 m_convolverR1.reset(); | 97 m_convolverR1.reset(); |
| 88 m_convolverL2.reset(); | 98 m_convolverL2.reset(); |
| 89 m_convolverR2.reset(); | 99 m_convolverR2.reset(); |
| 90 m_delayLineL.reset(); | 100 m_delayLineL.reset(); |
| 91 m_delayLineR.reset(); | 101 m_delayLineR.reset(); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 318 |
| 309 void HRTFPanner::trace(Visitor* visitor) | 319 void HRTFPanner::trace(Visitor* visitor) |
| 310 { | 320 { |
| 311 visitor->trace(m_databaseLoader); | 321 visitor->trace(m_databaseLoader); |
| 312 Panner::trace(visitor); | 322 Panner::trace(visitor); |
| 313 } | 323 } |
| 314 | 324 |
| 315 } // namespace blink | 325 } // namespace blink |
| 316 | 326 |
| 317 #endif // ENABLE(WEB_AUDIO) | 327 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |