Δευτέρα 15 Φεβρουαρίου 2016

Simple implementation of the Boids algorithm in Objective-C: counting time through audio


My first attempt to implement the Boids algorithm for iOS using the Sprite kit was a bit disappointing, since everything was moving really slow when the number of agents increased above around 20 or 30 – both on simulator and device.
Doing some tests for building a very accurate metronome (see previous posts), it became clear to me that audio-level sample-based metronomes are both very accurate and CPU-friendly:
– accurate: since everything was being counted on a 1/44100 of a second “frame-rate” and
– CPU friendly: since there the timing mechanism was somehow assigned on the sound card.
– Potentially even more CPU friendly, by making two different methods for (i) defining the acceleration (ones every, say, 0.3 seconds) and (ii) updating the position according to acceleration (every, say, 0.1 seconds).
Therefore, the thought was simple and straightforward: instead of making metronome clicks on specific time intervals, an app’s view elements could be updated. Take a look at the ABetterMetronome thread and things will become clear ;);)
Here’s the code! To run it you need to download The Amazing Audio Engine (TAAE), import it properly and place the TAAE main folder one level above the project’s folder.

Παρασκευή 12 Φεβρουαρίου 2016

A very accurate iOS metronome based on the Amazing Audio Engine and Pure Data

Making a *very* accurate iOS metronome for has been discussed under two different approaches:
1) using The Amazing Audio Engine (TAAE) approach, as presented in the ABetterMetronome example and
2) using Pure Data (PD) and libPD for iOS as presented in the linked video.
The aforementioned approaches are completely accurate, but in both examples there some things that makes them difficult to be extended to a not-only-metronome kind of app:
1) The TAAE approach is based on synthesising the metronome’s “click” sound sample-by-sample. The ABetterMetronome tutorial does not show how and if we could use other means to produce the metronome “click” sound, or play any other instrument note or sound.
2) In the PD approach, time scheduling is performed “inside” the PD patch. It seems that all the music-side reasoning has to be performed inside the PD patch, while it seems more reasonable to do the musical reasoning part of code in Objective-C or Swift instead.
Therefore, both examples discuss simple cases to make an accurate metronome. However, there is no discussion on how to harness the immense timing accuracy that they both have to iOS programming with more sophisticated musical reasoning. For instance, if you are making an app that decides in real-time about which notes to be played at certain (accurate) time intervals both aforementioned examples make it seem hard – while all the info is in there and it is completely easy!

The attached file is again a simple metronome that combines the TAAE and the PD approaches. However, in this example the programmer can decide on the Objective-C side of the code which notes to be played on the PD side. Hence the block frame counter approach of the TAAE example is combined with the facilities that PD offers, allowing accuracy and creativity to music-based app development.
Bonus: In the attached example, there is also a not-so-pretty but functional screen that updates the current beat of the metronome. It might seem trivial but it is not – when you need to update UI elements inside a AEBlockChannel it has to go through an NSOperationQueue block…

For more info do not hesitate to contact me! Here's my website and here is another blog of mine.

Accurate timing in iOS: don’t do it this way!

Following this great tutorial from HDEZ for making an iOS metronome with libPD one can make a very precise metronome.
However, if someone needs Pd only for getting beat-bang messages in Obj-C code then things are not so well…
The linked metronome app except from ugly, is also not accurate. So if you need a steady beat pulse provider for your music app, don’t do it this way! I’ll focus on the accurate timing mechanism I concluded with in a next post. To run it, make sure you properly import libPD as described in these videos.


P.S. This project may be no-good for its timing aspects, but it is probably the first implemented example online that discusses sending messages from Pd to Obj-C and not the other way around!
For more info do not hesitate to contact me! Here's my website and here is another blog of mine.