@@ -103,20 +103,24 @@ def get_sections_labeled_by_percussion_content_from_audio(
103103 return results
104104
105105
106- def identify_blastbeats (sections : list [LabeledSection ]) -> list [tuple [int , int ]]:
107- min_hits = 8 # primitive approach: 4 snares+bass in a series at least
108- start_idx = 0
106+ def identify_blastbeats (
107+ sections : list [LabeledSection ], min_hits
108+ ) -> list [tuple [int , int ]]:
109+ blastbeat_start_idx = 0
109110 hits = 0
110111 results = []
111112
112- for i , s in enumerate (sections ):
113- if s .snare_present and s .bass_drum_present :
113+ # Caveman approach: consider it as blast beat if a given number of consecutive labeled sections contain snare & bassdrum
114+ for i , section in enumerate (sections ):
115+ if section .snare_present and section .bass_drum_present :
114116 if hits == 0 :
115- start_idx = i
117+ blastbeat_start_idx = i
116118 hits += 1
117119 else :
118120 if hits >= min_hits :
119- results .append ((sections [start_idx ].start_idx , s .start_idx ))
121+ results .append (
122+ (sections [blastbeat_start_idx ].start_idx , section .start_idx )
123+ )
120124 hits = 0
121125
122126 return results
@@ -177,6 +181,7 @@ def process_song(
177181 step_size_in_seconds = 0.15 ,
178182 bass_drum_range = (10 , 100 ),
179183 snare_range = (170 , 600 ),
184+ min_consecutive_hits = 8 ,
180185):
181186 print ("Separating drum track..." )
182187 (time , audio_data , sample_rate ), drumtrack_path = extract_drums (file_path )
@@ -203,7 +208,7 @@ def process_song(
203208 peak_detection_band_width ,
204209 peak_detection_min_area_threshold ,
205210 )
206- blastbeat_intervals = identify_blastbeats (labeled_sections )
211+ blastbeat_intervals = identify_blastbeats (labeled_sections , min_consecutive_hits )
207212
208213 print ("Exporting result..." )
209214 save_result (
@@ -215,7 +220,7 @@ def process_song(
215220 import argparse
216221 import webbrowser
217222
218- OPEN_BROWSER_AFTER_PROCESSING = False
223+ OPEN_BROWSER_AFTER_PROCESSING = True
219224
220225 parser = argparse .ArgumentParser ()
221226 parser .add_argument ("--file" , type = str )
@@ -244,6 +249,5 @@ def process_song(
244249 webbrowser .open (f"file://{ Path (__file__ ).parent .resolve ()} /index.html" )
245250
246251# TODO:
247- # - experiment with compression of drum track before fft?
248252# - investigate false positives in all songs & tune parameters
249253# - make min consecutive hits configurable
0 commit comments