How alexsaadfalcon/cpp_music_viz works
Project type and purpose
• This is a standalone C++ desktop application (“Fractal Music Vizualizer”) that ties real-time audio analysis (FFT) to GPU‐based fractal rendering (Mandelbrot/Julia) via OpenGL.
• Its primary goal is to load a .wav track, compute an FFT on the audio stream, and drive fractal parameters in shaders to produce a music‐synchronized visualizer.
File structure
• Top‐level source:
• main.cpp — application entry and main loop
• sfml_sound.cpp — audio loading & playback (SFML Sound)
• fft2d.cc — FFT implementation
• mandel_julia.cpp + Shader.h + .glsl files — fractal engine & shader loader
• config_file.txt — runtime config (select .wav file)
• Build & config:
• CMakeLists.txt + install.sh — bootstrap CMake build, install deps
• lib/{glfw,glew,glad} — vendored OpenGL context, extension loaders
• Assets:
• bensound_*.wav — sample audio files
• examples/ — demo media
README
• Confirms Linux / Mac support via CMake
• Usage: ./install.sh → build; run build/musicViz; edit config_file.txt to swap tracks
• No external services or network; purely local compute & render
Main components
a. Audio Subsystem
– SFML Sound module reads the WAV file (config_file.txt)
– Outputs PCM samples to the FFT module
b. FFT Module
– fft2d.cc consumes PCM data, computes spectral bands
– Emits time‐bucketed amplitude data
c. Fractal Engine
– Prepares uniform data for GPU
d. Shader Pipeline
– .glsl files (mandel_julia_shader.glsl, complex_shader.glsl, etc.) loaded via Shader.h
– Vertex & fragment stages implement fractal drawing on the GPU
e. Rendering Engine & Window Context
– GLFW initializes window and GL context
– GLEW/GLAD load OpenGL function pointers
f. Configuration & Assets
– config_file.txt, WAV files, shader files live on disk
– Loaded at startup or hot‐reloaded as needed
g. Build System (CMake)
– CMakeLists.txt invokes compiler, links SFML, OpenGL, lib/{glfw,glew,glad}
Relationships & data flow
1. Startup → install.sh / CMake config → binary built
2. Run → read config_file.txt → SFML loads WAV
3. Audio → PCM stream → FFT → spectral data
4. Spectral data → parameter updates → Fractal Engine
5. Fractal Engine → set shader uniforms → GPU pipeline
6. GPU → fragment shader renders fractal to screen via GLFW window
7. Loop back for next audio frame
Architectural patterns & design principles
• Modular separation: Audio I/O, signal processing (FFT), rendering logic, and resource management are separate modules.
• GPU‐accelerated compute: heavy work (fractal iteration) pushed into fragment shader.
• Single‐process, event‐driven main loop (typical game/graphics app pattern).