Replay is a high-performance system audio recorder and player written in Go. It captures system audio output (loopback), compresses it in real-time using a hybrid Opus+Zstd pipeline, and provides a custom OpenGL-based GUI for managing playback segments.
-
System Loopback Recording: Automatically routes system audio (what you hear) to the recorder via PulseAudio monitor sources.
-
High-Efficiency Compression: Implements a two-stage compression pipeline:
-
Opus: For perceptual audio coding.
-
Zstd: For additional lossless compression of the bitstream.
-
Custom Audio Engine:
-
Low-latency I/O using PortAudio.
-
Lock-free Ring Buffers using atomic operations for thread-safe data transfer.
-
Hardware Accelerated UI:
-
Built from scratch using OpenGL 4.1 Core.
-
Custom shader pipeline (GLSL) for rendering UI elements.
-
No heavy UI frameworks — pure vertices and textures.
- Language: Go (Golang)
- Audio I/O: PortAudio (
gordonklaus/portaudio) - Graphics: OpenGL 4.1 (
go-gl), GLFW - Compression: Opus (
hraban/opus), Zstd (klauspost/compress/zstd) - System Integration: PulseAudio (
pactlCLI wrappers for routing)
The application avoids GC pauses and blocking operations in the audio callback thread by utilizing a custom Ring Buffer implementation (internal/buffer).
- Capture: Audio frames are captured via PortAudio.
- Buffering: Raw PCM data is written to a lock-free Ring Buffer (
buffer.go) usingsync/atomicto manage read/write pointers safe across goroutines. - Processing: A separate goroutine drains the buffer, encodes audio chunks into Opus frames, and wraps them in Zstd for storage efficiency.
- Storage: Data is written to disk in a custom binary format capable of handling multiple audio segments within a single file.
Instead of using standard widgets, the UI is rendered directly via the GPU:
- Shaders: Custom Vertex and Fragment shaders handle texture mapping and color blending (
shaders.go). - Event Loop: Integrated with GLFW for handling mouse inputs and window events, manually mapping cursor coordinates to normalized device coordinates (NDC) for UI interaction.
- Linux (Due to
pactldependency for loopback routing) - OpenGL drivers
GUI Mode (Default):
./replay --path=session.rep
CLI Mode:
# Record strictly via CLI
./replay --path=music.rep --mode=record
# Replay strictly via CLI
./replay --path=music.rep --mode=replay
- Record: Start capturing system audio.
- Stop: Finalize the current segment.
- Play/Pause: Playback the recorded segment.
- Prev/Next: Navigate between recorded segments (if multiple recordings exist in one session).
This project relies on pactl (PulseAudio Control) for automatic monitor source routing. It is designed primarily for Linux environments using PulseAudio or PipeWire-Pulse.
This project is distributed under the MIT License. See the LICENSE file for details.
Third-party LICENSES