| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; | 110 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; |
| 111 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat); | 111 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat); |
| 112 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth
Index); | 112 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth
Index); |
| 113 | 113 |
| 114 // We don't immediately start using this azimuth index, but instead approach
this index from the last index we rendered at. | 114 // We don't immediately start using this azimuth index, but instead approach
this index from the last index we rendered at. |
| 115 // This minimizes the clicks and graininess for moving sources which occur o
therwise. | 115 // This minimizes the clicks and graininess for moving sources which occur o
therwise. |
| 116 desiredAzimuthIndex = clampTo(desiredAzimuthIndex, 0, numberOfAzimuths - 1); | 116 desiredAzimuthIndex = clampTo(desiredAzimuthIndex, 0, numberOfAzimuths - 1); |
| 117 return desiredAzimuthIndex; | 117 return desiredAzimuthIndex; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in
putBus, AudioBus* outputBus, size_t framesToProcess) | 120 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in
putBus, AudioBus* outputBus, size_t framesToProcess, AudioBus::ChannelInterpreta
tion channelInterpretation) |
| 121 { | 121 { |
| 122 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; | 122 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; |
| 123 | 123 |
| 124 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <=
2; | 124 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <=
2; |
| 125 ASSERT(isInputGood); | 125 ASSERT(isInputGood); |
| 126 | 126 |
| 127 bool isOutputGood = outputBus && outputBus->numberOfChannels() == 2 && frame
sToProcess <= outputBus->length(); | 127 bool isOutputGood = outputBus && outputBus->numberOfChannels() == 2 && frame
sToProcess <= outputBus->length(); |
| 128 ASSERT(isOutputGood); | 128 ASSERT(isOutputGood); |
| 129 | 129 |
| 130 if (!isInputGood || !isOutputGood) { | 130 if (!isInputGood || !isOutputGood) { |
| 131 if (outputBus) | 131 if (outputBus) |
| 132 outputBus->zero(); | 132 outputBus->zero(); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 HRTFDatabase* database = m_databaseLoader->database(); | 136 HRTFDatabase* database = m_databaseLoader->database(); |
| 137 ASSERT(database); | |
| 138 if (!database) { | 137 if (!database) { |
| 139 outputBus->zero(); | 138 outputBus->copyFrom(*inputBus, channelInterpretation); |
| 140 return; | 139 return; |
| 141 } | 140 } |
| 142 | 141 |
| 143 // IRCAM HRTF azimuths values from the loaded database is reversed from the
panner's notion of azimuth. | 142 // IRCAM HRTF azimuths values from the loaded database is reversed from the
panner's notion of azimuth. |
| 144 double azimuth = -desiredAzimuth; | 143 double azimuth = -desiredAzimuth; |
| 145 | 144 |
| 146 bool isAzimuthGood = azimuth >= -180.0 && azimuth <= 180.0; | 145 bool isAzimuthGood = azimuth >= -180.0 && azimuth <= 180.0; |
| 147 ASSERT(isAzimuthGood); | 146 ASSERT(isAzimuthGood); |
| 148 if (!isAzimuthGood) { | 147 if (!isAzimuthGood) { |
| 149 outputBus->zero(); | 148 outputBus->zero(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } else if (m_crossfadeIncr < 0 && fabs(m_crossfadeX) < -m_crossfadeI
ncr) { | 284 } else if (m_crossfadeIncr < 0 && fabs(m_crossfadeX) < -m_crossfadeI
ncr) { |
| 286 // We've fully made the crossfade transition from 2 -> 1. | 285 // We've fully made the crossfade transition from 2 -> 1. |
| 287 m_crossfadeSelection = CrossfadeSelection1; | 286 m_crossfadeSelection = CrossfadeSelection1; |
| 288 m_crossfadeX = 0; | 287 m_crossfadeX = 0; |
| 289 m_crossfadeIncr = 0; | 288 m_crossfadeIncr = 0; |
| 290 } | 289 } |
| 291 } | 290 } |
| 292 } | 291 } |
| 293 } | 292 } |
| 294 | 293 |
| 295 void HRTFPanner::panWithSampleAccurateValues(double* desiredAzimuth, double* ele
vation, const AudioBus* inputBus, AudioBus* outputBus, size_t framesToProcess) | 294 void HRTFPanner::panWithSampleAccurateValues(double* desiredAzimuth, double* ele
vation, const AudioBus* inputBus, AudioBus* outputBus, size_t framesToProcess, A
udioBus::ChannelInterpretation channelInterpretation) |
| 296 { | 295 { |
| 297 // Sample-accurate (a-rate) HRTF panner is not implemented, just k-rate. Ju
st grab the current | 296 // Sample-accurate (a-rate) HRTF panner is not implemented, just k-rate. Ju
st grab the current |
| 298 // azimuth/elevation and use that. | 297 // azimuth/elevation and use that. |
| 299 // | 298 // |
| 300 // We are assuming that the inherent smoothing in the HRTF processing is goo
d enough, and we | 299 // We are assuming that the inherent smoothing in the HRTF processing is goo
d enough, and we |
| 301 // don't want to increase the complexity of the HRTF panner by 15-20 times.
(We need to cmopute | 300 // don't want to increase the complexity of the HRTF panner by 15-20 times.
(We need to cmopute |
| 302 // one output sample for each possibly different impulse response. That N^2
. Previously, we | 301 // one output sample for each possibly different impulse response. That N^2
. Previously, we |
| 303 // used an FFT to do them all at once for a complexity of N/log2(N). Hence,
N/log2(N) times | 302 // used an FFT to do them all at once for a complexity of N/log2(N). Hence,
N/log2(N) times |
| 304 // more complex.) | 303 // more complex.) |
| 305 pan(desiredAzimuth[0], elevation[0], inputBus, outputBus, framesToProcess); | 304 pan(desiredAzimuth[0], elevation[0], inputBus, outputBus, framesToProcess, c
hannelInterpretation); |
| 306 } | 305 } |
| 307 | 306 |
| 308 double HRTFPanner::tailTime() const | 307 double HRTFPanner::tailTime() const |
| 309 { | 308 { |
| 310 // Because HRTFPanner is implemented with a DelayKernel and a FFTConvolver,
the tailTime of the HRTFPanner | 309 // Because HRTFPanner is implemented with a DelayKernel and a FFTConvolver,
the tailTime of the HRTFPanner |
| 311 // is the sum of the tailTime of the DelayKernel and the tailTime of the FFT
Convolver, which is MaxDelayTimeSeconds | 310 // is the sum of the tailTime of the DelayKernel and the tailTime of the FFT
Convolver, which is MaxDelayTimeSeconds |
| 312 // and fftSize() / 2, respectively. | 311 // and fftSize() / 2, respectively. |
| 313 return MaxDelayTimeSeconds + (fftSize() / 2) / static_cast<double>(sampleRat
e()); | 312 return MaxDelayTimeSeconds + (fftSize() / 2) / static_cast<double>(sampleRat
e()); |
| 314 } | 313 } |
| 315 | 314 |
| 316 double HRTFPanner::latencyTime() const | 315 double HRTFPanner::latencyTime() const |
| 317 { | 316 { |
| 318 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t
o its tailTime of the | 317 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t
o its tailTime of the |
| 319 // same value. | 318 // same value. |
| 320 return (fftSize() / 2) / static_cast<double>(sampleRate()); | 319 return (fftSize() / 2) / static_cast<double>(sampleRate()); |
| 321 } | 320 } |
| 322 | 321 |
| 323 } // namespace blink | 322 } // namespace blink |
| 324 | 323 |
| OLD | NEW |