Ejemplo n.º 1
0
 def load(self):
     self.seedSegCount = self.csv['segmentation count'][self.seedIndex]
     self.seed = [None] * self.seedSegCount
     for i in xrange(0, self.seedSegCount):
         name = os.path.join(PgzLocation, 'normalized-' +
                             self.seedName+'(inst)'+'_'+str(i+1)+'.pgz')
         self.seed[i] = pre.load(name)
         print('loaded ', self.seed[i].name)
Ejemplo n.º 2
0
 def load(self):
     c = self.csv  # To simpilfy
     self.seedIndex = c.index[c['song name'] == self.seedName].tolist()[0]
     self.seedSegCount = self.csv['segmentation count'][self.seedIndex]
     print self.seedIndex
     print self.seedName
     self.seed = [None] * self.seedSegCount
     for i in xrange(0, self.seedSegCount):
         name = pathJoin(
             PgzLocation + self.cateName + '/inst/',
             self.seedName + '(inst)' + '_' + str(i + 1) + '.pgz')
         self.seed[i] = pre.load(name)
         print 'loaded ', self.seed[i].name
     self.progressBar.setText("\nDone Loading Segments.")
Ejemplo n.º 3
0
    def mashupLoadAtOnce(self):
        self.mashup = [None]*self.seedSegCount
        mashabilityList = [None]*self.seedSegCount
        mashupedIndex = []  # saved already mashuped seg index to filter repeat
        threshold = 0.82
        seg = []

        # load all segmentation
        for candIndex, candName in enumerate(self.csv['song name']):
            if candIndex == self.seedIndex:
                continue
            for candSegIndex in range(1, self.csv['segmentation count'][candIndex]+1):
                candSegPath = os.path.join(
                    PgzLocation, 'normalized-'+candName+'(inst)'+'_'+str(candSegIndex)+'.pgz')
                seg.append(pre.load(candSegPath))
        print("loaded all seg")

        # Mashupping
        for seedSegNow in range(0, self.seedSegCount):
            # iterate all segmentations in seed song

            #            # Notice: The first section and the last section will not be mashupped.
            #            if seedSegNow == 0 or seedSegNow == self.seedSegCount-1 :
            #                continue

            #            if seedSegNow == 0 or seedSegNow == 1 :
            #                continue

            maxMashability = -1000
            maxSeg = None
            maxIndex = -1
            for segIndex, cand in enumerate(seg):
                # iterate all segmentation
                mash = pre.Mashability(self.seed[seedSegNow], cand).mash()
                if maxMashability < mash:
                    maxMashability = mash
                    maxSeg = cand
                    maxIndex = segIndex
                if segIndex % 10 == 0:
                    print('compared : ', segIndex, ' of ', len(seg))
            print('maxSeg = ', maxSeg.name)
            mashabilityList[seedSegNow] = maxMashability

#            candWithVocalSegPath = os.path.join(SongPgzLocation,maxSeg.name[:maxSeg.name.rfind('(inst')]+maxSeg.name[maxSeg.name.rfind('_'):]+'.pgz')
#            print 'Mashed File: '+ maxSeg.name[:maxSeg.name.rfind('(inst')]+maxSeg.name[maxSeg.name.rfind('_'):]+'.pgz'
            vocalSegPath = os.path.join(SongPgzLocation, maxSeg.name[:maxSeg.name.rfind(
                '(inst')] + '(vocal)' + maxSeg.name[maxSeg.name.rfind('_'):]+'.pgz')

            print('Mashed File: ' + maxSeg.name[:maxSeg.name.rfind(
                '(inst')] + '(vocal)' + maxSeg.name[maxSeg.name.rfind('_'):]+'.wav')

            if maxMashability >= threshold:
                self.mashup[seedSegNow] = pre.load(vocalSegPath)

            else:
                print('Mashability < Threshold , Skip ...')

            print('Mashed : #', seedSegNow+1, ' of ', self.seedSegCount)

            del seg[maxIndex]

        print('selected : ')
        for index, candSeg in enumerate(self.mashup):
            if candSeg:
                print(candSeg.name, ' : ', mashabilityList[index])

        seg = [None] * self.seedSegCount

        for i in xrange(self.seedSegCount):
            # overlay cand and seed
            if self.mashup[i]:
                instSegPath = os.path.join(WavLocation, maxSeg.name + '.wav')
                instSig, instSr = librosa.load(instSegPath, sr=None)
                seg[i] = mashup.overlay(instSig, instSr, self.seed[i].signal,
                                        self.seed[i].sr, self.mashup[i].signal, self.mashup[i].sr)
            # Checkkkkkkkkkkk
            else:
                seg[i] = self.seed[i].signal

            # bridging
            if i == 0:
                signal = seg[i]
            else:
                signal = mashup.bridging(
                    signal, self.seed[0].sr, seg[i], self.seed[0].sr, 5000)
        self.mashuppedSig = signal

        self.saveMashuped()
