A web-based music generator that creates coherent and randomized musical pieces using the Web Audio API. This project explores algorithmic composition, generating dynamic drum patterns, basslines, chords, and melodies within a chosen scale.
- Discover it online: https://random-music.anthony-charretier.fr/
- YouTube Demo: https://www.youtube.com/watch?v=cw6gSLhoE0g
- Algorithmic Composition: Generates unique and coherent musical sequences for drums, bass, chords, and melodies.
- Two Generators:
- EightBits: Focuses on retro-inspired drum sounds and dynamic musical structures, including intros, breaks, and "riddims."
- Sine Wave: Utilizes sine and other basic waveforms with various effects (delay, distortion, reverb, filtering) to create evolving electronic soundscapes.
- Web Audio API: Leverages browser capabilities for real-time audio synthesis and processing.
- Dynamic Scale Changes: The EightBits generator randomly selects root notes and minor modes for varied harmonic content.
- Interactive Controls: Play, pause, stop, and select between different music generators.
- Visual Feedback: (Implied by
startDraw,stopDrawandupdateDisplayfunctions) The UI updates to show current musical parameters.
The project consists of two main music generation modules: eightBits.js and sine.js, along with a central main.js to manage playback and UI.
Timer.js: A custom timer utility for precise, Web Audio API-synchronized scheduling of musical events.Mode.js: (Used ineightBits.js) Manages musical scales, generating frequencies based on a root note and a chosen minor mode.- Buffers & Samples: Drum sounds are loaded as audio buffers.
- Oscillators: Sine, sawtooth, and square wave oscillators are used for synthesizing melodic and harmonic content.
- Web Audio Nodes: Extensive use of
GainNode,BiquadFilterNode(lowpass, highpass),DelayNode,ConvolverNode(reverb),WaveShaperNode(distortion),StereoPannerNode, andAnalyserNodefor rich sound design and effects.
This generator focuses on creating dynamic and structured tracks.
- Drum Kits: Loads various 8-bit inspired drum samples (kicks, snares, hats, claps, cymbals).
- Scales and Modes: Randomly picks a root note and a minor mode (
chromaticScale,minorModes) to define the harmonic context for the entire song. - Sequence Generation: Functions like
generateRandomBass,generateRandomNoteSequence,generateRandomChordSequence, andgenerateRandomMelodycreate musical phrases based on the current scale. - Song Structure: Implements "intro," "break," and "riddim" sections by dynamically changing drum patterns and musical phrases at specific song durations.
- Filtering: Applies lowpass filters with dynamic frequency sweeps to bass, notes, chords, and melodies, adding expressive movement.
This generator creates a more ambient, evolving electronic soundscape, primarily using synthesized waveforms and a robust effects chain.
- Drum Samples: Loads a different set of drum samples for percussion.
- Fixed Scale: Uses a fixed A minor scale (frequencies array) for all melodic and harmonic content.
- Complex FX Chain:
- LFO: A low-frequency oscillator modulates filter cutoff frequencies for movement.
- Distortion (
WaveShaperNode): Adds harmonic richness and grit. - Delay (
DelayNode): Creates echoes with feedback. - Filters (
BiquadFilterNode): Highpass and lowpass filters shape the sound. - Reverb (
ConvolverNode): A short impulse response reverb adds space. - Analyzer (
AnalyserNode): (Potentially for visualizers indraw.js).
- Synth Voices:
bassSynth,tbSynth,sqSynth,fundamentalSynth,thirdSynth,fifthSynth, andmelodySynthdefine distinct timbres for different musical roles using various oscillator types and ADSR-like gain envelopes. - Dynamic Sections: Generates new melody, chord, and bass sequences at different measures to introduce variations.
- A modern web browser (Chrome, Firefox, Edge, Safari) that supports the Web Audio API.
- Clone the repository:
git clone https://github.com/innermost47/random-music-js.git cd random-music-js - Serve the project:
You need a local web server to run this project, as it loads audio files via XHR. You can use:
- Live Server VS Code Extension: If you use VS Code, install the "Live Server" extension and open the project folder. Right-click
index.htmland select "Open with Live Server". - Node.js
http-server:Then opennpm install -g http-server http-server .http://localhost:8080(or whatever porthttp-servertells you) in your browser. - Python's built-in server:
Then open
python -m http.server
http://localhost:8000in your browser.
- Live Server VS Code Extension: If you use VS Code, install the "Live Server" extension and open the project folder. Right-click
- Open the
index.htmlfile in your web browser through a local web server. - Select a Song Type: Use the "Select Wave" dropdown to choose between "8-Bits" (EightBits generator) and "Sine Wave" (Sine Wave generator).
- Play: Click the "Play" button to start the music generation.
- Pause/Resume: Click the "Play/Pause" button again to pause or resume playback.
- Stop: Click the "Stop" button to stop the music and reset the generator.
- Help: Click the "Help" button to re-open the welcome modal (if implemented).
- HTML5
- CSS3
- JavaScript (ES Modules)
- Web Audio API
- Bootstrap (for UI components)
MIT