18
18
19
19
import json
20
20
import os
21
+ import time
22
+ import logging
21
23
22
24
import librosa
23
25
import numpy as np
@@ -74,6 +76,8 @@ def db_diff(self, power_db_f1, power_db_f2):
74
76
return average_diff
75
77
76
78
def find_loop_pairs (self , combine_beat_plp = False , concurrency = False ):
79
+ runtime_start = time .time ()
80
+
77
81
S = librosa .core .stft (y = self .audio )
78
82
S_power = np .abs (S ) ** 2
79
83
S_weighed = librosa .core .perceptual_weighting (
@@ -84,19 +88,28 @@ def find_loop_pairs(self, combine_beat_plp=False, concurrency=False):
84
88
bpm , beats = librosa .beat .beat_track (onset_envelope = onset_env )
85
89
86
90
beats = np .sort (beats )
91
+ logging .info ("Detected {} beats at {:.0f} bpm" .format (beats .size , bpm ))
87
92
88
93
chroma = librosa .feature .chroma_stft (S = S_power )
89
94
90
95
power_db = librosa .power_to_db (mel_spectrogram , ref = np .max )
91
96
min_duration = int (chroma .shape [- 1 ] * self .min_duration_multiplier )
92
97
98
+ runtime_end = time .time ()
99
+ prep_time = runtime_end - runtime_start
100
+ logging .info ("Finished initial prep in {:.3}s" .format (prep_time ))
101
+
93
102
def loop_subroutine (combine_beat_plp = combine_beat_plp , beats = beats ):
94
103
if combine_beat_plp :
95
104
onset_env = librosa .onset .onset_strength (S = mel_spectrogram )
96
105
pulse = librosa .beat .plp (onset_envelope = onset_env )
97
106
beats_plp = np .flatnonzero (librosa .util .localmax (pulse ))
98
107
beats = np .union1d (beats , beats_plp )
99
-
108
+ logging .info (
109
+ "Detected {} total points by combining PLP with existing beats" .format (
110
+ beats .size
111
+ )
112
+ )
100
113
candidate_pairs = []
101
114
102
115
self ._loop_finding_routine (
@@ -156,6 +169,9 @@ def loop_subroutine(combine_beat_plp=combine_beat_plp, beats=beats):
156
169
break
157
170
158
171
if retry and not combine_beat_plp :
172
+ logging .info (
173
+ "No suitable loop points found with current parameters. Retrying with additional beat points from PLP method."
174
+ )
159
175
pruned_list = loop_subroutine (combine_beat_plp = True )
160
176
161
177
if self .trim_offset [0 ] > 0 :
@@ -167,6 +183,8 @@ def loop_subroutine(combine_beat_plp=combine_beat_plp, beats=beats):
167
183
pruned_list [i ]["loop_end" ]
168
184
)
169
185
186
+ logging .info (f"Found { len (pruned_list )} possible loop points" )
187
+
170
188
return pruned_list
171
189
172
190
def apply_trim_offset (self , frame ):
0 commit comments