mac-hardware-toys 0.2.1__tar.gz
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.
- mac_hardware_toys-0.2.1/PKG-INFO +305 -0
- mac_hardware_toys-0.2.1/README.md +295 -0
- mac_hardware_toys-0.2.1/accelerometer +245 -0
- mac_hardware_toys-0.2.1/ambient-light +87 -0
- mac_hardware_toys-0.2.1/bandpass +128 -0
- mac_hardware_toys-0.2.1/fan-speed +465 -0
- mac_hardware_toys-0.2.1/frequency-shift +95 -0
- mac_hardware_toys-0.2.1/gyroscope +319 -0
- mac_hardware_toys-0.2.1/heartbeat +170 -0
- mac_hardware_toys-0.2.1/keyboard-brightness +502 -0
- mac_hardware_toys-0.2.1/lib/bootstrap.py +141 -0
- mac_hardware_toys-0.2.1/lib/dsp.py +201 -0
- mac_hardware_toys-0.2.1/lib/hardware.py +631 -0
- mac_hardware_toys-0.2.1/lib/mac_hardware_toys.egg-info/PKG-INFO +305 -0
- mac_hardware_toys-0.2.1/lib/mac_hardware_toys.egg-info/SOURCES.txt +29 -0
- mac_hardware_toys-0.2.1/lib/mac_hardware_toys.egg-info/dependency_links.txt +1 -0
- mac_hardware_toys-0.2.1/lib/mac_hardware_toys.egg-info/requires.txt +3 -0
- mac_hardware_toys-0.2.1/lib/mac_hardware_toys.egg-info/top_level.txt +6 -0
- mac_hardware_toys-0.2.1/lib/sensor_tone.py +449 -0
- mac_hardware_toys-0.2.1/lib/signal_stream.py +183 -0
- mac_hardware_toys-0.2.1/lib/spu_sensor.py +323 -0
- mac_hardware_toys-0.2.1/lid-angle +107 -0
- mac_hardware_toys-0.2.1/metronome +917 -0
- mac_hardware_toys-0.2.1/microphone +137 -0
- mac_hardware_toys-0.2.1/pyproject.toml +38 -0
- mac_hardware_toys-0.2.1/screen-brightness +319 -0
- mac_hardware_toys-0.2.1/setup.cfg +4 -0
- mac_hardware_toys-0.2.1/sine +121 -0
- mac_hardware_toys-0.2.1/speaker +100 -0
- mac_hardware_toys-0.2.1/visualizer +959 -0
- mac_hardware_toys-0.2.1/volume-shift +89 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mac-hardware-toys
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: A collection of pipe-able commands for playing with Apple Silicon sensor hardware and peripherals.
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: numpy>=1.26
|
|
8
|
+
Requires-Dist: pywavelets>=1.4
|
|
9
|
+
Requires-Dist: sounddevice>=0.4
|
|
10
|
+
|
|
11
|
+
# Use your Mac hardware like a modular synth!
|
|
12
|
+
|
|
13
|
+
A suite of commands like `accelerometer`, `microphone`, `bandpass`, `keyboard-brightness`, `screen-brightness`, and more that can be linked together using UNIX pipes.
|
|
14
|
+
|
|
15
|
+
All tools input and output a standardized mono audio signal that represents their sensor input/output values.
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/pirate/mac-hardware-toys
|
|
21
|
+
cd mac-hardware-toys
|
|
22
|
+
|
|
23
|
+
uv sync
|
|
24
|
+
source .venv/bin/activate
|
|
25
|
+
|
|
26
|
+
### Examples
|
|
27
|
+
|
|
28
|
+
# flash your screen according to your microphone input
|
|
29
|
+
microphone | screen-brightness
|
|
30
|
+
|
|
31
|
+
# play a sine wave tone based on your screen lid-angle
|
|
32
|
+
lid-angle | speaker
|
|
33
|
+
|
|
34
|
+
# flash the keyboard according to your heartbeat (keep your wrists on palm rests)
|
|
35
|
+
accelerometer | metronome | keyboard-brightness
|
|
36
|
+
|
|
37
|
+
# see more detail about any given signal by piping it into visualizer
|
|
38
|
+
microphone | visualizer
|
|
39
|
+
sine 1000 | visualizer
|
|
40
|
+
gyroscope | tee >(speaker) | visualizer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
<img width="1004" height="665" alt="Screenshot 2026-02-20 at 11 19 36 PM" src="https://github.com/user-attachments/assets/c30f02b1-2695-4e5f-9724-e01986ba799d" />
|
|
47
|
+
|
|
48
|
+
## Tools
|
|
49
|
+
|
|
50
|
+
### `accelerometer`
|
|
51
|
+
|
|
52
|
+
- Purpose: read Apple SPU accelerometer and emit mono signal.
|
|
53
|
+
- Args: `--rate <hz>` (<= 800), `--axis x|y|z|mag`, `--raw`.
|
|
54
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
55
|
+
|
|
56
|
+
### `ambient-light`
|
|
57
|
+
|
|
58
|
+
- Purpose: read ambient light sensor and emit tone mapped from low light to high light.
|
|
59
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as light goes `0% -> 100%`.
|
|
60
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--json`.
|
|
61
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
62
|
+
|
|
63
|
+
### `lid-angle`
|
|
64
|
+
|
|
65
|
+
- Purpose: read lid angle sensor and emit tone mapped from lid closed to open.
|
|
66
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as angle goes `--angle-min -> --angle-max`.
|
|
67
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--angle-min`, `--angle-max`, `--json`.
|
|
68
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
69
|
+
|
|
70
|
+
### `gyroscope`
|
|
71
|
+
|
|
72
|
+
- Purpose: read fused orientation (accel+gyro, Mahony AHRS) and emit tone mapped from the selected orientation axis.
|
|
73
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as selected axis angle maps to `0..360`.
|
|
74
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--json`, `--axis roll|pitch|yaw`, `--decimate`.
|
|
75
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
76
|
+
- `roll`/`pitch` are absolute to gravity; `yaw` is relative and can drift without magnetometer.
|
|
77
|
+
|
|
78
|
+
### `microphone`
|
|
79
|
+
|
|
80
|
+
- Purpose: capture mono mic signal and emit stream.
|
|
81
|
+
- Args: `--rate <hz>`, `--block-size <frames>`.
|
|
82
|
+
|
|
83
|
+
### `metronome [bpm]`
|
|
84
|
+
|
|
85
|
+
- Purpose: emit metronome pulses; with piped stdin it auto-detects/follows BPM.
|
|
86
|
+
- Args: optional `bpm`, `--rate` (fixed mode), `--pulse-ms`, `--tone-hz`, `--level`, `--accent-every`, `--accent-gain`, `--block-size`, `--count`, `--min-bpm`, `--max-bpm`, `--detect-low-hz`, `--detect-high-hz`, `--self-echo-ms`, `--follow`, `--debug`, `--raw`.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
### `bandpass <low_hz> <high_hz>`
|
|
91
|
+
|
|
92
|
+
- Purpose: realtime cascaded high/low-pass filter.
|
|
93
|
+
- Args: positional cutoffs or `--low/--high`, `--chunk-bytes`, `--raw --rate`.
|
|
94
|
+
|
|
95
|
+
### `frequency-shift <factor>`
|
|
96
|
+
|
|
97
|
+
- Purpose: best-effort realtime frequency scaling, takes a scalar multiplier like 0.1~1000.
|
|
98
|
+
- Args: `factor`, `--chunk-bytes`, `--raw --rate`.
|
|
99
|
+
|
|
100
|
+
### `volume-shift <gain>`
|
|
101
|
+
|
|
102
|
+
- Purpose: scalar amplitude gain.
|
|
103
|
+
- Args: `gain`, `--chunk-bytes`, `--raw --rate`.
|
|
104
|
+
|
|
105
|
+
### `heartbeat`
|
|
106
|
+
|
|
107
|
+
- Purpose: emit BPM/confidence JSON lines from incoming signal (typically bandpassed). When piped onward, it passes the signal through on stdout and writes JSON to stderr.
|
|
108
|
+
- Args: `--interval`, `--window-seconds`, `--emit-final`, `--chunk-bytes`, `--raw --rate`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### `speaker`
|
|
113
|
+
|
|
114
|
+
- Purpose: play incoming stream on default output device.
|
|
115
|
+
- Args: `--device-rate`, `--block-size`.
|
|
116
|
+
|
|
117
|
+
### `visualizer`
|
|
118
|
+
|
|
119
|
+
- Purpose: terminal waveform + level monitor.
|
|
120
|
+
- Args: `--fps`, `--window-seconds`, `--chunk-bytes`, `--raw --rate`.
|
|
121
|
+
|
|
122
|
+
### `keyboard-brightness`
|
|
123
|
+
|
|
124
|
+
- Purpose: beat-follow keyboard backlight control.
|
|
125
|
+
- Args: `--send-hz`, `--fade-ms`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--as-root`, `--pulse`, `--on-time`, `--off-time`, `--set`.
|
|
126
|
+
- Notes:
|
|
127
|
+
- `--set=<0..100>` without `--pulse` sets brightness and exits immediately (ignores stdin).
|
|
128
|
+
- `--pulse=<N>` ignores stdin and pulses N times; `--set` controls pulse max brightness.
|
|
129
|
+
|
|
130
|
+
### `screen-brightness`
|
|
131
|
+
|
|
132
|
+
- Purpose: beat-follow display brightness control.
|
|
133
|
+
- Args: `--send-hz`, `--min-level`, `--max-level`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--no-restore`, `--pulse`, `--on-time`, `--off-time`, `--set`.
|
|
134
|
+
- Notes:
|
|
135
|
+
- `--set=<0..100>` without `--pulse` sets display brightness and exits immediately (ignores stdin).
|
|
136
|
+
- `--pulse=<N>` ignores stdin and pulses N times; `--set` controls pulse max brightness.
|
|
137
|
+
|
|
138
|
+
### `fan-speed`
|
|
139
|
+
|
|
140
|
+
- Purpose: signal-follow fan RPM control (both fans in sync by default; beat-alternating optional).
|
|
141
|
+
- Args: `--send-hz`, `--min-rpm`, `--max-rpm`, `--min-frac`, `--max-frac`, `--pulse-depth`, `--couple`, `--alternate`, `--input-map`, `--beat-threshold`, `--beat-hold-ms`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--no-restore`.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Example Usage
|
|
146
|
+
|
|
147
|
+
Heartbeat from accelerometer:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
accelerometer | bandpass 0.8 3 | heartbeat
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Ambient light as signal source:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
ambient-light | visualizer
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Lid angle as JSONL:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
lid-angle --json
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Gyroscope fused orientation as JSONL:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
gyroscope --axis roll --json
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Music-reactive keyboard + speakers:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
microphone --rate 44100 \
|
|
175
|
+
| tee >(keyboard-brightness --send-hz 30 --fade-ms 20) \
|
|
176
|
+
| volume-shift 0.8 \
|
|
177
|
+
| speaker
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Metronome to speakers:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
metronome 120 | speaker
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Auto-follow metronome from mic input, emits a metronome tone in sync with the beat of whatever audio is playing:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
microphone | metronome | speaker
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Auto-follow metronome from accelerometer, driving keyboard pulses:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
accelerometer | metronome | keyboard-brightness
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Metronome driving keyboard pulses:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
metronome 120 | keyboard-brightness
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Heartbeat telemetry while still driving keyboard brightness:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
accelerometer | heartbeat | keyboard-brightness
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Set keyboard backlight to 100% and exit:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
keyboard-brightness --set=100
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Pulse keyboard 5 times (1.2s on / 5.5s off) at 100%:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
keyboard-brightness --pulse=5 --on-time=1.2 --off-time=5.5 --set=100
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Set screen brightness to 40% and exit:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
screen-brightness --set=40
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Pulse screen brightness 3 times:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
screen-brightness --pulse=3 --on-time=1.2 --off-time=5.5 --set=100
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Metronome driving fan pulses:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
metronome 120 | fan-speed --send-hz 4 --alternate --input-map beat --min-frac 0.30 --max-frac 0.70
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Slow sine fan sweep (sync L/R):
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
sine 0.1 | fan-speed
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
One source, multiple sinks:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
accelerometer \
|
|
250
|
+
| bandpass 0.8 3 \
|
|
251
|
+
| tee >(keyboard-brightness) \
|
|
252
|
+
| frequency-shift 1000 \
|
|
253
|
+
| volume-shift 0.8 \
|
|
254
|
+
| tee >(speaker) \
|
|
255
|
+
| visualizer
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Notes
|
|
261
|
+
|
|
262
|
+
- `accelerometer` requires root (AppleSPU HID access) and will auto-reexec through `sudo` by default.
|
|
263
|
+
- `ambient-light`, `lid-angle`, and `gyroscope` do the same for AppleSPU HID access.
|
|
264
|
+
- Set `MSIG_AUTO_SUDO=0` to disable auto-reexec and only print rerun guidance on stderr.
|
|
265
|
+
- `microphone`/`speaker` depend on `sounddevice` + PortAudio runtime.
|
|
266
|
+
- Keyboard/display brightness tools need supported hardware/permissions.
|
|
267
|
+
- `keyboard-brightness` uses the bundled Apple Silicon KBPulse binary at `lib/KBPulse` (arm64).
|
|
268
|
+
- `fan-speed` uses AppleSMC private IOKit APIs on Apple Silicon; writing fan targets typically requires `sudo`.
|
|
269
|
+
- `frequency-shift` is intentionally lightweight and artifact-prone at extreme factors.
|
|
270
|
+
|
|
271
|
+
## Stdio Audio Format
|
|
272
|
+
|
|
273
|
+
All stream tools read/write:
|
|
274
|
+
|
|
275
|
+
- header: `MSIG1 <sample_rate_hz>\n`
|
|
276
|
+
- payload: little-endian `float32` mono samples
|
|
277
|
+
|
|
278
|
+
Most processors also support raw float32 input via `--raw --rate <hz>`.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Why?
|
|
283
|
+
|
|
284
|
+
It's fun. Here are some ideas to get started:
|
|
285
|
+
|
|
286
|
+
- make your keyboard lights flash for security alerts using [Security Growler](https://github.com/pirate/security-growler)
|
|
287
|
+
- make your keyboard flash right before your display is about to sleep
|
|
288
|
+
- make your keyboard flash on incoming email
|
|
289
|
+
- make your keyboard flash to the beat of music
|
|
290
|
+
- make your keyboard flash when your boss's iPhone comes within bluetooth range
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Related Projects
|
|
295
|
+
|
|
296
|
+
- https://github.com/olvvier/apple-silicon-accelerometer IOReg accelerometer reading code
|
|
297
|
+
- https://github.com/EthanRDoesMC/KBPulse/ keyboard brightness code for M1, M2, M3, etc. macs
|
|
298
|
+
- https://github.com/maxmouchet/LightKit
|
|
299
|
+
- https://github.com/tcr/macbook-brightness
|
|
300
|
+
- http://stackoverflow.com/questions/3239749/programmatically-change-mac-display-brightness
|
|
301
|
+
- https://web.archive.org/web/20110828210316/http://mattdanger.net:80/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
|
|
302
|
+
- http://osxbook.com/book/bonus/chapter10/light/
|
|
303
|
+
- https://github.com/samnung/maclight/blob/master/lights_handle.cpp
|
|
304
|
+
- http://www.keindesign.de/stefan/Web/Sites/iWeb/Site/iSpazz.html the OG
|
|
305
|
+
- https://github.com/bhoeting/DiscoKeyboard
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Use your Mac hardware like a modular synth!
|
|
2
|
+
|
|
3
|
+
A suite of commands like `accelerometer`, `microphone`, `bandpass`, `keyboard-brightness`, `screen-brightness`, and more that can be linked together using UNIX pipes.
|
|
4
|
+
|
|
5
|
+
All tools input and output a standardized mono audio signal that represents their sensor input/output values.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/pirate/mac-hardware-toys
|
|
11
|
+
cd mac-hardware-toys
|
|
12
|
+
|
|
13
|
+
uv sync
|
|
14
|
+
source .venv/bin/activate
|
|
15
|
+
|
|
16
|
+
### Examples
|
|
17
|
+
|
|
18
|
+
# flash your screen according to your microphone input
|
|
19
|
+
microphone | screen-brightness
|
|
20
|
+
|
|
21
|
+
# play a sine wave tone based on your screen lid-angle
|
|
22
|
+
lid-angle | speaker
|
|
23
|
+
|
|
24
|
+
# flash the keyboard according to your heartbeat (keep your wrists on palm rests)
|
|
25
|
+
accelerometer | metronome | keyboard-brightness
|
|
26
|
+
|
|
27
|
+
# see more detail about any given signal by piping it into visualizer
|
|
28
|
+
microphone | visualizer
|
|
29
|
+
sine 1000 | visualizer
|
|
30
|
+
gyroscope | tee >(speaker) | visualizer
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
<img width="1004" height="665" alt="Screenshot 2026-02-20 at 11 19 36 PM" src="https://github.com/user-attachments/assets/c30f02b1-2695-4e5f-9724-e01986ba799d" />
|
|
37
|
+
|
|
38
|
+
## Tools
|
|
39
|
+
|
|
40
|
+
### `accelerometer`
|
|
41
|
+
|
|
42
|
+
- Purpose: read Apple SPU accelerometer and emit mono signal.
|
|
43
|
+
- Args: `--rate <hz>` (<= 800), `--axis x|y|z|mag`, `--raw`.
|
|
44
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
45
|
+
|
|
46
|
+
### `ambient-light`
|
|
47
|
+
|
|
48
|
+
- Purpose: read ambient light sensor and emit tone mapped from low light to high light.
|
|
49
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as light goes `0% -> 100%`.
|
|
50
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--json`.
|
|
51
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
52
|
+
|
|
53
|
+
### `lid-angle`
|
|
54
|
+
|
|
55
|
+
- Purpose: read lid angle sensor and emit tone mapped from lid closed to open.
|
|
56
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as angle goes `--angle-min -> --angle-max`.
|
|
57
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--angle-min`, `--angle-max`, `--json`.
|
|
58
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
59
|
+
|
|
60
|
+
### `gyroscope`
|
|
61
|
+
|
|
62
|
+
- Purpose: read fused orientation (accel+gyro, Mahony AHRS) and emit tone mapped from the selected orientation axis.
|
|
63
|
+
- Default mapping: `500 Hz -> 5000 Hz` and low volume -> high volume as selected axis angle maps to `0..360`.
|
|
64
|
+
- Args: `--rate`, `--low-hz`, `--high-hz`, `--low-volume`, `--high-volume`, `--json`, `--axis roll|pitch|yaw`, `--decimate`.
|
|
65
|
+
- Notes: requires root; when run from a terminal it auto-prompts via `sudo`.
|
|
66
|
+
- `roll`/`pitch` are absolute to gravity; `yaw` is relative and can drift without magnetometer.
|
|
67
|
+
|
|
68
|
+
### `microphone`
|
|
69
|
+
|
|
70
|
+
- Purpose: capture mono mic signal and emit stream.
|
|
71
|
+
- Args: `--rate <hz>`, `--block-size <frames>`.
|
|
72
|
+
|
|
73
|
+
### `metronome [bpm]`
|
|
74
|
+
|
|
75
|
+
- Purpose: emit metronome pulses; with piped stdin it auto-detects/follows BPM.
|
|
76
|
+
- Args: optional `bpm`, `--rate` (fixed mode), `--pulse-ms`, `--tone-hz`, `--level`, `--accent-every`, `--accent-gain`, `--block-size`, `--count`, `--min-bpm`, `--max-bpm`, `--detect-low-hz`, `--detect-high-hz`, `--self-echo-ms`, `--follow`, `--debug`, `--raw`.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### `bandpass <low_hz> <high_hz>`
|
|
81
|
+
|
|
82
|
+
- Purpose: realtime cascaded high/low-pass filter.
|
|
83
|
+
- Args: positional cutoffs or `--low/--high`, `--chunk-bytes`, `--raw --rate`.
|
|
84
|
+
|
|
85
|
+
### `frequency-shift <factor>`
|
|
86
|
+
|
|
87
|
+
- Purpose: best-effort realtime frequency scaling, takes a scalar multiplier like 0.1~1000.
|
|
88
|
+
- Args: `factor`, `--chunk-bytes`, `--raw --rate`.
|
|
89
|
+
|
|
90
|
+
### `volume-shift <gain>`
|
|
91
|
+
|
|
92
|
+
- Purpose: scalar amplitude gain.
|
|
93
|
+
- Args: `gain`, `--chunk-bytes`, `--raw --rate`.
|
|
94
|
+
|
|
95
|
+
### `heartbeat`
|
|
96
|
+
|
|
97
|
+
- Purpose: emit BPM/confidence JSON lines from incoming signal (typically bandpassed). When piped onward, it passes the signal through on stdout and writes JSON to stderr.
|
|
98
|
+
- Args: `--interval`, `--window-seconds`, `--emit-final`, `--chunk-bytes`, `--raw --rate`.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### `speaker`
|
|
103
|
+
|
|
104
|
+
- Purpose: play incoming stream on default output device.
|
|
105
|
+
- Args: `--device-rate`, `--block-size`.
|
|
106
|
+
|
|
107
|
+
### `visualizer`
|
|
108
|
+
|
|
109
|
+
- Purpose: terminal waveform + level monitor.
|
|
110
|
+
- Args: `--fps`, `--window-seconds`, `--chunk-bytes`, `--raw --rate`.
|
|
111
|
+
|
|
112
|
+
### `keyboard-brightness`
|
|
113
|
+
|
|
114
|
+
- Purpose: beat-follow keyboard backlight control.
|
|
115
|
+
- Args: `--send-hz`, `--fade-ms`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--as-root`, `--pulse`, `--on-time`, `--off-time`, `--set`.
|
|
116
|
+
- Notes:
|
|
117
|
+
- `--set=<0..100>` without `--pulse` sets brightness and exits immediately (ignores stdin).
|
|
118
|
+
- `--pulse=<N>` ignores stdin and pulses N times; `--set` controls pulse max brightness.
|
|
119
|
+
|
|
120
|
+
### `screen-brightness`
|
|
121
|
+
|
|
122
|
+
- Purpose: beat-follow display brightness control.
|
|
123
|
+
- Args: `--send-hz`, `--min-level`, `--max-level`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--no-restore`, `--pulse`, `--on-time`, `--off-time`, `--set`.
|
|
124
|
+
- Notes:
|
|
125
|
+
- `--set=<0..100>` without `--pulse` sets display brightness and exits immediately (ignores stdin).
|
|
126
|
+
- `--pulse=<N>` ignores stdin and pulses N times; `--set` controls pulse max brightness.
|
|
127
|
+
|
|
128
|
+
### `fan-speed`
|
|
129
|
+
|
|
130
|
+
- Purpose: signal-follow fan RPM control (both fans in sync by default; beat-alternating optional).
|
|
131
|
+
- Args: `--send-hz`, `--min-rpm`, `--max-rpm`, `--min-frac`, `--max-frac`, `--pulse-depth`, `--couple`, `--alternate`, `--input-map`, `--beat-threshold`, `--beat-hold-ms`, `--gain`, `--attack-ms`, `--release-ms`, `--baseline-ms`, `--decay-per-s`, `--debug`, `--no-restore`.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Example Usage
|
|
136
|
+
|
|
137
|
+
Heartbeat from accelerometer:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
accelerometer | bandpass 0.8 3 | heartbeat
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Ambient light as signal source:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
ambient-light | visualizer
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Lid angle as JSONL:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
lid-angle --json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Gyroscope fused orientation as JSONL:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
gyroscope --axis roll --json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Music-reactive keyboard + speakers:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
microphone --rate 44100 \
|
|
165
|
+
| tee >(keyboard-brightness --send-hz 30 --fade-ms 20) \
|
|
166
|
+
| volume-shift 0.8 \
|
|
167
|
+
| speaker
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Metronome to speakers:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
metronome 120 | speaker
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Auto-follow metronome from mic input, emits a metronome tone in sync with the beat of whatever audio is playing:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
microphone | metronome | speaker
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Auto-follow metronome from accelerometer, driving keyboard pulses:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
accelerometer | metronome | keyboard-brightness
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Metronome driving keyboard pulses:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
metronome 120 | keyboard-brightness
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Heartbeat telemetry while still driving keyboard brightness:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
accelerometer | heartbeat | keyboard-brightness
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Set keyboard backlight to 100% and exit:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
keyboard-brightness --set=100
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Pulse keyboard 5 times (1.2s on / 5.5s off) at 100%:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
keyboard-brightness --pulse=5 --on-time=1.2 --off-time=5.5 --set=100
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Set screen brightness to 40% and exit:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
screen-brightness --set=40
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Pulse screen brightness 3 times:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
screen-brightness --pulse=3 --on-time=1.2 --off-time=5.5 --set=100
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Metronome driving fan pulses:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
metronome 120 | fan-speed --send-hz 4 --alternate --input-map beat --min-frac 0.30 --max-frac 0.70
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Slow sine fan sweep (sync L/R):
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
sine 0.1 | fan-speed
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
One source, multiple sinks:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
accelerometer \
|
|
240
|
+
| bandpass 0.8 3 \
|
|
241
|
+
| tee >(keyboard-brightness) \
|
|
242
|
+
| frequency-shift 1000 \
|
|
243
|
+
| volume-shift 0.8 \
|
|
244
|
+
| tee >(speaker) \
|
|
245
|
+
| visualizer
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Notes
|
|
251
|
+
|
|
252
|
+
- `accelerometer` requires root (AppleSPU HID access) and will auto-reexec through `sudo` by default.
|
|
253
|
+
- `ambient-light`, `lid-angle`, and `gyroscope` do the same for AppleSPU HID access.
|
|
254
|
+
- Set `MSIG_AUTO_SUDO=0` to disable auto-reexec and only print rerun guidance on stderr.
|
|
255
|
+
- `microphone`/`speaker` depend on `sounddevice` + PortAudio runtime.
|
|
256
|
+
- Keyboard/display brightness tools need supported hardware/permissions.
|
|
257
|
+
- `keyboard-brightness` uses the bundled Apple Silicon KBPulse binary at `lib/KBPulse` (arm64).
|
|
258
|
+
- `fan-speed` uses AppleSMC private IOKit APIs on Apple Silicon; writing fan targets typically requires `sudo`.
|
|
259
|
+
- `frequency-shift` is intentionally lightweight and artifact-prone at extreme factors.
|
|
260
|
+
|
|
261
|
+
## Stdio Audio Format
|
|
262
|
+
|
|
263
|
+
All stream tools read/write:
|
|
264
|
+
|
|
265
|
+
- header: `MSIG1 <sample_rate_hz>\n`
|
|
266
|
+
- payload: little-endian `float32` mono samples
|
|
267
|
+
|
|
268
|
+
Most processors also support raw float32 input via `--raw --rate <hz>`.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Why?
|
|
273
|
+
|
|
274
|
+
It's fun. Here are some ideas to get started:
|
|
275
|
+
|
|
276
|
+
- make your keyboard lights flash for security alerts using [Security Growler](https://github.com/pirate/security-growler)
|
|
277
|
+
- make your keyboard flash right before your display is about to sleep
|
|
278
|
+
- make your keyboard flash on incoming email
|
|
279
|
+
- make your keyboard flash to the beat of music
|
|
280
|
+
- make your keyboard flash when your boss's iPhone comes within bluetooth range
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Related Projects
|
|
285
|
+
|
|
286
|
+
- https://github.com/olvvier/apple-silicon-accelerometer IOReg accelerometer reading code
|
|
287
|
+
- https://github.com/EthanRDoesMC/KBPulse/ keyboard brightness code for M1, M2, M3, etc. macs
|
|
288
|
+
- https://github.com/maxmouchet/LightKit
|
|
289
|
+
- https://github.com/tcr/macbook-brightness
|
|
290
|
+
- http://stackoverflow.com/questions/3239749/programmatically-change-mac-display-brightness
|
|
291
|
+
- https://web.archive.org/web/20110828210316/http://mattdanger.net:80/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
|
|
292
|
+
- http://osxbook.com/book/bonus/chapter10/light/
|
|
293
|
+
- https://github.com/samnung/maclight/blob/master/lights_handle.cpp
|
|
294
|
+
- http://www.keindesign.de/stefan/Web/Sites/iWeb/Site/iSpazz.html the OG
|
|
295
|
+
- https://github.com/bhoeting/DiscoKeyboard
|