Skip to content

Commit 3bc27c2

Browse files
committed
rm different blastbeat strategy
1 parent 1165c5a commit 3bc27c2

4 files changed

Lines changed: 8 additions & 64 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ venv
55
*.mp3
66
*.pkl
77
output/*
8-
cache.json
8+
download_cache.json
99
*.csv

downloading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from yt_dlp import YoutubeDL
77

8-
CACHE_FILE = Path(__file__).parent / "cache.json"
8+
CACHE_FILE = Path(__file__).parent / "download_cache.json"
99

1010

1111
def download_from_youtube_as_mp3(url: str) -> tuple[bool, Path | None]:

processing.py

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def get_sections_labeled_by_percussion_content_from_audio(
103103
return results
104104

105105

106-
def identify_hammer_blast(sections: list[LabeledSection]) -> list[tuple[int, int]]:
107-
# TODO: name doesn't really capture what this does, because it captures more than just hammer blasts
106+
def identify_blastbeats(sections: list[LabeledSection]) -> list[tuple[int, int]]:
108107
min_hits = 8 # primitive approach: 4 snares+bass in a series at least
109108
start_idx = 0
110109
hits = 0
@@ -123,32 +122,6 @@ def identify_hammer_blast(sections: list[LabeledSection]) -> list[tuple[int, int
123122
return results
124123

125124

126-
def identify_traditional_blast(sections: list[LabeledSection]) -> list[tuple[int, int]]:
127-
# TODO: too many false positives in real songs
128-
min_hits = 4
129-
start_idx = 0
130-
hits = 0
131-
seen_last_bass = False
132-
seen_last_snare = False
133-
results = []
134-
135-
for i, s in enumerate(sections):
136-
if not (s.bass_drum_present or s.snare_present):
137-
if hits >= min_hits:
138-
results.append((sections[start_idx].start_idx, s.start_idx))
139-
hits = 0
140-
elif (s.bass_drum_present and not seen_last_bass) or (
141-
s.snare_present and not seen_last_snare and seen_last_bass
142-
):
143-
if hits == 0:
144-
start_idx = i
145-
hits += 1
146-
147-
seen_last_bass, seen_last_snare = s.bass_drum_present, s.snare_present
148-
149-
return results
150-
151-
152125
def identify_bass_and_snare_frequencies(
153126
audio_data: np.ndarray,
154127
sample_rate: float,
@@ -230,14 +203,7 @@ def process_song(
230203
peak_detection_band_width,
231204
peak_detection_min_area_threshold,
232205
)
233-
234-
blastbeat_intervals = list(
235-
set(
236-
identify_hammer_blast(labeled_sections)
237-
# TODO: improve detection, then bring this back
238-
# + identify_traditional_blast(labeled_sections)
239-
)
240-
)
206+
blastbeat_intervals = identify_blastbeats(labeled_sections)
241207

242208
print("Exporting result...")
243209
save_result(
@@ -279,7 +245,4 @@ def process_song(
279245

280246
# TODO:
281247
# - experiment with compression of drum track before fft?
282-
# - improve blast beat detection algorithm (support bomb blasts, slow blasts etc.)
283-
# - investigate false positives in benighted song & calicuchima
284-
# - come up with f-score??
285-
# - for easier debugging, color blastbeats differently by type
248+
# - investigate false positives in all songs & tune parameters

test_processing.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from processing import LabeledSection, identify_hammer_blast, identify_traditional_blast
1+
from processing import LabeledSection, identify_blastbeats
22

33

44
def test_identify_blasts_1():
@@ -15,7 +15,7 @@ def test_identify_blasts_1():
1515
LabeledSection(10, 11, False, False),
1616
]
1717
expected = [(2, 10)]
18-
actual = identify_hammer_blast(input)
18+
actual = identify_blastbeats(input)
1919

2020
assert actual == expected
2121

@@ -32,25 +32,6 @@ def test_identify_blasts_2():
3232
LabeledSection(8, 9, True, True),
3333
]
3434
expected = []
35-
actual = identify_hammer_blast(input)
36-
37-
assert actual == expected
38-
39-
40-
def test_traditional_blast():
41-
input: list[LabeledSection] = [
42-
LabeledSection(1, 2, bass_drum_present=False, snare_present=False),
43-
LabeledSection(2, 3, bass_drum_present=True, snare_present=False),
44-
LabeledSection(3, 4, bass_drum_present=False, snare_present=True),
45-
LabeledSection(4, 5, bass_drum_present=True, snare_present=False),
46-
LabeledSection(5, 6, bass_drum_present=False, snare_present=True),
47-
LabeledSection(6, 7, bass_drum_present=False, snare_present=False),
48-
LabeledSection(7, 8, bass_drum_present=False, snare_present=False),
49-
LabeledSection(8, 9, bass_drum_present=False, snare_present=False),
50-
]
51-
52-
expected = [(2, 6)]
53-
54-
actual = identify_traditional_blast(input)
35+
actual = identify_blastbeats(input)
5536

5637
assert actual == expected

0 commit comments

Comments
 (0)