test: add unit and integration tests for M5 strumming analysis and beat quantization
This commit is contained in:
39
tests/test_strumming.py
Normal file
39
tests/test_strumming.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Unit tests for strumming direction estimation and pattern aggregation."""
|
||||
|
||||
import numpy as np
|
||||
|
||||
from songsplit.pipeline.s7_strumming import aggregate_strum_patterns, estimate_strum_direction
|
||||
from songsplit.schema.strumming import StrumEvent
|
||||
|
||||
|
||||
def test_estimate_strum_direction_phase_prior():
|
||||
sr = 22050
|
||||
audio = np.random.randn(sr).astype(np.float32)
|
||||
|
||||
# On-beat (beat 0.0) -> down
|
||||
dir_down, conf_down = estimate_strum_direction(audio, sr, onset_sec=0.1, beat=0.0)
|
||||
assert dir_down == "down"
|
||||
assert conf_down >= 0.5
|
||||
|
||||
# Off-beat (beat 0.5) -> up
|
||||
dir_up, conf_up = estimate_strum_direction(audio, sr, onset_sec=0.1, beat=0.5)
|
||||
assert dir_up == "up"
|
||||
assert conf_up >= 0.5
|
||||
|
||||
|
||||
def test_aggregate_strum_patterns_island_strum():
|
||||
# Famous "island strum": D . D U . U D U (slots: 0, 1, 2, 3, 4, 5, 6, 7 on 8th grid)
|
||||
# slots: 0.0 (D), 1.0 (D), 1.5 (U), 2.5 (U), 3.0 (D), 3.5 (U)
|
||||
events = [
|
||||
StrumEvent(beat=0.0, direction="down", strength=0.9, confidence=0.8),
|
||||
StrumEvent(beat=1.0, direction="down", strength=0.8, confidence=0.8),
|
||||
StrumEvent(beat=1.5, direction="up", strength=0.7, confidence=0.7),
|
||||
StrumEvent(beat=2.5, direction="up", strength=0.7, confidence=0.7),
|
||||
StrumEvent(beat=3.0, direction="down", strength=0.8, confidence=0.8),
|
||||
StrumEvent(beat=3.5, direction="up", strength=0.7, confidence=0.7),
|
||||
]
|
||||
|
||||
patterns = aggregate_strum_patterns(events, total_beats=4.0, grid="8th", pattern_beats=4.0, section_beats=4.0)
|
||||
assert len(patterns) == 1
|
||||
assert patterns[0].pattern == "D . D U . U D U"
|
||||
assert patterns[0].grid == "8th"
|
||||
Reference in New Issue
Block a user