The hardware: MacBook's accelerometer
Apple Silicon MacBook Pros contain a high-resolution 3-axis accelerometer — the same sensor family used in the iPhone for orientation, activity tracking, and the old "sudden motion sensor" that protected hard drives from drop damage. On M1 Pro and newer chips, this sensor samples at a high enough rate and with enough resolution that SlapMac can analyze the waveform of an impact, not just its peak value.
This is why MacBook Air and Intel Macs aren't supported. MacBook Air models have the sensor, but it's sampled at a lower rate and with less granularity — not enough for reliable slap-vs-bump discrimination. Intel Macs have a different sensor pipeline entirely.
SlapMac accesses the accelerometer through Apple's CoreMotion framework — the same framework used by health and fitness apps. It reads accelerometer data in real time with no elevated permissions beyond Accessibility (needed to show the overlay).
The 5 detection algorithms
SlapMac runs all five algorithms simultaneously on every frame of accelerometer data. Any one firing above your sensitivity threshold triggers a sound. They're designed to complement each other, not compete:
Peak Threshold
The baseline algorithm. It monitors the raw magnitude of the acceleration vector and fires when a single peak exceeds your sensitivity threshold. Fast and reliable for obvious hard slaps. Can false-positive on desk bumps at low sensitivity.
Wave Analysis
Looks for the characteristic "impact wave" shape — a sharp spike followed by a rapid decay. Filters out slow rolls and gradual movements that would fool peak threshold. Better for distinguishing a slap from, say, moving your laptop across a desk.
Frequency Analysis
Analyzes the frequency content of the acceleration signal in a short window. Hard slaps have a distinctive high-frequency transient. This algorithm uses that signature to reject low-frequency events like the laptop being picked up.
Adaptive
Learns your ambient environment. If you work on a desk with regular low-level vibration (standing desk motors, mechanical keyboards), this algorithm adjusts its baseline dynamically so those don't count as slaps.
Trend Analysis
Detects the overall motion trend across a slightly longer window. Useful for catching shake gestures — where no single peak is huge but the cumulative movement is significant. Powers the "shake" trigger in SlapMac.
How sensitivity and cooldown interact with the algorithms
Sensitivity sets the detection threshold across all algorithms. Higher sensitivity = more algorithms fire on lighter impacts. Lower sensitivity = only the most forceful slaps trigger any algorithm.
Cooldown is a post-fire lockout. After any algorithm fires, all five are suppressed for the cooldown period. This prevents a single slap from generating three sound events as its vibration rings out.
For most users: sensitivity around 45–60, cooldown around 20–30 seconds gives reliable per-slap triggering without false positives from keyboard typing or moving the machine.
Common tuning problems
"It fires when I type" — raise sensitivity by 15–20. Keyboard impacts don't have the same high-frequency signature as a slap, but at very low sensitivity the peak threshold can still catch them.
"It won't fire even when I slap hard" — lower sensitivity. The adaptive algorithm may have set a high baseline if you started the app during a period of high desk vibration (e.g., with a standing desk motor running).
"It fires twice per slap" — raise cooldown. The ringing vibration after a hard slap is catching a second trigger window. 25–35 seconds usually fixes this.
Is this safe for the MacBook?
Yes. SlapMac is a passive sensor reader — it doesn't control hardware or issue commands to the machine. The slap itself is the physical act; SlapMac just listens to what already happened. Apple Silicon MacBook Pros are engineered to withstand normal handling forces that exceed any reasonable desk slap. The sensor won't be damaged by normal use.