Thank you for the explanations, in my case I would then rather use center=False.
Given that and the documentation, I am still confused, may you please clarify what is still wrong here please ? sorry if I overly detail but I need to precisely relate frames <—> input signal length
(with sr=22050 ; win_size=1024 ; hop_size=256 ; n_fft=2048)
data_len = 250000
dummy_in = torch.ones(data_len,dtype=torch.float32).to(device)
STFT center=False means each frame starts at (frame_id*hop_length) and ends at (frame_id*hop_length+win_size-1) while signal goes from 0 to data_len-1
n_frames = int(np.floor((data_len-win_size)/hop_size))+1
crop_len = (n_frames-1)*hop_size+win_size
if crop_len+hop_size<=data_len:
print(’!!! error, missing signal windows !!!’)
dummy_in = dummy_in[:crop_len]
data_mag = torch.stft(dummy_in,n_fft,hop_length=hop_size,win_length=win_size,window=window,center=False,pad_mode=‘reflect’,normalized=False,onesided=True)
data_mag = torch.sqrt(torch.pow(data_mag[:,:,0],2)+torch.pow(data_mag[:,:,1],2))
if data_mag.shape[1]!=n_frames:
print('wrong number of STFT frames, expected ‘+str(n_frames)+’ and got '+str(data_mag.shape[1]))
the first check is ok, the signal is cropped to the maximum number of hops allowed without padding == 49856
the second not == wrong number of STFT frames, expected 973 and got 969
so I still have an error of 4 frames and I don’t understand what is not correct in my calculation given the center=False
it would be extremely helpful to get the exact way to relate frames and signal length
thank you in advance !