A C++ application that demonstrates real-time acoustic echo cancellation using PortAudio and SpeexDSP libraries.
This application captures audio from your microphone and system audio, applies echo cancellation using the SpeexDSP library, and outputs the cleaned audio in real-time. It's designed to reduce echo and feedback in audio applications.
- Real-time audio processing at 16kHz sample rate
- Acoustic echo cancellation using SpeexDSP
- Noise reduction and preprocessing
- Cross-platform audio I/O with PortAudio
- Configurable filter length and frame size
- Windows 10/11 (tested)
- Visual Studio 2019/2022 with C++ support
- CMake 3.15 or higher
- vcpkg package manager
- PortAudio: Cross-platform audio I/O library
- SpeexDSP: Audio processing library for echo cancellation and noise reduction
git clone <your-repo-url>
cd aec_demo/demo# From the aec_demo directory
.\vcpkg\vcpkg.exe install portaudio:x64-windows
.\vcpkg\vcpkg.exe install speexdsp:x64-windows# From the demo directory
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Releasecopy "..\vcpkg\installed\x64-windows\bin\*.dll" ".\build\Release\"Run the application from PowerShell:
cd C:\path\to\aec_demo\demo
.\build\Release\aec_demo.exeThe application will:
- Initialize PortAudio and detect audio devices
- Open microphone input, system audio reference, and speaker output streams
- Start real-time echo cancellation processing
- Display "Starting real-time echo cancellation. Press Ctrl+C to stop."
To stop: Press Ctrl+C
You can modify the audio parameters in main.cpp:
const int SAMPLE_RATE = 16000; // Sample rate in Hz
const int FRAME_SIZE = 160; // Frame size (10ms at 16kHz)
const int FILTER_LENGTH = FRAME_SIZE * 10; // Echo tail length (100ms)┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Microphone │───▶│ Echo │───▶│ Speakers │
│ Input │ │ Cancellation │ │ Output │
└─────────────┘ │ (SpeexDSP) │ └─────────────┘
│ │
┌─────────────┐ │ │
│ System Audio│───▶│ │
│ Reference │ │ │
└─────────────┘ └──────────────┘
- Ensure microphone permissions are enabled in Windows Settings
- Check that audio devices are connected and working
- Verify DLL files are in the same directory as the executable
- Adjust
FILTER_LENGTHfor different echo tail lengths - Modify
FRAME_SIZEfor different latency/quality trade-offs - Check audio device sample rate compatibility
- Ensure vcpkg toolchain path is correct
- Verify all dependencies are installed for x64-windows triplet
- Check that Visual Studio C++ tools are installed
- Currently uses default input/output devices only
- System audio capture may require specific loopback device setup
- No GUI for real-time parameter adjustment