Exemple #1
0
def hrtfFullSimulation(hrtfDatabase, referenceAzimuthDegrees, speakers, polarPattern, ordersToShow) :
	hrtfs = {}
	for elevationDegrees, azimuthDegrees, response in hrtfDatabase._data :
		if elevationDegrees!= 0 : continue
		samplingRate, data = bmaudio.loadWave(response)
		hrtfs[azimuthDegrees] = numpy.fft.rfft(data,nBins)

	spectrums = spectrumDict(ordersToShow, spectrumBins)
	for azimuthDegrees in numpy.arange(speakers)*360/speakers :
		hrtf = hrtfs[azimuthDegrees]
		a = math.radians(azimuthDegrees-referenceAzimuthDegrees)
		for order in ordersToShow :
			spectrums[order] += sum(polarPattern(a,order))/float(speakers) * hrtf
	leftHrtf = hrtfs[referenceAzimuthDegrees]
	for order in ordersToShow :
		spectrums[order] /= leftHrtf
	return spectrums
def fileToSpectrum(file) :
	samplerate, wave = bmaudio.loadWave(file)
	return numpy.fft.rfft(wave)
Ns = [72, 36, 24, 18, 12]
nBins = 1024*4

spectrumBins = nBins/2+1
filters = dict( [ (N, numpy.zeros(spectrumBins,numpy.complex)) for N in Ns ])
w = 2*math.pi*spectralRange/spectrumBins * numpy.arange(spectrumBins)

hrtfs = {}
delays = {}

for elevationDegrees, azimuthDegrees, response in hrtfDatabase._data :
	if elevationDegrees != 0 : continue
	from math import radians
	e = radians(elevationDegrees)
	a = radians(azimuthDegrees)
	samplingRate, data = bmaudio.loadWave(response)
	t = bmaudio.delayWithMinimumPhaseCorrelation(data,filterFreq=20000, interpolate=True) / samplingRate
	delays[azimuthDegrees] = t
	hrtfs[azimuthDegrees] = numpy.fft.rfft(data,nBins)


minDelay = min(delays.values())

for N in Ns :
	for azimuth in xrange(0,360,360/N) :
		filters[N] += hrtfs[azimuth] / N
for N in Ns :
	filters[N] /= hrtfs[90]

plot = bmaudio.SpectrumDisplay()
plot.inDb()