feat(temporal): swing vs straight groove detection#567
Open
seonghobae wants to merge 1 commit into
Open
Conversation
Add detect_groove(audio, sr, beat_times) to the temporal analysis module. It measures the dominant off-beat onset position within each inter-beat interval from the onset-strength envelope, aggregates the median relative position, and maps it to a long:short swing ratio (p/(1-p): ~1.0 straight, ~2.0 triplet swing). Feel is classified as swing at median position >= 0.58 (ratio >= ~1.4), the midpoint between straight (0.5) and triplet (2/3) placement. Confidence derives from the inverted, normalized IQR of off-beat positions, bounded to [0, 1]. Degenerate input (fewer than 3 beats, empty audio, no detectable off-beat onsets) and any internal error return a safe straight default with zero confidence; no exception escapes. The function is bounded to the passed in-memory arrays with no file/network/shell access. Tests synthesize deterministic click tracks with known feel and cover the module at 100% line coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGVapDZ3k7V7zKYk16P4C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
detect_groove(audio, sr, beat_times)function inservices/analysis-engine/src/bandscope_analysis/temporal/groove.pythatclassifies a performance as straight or swing feel directly from the
audio and the beat grid produced by the temporal analyzer.
Why
BandScope's temporal analysis already extracts BPM and beats but says nothing
about feel. Straight vs swing (triplet) is a first-class musical attribute
players want surfaced. This is a real, self-contained DSP feature with no new
dependencies.
How
librosa.onset.onset_strength) and itsframe times.
own onsets) and locates the dominant off-beat onset, measuring its relative
position
pin [0, 1].swing_ratio = p / (1 - p)(~1.0 straight, ~2.0 triplet swing).feel = "swing"when median position>= 0.58(ratio>= ~1.4), themidpoint between straight (0.5) and triplet (0.667) placement. Documented in
the module.
confidencefrom the consistency (inverted, normalized IQR) of the off-beatpositions, bounded to [0, 1].
onsets return
{"feel": "straight", "swing_ratio": 1.0, "confidence": 0.0}.No exception escapes.
no file/network/shell access. A
# Security Notes:block documents this.Tests
tests/test_groove.pysynthesizes deterministic click tracks with known feel:feel == "straight",swing_ratio ~= 1.11(assertedapprox(1.0, abs=0.35)).feel == "swing",swing_ratio ~= 2.21(assertedapprox(2.0, abs=0.5)).beats beyond audio, and an internally raised error all return the safe
default with
confidence == 0.0.New module is at 100% line coverage; full analysis-engine suite passes.
🤖 Generated with Claude Code