MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / compute_stft

Function compute_stft

utils/strand_util.py:372–405  ·  view source on GitHub ↗
(input, fft_size, hop_size, win_length, window_type="hann_window")

Source from the content-addressed store, hash-verified

370#assumes the input is (Batch,Time,dim) or (Batch,Time)
371#return (B,Freq,T,dim) containing real and imaginary values
372def compute_stft(input, fft_size, hop_size, win_length, window_type="hann_window"):
373 window = get_window(window_type, win_length).cuda()
374
375 if len(input.shape)==2:
376 #we have a (B,T) input so we can just run stft
377 x_stft = torch.stft(
378 input,
379 fft_size,
380 hop_size,
381 win_length,
382 window,
383 return_complex=True,
384 )
385 elif len(input.shape)==3:
386 #do stft for each dimension
387 dim=input.shape[-1]
388 stft_total=[]
389 for i in range(dim):
390 input_axis = input[:,:,i]
391 x_stft = torch.stft(
392 input_axis,
393 fft_size,
394 hop_size,
395 win_length,
396 window,
397 return_complex=True,
398 ).unsqueeze(-1)
399 stft_total.append(x_stft)
400 x_stft = torch.cat(stft_total,-1)
401 else:
402 return None
403
404
405 return x_stft
406
407#inverse of compute_stft
408def compute_istft(input, fft_size, hop_size, win_length, window_type="hann_window", spatial_size=256):

Callers

nothing calls this directly

Calls 1

get_windowFunction · 0.90

Tested by

no test coverage detected