40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
"""Unit tests for strumming direction estimation and pattern aggregation."""
|
|
|
|
import numpy as np
|
|
|
|
from unmix.pipeline.s7_strumming import aggregate_strum_patterns, estimate_strum_direction
|
|
from unmix.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"
|