| 472 | } |
| 473 | |
| 474 | HRTFKernel::HRTFKernel(AudioChannel * channel, int fftSize, float sampleRate) |
| 475 | : m_frameDelay(0) |
| 476 | , m_sampleRate(sampleRate) |
| 477 | { |
| 478 | ASSERT(channel); |
| 479 | |
| 480 | // Determine the leading delay (average group delay) for the response. |
| 481 | m_frameDelay = ExtractAverageGroupDelay(channel, fftSize / 2); |
| 482 | |
| 483 | float * impulseResponse = channel->mutableData(); |
| 484 | int responseLength = channel->length(); |
| 485 | |
| 486 | // We need to truncate to fit into 1/2 the FFT size (with zero padding) in order to do proper convolution. |
| 487 | int truncatedResponseLength = std::min(responseLength, fftSize / 2); // truncate if necessary to max impulse response length allowed by FFT |
| 488 | |
| 489 | // Quick fade-out (apply window) at truncation point |
| 490 | int numberOfFadeOutFrames = static_cast<unsigned>(sampleRate / 4410); // 10 sample-frames @44.1KHz sample-rate |
| 491 | ASSERT(numberOfFadeOutFrames < truncatedResponseLength); |
| 492 | |
| 493 | if (numberOfFadeOutFrames < truncatedResponseLength) |
| 494 | { |
| 495 | for (int i = truncatedResponseLength - numberOfFadeOutFrames; i < truncatedResponseLength; ++i) |
| 496 | { |
| 497 | float x = 1.0f - static_cast<float>(i - (truncatedResponseLength - numberOfFadeOutFrames)) / numberOfFadeOutFrames; |
| 498 | impulseResponse[i] *= x; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | m_fftFrame = std::unique_ptr<FFTFrame>(new FFTFrame(fftSize)); |
| 503 | m_fftFrame->doPaddedFFT(impulseResponse, truncatedResponseLength); |
| 504 | } |
| 505 | |
| 506 | std::unique_ptr<AudioChannel> HRTFKernel::createImpulseResponse() |
| 507 | { |
nothing calls this directly
no test coverage detected