General
Get audio files as .mp3
from YouTube:
NOTE:
The youtube-dl
tool has been blocked, but there is a fork: yt-dlp
yt-dlp -x --audio-format mp3 -o "feels.%(ext)s" https://www.youtube.com/watch?v=ozv4q2ov3Mk
yt-dlp -x --audio-format mp3 -o "pump-up-the-jam.%(ext)s" https://www.youtube.com/watch?v=9EcjWd-O4jI
yt-dlp -x --audio-format mp3 -o "blue-monday.%(ext)s" https://www.youtube.com/watch?v=c1GxjzHm5us
yt-dlp -x --audio-format mp3 -o "lady-bump.%(ext)s" https://www.youtube.com/watch?v=NelzIKT9ON4
yt-dlp -x --audio-format mp3 -o "girl-you-know-its-true.%(ext)s" https://www.youtube.com/watch?v=RdSmokR0Enk
Get the same files as .wav
:
yt-dlp -x --audio-format wav -o "feels.%(ext)s" https://www.youtube.com/watch?v=ozv4q2ov3Mk
yt-dlp -x --audio-format wav -o "pump-up-the-jam.%(ext)s" https://www.youtube.com/watch?v=9EcjWd-O4jI
yt-dlp -x --audio-format wav -o "blue-monday.%(ext)s" https://www.youtube.com/watch?v=c1GxjzHm5us
yt-dlp -x --audio-format wav -o "lady-bump.%(ext)s" https://www.youtube.com/watch?v=NelzIKT9ON4
yt-dlp -x --audio-format wav -o "girl-you-know-its-true.%(ext)s" https://www.youtube.com/watch?v=RdSmokR0Enk
Get audio file with MSYS2:
pacman -S mingw-w64-x86_64-ffmpeg
wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe
./yt-dlp.exe --ffmpeg-location /mingw64/bin/ffmpeg.exe -x --audio-format wav -o "faulty-towers.%(ext)s" https://www.youtube.com/watch?v=PseBNmbIzGg
Play an audio file on Linux:
play pump-up-the-jam.mp3
Play an audio file on MS Windows - external soundcard (0), internal speakers (1), monitor speakers (2):
sox pump-up-the-jam.mp3 -t waveaudio 0
sox pump-up-the-jam.mp3 -t waveaudio 1
sox pump-up-the-jam.mp3 -t waveaudio 2
Play with MSYS2 - internal speakers (0), monitor speakers (1):
pacman -S mingw-w64-x86_64-sox
/mingw64/bin/sox.exe faulty-towers.wav -t waveaudio 0
Expected results:
- feels.mp3: BPM according to other sources:
101,
101,
101
- pump-up-the-jam.mp3: BPM according to other sources: 125, 128, 124, 125, 61
- blue-monday.mp3: BPM according to other sources: 130, 126, 130, 130, 128
- lady-bump.mp3: BPM according to other sources: 122, 122, 122, 122
Goals
- Acceptable: Analyze an entire audio file, get a single BPM result (batch job).
Example: input: MP3 file, output:125
BPM - Good: Read audio from a stream, detect BPM in real time.
Example: input: stdin, output:{125, 133, 125}
BPM - Perfect: Read audio from a stream, detect BPM changes in real time, indicate in which bars (measures) changes occur, as well as in absolute time.
Example: input: stdin, output:{{bpm:125, bar:1, time:0.00}, {bpm:133, bar:10, time:6.00}, {bpm:125, bar:25, time:11.00}}
Conclusion
Use:
- Use aubio (complete library with various tools, among them a beat detector) for real-time detection, reading from files, pipes, etc, using an FFT algorithm from 2005.
- Use BTrack (small collection of C files) if you want to start from scratch. Good for real-time detection, using an FFT algorithm from 2011.
- Use beat-detector if you know Rust.
- Use bpm from the Linux package
bpm-tools
if nothing else is available, or if you are lazy. Applying a multiplying factor may improve results.
Results
read-from-aubiotrack
This program uses the output from aubiotrack
and calculates both the median and the average values.
make clean all
aubiotrack -i feels.wav | ./bin/read-from-aubiotrack
DEBUG: stored numbers = 381
DEBUG: read errors = 0
DEBUG: BPM median value: 102.222836
DEBUG: BPM average value: 106.508915
aubiotrack -i pump-up-the-jam.wav | ./bin/read-from-aubiotrack
DEBUG: stored numbers = 451
DEBUG: read errors = 0
DEBUG: BPM median value: 126.532626
DEBUG: BPM average value: 125.800103
aubiotrack -i blue-monday.wav | ./bin/read-from-aubiotrack
DEBUG: stored numbers = 977
DEBUG: read errors = 0
DEBUG: BPM median value: 131.987065
DEBUG: BPM average value: 131.713718
aubiotrack -i lady-bump.wav | ./bin/read-from-aubiotrack
DEBUG: stored numbers = 359
DEBUG: read errors = 0
DEBUG: BPM median value: 123.599973
DEBUG: BPM average value: 122.601263
aubiotrack -i girl-you-know-its-true.wav | ./bin/read-from-aubiotrack
DEBUG: stored numbers = 394
DEBUG: read errors = 0
DEBUG: BPM median value: 98.764457
DEBUG: BPM average value: 102.734908
Conclusion:
aubio tempo
uses the average of all values generated by aubiotrack
to calculate the BPM.
Anyhow, the median value is closer to the expected value in most cases.