← Back to Docs
Initialization & Configuration
Configuration Structure
The SDK is configured through cry_detect_config_t (defined in cry_detect.h):
typedef struct {
const char *engine_type; // "pure_c" | "svp_acl" | "magik" | "int8"
const char *weight_path; // path to model weights (.bin / .om / .mgk)
const char *capture_type; // "mpp" | "imp" | "file"
int silence_rms_threshold; // 0 = disable, 50 = default
cry_detect_callback_t callback; // result callback (can be NULL)
void *callback_data; // user data passed to callback
const char *alarm_strategy; // "asymmetric_envelope" or NULL
const char *alarm_params; // "k1=v1,k2=v2" or NULL for defaults
alarm_callback_t alarm_callback; // alarm event callback
void *alarm_callback_data; // alarm callback user data
} cry_detect_config_t;All fields are optional — pass NULL (or 0) to use defaults. The default engine and capture type are determined at compile time by the build system (see config.h).
Initialization Sequence
// 1. Create config (or pass NULL for all defaults)
cry_detect_config_t config = {
.engine_type = "pure_c",
.weight_path = "./model_weights.bin",
.callback = my_callback,
.callback_data = &my_context,
.alarm_strategy = "asymmetric_envelope",
.alarm_callback = my_alarm_callback,
};
// 2. Initialize
int ret = cry_detect_init(&config);
if (ret < 0) {
// Handle error (e.g., model file not found, unsupported engine)
return ret;
}
// 3. Start real-time detection
ret = cry_detect_start();
if (ret < 0) {
// Handle error (e.g., audio device unavailable)
cry_detect_deinit();
return ret;
}
// 4. Detection runs in background — results arrive via callbacks
// Your application can do other work here
// 5. Stop detection
cry_detect_stop();
// 6. Clean up
cry_detect_deinit();Compile-Time Configuration (`config.h`)
Audio parameters are defined in config.h and must match the training configuration:
Parameter
Value
Description
`CRY_SAMPLE_RATE`
16000
Sample rate (Hz)
`CRY_BIT_WIDTH`
16
Bit depth
`CRY_SOUND_MODE`
1
Mono
`CRY_FRAME_TIME_SEC`
5
Frame size (seconds)
`CRY_FRAME_STEP_SEC`
1
Step size (seconds, 4s overlap)
`AUDIO_BUF_SLOTS`
10
Ring buffer slots (~10s)
`AUDIO_SLOT_SAMPLES`
15975
Samples per slot (~1s)
Platform-specific audio parameters (device IDs, frame sizes) are selected automatically based on the AUDIO_CAPTURE_* macro.
Default Backend Selection
The build script defines which backends are compiled in:
Preprocessor Macro
Default Engine
Default Capture
`ENGINE_SVP_ACL`
`"svp_acl"`
`"mpp"`
`ENGINE_MAGIK`
`"magik"`
`"imp"`
`ENGINE_INT8`
`"int8"`
`"file"`
(none)
`"pure_c"`
`"file"`
File Processing Mode
For testing with WAV files (no microphone needed):
cry_detect_init(NULL); // all defaults
cry_detect_process_file("test.wav");
cry_detect_deinit();This is useful for offline testing on a PC or during CI.