Audio Processing Application
This chapter describes the GK7206 audio processing application example — sample_audio. It contains 9 independent audio programs covering the complete audio function chain: audio acquisition, playback, encoding/decoding, recording, and double talk.
The application source code is located in the SDK directory sample/audio/. It provides a comprehensive demonstration of audio functions and serves as a reference template for developing audio-related applications.
1 Application Overview
1.1 Features
This application contains 9 independent audio programs:
- sample_audio_ai - audio acquisition (AI, Audio Input)
- sample_audio_ao - audio output (AO, Audio Output)
- sample_audio_encoder - audio encoding (PCM → G711/AAC)
- sample_audio_decoder - audio decoding (G711/AAC → PCM)
- sample_audio_record_v1 - recording (version 1)
- sample_audio_record_v2 - recording (version 2)
- sample_audio_record_v3 - recording (version 3)
- sample_audio_record_detect - recording + detection
- sample_audio_doubletalk_v1/v2 - double talk (AEC echo cancellation)
1.2 Technical Specifications
| Parameter | Value |
|---|---|
Sample rates | 8000/16000/32000/44100/48000 Hz |
Channels | 1 (mono) / 2 (stereo) |
Sample bit depth | 16 bit |
Encoding formats | G711A/U, AAC |
Audio quality enhancement | VQE (Voice Quality Enhancement) |
Echo cancellation | AEC (Acoustic Echo Cancellation) |
Input/output files | PCM files (under /sd_card) |
1.3 Directory Structure
sample/audio/
├── Makefile # Build script
├── sample_audio_ai # Audio acquisition program
├── sample_audio_ai.c # Audio acquisition source
├── sample_audio_ao # Audio output program
├── sample_audio_ao.c # Audio output source
├── sample_audio_encoder # Audio encoding program
├── sample_audio_encoder.c # Audio encoding source
├── sample_audio_decoder # Audio decoding program
├── sample_audio_decoder.c # Audio decoding source
├── sample_audio_record_v1 # Recording program v1
├── sample_audio_record_v2 # Recording program v2
├── sample_audio_record_v3 # Recording program v3
├── sample_audio_record_detect # Recording + detection program
├── sample_audio_doubletalk_v1 # Double talk program v1
├── sample_audio_doubletalk_v2 # Double talk program v2
└── record_board/ # Board-level recording
├── sample_record_board_detect
└── sample_record_board_record2 Build and Deployment
2.1 Prerequisites
Before building this application, make sure the following preparations have been completed:
- SDK environment is set up: follow SDK Compilation to set up the cross-compilation toolchain and SDK configuration
- Audio hardware preparation:
- Acquisition tests: a microphone must be connected
- Playback tests: a speaker must be connected
2.2 Build the Application
# Enter the sample directory
cd <SDK_PATH>/sample
# Build the audio sample
make -C audio clean && make -C audioOr build from the top level:
make -C sample all2.3 Deploy to the Board
# Transfer to the development board via SCP
scp sample/audio/sample_audio_* root@<board IP>:/sd_card/
# Or download via TFTP
tftp -g -r sample_audio_ai <board IP>Info
Audio files are usually large, so it is recommended to run them from the SD card.
3 Audio Acquisition (AI)
3.1 Function Description
sample_audio_ai demonstrates audio acquisition, saving the audio data captured from the microphone into a PCM file.
3.2 Command Format
./sample_audio_ai [dev] [send_object] [binder_mode] [samplerate] [usr_samplerate] [channels] [workmode] [outfile] [vqe_type]Parameters:
| Parameter | Description | Values |
|---|---|---|
dev | Audio device number | 0/1 |
send_object | Send target | 0=AO, 1=encoder, 2=both |
binder_mode | Binder mode | 0/1 |
samplerate | Sample rate | 8000/16000/32000/44100/48000 |
usr_samplerate | User sample rate | 8000/16000/32000/44100/48000 |
channels | Number of channels | 1/2 |
workmode | Working mode | 0/1 |
outfile | Output file path | /sd_card/ai.pcm |
vqe_type | Audio quality enhancement type | 0/1 |
3.3 Typical Usage
# 8 kHz mono acquisition, saved to /sd_card/ai.pcm
./sample_audio_ai 0 0 0 8000 8000 1 0 /sd_card/ai.pcm 0
# 16 kHz mono acquisition with VQE enabled
./sample_audio_ai 0 0 0 16000 16000 1 0 /sd_card/ai.pcm 13.4 Expected Behavior
The program prints the following information when running:
audio ai sample running
ai dev: 0
samplerate: 8000
channels: 1
...
recording to /sd_card/ai.pcmDuring acquisition it keeps printing frame counts; press Ctrl+C to stop.
4 Audio Output (AO)
4.1 Function Description
sample_audio_ao demonstrates audio playback, reading audio data from a PCM file and playing it through the speaker.
4.2 Command Format
./sample_audio_ao [infile] [dev] [dev_rate] [dev_chn] [frm_rate] [frm_chn] [mode] [pcm_sample] [vqe]Parameters:
| Parameter | Description | Values |
|---|---|---|
infile | Input PCM file path | /sd_card/in.pcm |
dev | Audio device number | 0/1 |
dev_rate | Device sample rate | 8000/16000/32000/44100/48000 |
dev_chn | Device channel count | 1/2 |
frm_rate | Frame sample rate | 8000/16000/32000/44100/48000 |
frm_chn | Frame channel count | 1/2 |
mode | Playback mode | 0/1 |
pcm_sample | PCM sample bit depth | 16 |
vqe | Audio quality enhancement | 0/1 |
4.3 Typical Usage
# 8 kHz mono playback
./sample_audio_ao /sd_card/in.pcm 0 8000 1 30 0 0 16 0
# 16 kHz mono playback with VQE enabled
./sample_audio_ao /sd_card/in.pcm 0 16000 1 30 0 0 16 14.4 Expected Behavior
The program prints the following information when running:
audio ao sample running
ao dev: 0
samplerate: 8000
channels: 1
...
playing /sd_card/in.pcmDuring playback it keeps printing frame counts, and exits automatically when playback finishes.
5 Audio Encoding/Decoding
5.1 Audio Encoding (sample_audio_encoder)
Function: encodes a PCM file into G711/AAC format.
Command format:
./sample_audio_encoder [infile_samplerate] [infile_channels] [infile] [outfile]Typical usage:
# Encode to G711
./sample_audio_encoder 8000 1 /sd_card/in.pcm /sd_card/out.g711
# Encode to AAC
./sample_audio_encoder 8000 1 /sd_card/in.pcm /sd_card/out.aac5.2 Audio Decoding (sample_audio_decoder)
Function: decodes a G711/AAC file into PCM format.
Command format:
./sample_audio_decoder [mode] [infile_samplerate] [infile]Typical usage:
# Decode G711
./sample_audio_decoder 0 8000 /sd_card/in.g711
# Decode AAC
./sample_audio_decoder 1 8000 /sd_card/in.aac6 Recording Programs
6.1 Version Differences
There are three versions of the recording program; the main differences are in parameters and features:
| Version | Characteristics |
|---|---|
sample_audio_record_v1 | Basic recording |
sample_audio_record_v2 | Supports more parameters |
sample_audio_record_v3 | Supports more audio quality enhancement options |
6.2 Command Format
# v1
./sample_audio_record_v1 [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile] [vqe_type]
# v2
./sample_audio_record_v2 [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile] [vqe_type] [aec_mode]
# v3
./sample_audio_record_v3 [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile] [vqe_type] [aec_mode] [agc_mode]6.3 Typical Usage
# Basic recording
./sample_audio_record_v1 8000 8000 0 0 /sd_card/rec.pcm 0
# Recording with VQE and AEC enabled
./sample_audio_record_v2 16000 16000 0 0 /sd_card/rec.pcm 1 17 Double Talk Program
7.1 Function Description
sample_audio_doubletalk_v1/v2 demonstrates the double talk feature — performing audio acquisition and playback simultaneously with AEC (echo cancellation) enabled.
7.2 Command Format
./sample_audio_doubletalk_v1 [samplerate] [usr_samplerate] [channels] [binder_mode] [outfile] [infile] [infile_samplerate]7.3 Typical Usage
# Double talk test
./sample_audio_doubletalk_v1 8000 8000 1 0 /sd_card/out.pcm /sd_card/in.pcm 80007.4 Expected Behavior
The program performs acquisition and playback simultaneously; the AEC algorithm removes the echo to ensure bidirectional call quality.
8 Audio Quality Enhancement (VQE)
8.1 VQE Functions
VQE (Voice Quality Enhancement) provides the following functions:
| Function | Description |
|---|---|
| ANR | Adaptive noise reduction |
| AGC | Automatic gain control |
| AEC | Acoustic echo cancellation |
| EQ | Equalizer |
8.2 Enabling VQE
Set the vqe_type argument to 1 in the command to enable VQE:
./sample_audio_ai 0 0 0 8000 8000 1 0 /sd_card/ai.pcm 19 Key Programming Points
9.1 AI Acquisition Flow
// Step 1: Initialize the AI module
xmedia_ai_set_dev_attr(dev, &attr);
xmedia_ai_enable(dev);
// Step 2: Get an audio frame
xmedia_ai_get_frame(dev, &frame, timeout);
// Step 3: Process the audio frame
// ... write to file or send to the encoder ...
// Step 4: Release the audio frame
xmedia_ai_release_frame(dev, &frame);
// Step 5: Disable the AI module
xmedia_ai_disable(dev);9.2 AO Output Flow
// Step 1: Initialize the AO module
xmedia_ao_set_dev_attr(dev, &attr);
xmedia_ao_enable(dev);
// Step 2: Send an audio frame
xmedia_ao_send_frame(dev, &frame, timeout);
// Step 3: Disable the AO module
xmedia_ao_disable(dev);9.3 Audio Encoding/Decoding Flow
// Encoding
xmedia_acodec_create_encoder(&chn, &type);
xmedia_acodec_send_frame(chn, &pcm_frame);
xmedia_acodec_get_stream(chn, &encoded_stream);
// Decoding
xmedia_acodec_create_decoder(&chn, &type);
xmedia_acodec_send_stream(chn, &encoded_stream);
xmedia_acodec_get_frame(chn, &pcm_frame);10 Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
| No sound output | Speaker not connected or volume too low | Check the hardware connection, adjust volume |
| No data acquired | Microphone not connected | Check the hardware connection |
| Distorted sound | Sample rate mismatch | Check the sample rate settings |
| Severe echo | AEC not enabled | Enable VQE and AEC |
| Encoding/decoding failure | Unsupported encoding format | Check that the encoding format is supported |
