Exemple #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()
Exemple #2
0
def importRirs(downloadDir, insertIntoDbF):
	j = 0
	for room in OmniRooms:
		url = 'http://kakapo.dcs.qmul.ac.uk/irs/{}Omni.zip'.format(room)
		filename = join(downloadDir, 'omni.{}.zip'.format(room))
		unpackDir = join(downloadDir, 'omni.{}'.format(room))

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

		fileSelector = join(unpackDir, 'Omni', '*.wav')
		files = list(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()
Exemple #3
0
def loadAirRir(filename):
	"""Load a RIR struct from AIR database format. Returns the RIR itself and a dictionary with information about it.

	Possible Dictionary entries (not all must be available)
		fs          Sampling frequency
		rir_type    Type of impulse response
		            '1': binaural (with/without dummy head)
		                  acoustical path: loudspeaker -> microphones
		                  next to the pinna
		            '2': dual-channel (with mock-up phone)
		                 acoustical path: artificial mouth of dummy head
		                 -> dual-microphone mock-up at HHP or HFRP
		mock_up_type   Select mock-up device (for rir_type '2' only)
		                '1': bottom-bottom (BB) (default)
		                '2': bottom-top (BT)
		room        Room type
		            1,2,..,11:  'booth','office','meeting','lecture',
		                         'stairway','stairway1','stairway2',
		                         'corridor','bathroom','lecture1',
		                         'aula_carolina'
		            Available rooms for (1) binaural: 1,2,3,4,5,11
		                                (2) phone: 2,3,4,6,7,8,9,10
		channel     Select channel
		            '0': right; '1': left
		head        Select RIR with or without dummy head
		            (for 'rir_type=1' only)
		            '0': no dummy head; '1': with dummy head
		phone_pos   Position of mock-up phone (for 'rir_type=2' only)
		            '1': HHP (Hand-held), '2': HFRP (Hands-free)
		rir_no      RIR number (increasing distance, for 'rir_type=1' only)
		                Booth:    {0.5m, 1m, 1.5m}
		                Office:   {1m, 2m, 3m}
		                Meeting:  {1.45m, 1.7m, 1.9m, 2.25m, 2.8m}
		                Lecture:  {2.25m, 4m, 5.56m, 7.1m, 8.68m, 10.2m}
		                Stairway: {1m, 2m, 3m}
		                Aula Carolina: {1m, 2m, 3m, 5m, 15m, 20m}
		azimuth     Azimuth angle (0° left, 90° frontal, 180° right)
		                for 'rir_type=1' & 'room=5' -> 0:15:180
		                for 'rir_type=1' & 'room=11'& distance=3 ->0:45:180
	"""
	dic = scipy.io.loadmat(filename, struct_as_record = False)
	x = dic['h_air'][0]
	air_info = dic['air_info'][0][0] # air_info contains some more infos about the RIR
	info = {
		'fs': int(air_info.fs[0][0]),
		'room': str(air_info.room[0]),
		'channel': int(air_info.channel[0][0]),
		'head': int(air_info.head[0][0]),
	}

	# Apparently the struct is no complete and we have to parse further information from the filename
	# rir_type
	m = re.search(r'air_([^_]+)_', filename)
	assert m, 'Could not parse rir_type from filename {}'.format(filename)
	info['rir_type'] = 'binaural' if 'binaural' in util.baseFilename(filename) else 'phone'

	# further parsing depending on rir_type
	if info['rir_type'] == 'binaural': 
		m = re.search(r'air_binaural_' + info['room'] + r'_(\d+)_(\d+)_(\d+)_?([\d_]*).mat', filename)
		assert m, 'Could not parse filename {} (info: {})'.format(filename, info)
		assert int(m.group(1)) == info['channel']
		assert int(m.group(2)) == info['head']
		info['rir_no'] = int(m.group(3))
		if m.group(4): info['azimuth'] = str(m.group(4))
		info['distanceInMeter'] = Distances[info['room']][info['rir_no'] - 1]
	elif info['rir_type'] == 'phone':
		m = re.search(r'air_phone_(.+)_(\w{3,4})_(\d+).mat', filename)
		assert m, 'Could not parse filename {} (info: {})'.format(filename, info)
		
		info['mock_up_type'] = 'BT' if '_BT_' in filename else 'BB'
		if info['mock_up_type'] == 'BT': assert air_info.mock_up_type[0] == 'BT'

		info['phone_pos'] = str(air_info.phone_pos[0])
		assert m.group(2) == info['phone_pos']
	else:
		raise RuntimeError('Unknown rir_type {}'.format(info['rir_type']))

	return x, info
Exemple #4
0
def loadAirRir(filename):
	"""Load a RIR struct from AIR database format. Returns the RIR itself and a dictionary with information about it.

	Possible Dictionary entries (not all must be available)
		fs          Sampling frequency
		rir_type    Type of impulse response
		            '1': binaural (with/without dummy head)
		                  acoustical path: loudspeaker -> microphones
		                  next to the pinna
		            '2': dual-channel (with mock-up phone)
		                 acoustical path: artificial mouth of dummy head
		                 -> dual-microphone mock-up at HHP or HFRP
		mock_up_type   Select mock-up device (for rir_type '2' only)
		                '1': bottom-bottom (BB) (default)
		                '2': bottom-top (BT)
		room        Room type
		            1,2,..,11:  'booth','office','meeting','lecture',
		                         'stairway','stairway1','stairway2',
		                         'corridor','bathroom','lecture1',
		                         'aula_carolina'
		            Available rooms for (1) binaural: 1,2,3,4,5,11
		                                (2) phone: 2,3,4,6,7,8,9,10
		channel     Select channel
		            '0': right; '1': left
		head        Select RIR with or without dummy head
		            (for 'rir_type=1' only)
		            '0': no dummy head; '1': with dummy head
		phone_pos   Position of mock-up phone (for 'rir_type=2' only)
		            '1': HHP (Hand-held), '2': HFRP (Hands-free)
		rir_no      RIR number (increasing distance, for 'rir_type=1' only)
		                Booth:    {0.5m, 1m, 1.5m}
		                Office:   {1m, 2m, 3m}
		                Meeting:  {1.45m, 1.7m, 1.9m, 2.25m, 2.8m}
		                Lecture:  {2.25m, 4m, 5.56m, 7.1m, 8.68m, 10.2m}
		                Stairway: {1m, 2m, 3m}
		                Aula Carolina: {1m, 2m, 3m, 5m, 15m, 20m}
		azimuth     Azimuth angle (0° left, 90° frontal, 180° right)
		                for 'rir_type=1' & 'room=5' -> 0:15:180
		                for 'rir_type=1' & 'room=11'& distance=3 ->0:45:180
	"""
	dic = scipy.io.loadmat(filename, struct_as_record = False)
	x = dic['h_air'][0]
	air_info = dic['air_info'][0][0] # air_info contains some more infos about the RIR
	info = {
		'fs': int(air_info.fs[0][0]),
		'room': str(air_info.room[0]),
		'channel': int(air_info.channel[0][0]),
		'head': int(air_info.head[0][0]),
	}

	# Apparently the struct is no complete and we have to parse further information from the filename
	# rir_type
	m = re.search(r'air_([^_]+)_', filename)
	assert m, 'Could not parse rir_type from filename {}'.format(filename)
	info['rir_type'] = 'binaural' if 'binaural' in util.baseFilename(filename) else 'phone'

	# further parsing depending on rir_type
	if info['rir_type'] == 'binaural': 
		m = re.search(r'air_binaural_' + info['room'] + r'_(\d+)_(\d+)_(\d+)_?([\d_]*).mat', filename)
		assert m, 'Could not parse filename {} (info: {})'.format(filename, info)
		assert int(m.group(1)) == info['channel']
		assert int(m.group(2)) == info['head']
		info['rir_no'] = int(m.group(3))
		if m.group(4): info['azimuth'] = str(m.group(4))
		info['distanceInMeter'] = Distances[info['room']][info['rir_no'] - 1]
	elif info['rir_type'] == 'phone':
		m = re.search(r'air_phone_(.+)_(\w{3,4})_(\d+).mat', filename)
		assert m, 'Could not parse filename {} (info: {})'.format(filename, info)
		
		info['mock_up_type'] = 'BT' if '_BT_' in filename else 'BB'
		if info['mock_up_type'] == 'BT': assert air_info.mock_up_type[0] == 'BT'

		info['phone_pos'] = str(air_info.phone_pos[0])
		assert m.group(2) == info['phone_pos']
	else:
		raise RuntimeError('Unknown rir_type {}'.format(info['rir_type']))

	return x, info