Skip to content

8002 Hardware VAD, Software VAD and Low-Power UART Recording*

This document is based on the lvp_tws SDK and describes the hardware VAD and software VAD of the GX8002 (8002) chip, as well as how to use UART recording in low power (standby) mode. The recording configuration uses configs/example/record/gx8002d_dev_v1_4_1amic_uart0_500K_standby.config.

1. Two-Level VAD Overview*

The 8002 has two VAD levels, which can be used separately or together:

VAD Type Decision Location Characteristics Main Configuration
Hardware VAD AUDIO_IN module (hardware FFT) Always running, low power, quickly determines whether sound is present CONFIG_LVP_FFT_VAD_ENABLE
Software VAD VAD model output on the NPU (SED V2) Relatively higher power, provides more accurate voice activity detection CONFIG_SED_V2_VAD_MODEL_V221

Typical usage: the hardware VAD handles low-power wake-up and standby management, while the software VAD provides a second judgment when more accurate voice activity detection is required.

2. Hardware VAD*

2.1 FFT VAD*

The AUDIO_IN module calculates VAD directly on hardware logfbank/FFT data, so the MCU can determine whether sound is present without running an algorithm.

Configuration path: make menuconfig -> VUI Settings -> VAD Settings

  • Enable FFT Vad (CONFIG_LVP_FFT_VAD_ENABLE): enables the hardware FFT VAD. Standby state management and KWS task scheduling depend on this VAD.
  • Number of invalid vad (CONFIG_LVP_FFT_INVALID_VAD_NUM): number of consecutive contexts without VAD before the system is considered quiet. The reference configuration uses 25 (about 2 s; one context is about 80 ms).
  • Fallback Context Number When FFTVAD Valid (CONFIG_LVP_VAD_FALLBACK_CONTEXT): number of historical contexts to process when switching from the quiet state to the VAD-triggered state. The reference configuration uses 4.
  • Enable Auto Adjust VAD Parameter (CONFIG_LVP_ENABLE_AUTO_ADJUST_VAD_PARAMETER): automatically adjusts VAD parameters according to ambient noise.
  • Enable Noise Judgment (CONFIG_ENABLE_NOISE_JUDGEMENT): dynamically adjusts the FFT VAD threshold according to ambient noise.

In code, the hardware VAD result is read through LvpAudioInQueryFFTVad() and used for standby state switching in _LvpStandbyUpdateVad() of lvp/lvp_mode_bypass.c. In the quiet state, AUDIO_IN continues to work and the audio is stored in the buffer.

3. Software VAD*

The software VAD runs a VAD model on the NPU using the SED V2 framework to perform voice activity detection. The single-model example configuration provided by the SDK is configs/example/sed_v2/gx8002d_dev_1v4_vad_221.config.

3.1 Firmware Build*

cd lvp_tws
cp configs/example/sed_v2/gx8002d_dev_1v4_vad_221.config .config
make menuconfig
make

3.2 Configuration Description*

Key features of this configuration:

  • Work mode: SED V2 (CONFIG_LVP_INIT_WORKMODE_SED_V2=y, CONFIG_LVP_HAS_SED_V2_MODE=y)
  • Application: CONFIG_LVP_APP_SED_V2_DEMO=y
  • VAD model: CONFIG_SED_V2_VAD_MODEL_V221=y (SED V2 VAD model v2.2.1)
  • Hardware VAD and standby: CONFIG_LVP_FFT_VAD_ENABLE=y, CONFIG_LVP_STANDBY_ENABLE=y
  • Detection result: written to context->sed and read by the application through the LVP_SED_V2_ID event
  • Behavior: when speaking, the serial port prints the sed x state and the VAD LED (GPIO3, CONFIG_LVP_APP_SED_DEMO_VAD_LED=3) turns on; it turns off after more than 5 consecutive contexts without VAD

4. Low-Power UART Recording*

4.1 Working Principle*

The reference configuration uses BYPASS work mode + Standby:

  1. AUDIO_IN continuously captures, and the hardware FFT VAD continuously judges.
  2. After no sound for CONFIG_LVP_STATE_FVAD_COUNT_DOWN contexts, the MCU calls LvpPmuSuspend(LRT_GPIO | LRT_AUDIO_IN | LRT_I2C) to enter standby.
  3. When sound is detected, the AUDIO_IN interrupt wakes the MCU, and BYPASS mode continues to process PCM and sends the recording data to the PC over UART.
  4. The host uses the UART Message 2.0 protocol: MSG_NTF_START_PCM starts recording and MSG_NTF_STOP_PCM stops recording; the device reports PCM data through MSG_NTF_PCM_DATA.

Data flow: MIC → AUDIO_IN PCM buffer → AUDIO_IN_RECORD_DONE_EVENT_ID event → LvpAppEventTick() → UartRecordTask() → UART transmission.

Additional note: In standby (or quiet) state, AUDIO_IN continues to capture and writes audio into the buffer. After VAD triggers wake-up, the system can backfill CONFIG_LVP_VAD_FALLBACK_CONTEXT historical contexts; the current configuration uses 4 contexts (about 320 ms). Therefore, in theory, the several hundred milliseconds of audio before entering low power/wake-up can also be recorded, instead of starting only from the wake-up moment. The actual backfill length depends on the buffer size, VAD trigger timing, and the UART send queue/flow control; it may be truncated when the queue is full or recording has just started.

4.2 Recording Configuration*

Configuration file: lvp_tws/configs/example/record/gx8002d_dev_v1_4_1amic_uart0_500K_standby.config

Build command:

