Audio programming in iOS: comparing the play-through latencies of libPD and The Amazing Audio Engine

Being an audio/music developer for iOS devices and a guitar player, I had a very simple question:

Which programming framework should I use to achieve minimum latency for developing real-time audio effects processor for iOS devices?

Being acquainted with Pure Data (PD) and having developed some apps using libPD, this seemed like my first option. However, when I came across The Amazing Audio Engine (TAAE), I was impressed both by its accuracy and its efficiency in CPU performance – considering also that it is very easy to use.

So, I made a simple comparison that I think worths sharing! This comparison actually involves counting the latency in a simple play-through scenario, where audio signal passes through an iPhone 6 without any effects applied. In other words, the question is: how much does the audio signal get delayed, simply by passing through an iPhone 6, using lidPD and TAAE as audio “managers”?

The process is rather simple and and is illustrated in the graph below:

pd_taae_experiment_overview

In a few words: I connected two guitar cables to the two audio inputs of a Presonus Firebox sound card. Input 1 was the “test signal” and input 2 the “ground-truth” signal. For testing the latency introduced by libPD and TAAE, the “test signal” was connected to an iPhone 6 before reaching the sound card. For a sanity-check of the process, I also tested both inputs driven directly (without iPhone intervention) into the sound card – just to make sure that there is no inherent latency between the two inputs of the sound card.

For comparing the difference between input 1 (test signal) and input 2 (ground truth), I recorded the both signal in two separate channels in Ableton Live. At some point during the recording I made both cables touch each other, producing an impulse peak in both channels. Then I extracted both signals in separate wav files, imported them in Matlab to measure the distance between the peaks in both signals. I considered this distance (in samples or seconds) as the value of latency introduced by using the iPhone.

Three scenarios were examined:

1) Sanity-check: no iPhone intervening, just to make sure that there is no inherent latency between the two inputs.

Results: sanity-check latency: 0 samples — 0.0000 seconds.

2) Testing libPD latency: test signal passed through an iPhone 6 running only a simple program using a play-through PD patch. Note that the buffer duration in lipPD has to be set up through the AVAudioSessions  – thanks Michael Tyson for bringing that up.

pd_code

 

Results: libPD latency: 2335 samples — 0.0181 seconds

3) Testing TAAE latency: test signal passed through an iPhone 6 running only a TAAE program for simple play-through.

taae_code

Results: TAAE latency: 742 samples — 0.0168 seconds

Here’s a graph summarising the results:

pdtaaeComparison.png

 

It seems that TAAE has slightly less latency (not perceptible). In the future I intent to check wether latency changes when starting to load audio effects to the programs (e.g. equalisation, distortion, etc.), or the CPU performance of programs based on TAAE and libPD for applying real-time audio effects.