def getWeighted(self,mag,pitches): """ Creates the mask with the shape of \"mag\" and the pitches in \"pitches\" and having gaussians centered in the frequency bands """ filtered = np.zeros((self.ninst,mag.shape[0],mag.shape[1])) for j in range(self.ninst): #for all the inputed instrument pitches for p in range(len(pitches[j])): #for each pitch contour for t in range(len(pitches[j,p])): if pitches[j,p,t] > 0: slices_y = util.slicefft_slices(pitches[j,p,t],size=(mag.shape[-1]-1)*2,interval=self.interval,tuning_freq=self.tuning_freq,nharmonics=self.nharmonics,fmin=self.fmin,fmax=self.fmax,iscale=self.iscale,sampleRate=self.sampleRate) gss = [util.gaussian(np.linspace(-1,1,slices_y[k].stop-slices_y[k].start), 1/(slices_y[k].stop-slices_y[k].start), (slices_y[k].stop-slices_y[k].start)) for k in range(len(slices_y))] for k in range(len(slices_y)): filtered[j,t,slices_y[k]] = filtered[j,t,slices_y[k]] + (gss[k]-min(gss[k]))/(max(gss[k])-min(gss[k]))*self.harmonics[j,int(pitches[j,p,t]),k] gss = None slices_y = None filtered /= np.expand_dims(np.maximum(1e-18,filtered.max(axis=2)),axis=2) mask = np.zeros((mag.shape[0],self.ninst*mag.shape[1])) for j in range(self.ninst): #for all the inputed instrument pitches mask[:,j*mag.shape[1]:(j+1)*mag.shape[1]] = filtered[j,:,:] filtered = None j=None p=None t=None k=None return mask
def filterSpec(self,mag,pitches): """ Creates the mask with the shape of \"mag\" and the pitches in \"pitches\" """ filtered = np.ones((self.ninst,mag.shape[0],mag.shape[1])) * 0.001 for j in range(self.ninst): #for all the inputed instrument pitches for p in range(len(pitches[j])): #for each pitch contour for t in range(len(pitches[j,p])): if pitches[j,p,t] > 0: slices_y = util.slicefft_slices(pitches[j,p,t],size=(mag.shape[-1]-1)*2,interval=self.interval,tuning_freq=self.tuning_freq,nharmonics=self.nharmonics,fmin=self.fmin,fmax=self.fmax,iscale=self.iscale,sampleRate=self.sampleRate) for k in range(len(slices_y)): filtered[j,t,slices_y[k]] = filtered[j,t,slices_y[k]] + self.harmonics[j,int(pitches[j,p,t]),k] slices_y = None filtered[filtered < 0.001] = 0.001 mask = np.zeros((mag.shape[0],self.ninst*mag.shape[1])) for j in range(self.ninst): #for all the inputed instrument pitches mask[:,j*mag.shape[1]:(j+1)*mag.shape[1]] = filtered[j,:,:] / np.sum(filtered,axis=0) filtered = None j=None p=None t=None k=None return mask