This tool analyzes music files and extracts a smooth energy metric at 24 Hz, perfect for driving animations, visualizations, or any application that needs to sync with music energy. The energy curve resembles a rollercoaster that follows the natural rises and falls of the music.
- Energy Curve Extraction: Generates a smooth 24Hz energy metric (0-1) that captures the dynamic intensity of music
- Physics-Based Smoothing: Applies momentum and inertia constraints for natural, rollercoaster-like movement
- Multi-Stage Processing: Uses cascaded filtering techniques to create natural-feeling rises and falls
- Beat & Bar Detection: Identifies musical beats and organizes them into bars/measures
- Section Identification: Uses machine learning (K-means clustering) to detect different song sections
- Fallback Algorithm: Energy-based section detection when ML approach fails
- Drop Detection: Identifies significant musical drops with precise timing
- Build-up Recognition: Detects gradual energy increases before drops
- Spectral Centroid: Measures brightness/sharpness of sound
- Spectral Bandwidth: Captures width/spread of frequencies
- Chroma Features: Analyzes harmonic content and pitch classes
- Energy Zone Classification: Categorizes into low/medium/high energy zones
-
Multi-Panel Display: Four synchronized visualization panels:
- Energy curve with zone coloring (blue/green/red)
- Audio waveform with bar markers
- Spectral features with color-mapped pitch information
- Song structure with section boundaries
-
Interactive Controls:
- Play/pause toggle
- Skip forward/backward 10 seconds
- Toggle between full song view and scrolling view
- Real-time highlighting of played segments
Four CSV files with synchronized timestamps:
- Energy Data: Time-synchronized energy values
- Zone Data: Energy zone classifications (low/medium/high)
- Spectral Data: Centroid, bandwidth, and chroma values
- Structure Data: Bar boundaries, section changes, drops, and onsets
We've also created an immersive 3D visualization using Three.js that turns the music energy data into a first-person rollercoaster experience.
- First-Person Rollercoaster: Ride a rollercoaster track generated from music energy data
- Dynamic Environment: Environment changes between three themed zones based on music energy:
- Low Energy Zone: Underwater world with swaying plants and swimming fish
- Medium Energy Zone: Forest environment with pulsing trees and floating particles
- High Energy Zone: Volcanic landscape with rising fire particles and pulsing rocks
- Music-Reactive Elements: All objects in the scene react to different frequency bands:
- Bass frequencies affect object size and movement intensity
- Mid-range frequencies create pulsing effects
- Treble frequencies drive smaller particle animations
- Interactive Controls:
- Play/pause the music and restart the ride
- Toggle between first-person and orbit camera views (press 'V')
- Real-time display of current energy level and zone
# Navigate to the web directory
cd web
# Install dependencies
npm install
# Start the development server
npm run dev
Then open http://localhost:3000 in your browser to experience the visualization.
# Clone the repository
git clone https://github.com/yourusername/music-energy-analyzer.git
cd music-energy-analyzer
# Install dependencies
pip install -r requirements.txt
# Basic analysis with output to console
python music_energy_analyzer.py your_song.mp3
# Save the energy values to CSV files
python music_energy_analyzer.py your_song.mp3 --output energy_data.csv
# Static visualization of the energy curve
python music_energy_analyzer.py your_song.mp3 --visualize
# Play the song with real-time visualization
python music_energy_analyzer.py your_song.mp3 --play
# Play and save data simultaneously
python music_energy_analyzer.py your_song.mp3 --play --output energy_data.csv
- Full/Scroll View: Toggle between seeing the entire song or a scrolling window
- Skip Controls: Navigate 10 seconds forward or backward
- Play/Pause: Control audio playback
- Auto-Scrolling: Visualization follows playback position in scroll view mode
The script processes audio through multiple stages:
-
Feature Extraction: Extracts multiple audio features including:
- RMS energy (volume/intensity)
- Spectral contrast (difference between peaks and valleys in the spectrum)
- Spectral flux (rate of change of the spectrum)
- Beat detection and emphasis
- Build-up detection and drop recognition
-
Feature Combination: Combines these features with carefully tuned weights
-
Physics Simulation: Applies constraints that mimic real rollercoaster physics:
- Maximum acceleration/deceleration limits
- Momentum simulation
- Gravity effects
-
Multi-stage Smoothing: Creates a continuous, non-noisy curve:
- Savitzky-Golay filtering to preserve meaningful peaks
- Gaussian filtering for overall smoothness
- Adaptive smoothing based on local energy
-
Structural Analysis: Identifies important musical elements:
- Bar detection based on beats
- Section boundaries using machine learning
- Energy zone classification
-
Final Processing: Resamples data to exactly 24 Hz and normalizes to 0-1 range
When saving data with the --output
flag, the program generates four CSV files:
-
*_energy.csv
: Time and energy values (0-1)- Columns:
time,energy
- Columns:
-
*_zones.csv
: Energy zone classifications- Columns:
time,zone
(0=low, 1=medium, 2=high)
- Columns:
-
*_spectral.csv
: Spectral characteristics- Columns:
time,centroid,bandwidth,chroma_hue
- Columns:
-
*_structure.csv
: Structural elements- Columns:
feature,time
with features including:bar_boundaries
section_boundaries
drop_locations
onset_times
- Columns:
The extracted features can be used for:
- Driving 3D visualizations that react to music
- Synchronizing lighting systems or visual effects
- Creating music-reactive games or experiences
- Analyzing music structure for composition or remixing
- Music education and analysis
- Python 3.6+
- librosa
- numpy
- scipy
- matplotlib
- pygame (for interactive visualization)
- scikit-learn (for music structure detection)