How vvt3/audio-visualiser works
1. Project shape
- This is a single-page browser app built with React + Vite on the UI side and a vanilla JavaScript rendering/audio engine on the runtime side.
- The core architectural boundary is between React-managed controls/state and an independent animation/render loop that runs on <canvas>.
2. Entry and bootstrapping
- index.html and src/main.jsx form the app entry path.
- main.jsx mounts the React tree into the page, and App.jsx becomes the top-level coordinator for the visualizer.
3. UI layer
- src/components/MusicInput.jsx is the user interaction boundary for selecting an audio file.
- src/components/Canvas.jsx is the bridge between React and the graphics engine: React provides the host element and any needed state, while the engine performs actual drawing.
- App.jsx likely orchestrates these components and holds the minimal state needed to connect upload, playback, and rendering.
4. Rendering engine
- src/engine/audio.js contains the non-React logic for audio analysis and animation support.
- Based on the README, this engine is responsible for:
- decoding/analyzing uploaded audio via the Web Audio API
- generating procedural track data
- driving the animation loop with requestAnimationFrame
- rendering the rollercoaster scene to HTML5 Canvas
5. Main data flow
- User selects an audio file in MusicInput.
- That file is passed into the audio engine.
- The engine analyzes frequency/time-domain data and converts it into motion/track behavior.
- Canvas displays the resulting animated scene, including the cart moving along the generated path.
6. Separation of responsibilities
- React is used for stateful UI and layout only.
- The engine is deliberately kept outside React so the high-frequency visual updates do not cause React re-renders.
- This is a key performance boundary and likely the most important architectural decision in the repo.
7. Visual generation model
- The current implementation uses a procedural sine-wave-based track according to the README.
- The intended evolution is to replace that placeholder with track motion derived more directly from audio frequency bands, so the engine acts as a real-time translator from sound to geometry.
8. Animation/runtime behavior
- The visualizer is a live browser simulation, not a static render.
- The loop is driven by requestAnimationFrame, which suggests the engine continuously updates track/cart position and redraws the canvas in sync with browser refresh timing.
9. Styling and layout
- src/index.css, tailwind.config.js, and postcss.config.js indicate the app uses Tailwind CSS for presentation.
- Styling is separate from the simulation logic, which keeps the visualizer’s layout/header/control chrome distinct from the canvas renderer.
10. Build/tooling boundary
- vite.config.js defines the development/build pipeline.
- This is a frontend-only project with no backend service, database, or persistent storage in the current architecture.
11. Assets
- assets/screenshots contains documentation/demo imagery rather than runtime inputs.
- There is no evidence of server-hosted assets or remote APIs in the current design.
12. How to diagram it
- Draw three main boxes:
- React UI: App, MusicInput, Canvas
- Audio/Render Engine: audio.js, waveform/track generation, animation loop
- Browser Platform: Web Audio API, Canvas API, requestAnimationFrame
- The arrows should flow from file upload → audio analysis → procedural track/motion → canvas rendering, with React only coordinating the handoff and layout.
Main entry points: App.jsx App · audio.js audio.js · main.jsx main.jsx · MusicInput.jsx Music input
Components 15
App shell
React entry and top-level coordination
- index.html · Page shell that loads the app
index.html - main.jsx · Mounts the React tree
src/main.jsx
UI layer
User controls and canvas host
- App · Top-level UI coordinator for upload, playback, and rendering
src/App.jsx - Music input · User boundary for selecting audio files
src/components/MusicInput.jsx - Canvas · Hands off drawing to the engine while hosting the canvas element
src/components/Canvas.jsx
Audio engine
Non-React analysis, motion, and animation logic
- audio.js · Imperative audio-visual runtime outside React
src/engine/audio.js - Analysis · Decodes and inspects uploaded audio data
- Track synth · Turns analyzed audio into track and cart motion
- Animation loop · Continuously updates and redraws with requestAnimationFrame
Browser APIs
Canvas, audio, and frame-timing primitives
- Web Audio API · Audio decoding and frequency/time-domain access
- Canvas API · Immediate-mode 2D drawing target
- requestAnimationFrame · Browser refresh-synced update driver
Build and styles
Frontend build pipeline and presentation layer
- index.css · Global presentation and layout styling
src/index.css - Vite config · Development and production bundling setup
vite.config.js - Screenshots · Demo imagery for documentation
assets/screenshots
Connections 17
- index.html → main.jsx: loads · Browser loads the React entry point
- main.jsx → App: mounts · Bootstraps the top-level React component
- App → Music input: renders · Provides upload controls
- App → Canvas: renders · Provides the visualizer surface
- App → index.css: uses · Shares global layout and presentation styling
- Music input → audio.js: passes file · Selected audio is handed to the engine
- Canvas → audio.js: hosts · Canvas host is wired to the render engine
- audio.js → Analysis: analyzes · Engine decodes and inspects audio content
- Analysis → Web Audio API: uses · Relies on browser audio decoding and analysis
- audio.js → Track synth: generates · Converts analysis into motion and geometry
- Track synth → Animation loop: updates · Produces frame-by-frame scene state
- Animation loop → requestAnimationFrame: driven by · Frame updates are synchronized to browser refresh
- Animation loop → Canvas API: draws to · Renders the animated scene on canvas
- audio.js → Canvas API: renders · Direct canvas drawing occurs outside React
- App → audio.js: coordinates · App mediates the handoff between UI and runtime
- Screenshots → App: documents · Repository media shows the visualizer output
- Vite config → main.jsx: bundles · Build pipeline includes the app entry