对于我打算很快开始的项目,我需要播放压缩和未压缩的音频文件。为此,我打算使用 Core Audio 框架。然而,我之前没有音频编程经验,我真的不知道从哪里开始。是否有任何初学者级别的资源或示例项目可以演示如何使用 Core Audio 构建简单的音频播放器?
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)
尽管问题已经得到解答..我想添加更多提示,因为我几个月来一直在同一问题上苦苦挣扎:
这里是一个非常简单的示例代码,我根据 学习核心有声读物。
Matt Gallagher 音频流教程是绝对必须的..除了提供流音频直播的优秀示例之外..它还提供了多线程的简单示例..这让我想到了下一个非常重要的点
在Apple的并发指南中..他们建议反对 使用多线程.. 并为您提供大量建议,例如 GCD 和 NSOperations 等。 当涉及到核心音频时,这不是一个好主意.. 至少是实时音频.. b/c 实时音频对任何类型的阻塞或昂贵的操作..超出您的想象(即有时即使是简单的 NSLog 语句也会使音频中断甚至根本无法播放!) 这里是关于这部分音频的必读内容。
音频编程与我们大多数人习惯的编程不同。因此,请花点时间来理解概念.. 其中很多概念需要时间来理解.. 例如音频文件格式和音频流格式之间的区别.. 压缩音频和 PCM(非压缩)音频之间的区别..例子比比皆是。
我花了一段时间才理解的一个关键点:访问 iPad 库中的音频文件。读取它们的唯一方法是通过 AVAssetReader API 方法。而不是通过其他 API像 AudioFileReadPackets 等..(尽管如果您在项目中手动存储文件..那么您可以)..AVAssetReader 比其他 API 更不那么用户友好..但是一旦核心音频的概念深入人心..您不会发现太大的区别..我的 示例 使用 AVAssetReader
查看我与 贾斯汀 这里..在其中你会看到我陷入的很多陷阱,你会得到关于如何避免它们的想法。请记住,尤其是对于 Core Audio..,这不是要知道如何解决问题……而是要知道首先要解决什么问题。
如果您或任何其他人对核心音频有任何疑问,请随时在堆栈溢出上写一个问题,并通过评论我自己的问题之一向我指出,只是为了引起我的注意。 。这里的社区为我提供了很多帮助,我真的想提供帮助作为回报
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
在花了很长时间试图找出与您类似的问题后,我编写了一些示例代码。
示例代码允许用户从 iPod 库中选择一首歌曲,然后创建该文件的未压缩 (LPCM) 副本(使用 AVAssetReader/AVAssetWriter),并使用 AudioUnit(它是 CoreAudio 的一部分)播放它。
如果您想播放任意文件,只需删除创建未压缩副本的代码位(查找 AVAssetReader/AVAssetWriter),然后让类指向其他一些歌曲文件。
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/
我认为根据您的要求,您可以从上面的链接获得更好的支持
http://www.libsdl.org/
i think for your requirement you can get better support from above link
关于 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.