This commit is contained in:
2026-07-20 23:18:26 +02:00
parent a2f8c110c4
commit 98d971d92d
13 changed files with 799 additions and 711 deletions
+8 -47
View File
@@ -6,70 +6,31 @@
#include <math.h>
void goertzel_init(
Goertzel *g,
float freq,
float sampleRate,
int samples)
void goertzel_init(Goertzel *g, float freq, float sampleRate, int samples)
{
float omega =
2.0f * M_PI * freq / sampleRate;
g->coeff =
2.0f*cosf(omega);
float omega = 2.0f * M_PI * freq / sampleRate;
g->coeff = 2.0f*cosf(omega);
g->s1=0;
g->s2=0;
}
void goertzel_add(
Goertzel *g,
float sample)
void goertzel_add(Goertzel *g, float sample)
{
float s =
sample +
g->coeff*g->s1 -
g->s2;
float s = sample + g->coeff*g->s1 - g->s2;
g->s2=g->s1;
g->s1=s;
}
float goertzel_energy(
Goertzel *g)
float goertzel_energy(Goertzel *g)
{
float power =
g->s1*g->s1 +
g->s2*g->s2 -
g->coeff*g->s1*g->s2;
float power = g->s1*g->s1 + g->s2*g->s2 - g->coeff*g->s1*g->s2;
g->s1=0;
g->s2=0;
return power;
}
int goertzel_bin_freq(
int freq,
int sampleRate,
int samples)
int goertzel_bin_freq(int freq, int sampleRate, int samples)
{
int bin = (freq * samples + sampleRate / 2) / sampleRate;
return bin * sampleRate / samples;
}