debug + pep8

test_sound
Theophile Terraz 2025-11-06 16:40:12 +01:00
parent 6d60a2017c
commit 22771c7f3a
3 changed files with 26 additions and 28 deletions

View File

@ -1340,7 +1340,7 @@ class ResultsWindow(PamhyrWindow):
return return
# results # results
results=self._results[self._current_results[0]] results = self._results[self._current_results[0]]
if results is None: if results is None:
return return
@ -1352,16 +1352,20 @@ class ResultsWindow(PamhyrWindow):
t = self._timestamps t = self._timestamps
q = profile.get_key("Q") q = profile.get_key("Q")
scale=[] scale = []
low = 30; high = 84 low = 30
high = 84
for k in range(low, high): for k in range(low, high):
note=440*2**((k-49)/12) note = 440*2**((k-49)/12)
scale.append(note) # add musical note scale.append(note) # add musical note
n_notes = len(scale) # number of musical notes n_notes = len(scale) # number of musical notes
# rescale # rescale
# we start at low to high # we start at low to high
tmax = max(t); tmin = min(t); tmax = max(t)
qmax = max(q); qmin = min(q); qfact = (n_notes) / (qmax - qmin + 1) tmin = min(t)
qmax = max(q)
qmin = min(q)
qfact = (n_notes) / (qmax - qmin + 1)
for i in range(len(q)): for i in range(len(q)):
q[i] = int((q[i] - qmin) * qfact) q[i] = int((q[i] - qmin) * qfact)
nq = [q[0]] # (notes) nq = [q[0]] # (notes)
@ -1372,41 +1376,35 @@ class ResultsWindow(PamhyrWindow):
else: else:
nq.append(q[i+1]) nq.append(q[i+1])
dq.append(0.1) dq.append(0.1)
wq=[] wq = []
for i in range(len(dq)): # loop over dataset observations, create one note per observation
volume = 2048 volume = 2048
new_w = get_sine_wave(frequency = scale[nq[i]], duration = dq[i], amplitude = volume) for i in range(len(dq)):
wq = np.concatenate((wq,new_w)) new_w = get_sine_wave(frequency=scale[nq[i]],
duration=dq[i],
amplitude=volume)
wq = np.concatenate((wq, new_w))
p = pyaudio.PyAudio() p = pyaudio.PyAudio()
chunk = 1048 chunk = 1048
stream = p.open(format = stream = p.open(format=p.get_format_from_width(2),
p.get_format_from_width(2), channels=1,
channels = 1, rate=44100,
rate = 44100, output=True)
output = True)
def fn(): def fn():
i = 0 i = 0
while i < len(wq): while i < len(wq):
stream.write( 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 i += chunk
title = self._trad["playing_sound"]
dlg = WaitingDialog( dlg = WaitingDialog(
payload_fn=fn, payload_fn=fn,
title=title, title="playing_sound",
parent=self parent=self
) )
dlg.exec_() dlg.exec_()
#stop stream
stream.stop_stream() stream.stop_stream()
stream.close() stream.close()
#close PyAudio
p.terminate() p.terminate()

View File

@ -61,9 +61,6 @@ class ResultsTranslate(MainTranslate):
self._dict["ImageCoordinates"] = _translate( self._dict["ImageCoordinates"] = _translate(
"Results", "Image coordinates" "Results", "Image coordinates"
) )
self._dict["playing_sound"] = _translate(
"Results", "Playing sound..."
)
self._sub_dict["table_headers_reach"] = { self._sub_dict["table_headers_reach"] = {
"name": _translate("Results", "Reach name"), "name": _translate("Results", "Reach name"),

View File

@ -239,6 +239,9 @@ class MainTranslate(UnitTranslate):
"Results comparison with two " "Results comparison with two "
"incompatible study version" "incompatible study version"
) )
self._dict["playing_sound"] = _translate(
"MainWindow", "Playing sound..."
)
self._dict["x"] = _translate("MainWindow", "X (m)") self._dict["x"] = _translate("MainWindow", "X (m)")
self._dict["y"] = _translate("MainWindow", "Y (m)") self._dict["y"] = _translate("MainWindow", "Y (m)")