For a project that I intend to start on soon, I will need to play back compressed and uncompressed audio files. To do that, I intend to use the Core Audio framework. However, I have no prior experience in audio programming, and I'm really not sure where to start. Are there any beginner level resources or sample projects that can demonstrate how to build a simple audio player using Core Audio?
4 Answers
Although the questiona has already been answered.. I would like to add in a little more tips since I've struggled with the same issue for months:
Here is a very simple example code I created based on sample code on the learning core audio book.
The Matt Gallagher audio streaming tutorial is a definite must.. in addition to providing an excellent example of streaming audio live.. its also provides a simple example of multi-threading.. which brings me to the next VERY IMPORTANT point
In Apple's concurrency guide.. they advise against using multithreading.. and give you a host of suggestions like GCD and NSOperations etc etc.. NOT A GOOD IDEA when it comes to core audio.. at least real time audio.. b/c real time audio is extremely sensitive to any kind of blocking or expensive operations.. more than you can imagine (ie sometimes even simple NSLog statements can make the audio break up or even not play at all!!) Here is an indispensable read regarding this part of audio.
Audio programming is a different kind of programming than what most of us are used to. Hence take your time to understand concepts.. a lot of them will take time to sink in.. for example the difference between an audio file format and an audio streaming format.. the difference between compressed audio and PCM (non-compressed) audio.. examples abound.
One key point that took me a while to comprehend: to access audio files within the iPad library.. the only way to read them is via the AVAssetReader API methods.. not through the other APIs like AudioFileReadPackets etc.. (although if you store a file manually in your project.. then you can).. the AVAssetReader is a lot less user friendly than the other API.. but once the concepts of core audio sink in.. you won't find much of a difference.. My example uses AVAssetReader
See the discussion I've been having with Justin here.. in it you'll see a lot of pitfalls that i've fallen into and you'll get an idea on how to avoid them. Remember, especially with Core Audio.. it's not about knowing how to solve the problem.. it's about knowing what problem to solve in first place.
If you or any one else has any questions with regards to core audio please feel free to write up a question on stack overflow and point it out to me by commenting on one of my own questions just to bring it to my attention.. i've been helped a lot by the community here and i really wanna offer help in return
-
Great response. Thanks for the offer to help on Core Audio. Have you thought about blogging or somehow archiving more resources you've come across? Have you found much helpful resources out there towards updated content regarding Audio Units. I can't find anything that remotely correlates to recent versions of XCode. – May 17 '14 at 15:48
-
1@ShawnStrickland thanks man. I haven't worked on core audio for a while so blogging wouldn't be a good idea for me right now. apart from my github account i can't think of a better resource than the core audio book [referenced](http://www.amazon.com/Learning-Core-Audio-Hands-On-Programming/dp/0321636848) in the correct answer. Also add people like [justin](http://stackoverflow.com/users/191596/justin) to your twitter feed etc and try to just hang around their circles to get more in depth knowledge and analysis about this really complex subject – abbood May 19 '14 at 04:42
-
1@ShawnStrickland also [here](http://blog.piotry.me/post/61595140847/how-to-get-help-from-the-best-engineers-in-the-world) is the only blog post i've ever written (on my friends blog.. heh).. it's kinda related to the above.. check it out! – abbood May 19 '14 at 04:45
A preview of a book on Core Audio just came out. I've started reading it and as a beginner myself I find it helpful.
It has a tutorial style teaching method and is very clear in its explanations. I highly recommend it.

- 53,471
- 32
- 129
- 174
-
aboved mentioned book : Learning Core Audio by Chris Adamson is excellent - except for streaming audio where you are better off with this book : Beginning iPhone Games Development which has 4 chapters covering Core Audio and OpenAL. Each book has projects with full source code available online – Scott Stensland Sep 13 '12 at 19:50
I wrote some sample code after spending a long time trying to figure out a similar problem as yours.
The sample code allows the user to select a song from their iPod library, it then creates an uncompressed (LPCM) copy of the file (using AVAssetReader/AVAssetWriter), and plays it back using AudioUnit (which is part of CoreAudio).
If you want to play an arbitrary file, just remove the bits of my code that create the uncompressed copy (look for AVAssetReader/AVAssetWriter), and instead have the class point to some other song file.

- 603
- 5
- 18
i think for your requirement you can get better support from above link

- 4,588
- 9
- 33
- 37