8002 VAD Trigger Recording (Low-Power Cache + I2S Output)*
This document describes app/vad_i2s_out_standby in lvp_tws: a human-voice VAD trigger first replays cached history, then keeps streaming live audio over I2S. When idle, the application releases the suspend lock and the framework can enter deep standby. A single analog microphone can cache up to 2s with 400ms rollback; dual digital microphones cache 1s per channel with 200ms per channel rollback. The application only outputs I2S.
Configuration files:
lvp_tws/configs/example/vad_record/grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_1s.config # single AMIC, 1s cache
lvp_tws/configs/example/vad_record/grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_2s.config # single AMIC, 2s cache
lvp_tws/configs/example/vad_record/grus_gx8002b_dev_1v_1dmic_vad_lowpower_i2s.config # single DMIC, 1s cache
lvp_tws/configs/example/vad_record/grus_gx8002b_dev_1v_2dmic_vad_mono_i2s.config # dual DMIC, mixed mono output
1. Features and Interfaces*
| Item | Implementation |
|---|---|
| Trigger | Human-voice VAD (context->sed > 0), optionally hardware FFT VAD or cascade |
| Cache / rollback | 1ch up to 2s (example 1s) / 400ms rollback; 2ch 1s per channel / 200ms per channel (CONFIG_VAD_RECORD_CACHE_MS, CONFIG_VAD_RECORD_HISTORY_MS) |
| Stop | GPIO02 key (multi_button state machine); VAD must fall before re-triggering |
| Low power | Releases the suspend lock when idle; holds it while recording and while filling the boot cache |
| I2S | GX8002 master, 16kHz/16bit; mono for 1ch; dual DMIC mixed mono |
| VAD status | PAD0 for single AMIC/1-DMIC; PAD3 for dual DMIC (PAD0/PAD1 become PDM pins) |
| Logging | UART1 (CONFIG_MCU_PRINT_UART_PORT_1=y) |
Board pin usage (grus_gx8002b_dev_1v, single mic):
| PAD | Function |
|---|---|
| PAD0 | VAD status output |
| PAD2 | GPIO02 stop key input |
| PAD7~PAD10 | AOUT I2S MCLK / BCLK / LRCLK / DATA |
| PAD11 / PAD12 | UART1: logs |
For dual DMIC, PAD0/PAD1 are PDM_DATA/PDM_CLK_OUT and the VAD status pin moves to PAD3.
2. Data Flow and Cache*
AMIC/DMIC -> AIN PCM -> mic_buffer -> rollback ring (.audio_out, 40/64/72KB)
|
+-> AOUT I2S -> PAD10
- The ring lives in
.audio_out, sized byCONFIG_AUDIO_OUT_BUFFER_SIZE_KB: single AMIC 40KB for 1s / 64KB for 2s; dual DMIC 40KB (mixed mono). - On cold boot the read pointer starts
CACHE_MSbehind; the first frame pre-fillsHISTORY_MSfrom the mic buffer, so the first sound is pre-trigger history. - On a VAD trigger the output is unmuted and streams live audio; the GPIO02 key mutes it again.
- The application keeps awake during cold boot until the
CACHE_MScache is filled.
2.1 Low power versus rollback length*
audio_in DRAM is fixed at 0x20030000 and only 16KB:
- Single AMIC: mic buffer 40 frames = 400ms
- Single DMIC: mic buffer 20 frames = 200ms
- Dual DMIC: mic buffer 20 frames = 200ms per channel
During standby the CPU does not copy audio, but AIN keeps writing into the mic buffer. The .audio_out ring lives in MCU SRAM and survives standby, keeping the full 2s/1s history.
The application therefore:
- Holds the suspend lock during cold boot until the cache is filled, then releases it.
- Releases the lock when idle/after recording so
LvpPmuSuspendcan run; on suspend it callsgx_audio_out_free()only, notgx_audio_out_exit().exitgates the module clock but does not unregister the ISR, so a pending AOUT interrupt after standby wake reads registers without a clock and hangs the bus;VadRecordAudioInit()re-initializes AOUT on wake. - On wake, re-initializes AOUT without clearing the ring, appends the audio captured during sleep (at most one mic buffer) using the AIN write-pointer delta, then pushes the first frame
CACHE_MSbehind. - Holds the lock while recording.
2.2 Code Structure*
| File | Responsibility |
|---|---|
app/vad_i2s_out_standby/lvp_app_vad_i2s_out_standby.c |
App lifecycle, VAD decision, recording state machine, suspend lock, VAD status pin |
app/vad_i2s_out_standby/vad_i2s_out_audio.c/.h |
AOUT init, rollback ring, AIN copy/mix, pre-fill, push, statistics |
app/vad_i2s_out_standby/vad_i2s_out_key.c/.h |
GPIO02 stop key (multi_button) |
app/vad_i2s_out_standby/vad_i2s_out_log.h |
Log-level wrapper |
3. Configuration*
make menuconfig -> LVP Application Settings -> Application Settings
| Option | Default | Description |
|---|---|---|
CONFIG_VAD_RECORD_LOG_LEVEL |
1 |
0=error only, 1=init/key/trigger/stop, 2=+per-second stats and key level |
CONFIG_VAD_RECORD_CACHE_MS |
1ch 1000 / 2ch 1000 |
Max cached audio; 1ch ≤2s in menuconfig, 2ch ≤1s per channel |
CONFIG_VAD_RECORD_HISTORY_MS |
1ch 400 / 2ch 200 |
Trigger rollback; 1ch ≤400ms, 2ch ≤200ms per channel |
CONFIG_VAD_RECORD_STOP_GPIO |
2 |
Stop key GPIO (PAD2), -1 disables |
CONFIG_VAD_RECORD_STOP_GPIO_ACTIVE_LOW |
y |
Active low (button to GND, external pull-up) |
CONFIG_VAD_RECORD_TRIGGER_HUMAN |
y |
Human VAD only |
CONFIG_VAD_RECORD_TRIGGER_CASCADE |
- | FFT VAD + human VAD cascade |
CONFIG_VAD_RECORD_TRIGGER_FFT |
- | Hardware FFT VAD only |
CONFIG_VAD_RECORD_TRIGGER_CNT |
3 |
Consecutive 10ms FFT-VAD samples to trigger |
CONFIG_VAD_RECORD_VAD_GPIO |
1ch 0 / 2ch 3 |
VAD status output, -1 disables |
Key dependencies: CONFIG_LVP_INIT_WORKMODE_SED_V2, CONFIG_LVP_HAS_SED_V2_MODE, CONFIG_SED_V2_VAD_MODEL_V221, CONFIG_NPU_SRAM_SIZE_KB=67, CONFIG_LVP_FFT_VAD_ENABLE, CONFIG_LVP_STANDBY_ENABLE, CONFIG_AUDIO_OUT_BUFFER_SIZE_KB (40/64 per config), CONFIG_BOARD_HAS_AOUT_I2S_M=y, CONFIG_MCU_ENABLE_XIP=y (for 2s / dual configs), watchdog options.
4. Build and Run*
cd lvp_tws
cp configs/example/vad_record/grus_gx8002b_dev_1v_2dmic_vad_mono_i2s.config .config # or another vad_record config
make menuconfig # regenerate autoconf.h after switching configs
make
5. Debugging*
5.1 Logs (UART1)*
Normal boot:
[VAD_REC] ---- SampleAppInit ----
[VAD_REC] cold boot: keep awake until cache filled
[VAD_AOUT] aout ok: ch=1 ring=0x2001e000/40960(40960/ch) mclk=... mic=.../12800(400ms/ch)
[VAD_KEY] init: GPIO2, active low
[VAD_REC] trigger=HUMAN cache=1000ms rollback=400ms stop=GPIO key
[VAD_AOUT] first push: ch=1 ain_w=... prefill=400ms delay=1000ms read_off=... wake=0
[VAD_REC] boot cache filled, allow standby
Trigger and stop:
[VAD_REC] VAD trigger: output on (cache 1000ms, rollback 400ms, prefill 400ms), ring_w=..., press GPIO2 key to stop
[VAD_REC] stop key: output off
[VAD_REC] key latched, wait VAD fall before next trigger
[VAD_REC] vad released, allow trigger again
Per-second stats (CONFIG_VAD_RECORD_LOG_LEVEL=2):
[VAD_REC] t=5000ms cb/s=100 ain_B/s=32000 push/s=100 early=0 diff=32000 rw=... rd=... drop=0 rsz=0 rec=0 fft=0 sed=0 key=1
cb/s≈100 confirms 16kHz AOUT.ain_B/s≈32000 for 1ch, ≈64000 for 2ch.diffis ~32000 (1s) for 1ch and ~32000 (1s/ch) for 2ch after boot; after standby wake output still uses theCACHE_MSdelay, with the sleep-period audio appended to the ring tail.rszanddropshould stay 0;sed=1means human voice detected.
5.2 Waveform and audio*
- Probe PAD7~PAD10 with a scope/logic analyzer and confirm 16kHz frame sync and continuous DATA.
- Pull PAD2 (GPIO02) low and release while recording; I2S should stop and PAD0 returns low.
- Listen to the I2S output: after a trigger, the beginning should contain about 400ms (dual DMIC 200ms) of pre-trigger audio.
DMIC note*
On grus_gx8002b_dev_1v, DMIC uses PCM1 (audio_board.c enables PCM1 for PDM; PCM0 is for SADC/FFT). The application must read AUDIO_IN_CHANNEL_PCM1; reading PCM0 returns 0, which manifests as "no first frame, immediate standby".
6. Recording Schemes*
6.1 Single Analog Microphone (AMIC, 1ch, low-power standby)*
Two configs differ only in cache length:
| Config | Cache | Ring | Memory |
|---|---|---|---|
grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_1s.config |
CACHE_MS=1000 |
40KB | 24M, no XIP |
grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_2s.config |
CACHE_MS=2000 |
64KB | 24M, XIP |
| Item | Value |
|---|---|
| Microphone | AMIC, CONFIG_MIC_CHANNEL_NUM=1; mic buffer 40 frames = 400ms |
| Cache / rollback | CACHE_MS=1000/2000; HISTORY_MS=400 (400ms) |
| I2S | 16kHz/16bit mono, AOUT master, PAD7~PAD10 |
| VAD status | PAD0 |
| Stop key | PAD2 / GPIO02 |
| Low power | Releases the suspend lock when idle; holds it while recording |
cp configs/example/vad_record/grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_1s.config .config
make menuconfig && make
A 2s cache needs 64000 + 4 frames = 65280 bytes, which does not fit in 40KB, so 64KB is used; a 64KB ring overflows stage2 DRAM without XIP, so the 2s config enables XIP. At 24MHz do not enable CONFIG_ENABLE_PLL_FREQUENCY_50M.
6.2 Single Digital Microphone (DMIC, 1ch, low-power standby)*
Config: grus_gx8002b_dev_1v_1dmic_vad_lowpower_i2s.config
| Item | Value |
|---|---|
| Microphone | DMIC, CONFIG_TYPE_DMIC_TRACK=1, CONFIG_MIC_CHANNEL_NUM=1; mic buffer 20 frames = 200ms |
| Cache / rollback | CACHE_MS=1000 (1s); HISTORY_MS=200 (200ms) |
| I2S | 16kHz/16bit mono |
| Memory | 40KB audio_out, XIP |
| Low power | Releases the suspend lock when idle; holds it while recording |
cp configs/example/vad_record/grus_gx8002b_dev_1v_1dmic_vad_lowpower_i2s.config .config
make menuconfig && make
6.3 Dual Digital Microphone (DMIC, 2ch)*
| Config | Description |
|---|---|
grus_gx8002b_dev_1v_2dmic_vad_mono_i2s.config |
Two-channel capture, averaged into mono output |
- Microphone: DMIC 2ch, mic buffer 20 frames/ch = 200ms
- Cache / rollback:
CACHE_MS=1000(whole ring 1s);HISTORY_MS=200(200ms per channel) - I2S: averages ch0/ch1 into one stream and sends it with stereo timing (both channels carry the same stream) to PAD10; PAD0/1 are PDM_DATA/CLK, PAD3 is VAD status, PAD2 is the stop key
- Memory: 40KB audio_out, 24MHz
- Low power: releases the suspend lock when idle; holds it while recording
Pins:
| PAD | Function |
|---|---|
| PAD0 | PDM_DATA (func 7) |
| PAD1 | PDM_CLK_OUT (func 9) |
| PAD2 | GPIO02 stop key |
| PAD3 | VAD status output |
| PAD7~PAD10 | AOUT I2S |
| PAD11 / PAD12 | UART1 logs |
cp configs/example/vad_record/grus_gx8002b_dev_1v_2dmic_vad_mono_i2s.config .config
make menuconfig && make
6.4 Dual DMIC outputs mixed mono only*
Dual DMIC does not output stereo: when AOUT simultaneously reads two buffers at different addresses (non-interleaved stereo), a "tick" appears once per ring wrap and cannot be avoided from the application. Both mics are therefore averaged sample by sample into one stream, and AOUT configures a single buffer (buffer0 = buffer1 = s_ring) with stereo timing (pcm.channels=2, interlace=0, GX_AUDIO_OUT_LEFT_C); both channels carry the same stream.
Dual-channel notes: CONFIG_TYPE_DMIC + 2ch; ch1 base = ch0 + one channel size; _AinWptr uses AUDIO_IN_CHANNEL_PCM1; logfbank source is LOGFBANK_SOURCE_PDM_LEFT, human VAD only sees ch0.
6.5 Cache Capacity Evaluation*
16kHz/16bit PCM is 32000B per channel per second:
| Mode | Requirement | audio_out | Result |
|---|---|---|---|
| Single AMIC 1s | 32000B | 40KB | Fits |
| Single AMIC 2s | 64000B | 64KB | Fits |
| Single DMIC 1s | 32000B | 40KB | Fits |
| Dual DMIC 1s (mixed mono) | 32000B | 40KB | Fits (single mixed stream, 1s) |
- Cold boot / continuous awake: the read pointer starts
CACHE_MSbehind; after the ring fills, triggering keeps the full cache. - Standby wake: the ring survives standby; the AIN write-pointer delta appends sleep-period audio to the ring tail. A sleep longer than one mic buffer (single 400ms / dual 200ms) leaves a gap in the history.
6.6 Common Clock*
In clock_board.c, AIN and AOUT both derive from the same 24.576MHz PLL:
CLOCK_MODULE_AUDIO_IN_SYS: DTO 24.576MHz → 12.288MHz, then divided for ADC/PDMCLOCK_MODULE_AUDIO_PLAY: DTO 24.576MHz → 12.288MHz, AOUT yields 16kHz at 768FS- PDM clock 1.024MHz = 12.288MHz / 12, LRCLK 16kHz = 12.288MHz / 768
Both are integer divisions of the same PLL with no separate crystal. Do not enable CONFIG_ENABLE_PLL_FREQUENCY_50M: it makes the audio DTO take the 49.152M branch, so AOUT consumes about 12.5% faster than 16kHz, eating the rollback delay and causing periodic dropouts. CONFIG_AIN_AOUT_SAME_CLOCK is only valid when AOUT is an I2S slave; this scheme uses AOUT as master. If ppm-level drift remains, resync in _AoutCallback realigns it and rsz should stay 0.
7. Limitations*
- Cache capacity: 1ch up to 2s (example config 1s) / 400ms rollback; 2ch up to 1s per channel / 200ms per channel. The ring survives standby; a sleep longer than one mic buffer leaves a time gap in the history.
- Ring size is tied to
CONFIG_AUDIO_OUT_BUFFER_SIZE_KB; compile-time checks enforcering_per_channel >= CACHE_MS + 4 framesandCACHE_MS >= HISTORY_MS. - Do not exceed 64KB per channel: with a 72KB single-mic ring, AOUT consumes only ~8ms per frame (
cb/soscillates between 100/125); dropping to 40KB restores normal behavior. - Recording stops only by GPIO02 key; no fixed duration stop. Set
CONFIG_VAD_RECORD_STOP_GPIO=-1to disable. - Human VAD depends on the SED V2 model; when the model is not ready or the NPU is busy, only the hardware VAD decision is kept.