cd lvp_tws
cp configs/example/record/gx8002d_dev_v1_4_1amic_uart0_500K_standby.config .config
make menuconfig
make

Key configuration items:

Configuration Value Description
CONFIG_LVP_INIT_WORKMODE_BYPASS y Enter BYPASS mode at boot
CONFIG_LVP_HAS_BYPASS_MODE y Enable BYPASS mode
CONFIG_LVP_STANDBY_ENABLE y Enable standby for low-power recording
CONFIG_LVP_STATE_FVAD_COUNT_DOWN 18 Enter standby after about 18 contexts without sound
CONFIG_LVP_FFT_VAD_ENABLE y Hardware FFT VAD for wake-up and standby management
CONFIG_LVP_FFT_INVALID_VAD_NUM 25 Number of invalid VADs to filter
CONFIG_LVP_VAD_FALLBACK_CONTEXT 4 Number of historical contexts to backfill when VAD becomes valid
CONFIG_LVP_HAS_UART_RECORD y Enable the UART recording module
CONFIG_UART_RECORD_ENABLE y Enable the UART recording function
CONFIG_LVP_UART_RECORD_PORT 0 Recording uses UART0
CONFIG_LVP_UART_RECORD_PORT_BAUDRATE 500000 Recording baud rate is 500000
CONFIG_BOARD_HAS_UART0 y Enable UART0 at board level
CONFIG_LVP_HAS_UART_MESSAGE_2_0 y Use the UART Message 2.0 protocol
CONFIG_TYPE_AMIC y Analog microphone
CONFIG_BOARD_MIC_NUM 1 Single microphone
CONFIG_BOARD_MIC_GAIN_A 24 Analog microphone PGA gain 24 dB
CONFIG_PCM_SAMPLE_RATE_16K y Sample rate 16 kHz
CONFIG_PCM_FRAME_LENGTH_10MS y 10 ms per frame

In this configuration:

  • UART0 is used for recording data, and UART1 is used only for log output (CONFIG_MCU_PRINT_UART_PORT_1=y, CONFIG_BOARD_HAS_UART1_JUST_SUPPORT_PRINTF_LOG=y). The PC recording tool must be connected to UART0, and the debug log is output on UART1.
  • One context is 8 frames × 10 ms = 80 ms, so CONFIG_LVP_STATE_FVAD_COUNT_DOWN=18 enters standby after about 1.44 s without sound.

4.3 Recording Operation*

On Linux, use lvp_tws/tools/record/grus-record-tool:

sudo ./grus-record-tool -p /dev/ttyUSB0 -o record.pcm -d 10

On Windows, use grus-record-tool.exe from windows-grus-record-tool.zip, with the port name in the form COMx. For detailed tool parameters and output, see Serial recording.

Notes:

  • The recording baud rate must match the configuration. The tool supports 500000 and 1000000.
  • After the firmware enters standby, it does not continuously upload silence. When sound is detected, it wakes up and backfills CONFIG_LVP_VAD_FALLBACK_CONTEXT historical contexts, so the recording mainly consists of voice segments. If uninterrupted continuous recording is required, use the configuration without standby: configs/example/record/gx8002d_dev_v1_4_1amic_uart0_500K.config.
  • Use different UARTs for UART recording and log output to avoid mixing log data into the recording data.
  • If recording does not start, first confirm that the PC tool has issued the start command and that the port number, baud rate, and wiring are correct.

4.4 Dual-DMIC Low-Power Recording*

Configuration: lvp_tws/configs/example/record/gx8002d_dev_v1_4_2dmic_uart0_1M_standby.config

  • CONFIG_TYPE_DMIC=y, CONFIG_TYPE_DMIC_TRACK=2, CONFIG_MIC_CHANNEL_NUM=2
  • Mic buffer 20 frames per channel (200ms), logfbank 20 frames; audio_in uses 14400B (≤16KB)
  • UART0 at 1M baud; use -c 3 in the recording tool for both channels
  • After standby wake, at most 200ms per channel can be kept; 2 channels × 400ms needs 25.6KB and does not fit
sudo ./grus-record-tool -p /dev/ttyUSB0 -b 1000000 -c 3 -o record_2ch.pcm -d 10

The built-in UART recording (UART_RECORD_ENABLE) starts reporting PCM from the wake point and does not replay the 200ms stored in the mic buffer before wake-up. To validate that cached segment, use app/vad_i2s_out_standby, which pre-fills from the mic buffer, or add wake-up pre-fill logic to the recording path.

5. VAD Trigger Recording (Up to 2s Cache / 400ms Rollback + I2S)*

Section 4 above describes continuous UART recording. For "VAD triggers an audio output that includes cached history before the trigger", use app/vad_i2s_out_standby:

  • Application: lvp_tws/app/vad_i2s_out_standby
  • Single AMIC: configs/example/vad_record/grus_gx8002b_dev_1v_1amic_vad_lowpower_i2s_1s.config (1s cache, 400ms rollback; use ..._2s.config for 2s)
  • Single DMIC: configs/example/vad_record/grus_gx8002b_dev_1v_1dmic_vad_lowpower_i2s.config (1s cache, 200ms rollback)
  • Dual DMIC: configs/example/vad_record/grus_gx8002b_dev_1v_2dmic_vad_mono_i2s.config (mixed mono output)
  • Idle enters standby; cold boot fills the cache before sleeping; on wake the ring is reused and sleep-period audio appended; I2S output 16k/16bit; PAD0/PAD3 VAD status; PAD2 key stops.

See 8002 VAD Trigger Recording (Low-Power Cache + I2S Output) for details.