How It Works
The music engine consists of three core components that work together to create authentic LoFi soundscapes:Piano
Melodic foundation using sampled piano notes across 6 octaves (A, C, D#, F#)
Drums
Rhythmic backbone with kick, snare, and hi-hat patterns
Chords
Harmonic structure with procedurally generated chord progressions
Tone.js Integration
The engine is built on Tone.js, a powerful Web Audio framework that handles:- Sample Playback: High-quality piano and drum samples
- Signal Processing: Low-pass filters (1000Hz) for that classic LoFi warmth
- Stereo Effects: Stereo widening for spatial depth
- Master Output: Professional audio routing and mixing
Chord Progression System
- Generation
- Music Theory
- Customization
Chord progressions are generated procedurally using weighted intervals:
- Random starting chord from a curated chord library
- Each chord knows which chords can follow it naturally
- Progressions maintain musical coherence across transitions
- Configurable length for variety and structure
Instrumentation
Piano Samples
The piano uses 24 high-quality samples covering:- 4 notes: A, C, D#, F# (carefully selected for LoFi aesthetics)
- 6 octaves: 1-6 (spanning bass to treble ranges)
- Multiple velocities for dynamic expression
The limited note selection is intentional - it creates the characteristic LoFi sound by constraining the harmonic palette.
Drum Kit
Drum Components
Drum Components
Kick Drum
Kick Drum
- Bass frequency foundation
- Volume: -3dB (mixed for balance)
- Sample:
assets/engine/DrumSamples/kick.mp3
Snare
Snare
- Mid-range punch and rhythm
- Sampled from authentic LoFi kits
- Sample:
assets/engine/DrumSamples/snare.mp3
Hi-Hat
Hi-Hat
- High-frequency texture and groove
- Creates rhythmic subdivisions
- Sample:
assets/engine/DrumSamples/hat.mp3
Audio Processing
The engine applies professional audio processing to achieve the signature LoFi sound:| Effect | Purpose | Setting |
|---|---|---|
| Low-pass Filter | Removes harsh high frequencies | 1000Hz cutoff |
| Stereo Widener | Adds spatial depth | 0.5 width |
| Volume Control | Balances drum levels | -3dB on kick |
Playback Control
Control music playback using:- Spacebar: Play/pause the main track
- Visual Feedback: Real-time waveform visualization
- Volume Control: Adjust main track volume independently
Technical Architecture
The music engine follows a modular design:- Clean separation of concerns
- Easy extensibility for new instruments
- Predictable audio performance
- Maintainable codebase
All audio samples are preloaded on app start to ensure smooth, glitch-free playback.