Skip to content

Commit 493ee62

Browse files
committed
fix mic on Clue demo
The numpy in ulab doesn't seem to convert the result types the same way as regular numpy, so the result of the mic_samples subtraction had dtype=float, which was too big for that characteristic and caused an error once an app connected.
1 parent 58c8cb6 commit 493ee62

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/ble_adafruit_clue.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@
114114
clue._mic.record( # pylint: disable=protected-access
115115
mic_samples, len(mic_samples)
116116
)
117+
# Need to create an array of the correct type, because ulab
118+
# seems to get broadcasting of builtin Python types wrong.
119+
offset = np.array([32768], dtype=np.uint16)
117120
# This subtraction yields unsigned values which are
118121
# reinterpreted as signed after passing.
119-
mic_svc.sound_samples = mic_samples - 32768
122+
mic_svc.sound_samples = mic_samples - offset
120123
mic_last_update = now_msecs
121124

122125
neopixel_values = neopixel_svc.values

0 commit comments

Comments
 (0)