Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 // The value of 2 milliseconds is larger than the largest delay which exists in any HRTFKernel from the default HRTFDatabase (0.0136 seconds). | 41 // 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. | 42 // We ASSERT the delay values used in process() with this value. |
| 43 const double MaxDelayTimeSeconds = 0.002; | 43 const double MaxDelayTimeSeconds = 0.002; |
| 44 | 44 |
| 45 const int UninitializedAzimuth = -1; | 45 const int UninitializedAzimuth = -1; |
| 46 const unsigned RenderingQuantum = 128; | 46 const unsigned RenderingQuantum = 128; |
| 47 | 47 |
| 48 const float coefficientSampleRate = 11025.f; | |
|
Raymond Toy
2014/07/30 16:49:38
Where does 11025 come from? I thought the HRTF dat
KhNo
2014/07/31 16:45:54
This value is just determined to calculate fftsize
Raymond Toy
2014/07/31 17:25:13
Might be better to split this into two parts. One
| |
| 49 const size_t minimumFFTSize = 128; | |
| 50 const size_t maximumFFTSize = 1024; | |
| 51 | |
| 48 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) | 52 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) |
| 49 : Panner(PanningModelHRTF) | 53 : Panner(PanningModelHRTF) |
| 50 , m_databaseLoader(databaseLoader) | 54 , m_databaseLoader(databaseLoader) |
| 51 , m_sampleRate(sampleRate) | 55 , m_sampleRate(sampleRate) |
| 52 , m_crossfadeSelection(CrossfadeSelection1) | 56 , m_crossfadeSelection(CrossfadeSelection1) |
| 53 , m_azimuthIndex1(UninitializedAzimuth) | 57 , m_azimuthIndex1(UninitializedAzimuth) |
| 54 , m_elevation1(0) | 58 , m_elevation1(0) |
| 55 , m_azimuthIndex2(UninitializedAzimuth) | 59 , m_azimuthIndex2(UninitializedAzimuth) |
| 56 , m_elevation2(0) | 60 , m_elevation2(0) |
| 57 , m_crossfadeX(0) | 61 , m_crossfadeX(0) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 | 76 |
| 73 HRTFPanner::~HRTFPanner() | 77 HRTFPanner::~HRTFPanner() |
| 74 { | 78 { |
| 75 } | 79 } |
| 76 | 80 |
| 77 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) | 81 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) |
| 78 { | 82 { |
| 79 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra mes @44.1KHz. | 83 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra mes @44.1KHz. |
| 80 // Currently, we truncate the impulse responses to half this size, but an FF T-size of twice impulse response size is needed (for convolution). | 84 // Currently, we truncate the impulse responses to half this size, but an FF T-size of twice impulse response size is needed (for convolution). |
| 81 // 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. | 85 // 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. |
| 82 ASSERT(sampleRate >= 44100 && sampleRate <= 96000.0); | 86 ASSERT(sampleRate >= 8000 && sampleRate <= 96000.0); |
| 83 return (sampleRate < 88200.0) ? 512 : 1024; | 87 |
| 88 size_t fftSize = minimumFFTSize; | |
|
Raymond Toy
2014/07/30 16:49:38
This initial value seems useless since you give ff
KhNo
2014/07/31 16:45:54
Done.
| |
| 89 fftSize = floor(sampleRate / coefficientSampleRate) * minimumFFTSize; | |
| 90 fftSize = max(minimumFFTSize, fftSize); | |
| 91 fftSize = min(maximumFFTSize, fftSize); | |
| 92 return fftSize; | |
|
Raymond Toy
2014/07/30 16:49:38
If we expand the sample rate to 192 kHz, will this
KhNo
2014/07/31 16:45:54
Yes, it can be. kMaxFFTPow2Size is 15 for Android,
Raymond Toy
2014/07/31 17:25:13
One other thing. Don't we need to make fftSize a p
| |
| 84 } | 93 } |
| 85 | 94 |
| 86 void HRTFPanner::reset() | 95 void HRTFPanner::reset() |
| 87 { | 96 { |
| 88 m_convolverL1.reset(); | 97 m_convolverL1.reset(); |
| 89 m_convolverR1.reset(); | 98 m_convolverR1.reset(); |
| 90 m_convolverL2.reset(); | 99 m_convolverL2.reset(); |
| 91 m_convolverR2.reset(); | 100 m_convolverR2.reset(); |
| 92 m_delayLineL.reset(); | 101 m_delayLineL.reset(); |
| 93 m_delayLineR.reset(); | 102 m_delayLineR.reset(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 double HRTFPanner::latencyTime() const | 313 double HRTFPanner::latencyTime() const |
| 305 { | 314 { |
| 306 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the | 315 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the |
| 307 // same value. | 316 // same value. |
| 308 return (fftSize() / 2) / static_cast<double>(sampleRate()); | 317 return (fftSize() / 2) / static_cast<double>(sampleRate()); |
| 309 } | 318 } |
| 310 | 319 |
| 311 } // namespace WebCore | 320 } // namespace WebCore |
| 312 | 321 |
| 313 #endif // ENABLE(WEB_AUDIO) | 322 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |