Files
led-controller/main/beat.h
T
jimmyandClaude Opus 5.5 1c222771a5 refactor: move the v2 controller to the repository root
The ESP-IDF project, docs, tools, tests and web UI move from v2/ to the
root, and the Makefile, README, build scripts and test runner drop the
v2/ prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 23:44:58 +13:00

50 lines
1.7 KiB
C

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
typedef struct {
float bpm; // 0 until a tempo has been found
float confidence; // 0..1, how periodic the onsets are
bool locked; // beats are being emitted
uint32_t beat_count;
int64_t last_beat_us; // esp_timer time of the last beat, 0 if none
int meter; // beats per bar, 3 or 4
int bar_beat; // 1..meter of the last beat (best guess), 0 early on
bool bar_sure; // bar_beat is reliable, downbeats are being flashed
uint32_t downbeat_count;
uint32_t onset_count;
int64_t last_onset_us;
} beat_info_t;
// Event codes posted to subscriber queues
typedef enum {
BEAT_EVENT_ONSET,
BEAT_EVENT_BEAT,
} beat_event_t;
// Set up the detector and beat LED; call before feeding audio
esp_err_t beat_start(float sample_rate);
// Feed DC-free mono samples at full scale +/-1 (called from the mic task)
void beat_feed(const float *x, size_t n);
void beat_get_info(beat_info_t *out);
// The user tapped beat 1 just now: correct the bar position to match
void beat_tap(void);
// Have beat_event_t values posted (without blocking) to a queue of
// beat_event_t. Returns ESP_ERR_NO_MEM when all subscriber slots are taken.
esp_err_t beat_subscribe(QueueHandle_t q);
void beat_unsubscribe(QueueHandle_t q);
// Called from the audio task the moment a beat is emitted, before any queue
// fan-out, so the radio can send it with minimal delay. Must not block.
typedef void (*beat_cb_t)(const beat_info_t *info, float bpm, bool downbeat);
void beat_set_callback(beat_cb_t cb);