omnipython-apps 0.1.4.dev8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,449 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Input adapters. Each reports its rate, channel count and clock, and hands
6
+ the engine an audiocore source at the engine's rate and channel count.
7
+
8
+ ClipInput is a WAV clip. LiveInput is the board's microphone or line input, or
9
+ a Windows capture device, read by the pump's own thread (audioif's `Input`), so
10
+ a guitar goes through the effect with no Python in the path. On a board,
11
+ UsbInput is the USB sound card chosen under the picker's sound input, which
12
+ the bus writes straight into a ring the pump plays. In a browser,
13
+ BrowserInput is the page's microphone, which the app's loop moves into the
14
+ graph.
15
+ """
16
+
17
+ import array
18
+ import sys
19
+
20
+ import audiocore
21
+
22
+ from . import CHANNELS, SAMPLE_RATE, wavfile
23
+
24
+ try:
25
+ import audiospeed
26
+ except ImportError: # a build without it plays clips at their own rate only
27
+ audiospeed = None
28
+
29
+
30
+ #: The platforms that are a browser page.
31
+ BROWSERS = ("webassembly", "emscripten")
32
+
33
+
34
+ def in_browser():
35
+ return sys.platform in BROWSERS
36
+
37
+
38
+ def live_available():
39
+ """True where there is an input to open: the page's microphone, Windows'
40
+ capture devices, or a board whose microphone shares its speaker's I2S
41
+ clocks."""
42
+ if in_browser() or _usb_mic() is not None:
43
+ return True
44
+ try:
45
+ import _audioif
46
+ except ImportError:
47
+ return False
48
+ if not hasattr(_audioif, "Input"):
49
+ return False
50
+ if hasattr(_audioif, "same_clock"):
51
+ return True
52
+ try:
53
+ import board_peripherals as bp
54
+ except ImportError:
55
+ return False
56
+ wire = getattr(getattr(bp, "AUDIO_OUT", None), "wire", None)
57
+ return getattr(wire, "sd_in", None) is not None
58
+
59
+
60
+ class ClipInput:
61
+ """A WAV file, held in memory, played from the start or looped."""
62
+
63
+ kind = "clip"
64
+ clock = "file"
65
+
66
+ def __init__(self, path):
67
+ self.path = path
68
+ rate, ch, pcm = wavfile.read(path)
69
+ if ch == 1:
70
+ pcm = _mono_to_stereo(pcm)
71
+ elif ch > 2:
72
+ raise ValueError("clips with more than two channels aren't supported")
73
+ self.file_rate = rate
74
+ self.sample_rate = SAMPLE_RATE
75
+ self.channel_count = CHANNELS
76
+ self.frames = len(pcm) // CHANNELS
77
+ self.seconds = self.frames / rate
78
+ self._pcm = pcm
79
+
80
+ def source(self):
81
+ """A fresh source at the engine's rate, from the clip's first frame."""
82
+ raw = audiocore.RawSample(self._pcm, channel_count=CHANNELS,
83
+ sample_rate=self.file_rate)
84
+ if self.file_rate == SAMPLE_RATE:
85
+ return raw
86
+ if audiospeed is None:
87
+ raise ValueError("this build has no resampler for a %d Hz clip"
88
+ % self.file_rate)
89
+ return audiospeed.Resampler(raw)
90
+
91
+ def name(self):
92
+ p = self.path.replace("\\", "/")
93
+ return p[p.rfind("/") + 1:]
94
+
95
+
96
+ class BoardInput:
97
+ """The board's microphone or line input: the RX half of the speaker's own
98
+ I2S channel, so the two share a clock and the graph reads it directly.
99
+ The output has to be open first; Engine.set_effect opens it."""
100
+
101
+ kind = "live"
102
+ clock = "device"
103
+ clocks = 1
104
+ drift = None
105
+ name_in = "the board's input"
106
+ target = 0
107
+
108
+ def __init__(self, frames=128):
109
+ import _audioif
110
+
111
+ import board_peripherals as bp
112
+
113
+ power = getattr(bp, "audio_in_power", None)
114
+ if power is not None:
115
+ power(True)
116
+ self._power = power
117
+ self.sample_rate = SAMPLE_RATE
118
+ self.channel_count = CHANNELS
119
+ self.seconds = 0
120
+ self.file_rate = SAMPLE_RATE
121
+ self._mic = _audioif.Input(sample_rate=SAMPLE_RATE,
122
+ channel_count=CHANNELS, frames=frames)
123
+
124
+ def source(self):
125
+ return self._mic
126
+
127
+ def name(self):
128
+ return "live input"
129
+
130
+ def close(self):
131
+ if hasattr(self._mic, "deinit"):
132
+ self._mic.deinit()
133
+ if self._power is not None:
134
+ self._power(False)
135
+
136
+
137
+ def open_live(device=None, speaker=None, clock="auto", target=None):
138
+ if in_browser():
139
+ return BrowserInput(target=target)
140
+ usb = _usb_mic()
141
+ if usb is not None:
142
+ return UsbInput(*usb, target=target)
143
+ import _audioif
144
+
145
+ if hasattr(_audioif, "same_clock"):
146
+ return LiveInput(device, speaker, clock, target=target)
147
+ return BoardInput()
148
+
149
+
150
+ class LiveInput:
151
+ """A Windows capture device, live. `device` is an endpoint ID, or None for
152
+ the default.
153
+
154
+ When the speaker is part of the same device, the two share a clock and
155
+ the microphone feeds the graph directly: the pump reads it on its own
156
+ thread and is paced by it. When they are different devices, their clocks
157
+ drift apart by tens of parts per million, so the microphone writes into
158
+ an `audiopump.Ring` on a thread of its own and an
159
+ `audiopump.DriftResampler` reads it at the speaker's pace, holding the
160
+ ring at `target` frames. `clock` is "auto" (ask Windows which case this
161
+ is), "same" or "two".
162
+ """
163
+
164
+ kind = "live"
165
+ clock = "device"
166
+
167
+ # The microphone hands over 10 ms packets (480 frames) in shared mode and
168
+ # the speaker takes 10 ms at a time, so the ring's fill swings by twice
169
+ # that between the resampler's looks at it. 768 frames ran dry every
170
+ # second or two on the bench; 1024 (21 ms) held with no underrun.
171
+ RING_BLOCK = 128
172
+ RING_BLOCKS = 64
173
+ TARGET = 1024
174
+
175
+ def __init__(self, device=None, speaker=None, clock="auto", frames=128,
176
+ target=None):
177
+ import _audioif
178
+
179
+ self.device = device
180
+ self.sample_rate = SAMPLE_RATE
181
+ self.channel_count = CHANNELS
182
+ self.seconds = 0
183
+ self.file_rate = SAMPLE_RATE
184
+ self.name_in = _endpoint_name(_audioif, device, True)
185
+ if clock == "auto":
186
+ clock = "same" if _same_clock(_audioif, speaker, device) else "two"
187
+ self.clocks = 1 if clock == "same" else 2
188
+ self.ring = None
189
+ self.drift = None
190
+ self.target = 0
191
+ if self.clocks == 1:
192
+ self._mic = _audioif.Input(sample_rate=SAMPLE_RATE,
193
+ channel_count=CHANNELS, frames=frames,
194
+ device=device)
195
+ self._src = self._mic
196
+ else:
197
+ import audiopump
198
+
199
+ self.ring = audiopump.Ring(sample_rate=SAMPLE_RATE,
200
+ channel_count=CHANNELS,
201
+ frames=self.RING_BLOCK,
202
+ capacity=self.RING_BLOCKS)
203
+ # The Ring first: the microphone's thread writes into it from
204
+ # the moment the Input exists.
205
+ self._mic = _audioif.Input(sample_rate=SAMPLE_RATE,
206
+ channel_count=CHANNELS,
207
+ frames=self.RING_BLOCK, device=device,
208
+ ring=self.ring)
209
+ self.target = target or self.TARGET
210
+ self.drift = audiopump.DriftResampler(self.ring,
211
+ target=self.target)
212
+ self._src = self.drift
213
+
214
+ def source(self):
215
+ return self._src
216
+
217
+ def name(self):
218
+ return "live input"
219
+
220
+ def held_frames(self):
221
+ """Frames this side holds right now: what the microphone has waiting,
222
+ plus the ring's fill between two clocks."""
223
+ st = self._mic.stats()
224
+ held = st[6]
225
+ if self.drift is not None:
226
+ held += self.drift.fill
227
+ return held
228
+
229
+ def period_frames(self):
230
+ """The Windows engine's period for the microphone, 0 until it opens."""
231
+ st = self._mic.stats()
232
+ return st[8] if len(st) > 8 else 0
233
+
234
+ def stats(self):
235
+ return self._mic.stats()
236
+
237
+ def close(self):
238
+ self._mic.deinit()
239
+
240
+
241
+ def _usb_mic():
242
+ """``(device, label)`` of the USB microphone chosen under the picker's
243
+ sound input on a board, or None: nothing chosen there, something else
244
+ chosen, or no USB host."""
245
+ try:
246
+ import endpointkit
247
+ from usb.host import endpoints as usb_endpoints
248
+ except ImportError:
249
+ return None
250
+ for ep in endpointkit.selected("audio.in"):
251
+ if not ep.provider.name.startswith("usb-"):
252
+ return None
253
+ dev = usb_endpoints.device(ep)
254
+ if dev is not None:
255
+ return dev, ep.label
256
+ return None
257
+
258
+
259
+ class UsbInput:
260
+ """A USB sound card's input on a board's USB host port.
261
+
262
+ The bus writes the samples straight into an `audiopump.Ring`, and an
263
+ `audiopump.DriftResampler` plays it at the output's pace, holding
264
+ `target` frames, so no Python sits in the path. A mono input plays into
265
+ both channels.
266
+ """
267
+
268
+ kind = "live"
269
+ clock = "device"
270
+ clocks = 2
271
+
272
+ RING_BLOCK = 128
273
+ RING_BLOCKS = 32
274
+ TARGET = 512
275
+
276
+ def __init__(self, dev, label="USB input", target=None):
277
+ import audiopump
278
+ from usb.host.audio import Microphone
279
+
280
+ self.name_in = label
281
+ self.sample_rate = SAMPLE_RATE
282
+ self.channel_count = CHANNELS
283
+ self.seconds = 0
284
+ self.file_rate = SAMPLE_RATE
285
+ self._mic = Microphone(dev, rate=SAMPLE_RATE, bits=16)
286
+ self.ring = audiopump.Ring(sample_rate=SAMPLE_RATE,
287
+ channel_count=self._mic.channels,
288
+ frames=self.RING_BLOCK,
289
+ capacity=self.RING_BLOCKS)
290
+ self.target = target or self.TARGET
291
+ self.drift = audiopump.DriftResampler(self.ring, target=self.target)
292
+ self._mic.start(self.ring)
293
+
294
+ def source(self):
295
+ return self.drift
296
+
297
+ def name(self):
298
+ return "live input"
299
+
300
+ def held_frames(self):
301
+ return self.drift.fill
302
+
303
+ def period_frames(self):
304
+ return 48 # one USB frame, 1 ms
305
+
306
+ def stats(self):
307
+ return self._mic.stats()
308
+
309
+ def close(self):
310
+ self._mic.stop()
311
+
312
+
313
+ class BrowserInput:
314
+ """The page's microphone, the one the browser lets the page record from.
315
+
316
+ The browser hands the page its microphone in blocks of its own size, on
317
+ its own clock, so `service` moves what has arrived into an
318
+ `audiopump.Ring` from the app's loop, and an `audiopump.DriftResampler`
319
+ plays the ring at the output's pace, holding `target` frames. Until the
320
+ browser lets the page record, which it asks at the next tap or key,
321
+ `listening` is False and the input is silent.
322
+ """
323
+
324
+ kind = "live"
325
+ clock = "device"
326
+ clocks = 2
327
+ name_in = "the browser's microphone"
328
+
329
+ # The browser delivers 1024 frames (21 ms) a block, and a busy computer
330
+ # holds the page up for hundreds of ms at a time, so the ring is 1.4 s
331
+ # deep and keeps 256 ms. The output loses the time a stall takes but the
332
+ # microphone's blocks keep coming, so a stall that leaves more than twice
333
+ # the target waiting drops what arrives until the ring is back at the
334
+ # target: the skip lands in the gap the stall already made, and the
335
+ # board's delay doesn't grow behind the guitar.
336
+ RING_BLOCK = 128
337
+ RING_BLOCKS = 512
338
+ TARGET = 12288
339
+ # A stall as Live starts can leave the ring hundreds of ms over target,
340
+ # and at the resampler's usual 1000 ppm that takes minutes to play down.
341
+ # 5000 ppm takes it back in under a minute, 9 cents sharp meanwhile.
342
+ MAX_PPM = 5000
343
+
344
+ def __init__(self, target=None):
345
+ import audiopump
346
+ import boarddev
347
+ from audiodev import AudioFormat
348
+
349
+ self.sample_rate = SAMPLE_RATE
350
+ self.channel_count = CHANNELS
351
+ self.seconds = 0
352
+ self.file_rate = SAMPLE_RATE
353
+ self._mic = boarddev.pcm_in(AudioFormat(SAMPLE_RATE, CHANNELS, 16))
354
+ self._mic.open()
355
+ self.ring = audiopump.Ring(sample_rate=SAMPLE_RATE,
356
+ channel_count=CHANNELS,
357
+ frames=self.RING_BLOCK,
358
+ capacity=self.RING_BLOCKS)
359
+ self.target = target or self.TARGET
360
+ self.drift = audiopump.DriftResampler(self.ring, target=self.target,
361
+ max_ppm=self.MAX_PPM)
362
+ #: Bytes the ring holds when empty, how many it may hold before what
363
+ #: arrives is dropped, and how few it holds again when it's taken
364
+ #: back. The resampler's own fill is smoothed and stands still while
365
+ #: it waits, so the ring is what's counted.
366
+ self._room = self.ring.space()
367
+ self.limit = 2 * self.target * CHANNELS * 2
368
+ self.resume = self.target * CHANNELS * 2
369
+ self._dropping = False
370
+ self._buf = bytearray(4096)
371
+ self.received = 0
372
+ #: Bytes left out because too much was already waiting.
373
+ self.dropped = 0
374
+
375
+ @property
376
+ def listening(self):
377
+ """True once the browser has let the page record."""
378
+ return self.received > 0
379
+
380
+ def service(self):
381
+ """Move what the microphone has delivered into the ring; how many
382
+ bytes."""
383
+ moved = 0
384
+ buf = self._buf
385
+ while True:
386
+ room = min(len(buf), self.ring.space())
387
+ if room < 4:
388
+ break
389
+ n = self._mic.readinto(memoryview(buf)[:room])
390
+ if not n:
391
+ break
392
+ held = self._room - self.ring.space()
393
+ if self._dropping:
394
+ self._dropping = held > self.resume
395
+ elif held >= self.limit:
396
+ self._dropping = True
397
+ if self._dropping:
398
+ self.dropped += n
399
+ else:
400
+ self.ring.write(memoryview(buf)[:n])
401
+ moved += n
402
+ self.received += moved
403
+ return moved
404
+
405
+ def source(self):
406
+ return self.drift
407
+
408
+ def name(self):
409
+ return "live input"
410
+
411
+ def held_frames(self):
412
+ return self.drift.fill
413
+
414
+ def period_frames(self):
415
+ return 1024
416
+
417
+ def close(self):
418
+ self._mic.close()
419
+
420
+
421
+ def _endpoint_name(audioif, device, capture):
422
+ try:
423
+ return audioif.endpoint(device, capture)[1]
424
+ except (AttributeError, OSError):
425
+ return device or ("default input" if capture else "default output")
426
+
427
+
428
+ def _same_clock(audioif, speaker, mic):
429
+ try:
430
+ return audioif.same_clock(speaker, mic)
431
+ except (AttributeError, OSError):
432
+ # A build that can't tell: two clocks is the safe guess, since the
433
+ # resampler holds one clock as well as two.
434
+ return False
435
+
436
+
437
+ def _mono_to_stereo(pcm):
438
+ out = array.array("h", bytes(4 * len(pcm)))
439
+ try:
440
+ out[0::2] = pcm
441
+ out[1::2] = pcm
442
+ except NotImplementedError:
443
+ # MicroPython's arrays take no stepped slices.
444
+ j = 0
445
+ for v in pcm:
446
+ out[j] = v
447
+ out[j + 1] = v
448
+ j += 2
449
+ return out
apps/stompbox/meter.py ADDED
@@ -0,0 +1,72 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """The level meter: the peak of what the engine plays, and whether it clipped.
6
+
7
+ The engine hands `Level` each stretch of audio the pump has sent out. `read`
8
+ gives the highest peak since the last read, as a share of full scale before
9
+ the master, and whether it came within half a decibel of it.
10
+ """
11
+
12
+ FULL_SCALE = 32767
13
+ #: A peak this close to full scale lights the clip light: -0.5 dB.
14
+ CLIP_AT = 0.944
15
+ #: The most samples looked at in one stretch, the newest ones. A tick that
16
+ #: comes late brings more than that, and the meter mustn't make it later.
17
+ SCAN = 4096
18
+ #: The meter's bottom in decibels, and the decibels in one step of its bar.
19
+ FLOOR_DB = -48
20
+ STEP_DB = 2
21
+ STEPS = -FLOOR_DB // STEP_DB
22
+
23
+ # The level at the bottom of each step, from the top one down, so a level is
24
+ # placed with compares.
25
+ _EDGES = tuple(10 ** (-STEP_DB * k / 20) for k in range(STEPS))
26
+
27
+
28
+ class Level:
29
+ def __init__(self):
30
+ self._peak = 0
31
+
32
+ def feed(self, samples):
33
+ """Take in a stretch of signed 16-bit samples, every channel together.
34
+
35
+ ``max`` and ``min`` walk the buffer in C, so every sample is seen and
36
+ a single one at full scale is enough to light the clip light.
37
+ """
38
+ if len(samples) > SCAN:
39
+ samples = samples[len(samples) - SCAN:]
40
+ if not len(samples):
41
+ return
42
+ high = max(samples)
43
+ low = -min(samples)
44
+ if low > high:
45
+ high = low
46
+ if high > self._peak:
47
+ self._peak = high
48
+
49
+ def read(self, master=1.0):
50
+ """``(level, clipped)`` since the last read.
51
+
52
+ *master* is the gain between the effect and the audio that was fed
53
+ in. The level is the peak before it, 0.0 to 1.0, so the meter shows
54
+ what the effect puts out wherever the master is. With the master at
55
+ 0 nothing reaches the meter and both are zero.
56
+ """
57
+ peak = self._peak
58
+ self._peak = 0
59
+ if master <= 0 or not peak:
60
+ return 0.0, False
61
+ level = peak / (FULL_SCALE * master)
62
+ if level > 1.0:
63
+ level = 1.0
64
+ return level, level >= CLIP_AT
65
+
66
+
67
+ def steps(level):
68
+ """A level in 0.0 to 1.0 as lit steps of the bar, 0 to `STEPS`."""
69
+ for k in range(STEPS):
70
+ if level >= _EDGES[k]:
71
+ return STEPS - k
72
+ return 0
@@ -0,0 +1,135 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Output adapters. The output's clock drives the engine: it pulls the graph.
6
+
7
+ DefaultOutput is the board's `audio_out` role, or a computer's default device
8
+ through audiodev's player. WasapiOutput is a Windows speaker the pump writes
9
+ itself, with no Python in the path: the low-latency one, and the one a live
10
+ input wants.
11
+ """
12
+
13
+ from . import CHANNELS, SAMPLE_RATE
14
+ from .inputs import in_browser
15
+
16
+ #: Chunks of 40 ms the browser's player keeps scheduled ahead.
17
+ BROWSER_LOOKAHEAD = 5
18
+
19
+ VOLUME = 80 # the codec's, where the board has one: on an ES8311, -10 dB
20
+
21
+
22
+ class DefaultOutput:
23
+ kind = "default"
24
+
25
+ def __init__(self, latency=None, device=None):
26
+ from audiodev import AudioFormat, auto
27
+
28
+ fmt = AudioFormat(SAMPLE_RATE, CHANNELS, 16)
29
+ # A computer names the device the picker chose; a board's audio_out
30
+ # follows that choice itself and takes no such argument.
31
+ kwargs = {} if device is None else {"device": device}
32
+ if in_browser():
33
+ # A page's output runs late whenever the computer is busy, and
34
+ # two chunks ahead ran dry under load where five held.
35
+ kwargs["lookahead_chunks"] = BROWSER_LOOKAHEAD
36
+ try:
37
+ import board_peripherals as bp
38
+
39
+ self.player = bp.audio_out(fmt, latency=latency, **kwargs)
40
+ except (ImportError, AttributeError):
41
+ self.player = auto.audio_out(fmt, latency=latency, **kwargs)
42
+ if hasattr(self.player, "set_volume"):
43
+ self.player.set_volume(VOLUME)
44
+ self.sample_rate = SAMPLE_RATE
45
+ self.channel_count = CHANNELS
46
+ self.clock = "device"
47
+
48
+ def play(self, sample):
49
+ self.player.play(sample)
50
+
51
+ def stop(self):
52
+ self.player.stop()
53
+
54
+ def service(self):
55
+ self.player.service()
56
+
57
+ def describe(self):
58
+ t = getattr(self.player, "transport", None)
59
+ return "%s, %d Hz" % (type(t).__name__, self.sample_rate)
60
+
61
+ def close(self):
62
+ try:
63
+ self.player.stop()
64
+ finally:
65
+ self.player.close()
66
+
67
+
68
+ class WasapiOutput:
69
+ """A Windows speaker written by the pump's own thread (audioif's
70
+ "wasapi" sink). `device` is an endpoint ID, or None for the default.
71
+
72
+ `prime_ms` is the silence queued ahead of the first block and
73
+ `buffer_ms` the device buffer asked for: together they set how much the
74
+ speaker holds once the pump is ahead of it."""
75
+
76
+ kind = "wasapi"
77
+
78
+ def __init__(self, device=None, prime_ms=10, buffer_ms=20):
79
+ import audiobusio
80
+
81
+ sink = "wasapi:%d:%d:%d:%d" % (SAMPLE_RATE, CHANNELS, prime_ms,
82
+ buffer_ms)
83
+ if device:
84
+ sink += "@" + device
85
+ self.out = audiobusio.I2SOut(0, 1, 2, sample_rate=SAMPLE_RATE,
86
+ sink=sink)
87
+ self.device = device
88
+ self.sample_rate = SAMPLE_RATE
89
+ self.channel_count = CHANNELS
90
+ self.clock = "device"
91
+ self.name = device or "default output"
92
+ try:
93
+ import _audioif
94
+
95
+ self.name = _audioif.endpoint(device, False)[1]
96
+ except (AttributeError, OSError):
97
+ pass
98
+
99
+ @staticmethod
100
+ def available():
101
+ try:
102
+ import _audioif
103
+ except ImportError:
104
+ return False
105
+ return hasattr(_audioif, "sink_stats")
106
+
107
+ def play(self, sample):
108
+ self.out.play(sample, loop=False)
109
+
110
+ def stop(self):
111
+ self.out.stop()
112
+
113
+ def service(self):
114
+ pass
115
+
116
+ def stats(self):
117
+ import _audioif
118
+
119
+ return _audioif.sink_stats()
120
+
121
+ def held_frames(self):
122
+ """Frames queued in the speaker at the pump's last write."""
123
+ st = self.stats()
124
+ return st[6] if st else 0
125
+
126
+ def period_frames(self):
127
+ """The Windows engine's period for the speaker, 0 until it opens."""
128
+ st = self.stats()
129
+ return st[8] if st and len(st) > 8 else 0
130
+
131
+ def describe(self):
132
+ return "%s, WASAPI on the pump" % self.name
133
+
134
+ def close(self):
135
+ self.out.deinit()
@@ -0,0 +1,45 @@
1
+ # The guitar set: the effects the pedal picker shows first. "Show all" adds
2
+ # the rest. One effect name per line, as audioeffects spells it; a line
3
+ # starting with "##" names the group the next ones are in. Names a build
4
+ # doesn't carry are skipped.
5
+
6
+ ## Dynamics
7
+ Compressor
8
+ NoiseGate
9
+
10
+ ## Drive and fuzz
11
+ Overdrive
12
+ Distortion
13
+ Fuzz
14
+ Saturation
15
+
16
+ ## Amp and cabinet
17
+ CabinetSim
18
+
19
+ ## EQ and filter
20
+ GraphicEQ
21
+ ParametricEQ
22
+ LadderFilter
23
+
24
+ ## Pitch
25
+ Octaver
26
+ PitchShifter
27
+ Harmonizer
28
+
29
+ ## Modulation
30
+ Chorus
31
+ Phaser
32
+ Flanger
33
+ Tremolo
34
+ Vibrato
35
+
36
+ ## Delay
37
+ DigitalDelay
38
+ AnalogDelay
39
+ TapeDelay
40
+ SlapbackDelay
41
+
42
+ ## Reverb
43
+ Reverb
44
+ ShimmerHall
45
+ AirSpace