def deconv_a_file(filename): song_id = filename.split('.')[0] path_out_here = path_results + song_id + '/' # path_img_here = path_results + song_id + '_img/' SRC = np.load(path_SRC + filename) if os.path.exists(path_out_here): print '%s might be done already, I skip this.' % song_id print 'remove %s and %s to proceed.' % (path_out_here, path_img_here) if not os.path.exists(path_out_here): os.makedirs(path_out_here) # if not os.path.exists(path_img_here): # os.makedirs(path_img_here) filename_out = '%s_a_original.wav' % (song_id) librosa.output.write_wav(path_out_here + filename_out, librosa.istft(SRC, hop_length=N_FFT/2), sr=SAMPLE_RATE, norm=True) for depth in depths: print '--- deconve! ---' deconvedMASKS = auralise.get_deconve_mask(W[:depth], layer_names, SRC, depth) # size can be smaller than SRC due to downsampling print 'result; %d masks with size of %d, %d' % deconvedMASKS.shape for deconved_feature_ind, deconvedMASK_here in enumerate(deconvedMASKS): MASK = np.zeros(SRC.shape) MASK[0:deconvedMASK_here.shape[0], 0:deconvedMASK_here.shape[1]] = deconvedMASK_here deconvedSRC = np.multiply(SRC, MASK) filename_out = '%s_deconved_from_depth_%d_feature_%d.wav' % (song_id, depth, deconved_feature_ind) librosa.output.write_wav(path_out_here + filename_out, librosa.istft(deconvedSRC, hop_length=N_FFT/2), sr=SAMPLE_RATE, norm=True)
def deconv_a_file(filename): song_id = filename.split('.')[0] path_out_here = path_results + song_id + '/' # path_img_here = path_results + song_id + '_img/' SRC = np.load(path_SRC + filename) if os.path.exists(path_out_here): print '%s might be done already, I skip this.' % song_id print 'remove %s and %s to proceed.' % (path_out_here, path_img_here) if not os.path.exists(path_out_here): os.makedirs(path_out_here) # if not os.path.exists(path_img_here): # os.makedirs(path_img_here) filename_out = '%s_a_original.wav' % (song_id) librosa.output.write_wav(path_out_here + filename_out, librosa.istft(SRC, hop_length=N_FFT / 2), sr=SAMPLE_RATE, norm=True) for depth in depths: print '--- deconve! ---' deconvedMASKS = auralise.get_deconve_mask( W[:depth], layer_names, SRC, depth) # size can be smaller than SRC due to downsampling print 'result; %d masks with size of %d, %d' % deconvedMASKS.shape for deconved_feature_ind, deconvedMASK_here in enumerate( deconvedMASKS): MASK = np.zeros(SRC.shape) MASK[0:deconvedMASK_here.shape[0], 0:deconvedMASK_here.shape[1]] = deconvedMASK_here deconvedSRC = np.multiply(SRC, MASK) filename_out = '%s_deconved_from_depth_%d_feature_%d.wav' % ( song_id, depth, deconved_feature_ind) librosa.output.write_wav(path_out_here + filename_out, librosa.istft(deconvedSRC, hop_length=N_FFT / 2), sr=SAMPLE_RATE, norm=True)
# deconve depths = [5,4,3,2,1] for filename in filenames_SRC: song_id = filename.split('.')[0] SRC = np.load(path_SRC + filename) filename_out = '%s_a_original.wav' % (song_id) if not os.path.exists(path_SRC + song_id): os.makedirs(path_src + song_id) if not os.path.exists(path_SRC + song_id + '_img'): os.makedirs(path_src + song_id + '_img') librosa.output.write_wav(path_src+ song_id + '/' + filename_out, librosa.istft(SRC, hop_length=N_FFT/2), sr=SAMPLE_RATE, norm=True) for depth in depths: print '--- deconve! ---' deconvedMASKS = auralise.get_deconve_mask(W[:depth], layer_names, SRC, depth) # size can be smaller than SRC due to downsampling print 'result; %d masks with size of %d, %d' % deconvedMASKS.shape for deconved_feature_ind, deconvedMASK_here in enumerate(deconvedMASKS): MASK = np.zeros(SRC.shape) MASK[0:deconvedMASK_here.shape[0], 0:deconvedMASK_here.shape[1]] = deconvedMASK_here deconvedSRC = np.multiply(SRC, MASK) filename_out = '%s_deconved_from_depth_%d_feature_%d.wav' % (song_id, depth, deconved_feature_ind) librosa.output.write_wav(path_src+ song_id + '/' + filename_out, librosa.istft(deconvedSRC, hop_length=N_FFT/2), SAMPLE_RATE, norm=True) filename_img_out = 'spectrogram_%s_from_depth_%d_feature_%d.png' % (song_id, depth, deconved_feature_ind) imsave(path_src+song_id + '_img' + '/' + filename_img_out , np.flipud(np.multiply(np.abs(SRC), MASK))) filename_img_out = 'filter_for_%s_from_depth_%d_feature_%d.png' % (song_id, depth, deconved_feature_ind) imsave(path_src+song_id + '_img' + '/' + filename_img_out , np.flipud(MASK))
song_id = filename.split(".")[0] SRC = np.load(path_SRC + filename) filename_out = "%s_a_original.wav" % (song_id) if not os.path.exists(path_SRC + song_id): os.makedirs(path_src + song_id) if not os.path.exists(path_SRC + song_id + "_img"): os.makedirs(path_src + song_id + "_img") librosa.output.write_wav( path_src + song_id + "/" + filename_out, librosa.istft(SRC, hop_length=N_FFT / 2), sr=SAMPLE_RATE, norm=True ) for depth in depths: print "--- deconve! ---" deconvedMASKS = auralise.get_deconve_mask( W[:depth], layer_names, SRC, depth ) # size can be smaller than SRC due to downsampling print "result; %d masks with size of %d, %d" % deconvedMASKS.shape for deconved_feature_ind, deconvedMASK_here in enumerate(deconvedMASKS): MASK = np.zeros(SRC.shape) MASK[0 : deconvedMASK_here.shape[0], 0 : deconvedMASK_here.shape[1]] = deconvedMASK_here deconvedSRC = np.multiply(SRC, MASK) filename_out = "%s_deconved_from_depth_%d_feature_%d.wav" % (song_id, depth, deconved_feature_ind) librosa.output.write_wav( path_src + song_id + "/" + filename_out, librosa.istft(deconvedSRC, hop_length=N_FFT / 2), SAMPLE_RATE, norm=True, )