Ejemplo n.º 1
0
def importRirs(downloadDir, insertIntoDbF):
    j = 0
    for room in OmniRooms:
        url = 'http://kakapo.dcs.qmul.ac.uk/irs/{}Omni.zip'.format(room)
        filename = os.path.join(downloadDir, 'omni.{}.zip'.format(room))
        unpackDir = os.path.join(downloadDir, 'omni.{}'.format(room))

        dl = util.FileDownloader(url, filename)
        dl.download()
        dl.unpackTo(unpackDir)

        fileSelector = os.path.join(unpackDir, 'Omni', '*.wav')
        files = list(glob.glob(fileSelector))

        bar = util.ConsoleProgressBar()
        bar.start('Import OMNI %s' % room)
        for i, file in enumerate(sorted(
                files)):  # we sort to get same identifiers cross-platform
            identifier = '{:04d}_{}_{}'.format(j, room,
                                               util.baseFilename(file))
            j += 1
            insertIntoDbF(file, identifier, {
                'source': 'OMNI',
                'room': room,
            })
            bar.progress(i / len(files))
        bar.end()
Ejemplo n.º 2
0
def importRirs(downloadDir, insertIntoDbF):
    url = 'http://www.commsp.ee.ic.ac.uk/~sap/uploads/data/ACE/ACE_Corpus_RIRN_Single.tbz2'
    filename = os.path.join(downloadDir, 'ace.tbz2')
    unpackDir = os.path.join(downloadDir, 'ace')

    dl = util.FileDownloader(url, filename)
    dl.download()
    dl.unpackTo(unpackDir)

    files = []
    for root, dirnames, filenames in os.walk(unpackDir):
        for filename in fnmatch.filter(filenames, '*_RIR.wav'):
            files.append(os.path.join(root, filename))

    bar = util.ConsoleProgressBar()
    bar.start('Import ACE')
    for i, file in enumerate(
            sorted(files)):  # we sort to get same identifiers cross-platform
        try:
            *_, room, measurement, _ = util.pathParts(file)
        except:
            raise RuntimeError('Could not get room from %s' % file)
        identifier = '{:04d}_{}_{}'.format(i, room.lower(), measurement)
        insertIntoDbF(file, identifier, {
            'source': 'ACE',
            'room': room,
        })
        bar.progress(i / len(files))
    bar.end()
Ejemplo n.º 3
0
def importRirs(downloadDir, insertIntoDbF):
	url = 'http://www.openslr.org/resources/13/RWCP.tar.gz'
	filename = os.path.join(downloadDir, 'rwcp.tar.gz')
	unpackDir = os.path.join(downloadDir, 'rwcp')
	
	dl = util.FileDownloader(url, filename)
	dl.download()
	dl.unpackTo(unpackDir)

	files = []
	for root, dirnames, filenames in os.walk(os.path.join(unpackDir, 'RWCP/micarray/MICARRAY/data1')):
		for filename in filenames:
			if filename[-2:] != '.1': continue # we only use the front microphone
			files.append(os.path.join(root, filename))

	pattern = re.compile('(circle|cirline)\/(\w{3})\/imp(\d{3})')

	bar = util.ConsoleProgressBar()
	bar.start('Import RWCP')
	for i, file in enumerate(sorted(files)): # we sort to get same identifiers cross-platform
		m = pattern.search(file)
		assert m, 'Could parse room from path ({})'.format(file)
		room = m.group(2)
		identifier = '{:04d}_{}_{}'.format(i, room.lower(), m.group(3))

		x, fs = sf.read(file, dtype='float32', **RawFormat)
		x /= max(abs(x))
		x = (2**16 * x).astype(np.int16)

		insertIntoDbF((x, fs), identifier, {
			'source': 'RWCP',
			'room': room,
		})
		bar.progress(i / len(files))
	bar.end()
