Skip to content

NN Denoise*

Note

1. Overview*

Neural network denoising example App, demonstrating how to perform real-time denoising on microphone audio via NN (Neural Network) and output the denoised audio to the speaker. Supports physical button to toggle denoising, LED status indication, and VAD-based automatic mute.

2. Features*

  • NN real-time denoising processing (vpa_ns_nn)
  • Physical button (GPIO 16) single click toggles denoising on/off
  • LED (GPIO 5) indicates denoising status (low level = denoising on, high level = denoising off)
  • VAD-driven automatic mute: MUTE output after consecutive silence frames reach threshold, immediate recovery upon voice detection
  • Zero-copy audio path: microphone buffer directly used as audio output buffer

3. Directory Structure*

app/nn_denoise_app/
├── nn_denoise_app.c   # Main program
├── app.mk              # Build configuration
├── app.name            # Kconfig option
├── Kconfig             # Sub-configuration (empty)
└── audio_out/
    ├── audio_out.c     # Audio output driver (SDM/DAC)
    └── audio_out.h     # Audio output API
File Description
nn_denoise_app.c Main program, button handling, VAD mute logic, denoising toggle
app.mk Builds the main program and audio_out sub-module
app.name Defines the CONFIG_APP_NN_DENOISE option
audio_out/ Audio output driver wrapper, supports internal and external DAC

4. Configuration*

4.1 Kconfig Options*

This App has no additional Kconfig sub-configuration.

4.2 Macro Definitions*

#define NEED_SILENCE_FRAMES  30    // Consecutive silence frame count threshold (MUTE output after reaching)
#define BTN_NS_GPIO          16    // Denoising toggle button GPIO
#define LED1_GPIO            5     // Denoising status indicator LED GPIO

4.3 Audio Output API*

// Player status
typedef enum { AOUT_STATUS_IDLE, AOUT_STATUS_PREPARE, AOUT_STATUS_PLAYING } PLAYER_STATUS;

// Initialize audio output
int32_t aout_init(AOUT_PARAM *aout_param);
// Start playback (offset: offset, length: length)
int32_t aout_play(uint32_t offset, uint32_t length);
// Set volume (0-100)
int32_t aout_set_volume(uint32_t volume);
// Mute / Unmute
int32_t aout_set_mute(void);
int32_t aout_cancel_mute(void);

5. Working Principle*

5.1 Initialization Flow*

  1. Configure button GPIO 16 (pull-up input), register single-click callback _btn1_click_callback for denoising toggle
  2. Configure LED GPIO 5 (output), initial low level (denoising on)
  3. Read VPA context to obtain audio IO configuration parameters
  4. Initialize audio output: microphone buffer as playback buffer, sample rate follows VPA configuration, volume 100

5.2 Denoising Toggle*

Button single click → toggle denoising state → call vpa_ns_set_use_ns_mask_flag() → update LED:

Denoising on   →  LED low level
Denoising off  →  LED high level

5.3 VAD Mute Logic*

Checked on every Audio-in recording completion event:

context->vad == true   →  Immediately unmute, reset counter
context->vad == false  →  Counter +1
                          Counter >= 30  →  MUTE output

5.4 Event Handling*

Event Trigger Condition Handling Logic
EVENT_AUDIO_IN_RECORD_DONE Audio-in recording complete (trigger time determined by PCM frame length, configure accordingly) Start playback on first frame; execute VAD mute logic on subsequent frames

5.5 Main Loop*

app_task_loop() calls multi_button_tick() to drive button detection.

6. Usage*

6.1 Build*

cp configs/nn_denoise/8006_nn_denoise_app.config .config
make defconfig
make clean; make

6.2 Flash and Run*

cd tools/bootx/
./flash_nor.sh 0 -r 1000000

7. Expected Output*

  • After power-on, speaker outputs denoised microphone audio (real-time passthrough)
  • Press GPIO 16 button to toggle denoising, LED state flips
  • Automatic MUTE after microphone silence for approximately 1.2 seconds (30 frames × 40ms)

8. Notes*

  1. NN Model Dependency: Denoising relies on the vpa_ns_nn module in the VPA framework; ensure the firmware includes the NN denoising model
  2. Zero-copy Caution: Audio output directly uses the VPA microphone buffer; do not allocate or free this buffer additionally
  3. External DAC: If using an external DAC, enable CONFIG_ENABLE_EXTERNAL_DAC in audio_out.c; pin multiplexing and mute pin will differ
  4. Button Debouncing: Button detection is handled by the multi_button framework with built-in debouncing logic
  5. Suspend/Wakeup Not Implemented: The current SDK does not support suspend functionality; keep app_suspend() and app_resume() as empty implementations