Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PencilSynth: An Apple Pencil Controlled Synthesizer

DZone's Guide to

PencilSynth: An Apple Pencil Controlled Synthesizer

We all play synth: PencilSynth is an Apple Pencil controlled synthesizer. Learn how it works.

· Mobile Zone
Free Resource

Get gorgeous, multi-touch charts for your iOS application with just a few lines of code.


Here's another Apple Pencil experiment, PencilSynth is an AudioKit powered synthesiser (mis)using the Pencil as a joystick controller. It's based on AudioKit's TouchRegions demonstration and works like this:

  • Given:

        let touch:

UITouch 
  • The Pencil's horizontal position on the screen defines the output frequency:

        let frequency = 

touch.locationInView(view).x / view.bounds.width
  • The Pencil's vertical position on the screen defines the output modulating multiplier:

        let modulatingMultiplier = 

touch.locationInView(view).y / view.bounds.height
  • The Pencil's altitude angle defines the output carrier multiplier:

        let carrierMultiplier = 

(halfPi - touch.altitudeAngle) / halfPi
  • The Pencil's azimuth angle defines the output modulation index:

        let modulationIndex = 

(pi + touch.azimuthAngleInView(view)) / (pi * 2)

Those four normalised values are plugged into an instance of FMOscillator (which is taken directly from the TouchRegions demo):

   oscillator.frequency.value = (oscillator.frequency.maximum - oscillator.frequency.minimum) * Float(frequency)          oscillator.modulatingMultiplier.value = (oscillator.modulatingMultiplier.maximum -oscillator.modulatingMultiplier.minimum) * Float(modulatingMultiplier)          oscillator.carrierMultiplier.value = (oscillator.carrierMultiplier.maximum -oscillator.carrierMultiplier.minimum) * Float(carrierMultiplier)          oscillator.modulationIndex.value = (oscillator.modulationIndex.maximum - oscillator.modulationIndex.minimum) * Float(modulationIndex)

The orientation and rendering of the "virtual pencil" is taken straight from my PencilController demo.

The GitHub repository contains the AudioKit source, but all my code exists in the view controller class.

In conclusion, the Apple Pencil opens up a world of new interaction design paradigms (despite what Jony Ive may tell us!). PencilSynth and my Pencil based image processing app are, I think, demonstrations that the Pencil is an excellent input device for controlling continuous values across multiple dimensions.

As always, the source code for this project is available at my GitHub repository here. Enjoy!

.Net developers: use Highcharts, the industry's leading interactive charting library, without writing a single line of JavaScript.

Topics:
swift ,ios ,apple ,ipad ,apple pencil ,music

Published at DZone with permission of Simon Gladman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}