Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
ear_inference.c File Reference

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>
Include dependency graph for ear_inference.c:

Go to the source code of this file.

Macros

#define EAR_INFERENCE_SAMPLE_LIMIT   192000U

Functions

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.

Variables

static struct inference_context network
static pthread_mutex_t inference_mutex = PTHREAD_MUTEX_INITIALIZER
static pthread_cond_t inference_available = PTHREAD_COND_INITIALIZER
static pthread_t inference_thread
static bool started
static bool stopping
static bool pending
static bool ready
static int16_t collected [EAR_INFERENCE_SAMPLE_LIMIT]
static int16_t queued [EAR_INFERENCE_SAMPLE_LIMIT]
static size_t collected_count
static bool collected_timing_valid
static uint64_t collected_error_us
static atomic_uint_fast64_t generation
static uint64_t queued_generation
static uint64_t completed_generation
static struct ear_inference_result queued_evidence completed
static double score_threshold = 0.6
static unsigned class_index
static unsigned option_seen

Detailed Description

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.

Macro Definition Documentation

◆ EAR_INFERENCE_SAMPLE_LIMIT

#define EAR_INFERENCE_SAMPLE_LIMIT   192000U

Definition at line 31 of file ear_inference.c.

Function Documentation

◆ 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
settingsEARcam application settings path.
rateExact capture sample rate; no implicit resampling is performed.
enabledSet true for ONNX, false for a successfully selected native detector.
errorWritable failure diagnostic.
capacityAvailable 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
filenameImmutable 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
samplesBorrowed signed mono PCM; no pointer survives this call.
countNumber of samples in this continuous capture chunk.
end_usCapture end of the chunk in CLOCK_MONOTONIC microseconds, or zero when unknown.
error_usBound 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
errorWritable failure diagnostic.
capacityAvailable 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
resultWritable 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()

bool run_window ( struct ear_inference_result * result)
static

Accept finite probabilities without confusing them with measured loudness or localization confidence.

Definition at line 100 of file ear_inference.c.

Variable Documentation

◆ class_index

unsigned class_index
static

Definition at line 47 of file ear_inference.c.

◆ collected

int16_t collected[EAR_INFERENCE_SAMPLE_LIMIT]
static

Definition at line 39 of file ear_inference.c.

◆ collected_count

size_t collected_count
static

Definition at line 40 of file ear_inference.c.

◆ collected_error_us

uint64_t collected_error_us
static

Definition at line 42 of file ear_inference.c.

◆ collected_timing_valid

bool collected_timing_valid
static

Definition at line 41 of file ear_inference.c.

◆ completed

struct ear_inference_result queued_evidence completed
static

Definition at line 45 of file ear_inference.c.

◆ completed_generation

uint64_t completed_generation
static

Definition at line 44 of file ear_inference.c.

◆ generation

atomic_uint_fast64_t generation
static

Definition at line 43 of file ear_inference.c.

◆ inference_available

pthread_cond_t inference_available = PTHREAD_COND_INITIALIZER
static

Definition at line 36 of file ear_inference.c.

◆ inference_mutex

pthread_mutex_t inference_mutex = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 35 of file ear_inference.c.

◆ inference_thread

pthread_t inference_thread
static

Definition at line 37 of file ear_inference.c.

◆ network

struct inference_context network
static

Definition at line 34 of file ear_inference.c.

◆ option_seen

unsigned option_seen
static

Definition at line 47 of file ear_inference.c.

◆ pending

bool pending
static

Definition at line 38 of file ear_inference.c.

◆ queued

int16_t queued[EAR_INFERENCE_SAMPLE_LIMIT]
static

Definition at line 39 of file ear_inference.c.

◆ queued_generation

uint64_t queued_generation
static

Definition at line 44 of file ear_inference.c.

◆ ready

bool ready
static

Definition at line 38 of file ear_inference.c.

◆ score_threshold

double score_threshold = 0.6
static

Definition at line 46 of file ear_inference.c.

◆ started

bool started
static

Definition at line 38 of file ear_inference.c.

◆ stopping

bool stopping
static

Definition at line 38 of file ear_inference.c.