@@ -24,9 +24,7 @@ def crop_center(h1, h2):
2424 return h1
2525
2626
27- def split_lr_waves (
28- wave , mid_side = False , mid_side_b2 = False , reverse = False
29- ):
27+ def split_lr_waves (wave , mid_side = False , mid_side_b2 = False , reverse = False ):
3028 if reverse :
3129 wave_left = np .flip (np .asfortranarray (wave [0 ]))
3230 wave_right = np .flip (np .asfortranarray (wave [1 ]))
@@ -48,17 +46,23 @@ def run_librosa_stft(wv, n_fft, hop_length, reverse):
4846 return librosa .stft (wv , n_fft = n_fft , hop_length = hop_length )
4947 return librosa .stft (np .asfortranarray (wv ), n_fft = n_fft , hop_length = hop_length )
5048
49+
5150def wave_to_spectrogram_mt (
5251 wave , hop_length , n_fft , mid_side = False , mid_side_b2 = False , reverse = False
5352):
5453
5554 with ThreadPoolExecutor (max_workers = 2 ) as tp :
5655 spec = np .asfortranarray (
57- [spec for spec in tp .map (
58- run_librosa_stft ,
59- split_lr_waves (wave , mid_side , mid_side_b2 , reverse ),
60- [n_fft , n_fft ], [hop_length , hop_length ], [reverse , reverse ]
61- )]
56+ [
57+ spec
58+ for spec in tp .map (
59+ run_librosa_stft ,
60+ split_lr_waves (wave , mid_side , mid_side_b2 , reverse ),
61+ [n_fft , n_fft ],
62+ [hop_length , hop_length ],
63+ [reverse , reverse ],
64+ )
65+ ]
6266 )
6367
6468 return spec
@@ -144,10 +148,13 @@ def mask_silence(mag, ref, thres=0.2, min_range=64, fade_size=32):
144148def run_librosa_istft (specx , hop_length ):
145149 return librosa .istft (np .asfortranarray (specx ), hop_length = hop_length )
146150
151+
147152def spectrogram_to_wave (spec , hop_length , mid_side , mid_side_b2 , reverse ):
148153
149154 with ThreadPoolExecutor (max_workers = 2 ) as tp :
150- wave_left , wave_right = tp .map (run_librosa_istft , spec , [hop_length , hop_length ])
155+ wave_left , wave_right = tp .map (
156+ run_librosa_istft , spec , [hop_length , hop_length ]
157+ )
151158
152159 if reverse :
153160 return np .asfortranarray ([np .flip (wave_left ), np .flip (wave_right )])
0 commit comments