Ejemplo n.º 4
0
    def mashupLoadSeperately(self):
        self.mashup = [None]*self.seedSegCount
        mashabilityList = [None]*self.seedSegCount
        mashupedDic = {}
        threshold = 0.82
        for seedSegNow in xrange(0, self.seedSegCount):
            # iterate all segmentations in seed song
            maxMashability = -1000
            candSeg = None
            maxSeg = None
            for candIndex, candName in enumerate(self.csv['song name']):
                # iterate all songs in database
                if candIndex == self.seedIndex:
                    continue
                for candSegIndex in xrange(1, self.csv['segmentation count'][candIndex]+1):
                    # iterate all segmentations in candidate song
                    candSegPath = os.path.join(
                        PgzLocation, candName+'_'+str(candSegIndex)+'.pgz')
                    if canSedPath[:-4] in mashupedDic:
                        print(canSedPath, ' is already mashupped ')
                        continue
                    candSeg = pre.load(candSegPath)
                    mash = pre.Mashability(
                        self.seed[seedSegNow], candSeg).mash()
                    if maxMashability < mash:
                        maxMashability = mash
                        maxSeg = candSeg
                print('compared :', candName)
                if maxSeg is not None:
                    print('maxSeg = ', maxSeg.name)
                    mashabilityList[seedSegNow] = maxMashability
            print('Mashed : #', seedSegNow+1, ' of ', self.seedSegCount)

            if maxMashability >= threshold:
                self.mashup[seedSegNow] = maxSeg
            else:
                print('Mashability = ' + maxMashability +
                      ' < Threshold , Skip...')

            mashupedDic.add({maxSeg.name: True})
        print('selected : ')
        for index, candSeg in enumerate(self.mashup):
            print(candSeg.name, ' : ', mashabilityList[index])

        seg = [None] * self.seedSegCount

        for i in range(self.seedSegCount):
            # overlay cand and seed
            if self.mashup[i]:
                instSegPath = pathJoin(WavLocation, maxSeg.name + '.wav')
                instSig, instSr = librosa.load(instSegPath, sr=None)
                seg[i] = mashup.overlay(instSig, instSr, self.seed[i].signal,
                                        self.seed[i].sr, self.mashup[i].signal, self.mashup[i].sr)
            else:
                seg[i] = self.seed[i].signal

            # bridging
            if i == 0:
                signal = seg[i]
            else:
                signal = mashup.bridging(
                    signal, self.seed[0].sr, seg[i], self.seed[0].sr, 5000)

        self.mashuppedSig = signal
        self.saveMashuped()
