def getSignalFromMelGram( self, melGram, hop=64 ): hopScale = 4 randomSignal = 2*np.random.rand( melGram.shape[0]*hop + hop*hopScale ) - 1 randomSpectrogram = utility.getSpectrogram( randomSignal, hop=hop, frameSize=hop*hopScale ) #randomSpectrogram = np.random.randn( melGram.shape[0], hop*hopScale/2 + 1 ) + np.random.randn( melGram.shape[0], hop*hopScale/2 + 1 )*1j #randomSpectrogram[:, 0] = randomSpectrogram[:, 0].real + 0j #randomSpectrogram[:, -1] = randomSpectrogram[:, -1].real + 0j spectrogramScaler = np.zeros( randomSpectrogram.shape ) filters = self.MFCCer.getFilters( hop*hopScale, self.fs, 0, None, 0 ) for n in xrange( randomSpectrogram.shape[0] ): spectrogramScaler[n] = np.sum( filters*melGram[n], axis=1 ) #spectrogramScaler[n] = np.sum( filters, axis=1 ) return utility.getSignalFromSpectrogram( randomSpectrogram*spectrogramScaler, hop, np.hanning( hop*hopScale ) )
import separateHarmonicPercussive import sys import os import melNoiseTransform if __name__ == "__main__": if len(sys.argv) < 2: print "Usage: %s audio.wav" % (sys.argv[0]) sys.exit() audioData, fs = utility.getAudioData( sys.argv[1] ) hop = 1024 frameSize = 4096 spectrogram = utility.getSpectrogram( audioData, hop=hop, frameSize=frameSize ) seperator = separateHarmonicPercussive.HarmonicPercussiveSeparator( spectrogram ) harmonicSignal = utility.getSignalFromSpectrogram( seperator.harmonicSpectrogram, hop, np.hanning( frameSize ) ) percussiveSignal = utility.getSignalFromSpectrogram( seperator.percussiveSpectrogram, hop, np.hanning( frameSize ) ) impulse = np.zeros( 10000 ) impulse[0] = 1.0 kernelDictionary = ERBFilters.ERBFiltersToKernels( impulse, ERBFilters.makeERBFilters( fs, 200, 100, 5000 ) ) reconstructedHarmonicSignal, residual, scales, kernels, offsets = spikeGramTest.matchingPursuit( kernelDictionary, harmonicSignal, 16, 0, (2000.0*audioData.shape[0])/fs ) melTransformer = melNoiseTransform.melTransformer( fs ) N = np.min( [percussiveSignal.shape[0], residual.shape[0]] ) reconstructedNoiseSignal = melTransformer.getSignalFromMelGram( melTransformer.getMelGram( percussiveSignal[:N] + residual[:N] ) ) reconstructedNoiseSignal /= np.max( np.abs( reconstructedNoiseSignal ) ) reconstructedHarmonicSignal /= np.max( np.abs( reconstructedHarmonicSignal ) ) N = np.min( [reconstructedHarmonicSignal.shape[0], reconstructedNoiseSignal.shape[0]] )