Embedded Glass Break Detection: Offline Break Recognition SDK and DeploymentNEW
The Value of Glass Break Detection: Scenarios and Workflow
When a window shatters, the sound lasts less than a second — but for a security system, that second decides how fast it can respond, and whether users trust it. Glass is the most fragile entry point of any protected asset: homes while away, retail windows and display cases, warehouse skylights. A sensing layer that hears the break adds coverage exactly where cameras are sparse.
Scenario families: home security cameras (break-in detection while away), retail and warehouse anti-theft, alarm panels (acoustic front-end), smart locks and door sensors — plus the chain-store operation model where dozens of stores converge into one duty desk.
The Signature: Two-Stage Transient
Below is a real glass break recording — waveform (top) and Mel spectrogram (bottom). The instantaneous impact spike followed by the broadband shatter section is clearly visible:

Audio samples (real recordings — press play):
🔊 Glass break (real sample)
🔊 Another break recording
A complete break event contains two consecutive stages:
Impact — — a short, concentrated shock, typically milliseconds
Shatter — — dense, broadband, rapidly decaying high-frequency vibrations — the most distinctive signature
Common confusions differ fundamentally: a single collision (keys, dishes) has an isolated impact with no dense shatter; sustained sounds (music, speech) have no transient structure at all.
How Recognition Works: Preprocessing → Features → Algorithms
The engine follows the standard pipeline — adaptive denoising (5–10 dB SNR gain in typical noise), framing, then time-frequency feature extraction — and applies three glass-specific principles:
1. Find the event first — detect energy bursts and analyze around them; sustained background noise is inherently ignored
2. Two-stage consistency — a genuine break must show the complete impact + shatter structure
3. Cross-feature verification — onset speed, high-frequency ratio and decay pattern must agree
Alarm Linkage Workflow
Event → multi-feature verification → on-device response (recording + snapshot) → push the user → confirmation or timeout escalation (alarm panel, property management, emergency contacts). Every step is configurable per business.
Deployment: Positions and Calibration
Face the glass — — short pickup distance, direct sound dominates
Avoid dead corners and cabinets — — the high-frequency shatter evidence attenuates fastest behind obstacles
Calibrate on site — — standard sound source, thresholds against the ambient baseline
Chip and mount wisely — — co-mount with cameras; waterproofing outdoors
The SDK runs inside the camera SoC: events feed the NVR timeline, act as an alarm-panel trigger source, and reach users via the app — CPU increment under 50 MHz, event protocol mappable to existing alarm types, no platform rebuild required.
False-Alarm Control
Clinking dishes, music and TV are the biggest engineering challenge for glass break detection. Multi-class negative training combined with on-site calibration keeps the real-world false-alarm rate below 2%.
New confusing sounds encountered during integration can be reported through the feedback channel; model updates are delivered via OTA.
Chain-Store Night Security
For chain operators, nights multiply risk: dozens of stores, none staffed. Each store detects locally and uplinks events with location, time and clip references; one duty desk watches all stores.
Verify before you dispatch: on an event, the desk pulls the nearest camera. False alarm → terminate and label; valid → escalate (duty manager, nearest guard, evidence retention). Remote verification takes 30–60 seconds and dramatically raises the ratio of dispatched-to-valid incidents.
A healthy target: ≤3 false alarms per store per month (versus 8–15 previously), with lessons shared across the chain — what one store learns immediately strengthens the others.
Accuracy and Performance
Note: performance figures are based on internal test environments; actual results depend on hardware and deployment scenarios.
Platform and Hardware Requirements
Camera-class SoCs; CPU increment under 50 MHz; shares the SoC with video encoding; outdoor mounting supported with environmental protection.
C API and Embedded Integration
The glass break detection library exposes a concise streaming C API: the caller just keeps feeding 16 kHz mono PCM; framing, Mel preprocessing and model inference run internally, and frame-level probabilities are aggregated by the alarm strategy into event callbacks.
Full interface declaration (glass_detect.h):
/**
* glass_detect.h — 玻璃破碎识别统一接口
*
* 封装 Mel 预处理 + 推理引擎 + 报警策略, 内部模型消费线程处理音频。
* 与录音模块 (audio_capture.h) 相互独立: 调用者自行决定音频来源
* (录音回调 / wav 文件 / 网络流), 通过 glass_detect_feed 送入, 数据任意大小。
*
* 用法 (实时录音模式):
* glass_detect_t *d = glass_detect_create(mgk_path, NULL, NULL);
* glass_detect_set_listener(d, on_frame, on_onset, on_offset, NULL);
* glass_detect_start(d); // 启动内部模型消费线程
* audio_capture_start(rec, capture_cb, d); // 录音回调里调 glass_detect_feed
* ...
* glass_detect_stop(d); // 排空缓冲, 停止线程
* glass_detect_destroy(d);
*
* 用法 (wav 文件模式):
* glass_detect_t *d = glass_detect_create(mgk_path, NULL, NULL);
* glass_detect_set_listener(d, on_frame, on_onset, on_offset, NULL);
* glass_detect_start(d);
* 循环读文件: glass_detect_feed(d, pcm, n); // 任意数据大小
* glass_detect_stop(d);
* glass_detect_destroy(d);
*/
#ifndef GLASS_DETECT_H
#define GLASS_DETECT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* 识别事件 (报警策略输出, 用于事件结束回调) */
typedef struct {
float start_time; /* 事件开始时间 (秒) */
float end_time; /* 事件结束时间 (秒) */
float confidence; /* 事件置信度 */
float max_confidence; /* 事件内最大帧置信度 */
int frame_count; /* 事件持续帧数 */
} glass_detect_event_t;
/* 帧级回调: 每帧识别结果 (模型线程内执行) */
typedef void (*glass_detect_frame_cb_t)(float glass_prob, float timestamp,
void *user_data);
/* 事件开始回调: 策略判定玻璃破碎事件开始, 只有开始时间 */
typedef void (*glass_detect_onset_cb_t)(float start_time, void *user_data);
/* 事件结束回调: 策略判定玻璃破碎事件结束 (或停止识别时未结束的事件), 完整事件信息 */
typedef void (*glass_detect_offset_cb_t)(const glass_detect_event_t *event,
void *user_data);
typedef struct glass_detect_s glass_detect_t;
/* 创建/销毁; alarm_name/alarm_params 可传 NULL (用默认策略及参数) */
glass_detect_t *glass_detect_create(const char *mgk_path, /* 模型文件路径 (必填) */
const char *alarm_name, /* 报警策略名, NULL=默认 */
const char *alarm_params); /* 策略参数 key=val,key=val, NULL=默认 */
void glass_detect_destroy(glass_detect_t *det);
/* 设置事件回调 (create 后调用, 也可在运行中调整); 不需要的回调传 NULL */
void glass_detect_set_listener(glass_detect_t *det,
glass_detect_frame_cb_t on_frame,
glass_detect_onset_cb_t on_onset,
glass_detect_offset_cb_t on_offset,
void *user_data);
/* 启动/停止识别: 启动内部模型消费线程 / 排空缓冲后停止线程 */
int glass_detect_start(glass_detect_t *det);
void glass_detect_stop(glass_detect_t *det);
int glass_detect_is_running(glass_detect_t *det);
/* 设置事件识别策略 (可在运行中调整) */
int glass_detect_set_alarm(glass_detect_t *det, const char *alarm_name,
const char *alarm_params);
/* 送入 PCM 数据 (16bit 单声道 16kHz), 线程安全, 任意数据大小 */
int glass_detect_feed(glass_detect_t *det, const int16_t *pcm, int num_samples);
#ifdef __cplusplus
}
#endif
#endif /* GLASS_DETECT_H */
A minimal WAV-inference demo (excerpt; the full file ships at src/glassDetect/c/glass_demo.c):
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "glass_detect.h"
#define DEFAULT_MGK "glass_detect_v7.mgk" /* 模型文件 */
#define DEFAULT_WAV "test_glass.wav" /* 16kHz 单声道 16bit PCM */
#define FEED_CHUNK 16000 /* 每次送入 1 秒音频 */
/* 帧级回调: 每帧输出玻璃破碎概率 (约 1 秒一帧) */
static void on_frame(float glass_prob, float timestamp, void *user_data)
{
(void)user_data;
printf("%8.2fs glass=%.4f\n", timestamp, glass_prob);
}
/* 事件开始回调: 策略判定玻璃破碎事件开始 */
static void on_onset(float start_time, void *user_data)
{
(void)user_data;
printf("[EVENT] glass start at %.2fs\n", start_time);
}
/* 事件结束回调: 应用层可据此做后续统计或分级响应 */
static void on_offset(const glass_detect_event_t *ev, void *user_data)
{
(void)user_data;
printf("[EVENT] glass end at %.2fs (dur=%.2fs, conf=%.3f, frames=%d)\n",
ev->end_time, ev->end_time - ev->start_time,
ev->confidence, ev->frame_count);
}
static int read_wav_pcm(const char *path, int16_t **pcm, int *n, int *sr); /* 完整实现见源文件 */
int main(void)
{
glass_detect_t *det;
int16_t *pcm = NULL;
int num_samples = 0, sample_rate = 0;
int pos;
if (read_wav_pcm(DEFAULT_WAV, &pcm, &num_samples, &sample_rate) != 0)
return 1;
/* 1. 创建识别器: 模型文件 + 默认报警策略 (NULL) */
det = glass_detect_create(DEFAULT_MGK, NULL, NULL);
if (!det) return 1;
/* 2. 注册回调 (均为可选) */
glass_detect_set_listener(det, on_frame, on_onset, on_offset, NULL);
/* 3. 启动内部模型消费线程 */
glass_detect_start(det);
/* 4. 分块送入 PCM; 实时录音时改在录音回调里 feed */
for (pos = 0; pos < num_samples; pos += FEED_CHUNK) {
int n = num_samples - pos;
if (n > FEED_CHUNK) n = FEED_CHUNK;
glass_detect_feed(det, pcm + pos, n);
}
/* 5. 停止并销毁 */
glass_detect_stop(det);
glass_detect_destroy(det);
free(pcm);
return 0;
}
Build and run:
$(CC) glass_demo.c -I. -L. -lglassdetect -lpthread -lm -o glass_demo
./glass_demoConclusion
Deployment quality decides how well the feature performs in the field. If you are a security integrator or OEM shipping glass break detection, an online trial with full technical support is available.