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

Method interpolateFrequencyComponents

src/internal/src/FFTFrame.cpp:49–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void FFTFrame::interpolateFrequencyComponents(const FFTFrame & frame1, const FFTFrame & frame2, double interp)
50{
51 // FIXME : with some work, this method could be optimized
52
53 float * realP = realData();
54 float * imagP = imagData();
55
56 const float * realP1 = frame1.realData();
57 const float * imagP1 = frame1.imagData();
58 const float * realP2 = frame2.realData();
59 const float * imagP2 = frame2.imagData();
60
61 m_FFTSize = frame1.fftSize();
62 m_log2FFTSize = frame1.log2FFTSize();
63
64 double s1base = (1.0 - interp);
65 double s2base = interp;
66
67 double phaseAccum = 0.0;
68 double lastPhase1 = 0.0;
69 double lastPhase2 = 0.0;
70
71 realP[0] = static_cast<float>(s1base * realP1[0] + s2base * realP2[0]);
72 imagP[0] = static_cast<float>(s1base * imagP1[0] + s2base * imagP2[0]);
73
74 int n = m_FFTSize / 2;
75
76 for (int i = 1; i < n; ++i)
77 {
78 Complex c1(realP1[i], imagP1[i]);
79 Complex c2(realP2[i], imagP2[i]);
80
81 double mag1 = abs(c1);
82 double mag2 = abs(c2);
83
84 // Interpolate magnitudes in decibels
85 double mag1db = 20.0 * log10(mag1);
86 double mag2db = 20.0 * log10(mag2);
87
88 double s1 = s1base;
89 double s2 = s2base;
90
91 double magdbdiff = mag1db - mag2db;
92
93 // Empirical tweak to retain higher-frequency zeroes
94 double threshold = (i > 16) ? 5.0 : 2.0;
95
96 if (magdbdiff < -threshold && mag1db < 0.0)
97 {
98 s1 = pow(s1, 0.75);
99 s2 = 1.0 - s1;
100 }
101 else if (magdbdiff > threshold && mag2db < 0.0)
102 {
103 s2 = pow(s2, 0.75);
104 s1 = 1.0 - s2;
105 }
106

Callers 1

Calls 4

log2FFTSizeMethod · 0.80
realDataMethod · 0.45
imagDataMethod · 0.45
fftSizeMethod · 0.45

Tested by

no test coverage detected