echo-link/README.md
Echo-Link is a real-time audio streaming application designed to capture audio from a system's input device (e.g., microphone), encode it, transmit it over a network, decode it on the receiving end, and play it back through the system's output device (e.g., speakers). The project leverages modern C++ features, PortAudio for cross-platform audio I/O, Opus for high-quality audio compression, and ASIO for efficient networking.
The diagram above illustrates the main components and data flow in Echo-Link:
-
Audio Capture
PortAudioCaptureinterfaces with the OS audio subsystem (ALSA, Core Audio, WASAPI, etc.) via PortAudio.- Captures raw PCM audio frames from the hardware audio input buffer (microphone).
- Frames are pushed into a thread-safe queue.
-
Audio Encoding
AudioCodecencodes PCM frames into compressed Opus packets for efficient network transmission.
-
Network Transmission
NetworkManagerhandles UDP-based asynchronous sending and receiving of audio packets using ASIO.- Outgoing packets are sent to the remote peer; incoming packets are received and queued for decoding.
-
Audio Decoding
AudioCodecdecodes received Opus packets back into PCM frames.
-
Audio Playback
PortAudioPlaybackpulls decoded PCM frames from a queue and writes them to the hardware audio output buffer (speakers/headphones) via PortAudio.
-
ThreadSafeQueue
- Generic, thread-safe queues are used throughout to safely pass audio frames and network packets between threads and modules.
| Class/Interface | Description |
|---|---|
Application |
Central orchestrator. Manages modules, queues, and threads for encoding, decoding, and I/O. |
IAudioSource |
Abstract interface for audio sources (capture). |
PortAudioCapture |
Captures audio from the system input device using PortAudio. |
FakeAudioSource |
Simulates an audio source by reading from a file (for testing). |
IAudioPlayback |
Abstract interface for audio playback devices. |
PortAudioPlayback |
Plays audio to the system output device using PortAudio. |
AudioCodec |
Encodes/decodes audio frames using the Opus codec. |
NetworkManager |
Handles UDP networking using ASIO. |
ThreadSafeQueue<T> |
Thread-safe queue for passing data between modules/threads. |
-
Capture: Audio is captured from the system's hardware audio input buffer via
PortAudioCapture. -
Encode: Captured PCM frames are encoded to Opus packets by
AudioCodec. -
Transmit: Encoded packets are sent over the network by
NetworkManager. -
Receive: Incoming packets are received by
NetworkManagerand queued for decoding. -
Decode: Received Opus packets are decoded back to PCM frames by
AudioCodec. -
Playback: Decoded PCM frames are played back through the system's hardware audio output buffer via
PortAudioPlayback.
- C++17 or newer compiler
- PortAudio (development headers and libraries)
- Opus (development headers and libraries)
- ASIO (standalone or Boost)
- CMake (recommended for building)
mkdir build
cd build
cmake ..
makeAfter building, run the application binary. You may need to specify configuration parameters (e.g., input/output device, network peer address) depending on your setup.
- Custom Audio Sources: Implement the
IAudioSourceinterface for new capture methods. - Custom Playback Devices: Implement the
IAudioPlaybackinterface for new playback methods. - Alternative Codecs: Extend or replace
AudioCodecfor different audio codecs.
