| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 m_convolverL1(fftSizeForSampleRate(sampleRate)), | 53 m_convolverL1(fftSizeForSampleRate(sampleRate)), |
| 54 m_convolverR1(fftSizeForSampleRate(sampleRate)), | 54 m_convolverR1(fftSizeForSampleRate(sampleRate)), |
| 55 m_convolverL2(fftSizeForSampleRate(sampleRate)), | 55 m_convolverL2(fftSizeForSampleRate(sampleRate)), |
| 56 m_convolverR2(fftSizeForSampleRate(sampleRate)), | 56 m_convolverR2(fftSizeForSampleRate(sampleRate)), |
| 57 m_delayLineL(MaxDelayTimeSeconds, sampleRate), | 57 m_delayLineL(MaxDelayTimeSeconds, sampleRate), |
| 58 m_delayLineR(MaxDelayTimeSeconds, sampleRate), | 58 m_delayLineR(MaxDelayTimeSeconds, sampleRate), |
| 59 m_tempL1(AudioUtilities::kRenderQuantumFrames), | 59 m_tempL1(AudioUtilities::kRenderQuantumFrames), |
| 60 m_tempR1(AudioUtilities::kRenderQuantumFrames), | 60 m_tempR1(AudioUtilities::kRenderQuantumFrames), |
| 61 m_tempL2(AudioUtilities::kRenderQuantumFrames), | 61 m_tempL2(AudioUtilities::kRenderQuantumFrames), |
| 62 m_tempR2(AudioUtilities::kRenderQuantumFrames) { | 62 m_tempR2(AudioUtilities::kRenderQuantumFrames) { |
| 63 ASSERT(databaseLoader); | 63 DCHECK(databaseLoader); |
| 64 } | 64 } |
| 65 | 65 |
| 66 HRTFPanner::~HRTFPanner() {} | 66 HRTFPanner::~HRTFPanner() {} |
| 67 | 67 |
| 68 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) { | 68 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) { |
| 69 // The HRTF impulse responses (loaded as audio resources) are 512 | 69 // The HRTF impulse responses (loaded as audio resources) are 512 |
| 70 // sample-frames @44.1KHz. Currently, we truncate the impulse responses to | 70 // sample-frames @44.1KHz. Currently, we truncate the impulse responses to |
| 71 // half this size, but an FFT-size of twice impulse response size is needed | 71 // half this size, but an FFT-size of twice impulse response size is needed |
| 72 // (for convolution). So for sample rates around 44.1KHz an FFT size of 512 | 72 // (for convolution). So for sample rates around 44.1KHz an FFT size of 512 |
| 73 // is good. For different sample rates, the truncated response is resampled. | 73 // is good. For different sample rates, the truncated response is resampled. |
| 74 // The resampled length is used to compute the FFT size by choosing a power | 74 // The resampled length is used to compute the FFT size by choosing a power |
| 75 // of two that is greater than or equal the resampled length. This power of | 75 // of two that is greater than or equal the resampled length. This power of |
| 76 // two is doubled to get the actual FFT size. | 76 // two is doubled to get the actual FFT size. |
| 77 | 77 |
| 78 ASSERT(AudioUtilities::isValidAudioBufferSampleRate(sampleRate)); | 78 DCHECK(AudioUtilities::isValidAudioBufferSampleRate(sampleRate)); |
| 79 | 79 |
| 80 int truncatedImpulseLength = 256; | 80 int truncatedImpulseLength = 256; |
| 81 double sampleRateRatio = sampleRate / 44100; | 81 double sampleRateRatio = sampleRate / 44100; |
| 82 double resampledLength = truncatedImpulseLength * sampleRateRatio; | 82 double resampledLength = truncatedImpulseLength * sampleRateRatio; |
| 83 | 83 |
| 84 return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); | 84 return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void HRTFPanner::reset() { | 87 void HRTFPanner::reset() { |
| 88 m_convolverL1.reset(); | 88 m_convolverL1.reset(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 118 | 118 |
| 119 void HRTFPanner::pan(double desiredAzimuth, | 119 void HRTFPanner::pan(double desiredAzimuth, |
| 120 double elevation, | 120 double elevation, |
| 121 const AudioBus* inputBus, | 121 const AudioBus* inputBus, |
| 122 AudioBus* outputBus, | 122 AudioBus* outputBus, |
| 123 size_t framesToProcess, | 123 size_t framesToProcess, |
| 124 AudioBus::ChannelInterpretation channelInterpretation) { | 124 AudioBus::ChannelInterpretation channelInterpretation) { |
| 125 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; | 125 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; |
| 126 | 126 |
| 127 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <= 2; | 127 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <= 2; |
| 128 ASSERT(isInputGood); | 128 DCHECK(isInputGood); |
| 129 | 129 |
| 130 bool isOutputGood = outputBus && outputBus->numberOfChannels() == 2 && | 130 bool isOutputGood = outputBus && outputBus->numberOfChannels() == 2 && |
| 131 framesToProcess <= outputBus->length(); | 131 framesToProcess <= outputBus->length(); |
| 132 ASSERT(isOutputGood); | 132 DCHECK(isOutputGood); |
| 133 | 133 |
| 134 if (!isInputGood || !isOutputGood) { | 134 if (!isInputGood || !isOutputGood) { |
| 135 if (outputBus) | 135 if (outputBus) |
| 136 outputBus->zero(); | 136 outputBus->zero(); |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 | 139 |
| 140 HRTFDatabase* database = m_databaseLoader->database(); | 140 HRTFDatabase* database = m_databaseLoader->database(); |
| 141 if (!database) { | 141 if (!database) { |
| 142 outputBus->copyFrom(*inputBus, channelInterpretation); | 142 outputBus->copyFrom(*inputBus, channelInterpretation); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // IRCAM HRTF azimuths values from the loaded database is reversed from the | 146 // IRCAM HRTF azimuths values from the loaded database is reversed from the |
| 147 // panner's notion of azimuth. | 147 // panner's notion of azimuth. |
| 148 double azimuth = -desiredAzimuth; | 148 double azimuth = -desiredAzimuth; |
| 149 | 149 |
| 150 bool isAzimuthGood = azimuth >= -180.0 && azimuth <= 180.0; | 150 bool isAzimuthGood = azimuth >= -180.0 && azimuth <= 180.0; |
| 151 ASSERT(isAzimuthGood); | 151 DCHECK(isAzimuthGood); |
| 152 if (!isAzimuthGood) { | 152 if (!isAzimuthGood) { |
| 153 outputBus->zero(); | 153 outputBus->zero(); |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Normally, we'll just be dealing with mono sources. | 157 // Normally, we'll just be dealing with mono sources. |
| 158 // If we have a stereo input, implement stereo panning with left source | 158 // If we have a stereo input, implement stereo panning with left source |
| 159 // processed by left HRTF, and right source by right HRTF. | 159 // processed by left HRTF, and right source by right HRTF. |
| 160 const AudioChannel* inputChannelL = | 160 const AudioChannel* inputChannelL = |
| 161 inputBus->channelByType(AudioBus::ChannelLeft); | 161 inputBus->channelByType(AudioBus::ChannelLeft); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 double frameDelayL2; | 227 double frameDelayL2; |
| 228 double frameDelayR2; | 228 double frameDelayR2; |
| 229 database->getKernelsFromAzimuthElevation(azimuthBlend, m_azimuthIndex1, | 229 database->getKernelsFromAzimuthElevation(azimuthBlend, m_azimuthIndex1, |
| 230 m_elevation1, kernelL1, kernelR1, | 230 m_elevation1, kernelL1, kernelR1, |
| 231 frameDelayL1, frameDelayR1); | 231 frameDelayL1, frameDelayR1); |
| 232 database->getKernelsFromAzimuthElevation(azimuthBlend, m_azimuthIndex2, | 232 database->getKernelsFromAzimuthElevation(azimuthBlend, m_azimuthIndex2, |
| 233 m_elevation2, kernelL2, kernelR2, | 233 m_elevation2, kernelL2, kernelR2, |
| 234 frameDelayL2, frameDelayR2); | 234 frameDelayL2, frameDelayR2); |
| 235 | 235 |
| 236 bool areKernelsGood = kernelL1 && kernelR1 && kernelL2 && kernelR2; | 236 bool areKernelsGood = kernelL1 && kernelR1 && kernelL2 && kernelR2; |
| 237 ASSERT(areKernelsGood); | 237 DCHECK(areKernelsGood); |
| 238 if (!areKernelsGood) { | 238 if (!areKernelsGood) { |
| 239 outputBus->zero(); | 239 outputBus->zero(); |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 | 242 |
| 243 ASSERT(frameDelayL1 / sampleRate() < MaxDelayTimeSeconds && | 243 ASSERT(frameDelayL1 / sampleRate() < MaxDelayTimeSeconds && |
| 244 frameDelayR1 / sampleRate() < MaxDelayTimeSeconds); | 244 frameDelayR1 / sampleRate() < MaxDelayTimeSeconds); |
| 245 ASSERT(frameDelayL2 / sampleRate() < MaxDelayTimeSeconds && | 245 ASSERT(frameDelayL2 / sampleRate() < MaxDelayTimeSeconds && |
| 246 frameDelayR2 / sampleRate() < MaxDelayTimeSeconds); | 246 frameDelayR2 / sampleRate() < MaxDelayTimeSeconds); |
| 247 | 247 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 (fftSize() / 2) / static_cast<double>(sampleRate()); | 353 (fftSize() / 2) / static_cast<double>(sampleRate()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 double HRTFPanner::latencyTime() const { | 356 double HRTFPanner::latencyTime() const { |
| 357 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition to | 357 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition to |
| 358 // its tailTime of the same value. | 358 // its tailTime of the same value. |
| 359 return (fftSize() / 2) / static_cast<double>(sampleRate()); | 359 return (fftSize() / 2) / static_cast<double>(sampleRate()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |