def stft_mc(x,N=1024,hop=None,window='hann'):
# N=1024
if hop is None:
hop=N/2
S=x.shape
if len(S)==1:
nch=1
nsampl=len(x)
x=np.reshape(x,(1,nsampl))
else:
nch=S[0]
nsampl=S[1]
xdtype=x.dtype
nfram=int(scipy.ceil(float(nsampl)/float(hop)))
npad=int(nfram)*hop-nsampl
pad=np.zeros((nch,npad)).astype(xdtype)
x=np.concatenate((x,pad),axis=1)
#pad the edges to avoid window taper effects
pad=np.zeros((nch,N)).astype(xdtype)
x=np.concatenate((pad,x,pad),axis=1)
for ich in range(0,nch):
x0=x[ich,:]
if not x0.flags.c_contiguous:
x0=x0.copy(order='C')
X0=librosa.core.stft(x0,n_fft=N,hop_length=hop,window=window,center=False,dtype=np.complex64)
if ich==0:
X=np.zeros((N/2+1,X0.shape[1],nch)).astype(np.complex64)
X[:,:,0]=X0
else:
X[:,:,ich]=X0
return X
评论列表
文章目录