MCPcopy Create free account
hub / github.com/benkuper/Chataigne / process

Method process

Source/Module/modules/audio/analysis/FFTAnalyzer.cpp:31–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31void FFTAnalyzer::process(float* fftSamples, int numSamples)
32{
33 if (!enabled->boolValue()) return;
34
35 float result = 0;
36 float targetPos = position->floatValue();
37 float maxDist = size->floatValue() / 2;
38
39 int numGoodSamples = 0;
40 float totalCoef = 0;
41 for (int i = 0; i < numSamples; ++i)
42 {
43 float pos = i * 1.0f / numSamples;
44 float dist = jmin<float>(fabsf(targetPos - pos) / maxDist, 1);
45 if (dist >= 1) continue;
46
47 numGoodSamples++;
48 float factor = cosf(dist * MathConstants<float>::pi / 2); //smooth
49
50 result += fftSamples[i] * factor;
51 totalCoef += factor;
52 }
53
54 if (totalCoef > 0)
55 {
56 result /= totalCoef;
57 value->setValue(result);
58 }
59}
60
61void FFTAnalyzer::onContainerNiceNameChanged()
62{

Callers 1

Calls 1

setValueMethod · 0.45

Tested by

no test coverage detected