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 blink { | 39 namespace blink { |
| 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 // Support sample rate from 3 kHz to 192 kHz. | |
|
Raymond Toy
2014/09/04 17:27:20
This comment seems unrelated to the following code
KhNo
2014/09/05 05:03:25
I changed logic to find correct fft size. Do not n
| |
| 49 const size_t minfftSize = 32; | |
| 50 const size_t maxfftSize = 4096; | |
| 51 const float coefficientSampleRate = 2756.25f; | |
|
Raymond Toy
2014/09/04 17:27:20
No trialing "f" required according to blink style.
KhNo
2014/09/05 05:03:25
Done.
| |
| 52 | |
| 48 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) | 53 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) |
| 49 : Panner(PanningModelHRTF) | 54 : Panner(PanningModelHRTF) |
| 50 , m_databaseLoader(databaseLoader) | 55 , m_databaseLoader(databaseLoader) |
| 51 , m_sampleRate(sampleRate) | 56 , m_sampleRate(sampleRate) |
| 52 , m_crossfadeSelection(CrossfadeSelection1) | 57 , m_crossfadeSelection(CrossfadeSelection1) |
| 53 , m_azimuthIndex1(UninitializedAzimuth) | 58 , m_azimuthIndex1(UninitializedAzimuth) |
| 54 , m_elevation1(0) | 59 , m_elevation1(0) |
| 55 , m_azimuthIndex2(UninitializedAzimuth) | 60 , m_azimuthIndex2(UninitializedAzimuth) |
| 56 , m_elevation2(0) | 61 , m_elevation2(0) |
| 57 , m_crossfadeX(0) | 62 , m_crossfadeX(0) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 | 77 |
| 73 HRTFPanner::~HRTFPanner() | 78 HRTFPanner::~HRTFPanner() |
| 74 { | 79 { |
| 75 } | 80 } |
| 76 | 81 |
| 77 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) | 82 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) |
| 78 { | 83 { |
| 79 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra mes @44.1KHz. | 84 // 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). | 85 // 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. | 86 // 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); | 87 ASSERT(sampleRate >= 3000.f && sampleRate <= 192000.f); |
|
Raymond Toy
2014/09/04 17:27:20
No ".f" allowed per blink style guide.
KhNo
2014/09/05 05:03:25
Done.
| |
| 83 return (sampleRate < 88200.0) ? 512 : 1024; | 88 |
| 89 if (sampleRate < 3000.f) | |
| 90 return minfftSize; | |
| 91 if (sampleRate > 192000.f) | |
| 92 return maxfftSize; | |
| 93 | |
| 94 int scale = floor(sampleRate / coefficientSampleRate); | |
| 95 return scale * minfftSize; | |
|
Raymond Toy
2014/09/04 17:27:20
Don't you need to make sure the returned FFT size
KhNo
2014/09/05 05:03:25
Yes, it is required. I think I missed it during up
| |
| 84 } | 96 } |
| 85 | 97 |
| 86 void HRTFPanner::reset() | 98 void HRTFPanner::reset() |
| 87 { | 99 { |
| 88 m_convolverL1.reset(); | 100 m_convolverL1.reset(); |
| 89 m_convolverR1.reset(); | 101 m_convolverR1.reset(); |
| 90 m_convolverL2.reset(); | 102 m_convolverL2.reset(); |
| 91 m_convolverR2.reset(); | 103 m_convolverR2.reset(); |
| 92 m_delayLineL.reset(); | 104 m_delayLineL.reset(); |
| 93 m_delayLineR.reset(); | 105 m_delayLineR.reset(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 double HRTFPanner::latencyTime() const | 316 double HRTFPanner::latencyTime() const |
| 305 { | 317 { |
| 306 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the | 318 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the |
| 307 // same value. | 319 // same value. |
| 308 return (fftSize() / 2) / static_cast<double>(sampleRate()); | 320 return (fftSize() / 2) / static_cast<double>(sampleRate()); |
| 309 } | 321 } |
| 310 | 322 |
| 311 } // namespace blink | 323 } // namespace blink |
| 312 | 324 |
| 313 #endif // ENABLE(WEB_AUDIO) | 325 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |