Loading...
Searching...
No Matches
One-window acoustic inference worker with source-time and measured-level evidence.
More...
#include "ear_inference.h"
#include "../../src/inference_model.h"
#include <math.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
Go to the source code of this file.
|
| static bool | model_setting (void *unused, const char *key, const char *value) |
| | Keep class/threshold selection module-owned rather than assigning acoustic semantics to the common parser.
|
| bool | ear_inference_configure (const char *settings_path, unsigned rate, bool *enabled, char *error, size_t capacity) |
| | Select the explicit detector and qualify an ONNX PCM contract before capture starts.
|
| static bool | run_window (struct ear_inference_result *result) |
| | Accept finite probabilities without confusing them with measured loudness or localization confidence.
|
| static void * | classify_windows (void *unused) |
| | Own the model session off the ALSA thread and publish only still-current capture generations.
|
| 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.
|
One-window acoustic inference worker with source-time and measured-level evidence.
The capture thread never shares its live sample buffer with ORT; stale generations are discarded.
Definition in file ear_inference.c.
◆ EAR_INFERENCE_SAMPLE_LIMIT
| #define EAR_INFERENCE_SAMPLE_LIMIT 192000U |
◆ classify_windows()
| void * classify_windows |
( |
void * | unused | ) |
|
|
static |
Own the model session off the ALSA thread and publish only still-current capture generations.
Definition at line 122 of file ear_inference.c.
◆ 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()
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.
◆ model_setting()
| bool model_setting |
( |
void * | unused, |
|
|
const char * | key, |
|
|
const char * | value ) |
|
static |
Keep class/threshold selection module-owned rather than assigning acoustic semantics to the common parser.
Definition at line 50 of file ear_inference.c.
◆ run_window()
Accept finite probabilities without confusing them with measured loudness or localization confidence.
Definition at line 100 of file ear_inference.c.
◆ class_index
◆ collected
◆ collected_count
◆ collected_error_us
| uint64_t collected_error_us |
|
static |
◆ collected_timing_valid
| bool collected_timing_valid |
|
static |
◆ completed
◆ completed_generation
| uint64_t completed_generation |
|
static |
◆ generation
| atomic_uint_fast64_t generation |
|
static |
◆ inference_available
| pthread_cond_t inference_available = PTHREAD_COND_INITIALIZER |
|
static |
◆ inference_mutex
| pthread_mutex_t inference_mutex = PTHREAD_MUTEX_INITIALIZER |
|
static |
◆ inference_thread
| pthread_t inference_thread |
|
static |
◆ network
◆ option_seen
◆ pending
◆ queued
◆ queued_generation
| uint64_t queued_generation |
|
static |
◆ ready
◆ score_threshold
| double score_threshold = 0.6 |
|
static |
◆ started
◆ stopping