Formerly part of EffectNoiseReduction::Worker::ReduceNoise()
| 270 | |
| 271 | // Formerly part of EffectNoiseReduction::Worker::ReduceNoise() |
| 272 | void SpectrumTransformer::OutputStep() |
| 273 | { |
| 274 | if (!mNeedsOutput) |
| 275 | return; |
| 276 | if (QueueIsFull()) { |
| 277 | const auto last = mSpectrumSize - 1; |
| 278 | Window &record = **mQueue.rbegin(); |
| 279 | |
| 280 | const float *pReal = &record.mRealFFTs[1]; |
| 281 | const float *pImag = &record.mImagFFTs[1]; |
| 282 | float *pBuffer = &mFFTBuffer[2]; |
| 283 | auto nn = mSpectrumSize - 2; |
| 284 | for (; nn--;) { |
| 285 | *pBuffer++ = *pReal++; |
| 286 | *pBuffer++ = *pImag++; |
| 287 | } |
| 288 | mFFTBuffer[0] = record.mRealFFTs[0]; |
| 289 | // The Fs/2 component is stored as the imaginary part of the DC component |
| 290 | mFFTBuffer[1] = record.mImagFFTs[0]; |
| 291 | |
| 292 | // Invert the FFT into the output buffer |
| 293 | InverseRealFFTf(mFFTBuffer.data(), hFFT.get()); |
| 294 | |
| 295 | // Overlap-add |
| 296 | if (mOutWindow.size() > 0) { |
| 297 | auto pOut = mOutOverlapBuffer.data(); |
| 298 | auto pWindow = mOutWindow.data(); |
| 299 | auto pBitReversed = &hFFT->BitReversed[0]; |
| 300 | for (size_t jj = 0; jj < last; ++jj) { |
| 301 | auto kk = *pBitReversed++; |
| 302 | *pOut++ += mFFTBuffer[kk] * (*pWindow++); |
| 303 | *pOut++ += mFFTBuffer[kk + 1] * (*pWindow++); |
| 304 | } |
| 305 | } |
| 306 | else { |
| 307 | auto pOut = mOutOverlapBuffer.data(); |
| 308 | auto pBitReversed = &hFFT->BitReversed[0]; |
| 309 | for (size_t jj = 0; jj < last; ++jj) { |
| 310 | auto kk = *pBitReversed++; |
| 311 | *pOut++ += mFFTBuffer[kk]; |
| 312 | *pOut++ += mFFTBuffer[kk + 1]; |
| 313 | } |
| 314 | } |
| 315 | auto buffer = mOutOverlapBuffer.data(); |
| 316 | if (mOutStepCount >= 0) { |
| 317 | // Output the first portion of the overlap buffer, they're done |
| 318 | DoOutput(buffer, mStepSize); |
| 319 | } |
| 320 | // Shift the remainder over. |
| 321 | memmove(buffer, buffer + mStepSize, sizeof(float)*(mWindowSize - mStepSize)); |
| 322 | std::fill(buffer + mWindowSize - mStepSize, buffer + mWindowSize, 0.0f); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | bool SpectrumTransformer::QueueIsFull() const |
| 327 | { |
nothing calls this directly
no test coverage detected