Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo 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 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.")