MCPcopy Create free account
hub / github.com/LabSound/LabSound / process

Method process

src/internal/src/FFTConvolver.cpp:23–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23void FFTConvolver::process(FFTFrame * fftKernel, const float * sourceP, float * destP, int framesToProcess)
24{
25 int halfSize = fftSize() / 2;
26
27 // framesToProcess must be an exact multiple of halfSize,
28 // or halfSize is a multiple of framesToProcess when halfSize > framesToProcess.
29 bool isGood = !(halfSize % framesToProcess && framesToProcess % halfSize);
30 ASSERT(isGood);
31
32 if (!isGood)
33 return;
34
35 // for testing, disable the convolver
36 //for (int i = 0; i < framesToProcess; ++i)
37 // destP[i] = sourceP[i];
38 //return;
39
40 int numberOfDivisions = halfSize <= framesToProcess ? (framesToProcess / halfSize) : 1;
41 int divisionSize = numberOfDivisions == 1 ? framesToProcess : halfSize;
42
43 for (int i = 0; i < numberOfDivisions; ++i, sourceP += divisionSize, destP += divisionSize)
44 {
45 // Copy samples to input buffer (note constraint above!)
46 float * inputP = m_inputBuffer.data();
47
48 // Sanity check
49 bool isCopyGood1 = sourceP && inputP && m_readWriteIndex + divisionSize <= m_inputBuffer.size();
50 ASSERT(isCopyGood1);
51 if (!isCopyGood1)
52 return;
53
54 memcpy(inputP + m_readWriteIndex, sourceP, sizeof(float) * divisionSize);
55
56 // Copy samples from output buffer
57 float * outputP = m_outputBuffer.data();
58
59 // Sanity check
60 bool isCopyGood2 = destP && outputP && m_readWriteIndex + divisionSize <= m_outputBuffer.size();
61 ASSERT(isCopyGood2);
62 if (!isCopyGood2)
63 return;
64
65 memcpy(destP, outputP + m_readWriteIndex, sizeof(float) * divisionSize);
66 m_readWriteIndex += divisionSize;
67
68 // Check if it's time to perform the next FFT
69 if (m_readWriteIndex == halfSize)
70 {
71
72 // The input buffer is now filled (get frequency-domain version)
73 m_frame.computeForwardFFT(m_inputBuffer.data());
74 m_frame.multiply(*fftKernel);
75 m_frame.computeInverseFFT(m_outputBuffer.data());
76
77 // Overlap-add 1st half from previous time
78 vadd(m_outputBuffer.data(), 1, m_lastOverlapBuffer.data(), 1, m_outputBuffer.data(), 1, halfSize);
79
80 // Finally, save 2nd half of result

Callers

nothing calls this directly

Calls 6

vaddFunction · 0.85
sizeMethod · 0.80
dataMethod · 0.45
computeForwardFFTMethod · 0.45
multiplyMethod · 0.45
computeInverseFFTMethod · 0.45

Tested by

no test coverage detected