def source_separation(self, x):
if not Duration()(x) > 10:
stftx = librosa.stft(x)
real = stftx.real
imag = stftx.imag
ssp = find_sparse_source_points(real, imag) #find sparsity in the signal
cos_dist = cosine_distance(ssp) #cosine distance from sparse data
sources = find_number_of_sources(cos_dist) #find possible number of sources
if (sources == 0) or (sources == 1): #this means x is an instrumental track and doesn't have more than one source
print "There's only one visible source"
return x
else:
print "Separating sources"
xs = NMF(stftx, sources)
return xs[0] #take the bass part #TODO: correct NMF to return noiseless reconstruction
else:
stftx = librosa.stft(x[:441000]) #take 10 seconds of signal data to find sources
print "It can take some time to find any source in this signal"
real = stftx.real
imag = stftx.imag
ssp = find_sparse_source_points(real, imag) #find sparsity in the signal
cos_dist = cosine_distance(ssp) #cosine distance from sparse data
sources = find_number_of_sources(cos_dist) #find possible number of sources
if (sources == 0) or (sources == 1): #this means x is an instrumental track and doesn't have more than one source
print "There's only one visible source"
return x
else:
print "Separating sources"
xs = NMF(librosa.stft(x), sources)
return xs[0] #take the bass part #TODO: correct NMF to return noiseless reconstruction
评论列表
文章目录