A real-time ECG waveform viewer written in C++17 using SDL2. Simulates a scrolling cardiac waveform (PQRST complex) at 72 BPM with hardware-accelerated, double-buffered rendering.
- Simulates a physiologically-shaped PQRST cardiac cycle at 72 BPM
- Producer/consumer architecture — waveform data is generated on a background thread and rendered on the main thread
- Double-buffered rendering via SDL2 render targets for tear-free output
- Thread-safe sample buffer with mutex-guarded access
- Resizable window — back-buffer is rebuilt automatically on resize
- Targets ~60 FPS with a 16 ms render loop
- macOS (currently built for
x86_64) - Clang with C++17 support
- SDL2 — install via Homebrew:
brew install sdl2makemake runOr directly:
./waveform| Key / Action | Behavior |
|---|---|
Esc |
Quit |
| Close window | Quit |
| Resize window | Rescales display |
sdl-waveform/
├── main.cpp # All source — producer thread, renderer, SDL setup
├── Makefile # Build rules (clang++, sdl2-config)
└── waveform # Compiled binary (generated)
The application uses two threads:
- Producer thread — recalculates 2000 samples of a PQRST waveform 60 times per second, advancing phase to create the scrolling animation. Writes into a mutex-protected
WaveformDatabuffer. - Main thread — polls SDL events, then calls
onPaint()which locks the buffer, maps samples to screen coordinates, and renders green line segments onto an off-screen texture before blitting to the screen.