Audio Recording Example*
Tip
- SDK Path: http://gitlab.nationalchip.com/nationalchip/voice-wifi-solution/ovp_aiot
- App Path: app/audio_record_sample_app/ under the SDK path
- Applicable Chips: 8005/8006
1. Overview*
The audio recording example App demonstrates how to capture microphone audio and stream PCM data to a PC via UART DMA. It supports capturing both raw microphone audio and AEC (Acoustic Echo Cancellation) processed audio. The accompanying tools.zip provides the PC-side receiving program source code.
2. Features*
- Microphone audio capture, supporting both raw and AEC-processed data sources
- High-speed audio data transmission via UART0 (921600 baud rate) DMA
- Custom frame protocol: 5-byte header + 1280-byte PCM data
- External PA (Power Amplifier) mode support
- Silence detection and automatic MUTE control
- Optional hard loopback path (simultaneous audio playback for echo cancellation reference)
3. Directory Structure*
app/audio_record_sample_app/
├── audio_record_sample_app.c # Main program
├── app.mk # Build configuration
├── app.name # Kconfig option
├── test_wav.h # Test PCM data (loopback reference)
└── tools.zip # PC-side serial receiving program source code (Windows + Linux)
| File | Description |
|---|---|
audio_record_sample_app.c |
Audio capture, UART transmission, protocol framing |
app.mk |
Compiles audio_record_sample_app.c |
app.name |
Defines the CONFIG_APP_AUDIO_RECORD option |
tools.zip |
PC-side companion serial receiving program source code (includes Windows and Linux versions) |
4. Configuration*
4.1 Macro Definitions*
#define AUDIO_OUT_BUFFER_LEN 8192 // Playback DMA buffer size
#define APP_ENABLE_EXTERNAL_PA 1 // External PA support (1: enable, 0: disable)
#define APP_ENABLE_MUTE_CONTROL 1 // Mute control (1: enable, 0: disable)
#define APP_ENABLE_MUTE_PIN 7 // Mute control GPIO pin
#define FRAM 1280 // Audio data bytes per frame
4.2 Transmission Protocol*
UART frame format (5-byte header + data):
| Field | Length | Value |
|---|---|---|
| Sync header | 4 bytes | 0x11 0x22 0x33 0x44 |
| Type | 1 byte | 0x01 (audio data) |
| PCM data | 1280 bytes | Microphone audio data |
5. Working Principle*
5.1 Initialization Flow*
- Configure UART0: 921600 baud rate, DMA transmission mode
- Initialize the audio output path (hard loopback reference, can be commented out to disable)
- Configure SDM/DAC audio playback parameters
- If external PA is enabled: switch pin multiplexing and volume mapping table
- If mute control is enabled: configure GPIO 7 as output
5.2 Event Handling*
app_event_response() responds to the Audio-in recording complete event:
| Event | Trigger Condition | Handling Logic |
|---|---|---|
EVENT_AUDIO_IN_RECORD_DONE |
Audio-in recording complete (trigger time determined by PCM frame length, configure accordingly) | Get VPA context, extract microphone frame, wrap protocol header, transmit via UART DMA |
Data source switching (as noted in code comments):
// Raw microphone audio
vpa_get_mic_frame(context, &src_addr, &src_len);
// AEC-processed audio
vpa_get_ref_frame(context, &src_addr, &src_len);
5.3 Silence Detection*
Automatically MUTEs the output after 30 consecutive silent frames, and unmutes when speech is detected.
5.4 Main Loop*
app_task_loop() is an empty implementation.
6. Usage*
6.1 Compilation*
cp configs/example/app/8006_audio_record_sample_app.config .config
make defconfig
make clean; make
Or select via menuconfig:
make menuconfig
# OVP Application Settings → Applications Selection → Audio Record Sample
6.2 Flashing and Running*
cd tools/bootx/
./flash_nor.sh 0 -r 1000000
6.3 PC-side Reception*
Extract tools.zip, refer to the PC-side source code within to compile and run the receiving program. UART parameters: 921600 baud rate.
7. Expected Output*
The PC-side receiving program continuously receives PCM audio frames with the protocol header.
8. Notes*
- Data Source Selection: Raw microphone audio is sent by default. To use AEC-processed data, change
vpa_get_mic_frametovpa_get_ref_frameinapp_event_response() - Hard Loopback Path: Keep the
audio_out_init()call for hard loopback analysis; comment it out if not needed to reduce interference - External PA: Setting
APP_ENABLE_EXTERNAL_PAto 1 modifies pin multiplexing and volume mapping; configure according to the actual hardware - UART Parameters: Fixed to UART0, 921600 baud rate; the PC side must match
- Sleep/Wake-up Not Implemented: The current SDK does not support sleep functionality; keep
app_suspend()andapp_resume()as empty implementations