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

Function compute_istft

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

Source from the content-addressed store, hash-verified

406
407#inverse of compute_stft
408def compute_istft(input, fft_size, hop_size, win_length, window_type="hann_window", spatial_size=256):
409 window = get_window(window_type, win_length).cuda()
410
411 #if the input if 5 dimensional and the last dimension 2, then we view it as complex
412 if len(input.shape)==5 and input.shape[-1]==2:
413 input=torch.view_as_complex(input)
414
415 if len(input.shape)==3:
416 #we have a (B,T) input so we can just run stft
417 x= torch.istft(
418 input,
419 n_fft=fft_size,
420 hop_length=hop_size,
421 win_length=win_length,
422 window=window,
423 onesided=True,
424 return_complex=False,
425 )
426 elif len(input.shape)==4:
427 #do stft for each dimension
428 dim=input.shape[-1]
429 x_total=[]
430 for i in range(dim):
431 input_axis = input[:,:,:,i]
432 x_axis = torch.istft(
433 input_axis,
434 n_fft=fft_size,
435 hop_length=hop_size,
436 win_length=win_length,
437 window=window,
438 onesided=True,
439 return_complex=False,
440 length=spatial_size,
441 ).unsqueeze(-1)
442 x_total.append(x_axis)
443 x = torch.cat(x_total,-1)
444 else:
445 return None
446
447
448 return x
449
450
451def compute_fft(input):

Callers

nothing calls this directly

Calls 1

get_windowFunction · 0.90

Tested by

no test coverage detected