(input, fft_size, hop_size, win_length, window_type="hann_window")
| 370 | #assumes the input is (Batch,Time,dim) or (Batch,Time) |
| 371 | #return (B,Freq,T,dim) containing real and imaginary values |
| 372 | def 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 |
| 408 | def compute_istft(input, fft_size, hop_size, win_length, window_type="hann_window", spatial_size=256): |
nothing calls this directly
no test coverage detected