Files
buzz_detector/main/fingerprint.h
T
2026-10-13 19:47:46 -05:00

23 lines
1002 B
C

#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#include "feature_params.h"
// Scratch for one FFT. Each caller thread owns its own context (processing task,
// selftest) so features_compute() needs no locking. 16-byte aligned for the S3 FFT.
typedef struct {
float fft[2 * FRAME_LEN] __attribute__((aligned(16)));
} features_ctx_t;
esp_err_t features_init(void); // window, band edges, FFT tables (idempotent)
// pcm: FRAME_LEN int16 samples. Outputs a unit-norm fingerprint and the DC-free RMS
// (int16 units). Returns false if the fingerprint is degenerate (silence / flat):
// fp is then all zeros and scores 0.
bool features_compute(features_ctx_t *ctx, const int16_t *pcm, float fp[NUM_BANDS], float *rms_out);
const int *features_band_edges(void); // NUM_BANDS + 1 FFT-bin edges
bool features_l2_normalize(float *v, int n); // false (and zeros) if norm ~ 0
float features_dot(const float *a, const float *b); // cosine for unit vectors