How to Use Avaudioengine to Read from a File, Process with an Audio Unit and Write to a File, Faster Than Real-Time

How to automatize audio unit bypass?

Automatizing an FX bypass doesn't really need the same level of precision than other kind of automations. So, finally, I used AudioUnitSetProperty at the beginning of the slice. Doing this way, the discrepancy with the actual timing is of ± 40ms in the worse case. It's not negligible, but I also feel natural not to bypass an effect during a sound but a little bit before instead. Doing like that, a delay of a few ms is not really an issue.

performance wise, should I use AVAudioEngine for multiple sound effects yes or no?

You should manage a single AVAudioEngine instance to which all your effects and player are connected, and connect/disconnect nodes as sounds play.

Having multiple AVAudioEngine instances isn't a problem because of the performance overhead, but because it'll become too complicated to manage them all in real time, having them all respond to AVAudioSession.routeChangeNotification and AVAudioSession.interruptionNotification, keeping all the players in sync, testing each one of them using renderOffline, and so on.

I recommend you watch WWDC 2014 Session 502 - AVAudioEngine in Practice, for a good introduction to this API. One of the use cases they bring up is very similar to yours – and they use just one AVAudioEngine instance :-)

Finding cause of crackle and pops in custom AUAudioUnit

This is a typical bug caused by incrementing time and calculating a new phase (for the sine function parameter) every loop iteration, which produces phase discontinuities when changing frequencies.

One simple solution is to increment phase instead of time. It's easy to compute the phase delta per unit time for a given frequency, and do that computation outside the inner loop. Since this phase delta is small, there will be no big phase discontinuities to produce crackles and pops.

Calculating a new phase this way each iteration only requires addition, not multiplication (by 2.0 * M_PI, etc.).

You might also want to bound the range of the phase inside +- M_PI or +-2pi, instead of letting it grow arbitrarily large, which can cause range reduction errors inside the sine function.



Related Topics



Leave a reply



Submit