Bounded PCM classification without allowing model latency to stall ALSA capture. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>

Go to the source code of this file.
Data Structures | |
| struct | ear_inference_result |
| One classified audio window; probability and measured level are different evidence. More... | |
Functions | |
| bool | ear_inference_configure (const char *settings, unsigned rate, bool *enabled, char *error, size_t capacity) |
| Select the explicit detector and qualify an ONNX PCM contract before capture starts. | |
| bool | ear_inference_start (char *error, size_t capacity) |
| Start the sole classifier thread after successful ONNX configuration. | |
| void | ear_inference_push (const int16_t *samples, size_t count, uint64_t end_us, uint64_t error_us) |
| Supply capture samples without waiting for model execution or a busy model mailbox. | |
| bool | ear_inference_take (struct ear_inference_result *result) |
| Consume at most one completed original-window result without blocking capture. | |
| void | ear_inference_discontinuity (void) |
| Invalidate queued/completed evidence after capture continuity breaks, including in-flight generations. | |
| void | ear_inference_stop (void) |
| Request termination, join the classifier and release its model; repeat calls are harmless. | |
| int | ear_inference_file (const char *filename) |
| Classify exact whole windows from a regular little-endian signed-16 mono PCM file. | |
Detailed Description
Bounded PCM classification without allowing model latency to stall ALSA capture.
Definition in file ear_inference.h.
Function Documentation
◆ ear_inference_configure()
| bool ear_inference_configure | ( | const char * | settings, |
| unsigned | rate, | ||
| bool * | enabled, | ||
| char * | error, | ||
| size_t | capacity ) |
Select the explicit detector and qualify an ONNX PCM contract before capture starts.
- Parameters
-
settings EARcam application settings path. rate Exact capture sample rate; no implicit resampling is performed. enabled Set true for ONNX, false for a successfully selected native detector. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True for an accepted native or ONNX selection; false never means native fallback.
- Precondition
- No inference thread or previously configured model is active.
Definition at line 69 of file ear_inference.c.
◆ ear_inference_discontinuity()
| void ear_inference_discontinuity | ( | void | ) |
Invalidate queued/completed evidence after capture continuity breaks, including in-flight generations.
Definition at line 209 of file ear_inference.c.
◆ ear_inference_file()
| int ear_inference_file | ( | const char * | filename | ) |
Classify exact whole windows from a regular little-endian signed-16 mono PCM file.
- Parameters
-
filename Immutable replay input; no hardware or simulated exposure timing is invented.
- Returns
- Zero after complete replay, otherwise one for invalid input or model failure.
- Precondition
- The model is configured but its capture worker is not running.
Definition at line 233 of file ear_inference.c.
◆ ear_inference_push()
| void ear_inference_push | ( | const int16_t * | samples, |
| size_t | count, | ||
| uint64_t | end_us, | ||
| uint64_t | error_us ) |
Supply capture samples without waiting for model execution or a busy model mailbox.
- Parameters
-
samples Borrowed signed mono PCM; no pointer survives this call. count Number of samples in this continuous capture chunk. end_us Capture end of the chunk in CLOCK_MONOTONIC microseconds, or zero when unknown. error_us Bound on capture-window timing uncertainty, not inference duration.
Complete windows may replace pending work; overload loses evidence rather than blocking ALSA.
- Precondition
- One capture producer owns push/discontinuity calls until stop begins.
Definition at line 166 of file ear_inference.c.
◆ ear_inference_start()
| bool ear_inference_start | ( | char * | error, |
| size_t | capacity ) |
Start the sole classifier thread after successful ONNX configuration.
- Parameters
-
error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True after thread creation, not proof of a classified acoustic event.
Definition at line 155 of file ear_inference.c.
◆ ear_inference_stop()
| void ear_inference_stop | ( | void | ) |
Request termination, join the classifier and release its model; repeat calls are harmless.
- Precondition
- The capture producer has stopped supplying new chunks.
Definition at line 219 of file ear_inference.c.
◆ ear_inference_take()
| bool ear_inference_take | ( | struct ear_inference_result * | result | ) |
Consume at most one completed original-window result without blocking capture.
- Parameters
-
result Writable destination, unchanged when no result is available.
- Returns
- True for a newly consumed completion; its window time is not its inference completion time.
Definition at line 199 of file ear_inference.c.