Exponential smoothing FFT:n arvoille. Rauhoittaa piikkien pomppimista.
This commit is contained in:
@ -71,7 +71,8 @@ void compute_fft(float* time_data, float* freq_out) {
|
||||
|
||||
for (int i = 0; i < FFT_SIZE / 2; ++i) {
|
||||
float mag = sqrtf(real[i] * real[i] + imag[i] * imag[i]) / FFT_SIZE;
|
||||
|
||||
//float db = 20.0f * log10f(mag + 1e-6f); // Decibels
|
||||
//float normalized = (db + 60.0f) / 60.0f; // [0,1]
|
||||
freq_out[i] = mag;
|
||||
}
|
||||
}
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@ -189,8 +189,14 @@ int __cdecl main(int argc, char* argv[])
|
||||
//maximum = max(fft_output[i], maximum);
|
||||
//fft_output[i] = fft_output[i] / maximum;
|
||||
if (i < (FFT_SIZE / 4)) // Limit uniform fft size. High frequencys contain nothing interesing.
|
||||
{
|
||||
fft_uniform[i] = min(1.0,fft_output[i]*20.0);
|
||||
{
|
||||
float gain = 50.0f;
|
||||
float alpha = 0.15f; // "Hidastaa" FFT:n piikkej<65>
|
||||
float threshhold = 0.05f; // Alin arvo mik<69> p<><70>stet<65><74>n shaderille (v<>hent<6E><74> "noisea")
|
||||
float x_t = fft_output[i] * gain;
|
||||
// Exponential smoothing kaava
|
||||
// s(t) = alpha*x(t)+(1-alpha)*s(t-1)
|
||||
fft_uniform[i] = (x_t < threshhold) ? 0.f : alpha*(x_t) + (1-alpha)*fft_uniform[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user