def prepare_harder():

	freqs = np.array(np.exp(np.linspace(np.log(264), np.log(2000), 150)))
	round_freqs = np.round(freqs, 0)

	T = 0.1 #n/fs = 9600/96000
	chunk = 9600

	round_freqs = round_freqs * T #indeski frekvencija

	timedata = [] 	#sample-ovi, svaki red je 9600 samplova

	#prvi ton
	fs, data = read('training/trainingG4.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	#drugi ton
	fs, data = read('training/trainingF5.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	fs, data = read('training/trainingD6.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	fs, data = read('training/trainingA6.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])	

	timedata = np.array(timedata)

	fftdata = []

	for row in timedata:																		#za svaki zvuk se racuna fft
		fftdata.append(calculatefft(fs, row)[0])

	amps = []	

	for row in fftdata:																			#uzimanje odgovarajucih amplituda za frekvencije
		#amps.append(row[round_freqs])
		amps.append(adaptivelocalmax(row, round_freqs))

	y = []
	for i in range(0, 3000):
		y.append([1, 0, 0, 0])

	for i in range(0, 3000):
		y.append([0, 1, 0, 0])

	for i in range(0, 3000):
		y.append([0, 0, 1, 0])

	for i in range(0, 3000):
		y.append([0, 0, 0, 1])

	x = np.array(amps)
	y = np.array(y)

	return x, y
示例#2
0
		if event.type == pygame.KEYDOWN and event.key == pygame.K_s:
			pl.orientation = 0
		if event.type == pygame.KEYDOWN and event.key == pygame.K_w:
			pl.orientation = 1
		if event.type == pygame.KEYDOWN and event.key == pygame.K_d:
			pl.orientation = 2
		if event.type == pygame.KEYDOWN and event.key == pygame.K_a:
			pl.orientation = 3

	a = record(p, stream)
	#rms = sqrt(mean(square(a)))
	a = calculatefft(RATE, a)[0]
	
	amptest = []
	amptest.append(adaptivelocalmax(a, round_freqs.astype(np.int64)))

	res = ann.predict(np.array(amptest))

	a = np.argmax(res)
	b = np.amax(res)
	if b > 0.98:
		pl.orientation = a

	pl.move()
	if(pl.checkApple(ap)):
		ap.generatePosition()
			
	screen.fill((0, 0, 0))

	texts(pl.score)