コード例 #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):
        print "------------------ Test4  DB persistence ---------"

        ppdb = XMDCTBDB('NonPersistentMPdb.db', persistent=False)
        self.assertTrue(os.path.exists('./NonPersistentMPdb.db'))
        del ppdb
        self.assertFalse(os.path.exists('./NonPersistentMPdb.db'))

        ppdb = XMDCTBDB('PersistentMPdb.db', persistent=True)
        self.assertTrue(os.path.exists('./PersistentMPdb.db'))
        del ppdb
        self.assertTrue(os.path.exists('./PersistentMPdb.db'))

        # now add something in the base
        ppdb = XMDCTBDB('./PersistentMPdb.db', load=True)
        ppdb.keyformat = None
        self.assertTrue(ppdb.persistent)
        ppdb.add(zip((440, ), (1.45, )), 4)

        # delete the base and reload it
        del ppdb

        ppdb = XMDCTBDB('./PersistentMPdb.db', load=True)
        ppdb.keyformat = None
        T, fi = ppdb.get(440)
        self.assertTrue(abs(T[0] - 1.45) < 0.01)
        self.assertEqual(fi[0], 4)
コード例 #3
0
    def runTest(self):
        print "------------------ Test 8  different formattings ---------"
        dbFormat1 = XMDCTBDB('format1.db', load=False, persistent=False)
        dbFormat0 = XMDCTBDB('format2.db', load=False, persistent=False)
        dbFormat1.keyformat = None
        key1 = [0, 12]
        data = 13.0

        dbFormat1.add(zip((key1[1], ), (data, )), 2)
        dbFormat0.add(zip((key1, ), (data, )), 2)

        T, fi = dbFormat0.get(key1)
        print fi
コード例 #4
0
    def runTest(self):
        ''' what happens when the same key is used with a different value? we should be able to retrieve
        a list of possible songs
        '''
        print "------------------ Test 7  handling uniqueness ---------"
        dummyDb = XMDCTBDB('dummyDb.db', load=False, persistent=False)
        dummyDb.keyformat = None
        dummyDb.add(zip((440, 128, 440), (12.0, 16.0, 45.0)), 1)
        dummyDb.add(zip((512, 320, 440), (54.0, 16.0, 11.0)), 2)

        #        print dummyDb.get_stats()
        self.assertEqual(6, dummyDb.get_stats()['ndata'])

        T, fileIndex = dummyDb.get(440)
        print zip(T, fileIndex)
コード例 #5
0
    def runTest(self):
        print "------------------ Test2  DB Handle ---------"
        print 'Creating a hash table using Berkeley DB'
        dbName = 'dummy.db'

        ppbdb = XMDCTBDB(dbName, load=False, persistent=False)
        ppbdb.keyformat = None
        print 'populating with a key from MP'
        F = 128
        T = 125.0
        FileIdx = 104

        ppbdb.add(zip((F, ), (T, )), FileIdx)
        estT, estFileI = ppbdb.get(F)

        # refactoring, renvoi une liste de candidats

        self.assertEqual(estFileI[0], FileIdx)
        self.assertTrue(abs(estT[0] - T) < 0.01)

        print ppbdb.get_stats()
        print ppbdb
        del ppbdb