BPM Calculation Algorithm
SHOWBEATSYNC's accuracy is achieved through multi-stage cleanup and strict mathematical logic.
1️⃣ Transient Detection Core: Spectral Flux
Unlike primitive algorithms that simply search for beats by volume peaks, SHOWBEATSYNC uses the Spectral Flux algorithm. Simple volume detectors are easily fooled by heavily compressed tracks. Spectral Flux reacts to new sounds, not just high volume. It can isolate a quiet snare drum hit even against a roaring synthesizer.
- Windowing: The incoming audio signal is sliced into 1024-sample windows with a hop size of 512 samples.
- FFT: Fast Fourier Transform is applied to each window.
- Difference Calculation: The algorithm looks for positive energy changes in each frequency band.
- Onset Detection: Registers a transient when new energy suddenly appears.
2️⃣ Tempo Tracking
Detecting individual beats is only the first step. The tempo tracking algorithm measures the time intervals between the detected transients.
- The collected intervals are passed through statistical prediction algorithms.
- The system builds an internal phase grid and tries to align it with the incoming beats.
- Two parameters are generated: the estimated BPM and the Confidence.
3️⃣ Heuristic Layer (Post-processing)
SHOWBEATSYNC passes the "raw" BPM through 3 levels of strict filtering:
Filter 1: Octave Correction
The user sets a hardware band-pass filter using the BPM Range setting. Any values that fall outside the logic are forcibly multiplied or divided by 2.
Filter 2: Moving Average Smoothing
A vector buffer stores the last 6 reliable tempo values to smooth out jitter. This acts as a software flywheel, generating an absolutely linear MIDI Clock.
Filter 3: Anti-Breakdown / Flywheel
If the confidence drops below 46%, the logic gate snaps shut. The history vector is frozen and continues to move rhythmically "by inertia" via the Windows multimedia timer.
4️⃣ Hardware Routing and Timings
- Audio Thread: The audio stream runs in real-time at maximum priority. The calculation of FFT occurs right inside the callback function.
- MIDI Thread: Generation of Clock and Note commands is moved to a separate high-precision asynchronous timer, guaranteeing no micro-freezes.