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
Pulling Data from a Cmsamplebuffer in Order to Create a Deep Copy
How to Write Keyboard Notifications in Swift 3
How to Get the Result Value of Alamofire.Request().Responsejson in Swift 2
Swift How to Modify Exif Info in Images Taken from Mobile Camera
Connecting to a Bluetooth Device from iOS, No Mfi
Autorelease Pools and When Release Is Called Under iOS
Becomefirstresponder Not Working in iOS 8
How to Use Reusable Cells in Uitableview for iOS
Debugging Mobile Safari in iOS 8 and iOS 9
Is the Function 'Dlopen()' Private API
Uitableview Not Visible the Last Cell When Scroll Down
Opens Apple Maps App from iOS App with Directions
Uiview/Calayer: Transform Triggers Layoutsubviews in Superview
Obj-C Afnetworking 2.0 Post Request Does Not Work
Try Sample Avcam from Apple Found Error
New Itunes User Interface Unable to Find "Ready to Upload Binary"