Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit 392d8c98 authored by Ed Rogers's avatar Ed Rogers
Browse files

Introduce SoundRecord for recording played sounds

parent b4fbaa00
......@@ -4,6 +4,13 @@ import random
from SoundLibrary import SoundLibrary
class SoundRecord:
def __init__(self, freq, volume, time):
self.freq = freq
self.volume = volume
self.heard = False
class HearingTest:
upper_lim = 100
lower_lim = 0
......@@ -26,7 +33,7 @@ class HearingTest:
return self.library.freqs
def handle_key_press(self):
# recent_sound = self.sounds[-1]
recent_sound = self.sounds[-1]
# if time.clock() - recent_sound.time_played < self.max_response_time:
# pass
# TODO finish me
......@@ -37,10 +44,12 @@ class HearingTest:
volume = random.random()
freq = random.choice(self.bands), volume)
played_time = time.clock()
# TODO randomise time
next_sleep_time = 1
# TODO register sound playing for score
self.sounds.append(SoundRecord(freq, volume, played_time))
test_finished = False
return test_finished, freq, volume, next_sleep_time
return test_finished, freq, volume, played_time, next_sleep_time
......@@ -84,7 +84,7 @@ class HearingMplCanvas(FigureCanvas):
class HearingTestThread(QtCore.QThread):
played_sound = QtCore.pyqtSignal(float, float)
played_sound = QtCore.pyqtSignal(float, float, float)
def __init__(self, test: HearingTest):
......@@ -96,8 +96,8 @@ class HearingTestThread(QtCore.QThread):
def run(self):
for _ in range(5):
# TODO convert to finished at end of test
finished, freq, volume, next_sleep_time = self.test.play_next_sound()
self.played_sound.emit(freq, volume)
finished, freq, volume, played_time, next_sleep_time = self.test.play_next_sound()
self.played_sound.emit(freq, volume, played_time)
......@@ -156,8 +156,8 @@ class TestWindow(QMainWindow):
# need to prevent another thread starting
def sound_played(self, freq, volume):
self.log.append('Played freq {}, at volume {} and time {}'.format(freq, volume, time.clock()))
def sound_played(self, freq, volume, played_time):
self.log.append('Played freq {}, at volume {} and time {}'.format(freq, volume, played_time))
def test_finished(self):
self.test_running = False
......@@ -5,7 +5,7 @@ from typing import List
class SoundLibrary:
def __init__(self, fs: float, sample_length: int, freqs: List[float]):
def __init__(self, fs: float, sample_length: float, freqs: List[float]):
self._data = {}
self.fs = fs
self.sample_length = sample_length
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment