From b48a1c6292a095fea59b30e0ab814961128b23cc Mon Sep 17 00:00:00 2001 From: gferraro Date: Wed, 8 Nov 2023 10:49:19 +1300 Subject: [PATCH] filter tracks below 1000 --- Melt/identify_tracks.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Melt/identify_tracks.py b/Melt/identify_tracks.py index 42a9b6f..f6b6120 100644 --- a/Melt/identify_tracks.py +++ b/Melt/identify_tracks.py @@ -59,9 +59,10 @@ def load_samples( power=1, db_scale=False, filter_freqs=True, + filter_below=None, ): logging.debug( - "Loading samples with length %s stride %s hop length %s and mean_sub %s mfcc %s break %s htk %s n mels %s fmin %s fmax %s filtering freqs %s", + "Loading samples with length %s stride %s hop length %s and mean_sub %s mfcc %s break %s htk %s n mels %s fmin %s fmax %s filtering freqs %s filter below %s", segment_length, stride, hop_length, @@ -73,6 +74,7 @@ def load_samples( fmin, fmax, filter_freqs, + filter_below, ) mels = [] i = 0 @@ -97,6 +99,13 @@ def load_samples( track_frames = butter_bandpass_filter( track_frames, t.freq_start, t.freq_end, sr ) + elif filter_below and t.freq_end < filter_below: + logging.info( + "Filter freq below %s %s %s", filter_below, t.freq_start, t.freq_end + ) + track_frames = butter_bandpass_filter( + track_frames, t.freq_start, t.freq_end, sr + ) while True: data = track_frames[sr_start:sr_end] if len(data) != sample_size: @@ -323,6 +332,7 @@ def classify(file, models): for model_file in models: model, meta = load_model(model_file) filter_freqs = meta.get("filter_freq", True) + filter_below = meta.get("filter_below", 1000) labels = meta.get("labels") multi_label = meta.get("multi_label") @@ -366,6 +376,7 @@ def classify(file, models): power=power, db_scale=db_scale, filter_freqs=filter_freqs, + filter_below=filter_below, ) data = mel_data if len(data) == 0: