mirror of https://gitlab.com/pamhyr/pamhyr2
debug + pep8
parent
6d60a2017c
commit
22771c7f3a
|
|
@ -1340,7 +1340,7 @@ class ResultsWindow(PamhyrWindow):
|
|||
return
|
||||
|
||||
# results
|
||||
results=self._results[self._current_results[0]]
|
||||
results = self._results[self._current_results[0]]
|
||||
if results is None:
|
||||
return
|
||||
|
||||
|
|
@ -1352,16 +1352,20 @@ class ResultsWindow(PamhyrWindow):
|
|||
t = self._timestamps
|
||||
q = profile.get_key("Q")
|
||||
|
||||
scale=[]
|
||||
low = 30; high = 84
|
||||
scale = []
|
||||
low = 30
|
||||
high = 84
|
||||
for k in range(low, high):
|
||||
note=440*2**((k-49)/12)
|
||||
note = 440*2**((k-49)/12)
|
||||
scale.append(note) # add musical note
|
||||
n_notes = len(scale) # number of musical notes
|
||||
# rescale
|
||||
# we start at low to high
|
||||
tmax = max(t); tmin = min(t);
|
||||
qmax = max(q); qmin = min(q); qfact = (n_notes) / (qmax - qmin + 1)
|
||||
tmax = max(t)
|
||||
tmin = min(t)
|
||||
qmax = max(q)
|
||||
qmin = min(q)
|
||||
qfact = (n_notes) / (qmax - qmin + 1)
|
||||
for i in range(len(q)):
|
||||
q[i] = int((q[i] - qmin) * qfact)
|
||||
nq = [q[0]] # (notes)
|
||||
|
|
@ -1372,41 +1376,35 @@ class ResultsWindow(PamhyrWindow):
|
|||
else:
|
||||
nq.append(q[i+1])
|
||||
dq.append(0.1)
|
||||
wq=[]
|
||||
for i in range(len(dq)): # loop over dataset observations, create one note per observation
|
||||
volume = 2048
|
||||
new_w = get_sine_wave(frequency = scale[nq[i]], duration = dq[i], amplitude = volume)
|
||||
wq = np.concatenate((wq,new_w))
|
||||
wq = []
|
||||
volume = 2048
|
||||
for i in range(len(dq)):
|
||||
new_w = get_sine_wave(frequency=scale[nq[i]],
|
||||
duration=dq[i],
|
||||
amplitude=volume)
|
||||
wq = np.concatenate((wq, new_w))
|
||||
p = pyaudio.PyAudio()
|
||||
chunk = 1048
|
||||
stream = p.open(format =
|
||||
p.get_format_from_width(2),
|
||||
channels = 1,
|
||||
rate = 44100,
|
||||
output = True)
|
||||
|
||||
|
||||
stream = p.open(format=p.get_format_from_width(2),
|
||||
channels=1,
|
||||
rate=44100,
|
||||
output=True)
|
||||
|
||||
def fn():
|
||||
i = 0
|
||||
while i < len(wq):
|
||||
stream.write(
|
||||
wq[i:min(i+chunk,len(wq))].astype(np.int16).tobytes()
|
||||
wq[i:min(i+chunk, len(wq))].astype(np.int16).tobytes()
|
||||
)
|
||||
i += chunk
|
||||
|
||||
title = self._trad["playing_sound"]
|
||||
dlg = WaitingDialog(
|
||||
payload_fn=fn,
|
||||
title=title,
|
||||
title="playing_sound",
|
||||
parent=self
|
||||
)
|
||||
dlg.exec_()
|
||||
|
||||
#stop stream
|
||||
stream.stop_stream()
|
||||
stream.close()
|
||||
|
||||
#close PyAudio
|
||||
p.terminate()
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@ class ResultsTranslate(MainTranslate):
|
|||
self._dict["ImageCoordinates"] = _translate(
|
||||
"Results", "Image coordinates"
|
||||
)
|
||||
self._dict["playing_sound"] = _translate(
|
||||
"Results", "Playing sound..."
|
||||
)
|
||||
|
||||
self._sub_dict["table_headers_reach"] = {
|
||||
"name": _translate("Results", "Reach name"),
|
||||
|
|
|
|||
|
|
@ -239,6 +239,9 @@ class MainTranslate(UnitTranslate):
|
|||
"Results comparison with two "
|
||||
"incompatible study version"
|
||||
)
|
||||
self._dict["playing_sound"] = _translate(
|
||||
"MainWindow", "Playing sound..."
|
||||
)
|
||||
|
||||
self._dict["x"] = _translate("MainWindow", "X (m)")
|
||||
self._dict["y"] = _translate("MainWindow", "Y (m)")
|
||||
|
|
|
|||
Loading…
Reference in New Issue