← Back to Docs

API Overview

System Architecture

The soundSDK is organized into three independent layers, each providing a standard C interface:

┌─────────────────────────────────────────────┐
│              Application Code                │
│  cry_detect_init / start / stop / deinit     │
├─────────────────────────────────────────────┤
│              Processing Layer                │
│  cry_processor: Mel → Inference → Callback   │
├──────────────────┬──────────────────────────┤
│  Audio Capture   │   Inference Engine        │
│  (audio_capture) │   (inference_engine)      │
├────────┬─────────┴──────┬───────────────────┤
│  MPP   │  IMP  │  file  │ pure_c │ svp_acl   │
│(海思)  │(君正)  │ (PC)   │ (FP32) │ .om(NPU)  │
└────────┴────────┴────────┴────────┴──────────┘

1. Audio Capture Layer (`audio_capture_interface.h`)

Abstracts audio input via a vtable pattern. Supports three backends:

Backend
Type String
Platform
SDK
MPP
`"mpp"`
HiSilicon Hi3519DV500
`ss_mpi_ai_*`
IMP
`"imp"`
Ingenic T23/T33
`IMP_AI_*`
File
`"file"`
PC / any Linux
Standard file I/O

Each backend implements init(), start(), stop(), destroy(), is_running(). The capture thread writes PCM data into a lock-free ring buffer and never blocks — if the buffer is full, it prints a warning and continues.

2. Processing Layer (`cry_processor.h`)

A dedicated processing thread runs a 1-second loop:

1. Wait for ≥5 ready slots in the ring buffer (~5 seconds of audio)

2. Compute Mel spectrogram (225×225 float32)

3. Silence detection: RMS < threshold → skip inference

4. Run CNN inference → probability

5. Trigger user callback

6. Advance 1 slot (1s step, 4s overlap)

3. Inference Engine Layer (`inference_engine.h`)

Pluggable backends via a factory pattern:

Engine
Type String
Precision
Platform
Pure C
`"pure_c"`
float32
All platforms
INT8 Quantized
`"int8"`
int8
ARM Linux
SVP ACL
`"svp_acl"`
INT8 (NPU)
HiSilicon Hi3519DV500
Magik
`"magik"`
INT8 (NPU)
Ingenic T33

Ring Buffer (`audio_buffer.h`)

Thread-safe, lock-free ring buffer with 10 slots, each holding ~1 second of PCM (15975 samples × int16 = ~32KB). Total ~330KB memory.

• Producer (capture thread): acquires free slot → writes PCM → commits

• Consumer (processing thread): waits for ≥5 ready → copies → advances 1 slot

• Statistics: tracks overrun / underrun counts for diagnostics

Alarm Strategy (`alarm_strategy.h`)

Converts frame-level probabilities into alarm events. The default "asymmetric_envelope" strategy uses fast-attack / slow-release logic to avoid alarm jitter. Configurable parameters: attack/release coefficients, high/low thresholds, minimum event duration.

Configuration (`config.h`)

Compile-time constants for audio parameters (sample rate, frame size, step) and platform defaults. Build scripts select the appropriate backend via preprocessor defines (AUDIO_CAPTURE_MPP, ENGINE_SVP_ACL, etc.).