Ejemplo n.º 5
0
    def mashupLoadAtOnce(self):
        self.mashup = [None] * self.seedSegCount
        mashabilityList = [None] * self.seedSegCount
        mashupedIndex = []  # saved already mashuped seg index to filter repeat
        threshold = 0.82
        seg = []

        # load all segmentation
        for candIndex, candName in enumerate(self.csv['song name']):
            if candIndex == self.seedIndex:
                continue
            for candSegIndex in xrange(
                    1, self.csv['segmentation count'][candIndex] + 1):
                candSegPath = pathJoin(
                    PgzLocation + self.cateName + '/inst/',
                    candName + '(inst)' + '_' + str(candSegIndex) + '.pgz')
                seg.append(pre.load(candSegPath))
        print "loaded all segments"

        #Mashupping
        for seedSegNow in xrange(0, self.seedSegCount):
            # iterate all segmentations in seed song
            maxMashability = -1000
            maxSeg = None
            maxIndex = -1
            for segIndex, cand in enumerate(seg):
                # iterate all segmentation
                masha = pre.Mashability(self.seed[seedSegNow], cand).mash()
                if maxMashability < masha:
                    maxMashability = masha
                    maxSeg = cand
                    maxIndex = segIndex
                if segIndex % 10 == 0:
                    print 'compared : ', segIndex, ' of ', len(seg)
            print 'maxSeg = ', maxSeg.name
            mashabilityList[seedSegNow] = maxMashability

            vocalSegPath = pathJoin(
                SongPgzLocation + self.cateName + '/vocal/',
                maxSeg.name[:maxSeg.name.rfind('(inst')] + '(vocal)' +
                maxSeg.name[maxSeg.name.rfind('_'):] + '.pgz')

            print 'Mashed File: ' + maxSeg.name[:maxSeg.name.rfind(
                '(inst')] + '(vocal)' + maxSeg.name[maxSeg.name.
                                                    rfind('_'):] + '.wav'

            if maxMashability >= threshold:
                self.mashup[seedSegNow] = pre.load(vocalSegPath)
            else:
                print('Mashability = ' + str(maxMashability) +
                      ' < Threshold , Skip ...')

            print "Mashed : #" + str(seedSegNow + 1) + " of " + str(
                self.seedSegCount)

            del seg[maxIndex]

        print 'selected : '
        for index, candSeg in enumerate(self.mashup):
            if candSeg:
                print candSeg.name, ' : ', mashabilityList[index]

        seg = [None] * self.seedSegCount

        for i in xrange(self.seedSegCount):
            # overlay cand and seed
            if self.mashup[i]:
                instSegPath = pathJoin(WavLocation + self.cateName + '/inst/',
                                       maxSeg.name + '.wav')
                instSig, instSr = librosa.load(instSegPath, sr=None)
                seg[i] = mashup.overlay(instSig, instSr, self.seed[i].signal,
                                        self.seed[i].sr, self.mashup[i].signal,
                                        self.mashup[i].sr)

            else:
                seg[i] = self.seed[i].signal

            # bridging
            if i == 0:
                signal = seg[i]
            else:
                signal = mashup.bridging(signal, self.seed[0].sr, seg[i],
                                         self.seed[0].sr, 5000)

        self.mashuppedSig = signal
        self.saveMashuped()
        self.progressBar.setText("\nMashupped Song\nhas been saved.")
Ejemplo n.º 6
0
class COLOR:  # {{{
    END = '\033[0m'
    RED = '\033[31m'
    GREEN = '\033[32m'
    ORANGE = '\033[33m'
    BLUE = '\033[34m'
    PURPLE = '\033[35m'  # }}}


#Read Song List and Choose which song as seed
csv = read_csv(os.path.join(PgzLocation, 'metadata.csv'))
print COLOR.ORANGE + '{:<3} |  {:<12} '.format('ID', 'Song Name') + COLOR.END
print '================'

for count, name in enumerate(csv['song name']):
    print '{:<3} | {:<12} '.format(count, name)
id = input("Please Enter ID...")

#Load songs and metadata
seed_seg_count = csv['segmentation count'][id]
seedname = csv['song name'][id]
seed = [None] * seed_seg_count
for i in xrange(0, seed_seg_count):
    name = os.path.join(PgzLocation, seedname + '_' + str(i + 1) + '.pgz')
    seed[i] = pre.load(name)
    print 'loaded ', seed[i].name
signal = seed[0].signal
for i in seed:
    print i.name, i.signal.shape
    signal = np.concatenate((signal, i.signal))