コード例 #1
0
    def runTest(self):
        print "------------------ Test3  Populate from MP coeffs ---------"
        fileIndex = 2
        RandomAudioFilePath = file_names[fileIndex]
        print 'Working on %s' % RandomAudioFilePath
        sizes = [2**j for j in range(7, 15)]
        segDuration = 5
        nbAtom = 20

        pySig = signals.Signal(op.join(audio_files_path, RandomAudioFilePath),
                               mono=True,
                               normalize=True)

        segmentLength = ((segDuration * pySig.fs) / sizes[-1]) * sizes[-1]
        nbSeg = floor(pySig.length / segmentLength)
        # cropping
        pySig.crop(0, segmentLength)

        # create dictionary
        pyDico = Dico(sizes)

        approx, decay = mp.mp(pySig, pyDico, 20, nbAtom, pad=True, debug=0)

        ppdb = XMDCTBDB('MPdb.db', load=False)
        #        ppdb.keyformat = None
        ppdb.populate(approx, None, fileIndex)

        nKeys = ppdb.get_stats()['ndata']
        # compare the number of keys in the base to the number of atoms

        print ppdb.get_stats()
        self.assertEqual(nKeys, approx.atom_number)

        # now try to recover the fileIndex knowing one of the atoms
        Key = [
            log(approx.atoms[0].length, 2),
            approx.atoms[0].reduced_frequency * pySig.fs
        ]
        T, fileI = ppdb.get(Key)
        Treal = (float(approx.atoms[0].time_position) / float(pySig.fs))
        print T, Treal
        self.assertEqual(fileI[0], fileIndex)
        Tpy = np.array(T)
        self.assertTrue((np.abs(Tpy - Treal)).min() < 0.1)

        # last check: what does a request for non-existing atom in base return?
        T, fileI = ppdb.get((11, 120.0))
        self.assertEqual(T, [])
        self.assertEqual(fileI, [])

        # now let's just retrieve the atoms from the base and see if they are
        # the same
        histograms = ppdb.retrieve(approx, None, offset=0)
        #        plt.figure()
        #        plt.imshow(histograms[0:10,:])
        #        plt.show()
        del ppdb
コード例 #2
0
    def runTest(self):
        ppdb = XMDCTBDB('tempdb.db',
                        load=False,
                        persistent=True,
                        time_max=500.0)

        pySig = signals.LongSignal(op.join(audio_files_path, file_names[0]),
                                   frame_duration=5,
                                   mono=False,
                                   Noverlap=0)

        self.assertEqual(pySig.segment_size, 5.0 * pySig.fs)

        max_nb_seg = 10
        nb_atoms = 150

        scales = SpreadDico([8192], penalty=0.1, mask_time=2, mask_freq=20)

        #        scales = Dico([8192])
        for segIdx in range(min(max_nb_seg, pySig.n_seg)):
            pySigLocal = pySig.get_sub_signal(segIdx,
                                              1,
                                              mono=True,
                                              normalize=False,
                                              channel=0,
                                              pad=scales.get_pad())
            print "MP on segment %d" % segIdx
            # run the decomposition
            approx, decay = mp.mp(pySigLocal, scales, 2, nb_atoms, pad=False)

            print "Populating database with offset " + str(
                segIdx * pySig.segment_size / pySig.fs)
            ppdb.populate(approx,
                          None,
                          0,
                          offset=float((segIdx * pySig.segment_size) -
                                       scales.get_pad()) / float(pySig.fs))

        # ok we have a DB with only 1 file and different segments, now
        nb_test_seg = 15
        long_sig_test = signals.LongSignal(op.join(audio_files_path,
                                                   file_names[0]),
                                           frame_duration=5,
                                           mono=False,
                                           Noverlap=0.5)
        count = 0
        for segIdx in range(min(nb_test_seg, long_sig_test.n_seg)):
            pySigLocal = long_sig_test.get_sub_signal(segIdx,
                                                      1,
                                                      mono=True,
                                                      normalize=False,
                                                      channel=0,
                                                      pad=scales.get_pad())
            #            print "MP on segment %d" % segIdx
            # run the decomposition
            approx, decay = mp.mp(pySigLocal, scales, 2, nb_atoms, pad=False)
            print approx.atom_number

            histograms = ppdb.retrieve(approx, None, nbCandidates=1)
            maxI = np.argmax(histograms[:])
            OffsetI = maxI / 1
            estFileI = maxI % 1

            oracle_value = segIdx * long_sig_test.segment_size * (
                1 - long_sig_test.overlap) / long_sig_test.fs
            print "Seg %d Oracle: %1.1f - found %1.1f" % (segIdx, oracle_value,
                                                          OffsetI)
            if abs(OffsetI - oracle_value) < 5:
                count += 1

        glob = float(count) / float(min(nb_test_seg, long_sig_test.n_seg))
        print "Global Score of %1.3f" % glob
        self.assertGreater(glob, 0.8)
コード例 #3
0
    def runTest(self):
        ''' time to test the fingerprinting scheme, create a base with 10 atoms for 8 songs, then
            Construct the histograms and retrieve the fileIndex and time offset that is the most
            plausible '''
        print "------------------ Test5  DB construction ---------"
        #        # create the base : persistent
        ppdb = XMDCTBDB('LargeMPdb.db', load=False, time_res=0.2)
        print ppdb
        padZ = 2 * sizes[-1]
        # BUGFIX: pour le cas MP classique: certains atome reviennent : pas
        # cool car paire key/data existe deja!
        pyDico = LODico(sizes)
        segDuration = 5
        nbAtom = 50
        sig = signals.LongSignal(op.join(audio_files_path, file_names[0]),
                                 frame_size=sizes[-1],
                                 mono=False,
                                 Noverlap=0)

        segmentLength = ((segDuration * sig.fs) / sizes[-1]) * sizes[-1]
        max_seg_num = 5
        #        " run MP on a number of files"
        nbFiles = 8
        keycount = 0
        for fileIndex in range(nbFiles):
            RandomAudioFilePath = file_names[fileIndex]
            print fileIndex, RandomAudioFilePath
            if not (RandomAudioFilePath[-3:] == 'wav'):
                continue

            pySig = signals.LongSignal(op.join(audio_files_path,
                                               RandomAudioFilePath),
                                       frame_size=segmentLength,
                                       mono=False,
                                       Noverlap=0)

            nbSeg = int(pySig.n_seg)
            print 'Working on ' + str(RandomAudioFilePath) + ' with ' + str(
                nbSeg) + ' segments'
            for segIdx in range(min(nbSeg, max_seg_num)):
                pySigLocal = pySig.get_sub_signal(segIdx,
                                                  1,
                                                  True,
                                                  True,
                                                  channel=0,
                                                  pad=padZ)
                print "MP on segment %d" % segIdx
                # run the decomposition
                approx, decay = mp.mp(pySigLocal,
                                      pyDico,
                                      40,
                                      nbAtom,
                                      pad=False)

                print "Populating database with offset " + str(
                    segIdx * segmentLength / sig.fs)
                ppdb.populate(approx,
                              None,
                              fileIndex,
                              offset=float((segIdx * segmentLength) - padZ) /
                              sig.fs)

                keycount += approx.atom_number

        print ppdb.get_stats()