| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 : Panner(PanningModelHRTF) | 47 : Panner(PanningModelHRTF) |
| 48 , m_databaseLoader(databaseLoader) | 48 , m_databaseLoader(databaseLoader) |
| 49 , m_sampleRate(sampleRate) | 49 , m_sampleRate(sampleRate) |
| 50 , m_crossfadeSelection(CrossfadeSelection1) | 50 , m_crossfadeSelection(CrossfadeSelection1) |
| 51 , m_azimuthIndex1(UninitializedAzimuth) | 51 , m_azimuthIndex1(UninitializedAzimuth) |
| 52 , m_elevation1(0) | 52 , m_elevation1(0) |
| 53 , m_azimuthIndex2(UninitializedAzimuth) | 53 , m_azimuthIndex2(UninitializedAzimuth) |
| 54 , m_elevation2(0) | 54 , m_elevation2(0) |
| 55 , m_crossfadeX(0) | 55 , m_crossfadeX(0) |
| 56 , m_crossfadeIncr(0) | 56 , m_crossfadeIncr(0) |
| 57 , m_convolverL1(fftSizeForSampleRate(sampleRate)) | 57 , m_convolverL1(AudioUtilities::fftSizeForSampleRate(sampleRate)) |
| 58 , m_convolverR1(fftSizeForSampleRate(sampleRate)) | 58 , m_convolverR1(AudioUtilities::fftSizeForSampleRate(sampleRate)) |
| 59 , m_convolverL2(fftSizeForSampleRate(sampleRate)) | 59 , m_convolverL2(AudioUtilities::fftSizeForSampleRate(sampleRate)) |
| 60 , m_convolverR2(fftSizeForSampleRate(sampleRate)) | 60 , m_convolverR2(AudioUtilities::fftSizeForSampleRate(sampleRate)) |
| 61 , m_delayLineL(MaxDelayTimeSeconds, sampleRate) | 61 , m_delayLineL(MaxDelayTimeSeconds, sampleRate) |
| 62 , m_delayLineR(MaxDelayTimeSeconds, sampleRate) | 62 , m_delayLineR(MaxDelayTimeSeconds, sampleRate) |
| 63 , m_tempL1(RenderingQuantum) | 63 , m_tempL1(RenderingQuantum) |
| 64 , m_tempR1(RenderingQuantum) | 64 , m_tempR1(RenderingQuantum) |
| 65 , m_tempL2(RenderingQuantum) | 65 , m_tempL2(RenderingQuantum) |
| 66 , m_tempR2(RenderingQuantum) | 66 , m_tempR2(RenderingQuantum) |
| 67 { | 67 { |
| 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) | |
| 76 { | |
| 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, | |
| 79 // 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 // 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))); | |
| 92 } | |
| 93 | |
| 94 void HRTFPanner::reset() | 75 void HRTFPanner::reset() |
| 95 { | 76 { |
| 96 m_convolverL1.reset(); | 77 m_convolverL1.reset(); |
| 97 m_convolverR1.reset(); | 78 m_convolverR1.reset(); |
| 98 m_convolverL2.reset(); | 79 m_convolverL2.reset(); |
| 99 m_convolverR2.reset(); | 80 m_convolverR2.reset(); |
| 100 m_delayLineL.reset(); | 81 m_delayLineL.reset(); |
| 101 m_delayLineR.reset(); | 82 m_delayLineR.reset(); |
| 102 } | 83 } |
| 103 | 84 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 299 |
| 319 void HRTFPanner::trace(Visitor* visitor) | 300 void HRTFPanner::trace(Visitor* visitor) |
| 320 { | 301 { |
| 321 visitor->trace(m_databaseLoader); | 302 visitor->trace(m_databaseLoader); |
| 322 Panner::trace(visitor); | 303 Panner::trace(visitor); |
| 323 } | 304 } |
| 324 | 305 |
| 325 } // namespace blink | 306 } // namespace blink |
| 326 | 307 |
| 327 #endif // ENABLE(WEB_AUDIO) | 308 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |