Exploring Apple’s 3D Touch

The public APIs

First, let’s start with Apple’s published documentation. On supported devices, each UITouch now has the following relevant new properties:

  • force, a CGFloat
  • maximumPossibleForce, which is also a CGFloat

Beginning the experiments

maximumPossibleForce

Answering the last question was perhaps the most straight-forward. Spinning up a project and listening for a touch in a view, I can print the touch’s maximumPossibleForce. On my iPhone 6S, it’s 6.666666666667. I haven’t tested it on a 6S Plus.

touch timing

In making a basic MIDI controller, one of my primary interests in the force value is computing the velocity of a note trigger, meaning I’ll want to map the force’s native CGFloat value to a number between 1 and 127 (a Note On message with a velocity of 0 is usually interpreted to be synonymous with a Note Off message).

force quantization

The next thing to catch attention, and subsequently send me into a flurry of investigative Python coding, was the nature of the force values that I was seeing at the gentle-pressure end of the spectrum. At extremely light force levels, I was mostly seeing the actual force value fluctuate between one of a few specific numbers. Yes, they are floating point, but they also exhibited extreme uniformity to the point that it was easy to hypothesize that the actual values were merely integers divided by a multiple-of-3 divisor.

>>> len(sorted_forces)
336
[0.0,
0.0166666666666667,
0.0333333333333333,
0.05,
0.0666666666666667,
0.0833333333333333,
0.1,
0.116666666666667,
0.133333333333333,
0.15,
... ]
indexed_distances = { ix: val for ix, val in enumerate(distances) }
integer_stride = int(round(val * 60 * 100)) / 100.0

Conclusions

At this point, it seems pretty safe to say that the floating point value that Apple propagates to the developer interface is actually an integer between 0 and 400 that’s divided by 60 somewhere along the way.

Why would Apple do this?

My initial guess is that it’s two-fold, and the first is liability/cost/safety. The nearest power-of-two multiple to support the maximum force value is 512, or a 9 bit register. In all likelihood, they’re able to generate force values that go higher than the 6.666667 that’s documented, possibly all the way up to the 8.5166667 value that corresponds to 511/60

--

--

software writer. music writer. music software writer.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
r. kevin nelson

r. kevin nelson

software writer. music writer. music software writer.