Starting with the Core Audio framework
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开发者_JS百科, 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?
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.
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
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.
http://www.libsdl.org/
i think for your requirement you can get better support from above link
精彩评论