import numpy as np import scipy def spsi(msgram, fftsize, hop_length) : """ Takes a 2D spectrogram ([freqs,frames]), the fft length (= window length) and the hope size (both in units of samples). Returns an audio signal. """ numBins, numFrames = msgram.shape y_out=np.zeros(numFrames*hop_length+fftsize-hop_length) #np.zeros(numFrames*hop_length+fftsize-hop_length) m_phase=np.zeros(numBins); m_win=scipy.signal.hanning(fftsize, sym=True) # assumption here that hann was used to create the frames of the spectrogram #processes one frame of audio at a time for i in range(numFrames) : m_mag=msgram[:, i] for j in range(1,numBins-1) : if(m_mag[j]>m_mag[j-1] and m_mag[j]>m_mag[j+1]) : #if j is a peak alpha=m_mag[j-1]; beta=m_mag[j]; gamma=m_mag[j+1]; denom=alpha-2*beta+gamma; if(denom!=0) : p=0.5*(alpha-gamma)/denom; else : p=0; phaseRate=2*np.pi*(j+p)/fftsize; #adjusted phase rate m_phase[j]= m_phase[j] + hop_length*phaseRate; #phase accumulator for this peak bin peakPhase=m_phase[j]; # If actual peak is to the right of the bin freq if (p>0) : # First bin to right has pi shift bin=j+1; m_phase[bin]=peakPhase+np.pi; # Bins to left have shift of pi bin=j-1; while((bin>1) and (m_mag[bin]1) and (m_mag[bin]