Ejemplo n.º 4
0
def importRirs(downloadDir, insertIntoDbF):
    url = 'http://www.commsp.ee.ic.ac.uk/~sap/uploads/data/MARDY.rar'
    filename = os.path.join(downloadDir, 'mardy.rar')
    unpackDir = os.path.join(downloadDir, 'mardy')

    dl = util.FileDownloader(url, filename)
    dl.download()
    dl.unpackTo(unpackDir)

    fileSelector = os.path.join(unpackDir, '*.wav')
    files = list(glob.glob(fileSelector))

    bar = util.ConsoleProgressBar()
    bar.start('Import MARDY')
    for i, file in enumerate(
            sorted(files)):  # we sort to get same identifiers cross-platform
        filename = os.path.basename(file)
        m = re.search(r'ir_(\d)_([LCR])_(\d).wav', filename)
        assert m, 'Could not parse rir info from filename {}'.format(filename)
        assert m.group(2) in Positions, 'invalid position {}'.format(
            m.groups(2))
        distanceInMeter = int(m.group(1))
        position = Positions[m.group(2)]
        microphoneIndexInArray = int(m.group(3))
        if microphoneIndexInArray == 4:
            identifier = '{:04d}_{}_{}'.format(i, distanceInMeter, position[0])
            insertIntoDbF(
                file, identifier, {
                    'source': 'MARDY',
                    'distanceInMeter': distanceInMeter,
                    'position': position,
                })
        bar.progress(i / len(files))
    bar.end()
Ejemplo n.º 5
0
def main(dbFilename, targetFs, force=False):
	util.createDirectory(NormalizeDir)

	rirDb = json.load(open(dbFilename))

	bar = util.ConsoleProgressBar()
	bar.start('Normalize RIRs')
	i = 0
	for rirId, rir in rirDb.items():
		targetFilename = os.path.join(NormalizeDir, rir['id'] + '.wav')
		if not force:
			if rir['filename'] == targetFilename and \
				rir['fs'] == targetFs and \
				targetFilename:
				continue

		x, fs_x = sf.read(os.path.join(ImportDir, rir['id'] + '.wav'), dtype='float32')
		y, fs_y = x, fs_x

		if fs_y != targetFs:
			y = resample(y, targetFs / fs_y, 'sinc_best')
			fs_y = targetFs

		rir['length_org'] = len(y) / fs_y
		y = util.trimSilence(y, 0.001, trimRight=False)
		y = util.normalizeAmplitude(y)

		sf.write(targetFilename, y, fs_y)
		
		rir['filename'] = targetFilename
		rir['fs'] = fs_y
		rir['length'] = len(y) / fs_y

		i += 1
		bar.progress(i / len(rirDb))
	bar.end()

	with open(dbFilename, 'w') as dbFile:
		json.dump(rirDb, dbFile, sort_keys=True, indent=4)
Ejemplo n.º 6
0
def importRirs(downloadDir, insertIntoDbF):
	url = 'https://www2.iks.rwth-aachen.de/air/air_database_release_1_4.zip'
	filename = os.path.join(downloadDir, 'air_1_4.zip')
	unpackDir = os.path.join(downloadDir, 'air_1_4')

	dl = util.FileDownloader(url, filename)
	dl.download()
	dl.unpackTo(unpackDir)

	files = []
	for root, dirnames, filenames in os.walk(os.path.join(unpackDir, 'AIR_1_4')):
		for filename in filenames:
			if os.path.splitext(filename)[1] != '.mat': continue
			files.append(os.path.join(root, filename))

	bar = util.ConsoleProgressBar()
	bar.start('Import AIR')
	for i, file in enumerate(sorted(files)): # we sort to get same identifiers cross-platform
		x, info = loadAirRir(file)
		info['source'] = 'AIR'
		identifier = '{:04d}_{}_{}'.format(i, info['rir_type'][:2], info['room'])
		insertIntoDbF((x, int(info['fs'])), identifier, info)
		bar.progress(i / len(files))
	bar.end()
Ejemplo n.º 7
0
        # FIXME: Total hack - add in can_exec rather than parse the insanity
        # of misc_macros. We are just going to preten that this is an interface
        # to make the expansion work correctly.
        can_exec = refpolicy.Interface("can_exec")
        av = access.AccessVector([
            "$1", "$2", "file", "execute_no_trans", "read", "getattr", "lock",
            "execute", "ioctl"
        ])

        can_exec.children.append(refpolicy.AVRule(av))
        headers.children.append(can_exec)

        o("done.\n")

    if output and not debug:
        status = util.ConsoleProgressBar(sys.stdout, steps=len(modules))
        status.start("Parsing interface files")

    failures = []
    for x in modules:
        m = refpolicy.Module()
        m.name = x[0]
        try:
            if expand:
                parse_file(x[1], m, spt)
            else:
                parse_file(x[1], m)
        except ValueError, e:
            o(str(e) + "\n")
            failures.append(x[1])
            continue