music-beat-detector
music-beat-detector is a library that analyzes a music stream and detects any beat. It can be used to control lights or any magic effect by the music wave.
Bundled with this library there are three components:
MusicBeatDetector
is able to analyze any PCM 16bit Little Endian audio stream. It detects music peaks and realtime bpm.MusicBeatScheduler
is able to sync any detected peak with the listened audio. It's useful to control some lights or any other effect.MusicGraph
generates an SVG graph that displays every detected peak. It's useful to tune the peak detection.
Example
const fs = const Speaker = const createMusicStream = const MusicBeatDetector MusicBeatScheduler MusicGraph = const musicSource = processargv2 //get the first argument on cli const musicGraph = const musicBeatScheduler = { console // your music effect goes here} const musicBeatDetector = plotter: musicGraph scheduler: musicBeatScheduler
Usage
You can play any music sound supported by the library create-music-stream. Note: The beat detection performs better on mp3 files then YouTube videos.
node examplejs /trackmp3node examplejs https://www.youtube.com/watch?v=qeMFqkcPYcgnode examplejs https://www.youtube.com/watch?v=Zi_XLOBDo_Ynode examplejs https://www.youtube.com/watch?v=n_GFN3a0yj0node examplejs https://www.youtube.com/watch?v=59Q_lhgGANc
Reference
new MusicBeatDetector(options)
Param | Default | Description |
---|---|---|
options.sensitivity | 0.6 | Response to the music wave (value from 0.5 to 1) |
options.plotter | - | Instance of MusicGraph |
options.scheduler | - | Instance of MusicBeatScheduler |
options.minThreashold | 1638 | Peaks under this level are ignored (usually they're noise) |
options.debugFilter | false | Stream the filtered music throught the lowpass filter (for debug purpose) |
getAnalyzer()
- Returns a transformer stream that analyze the music
new MusicBeatScheduler(effectCallback)
getScheduler()
- returns an instance used byMusicBeatDetector
start()
- start effects (usually controlled by speaker events)
new MusicGraph(secondWidth, secondHeight)
getPlotter()
- returns an instance used byMusicBeatDetector
getSVG()
- returns a string with the SVG that displays the analyzed music
Contributors
- chrvadala (author)