thing
This commit is contained in:
+8
-47
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user