有没有一种“简单”的方法?如何在 iPhone 上播放线性 PCM 音频?

发布于 2024-08-21 01:19:52 字数 430 浏览 5 评论 0原文

我正在制作一个媒体播放应用程序,它从第三方解码器获取未压缩的线性 PCM(超原始)音频,但是当涉及到播放我能想象到的最简单的音频格式时,我会发疯

。最终的应用程序将随着源文件从服务器流式传输而逐渐获取 PCM 数据,因此我最初查看了音频队列(因为我似乎可以随时给它字节),但结果证明这是愚蠢的 - 特别是因为苹果自己的音频队列示例代码似乎在一次神奇的 OpenGL 实地考察和不必要的封装中展开。

我最终在(非流式)原型设计过程中使用了 AVAudioPlayer;我目前创建了一个 WAVE 标头并将其添加到 PCM 数据的开头以使 AVAudioPlayer 接受它(因为它不能接受原始 PCM)

显然这对于​​流式传输没有用(WAVE 在标头中设置了整个文件长度,因此数据无法随时添加)..

..本质上:有没有办法只给 iPhone OS 一些 PCM 字节并让它播放它们?

I'm making a media playback app which gets given uncompressed linear PCM (über raw) audio from a third-party decoder, but I'm going crazy when it comes to just playing back the most simple audio format I can imagine..

The final app will get the PCM data progressively as the source file streams from a server, so I looked at Audio Queues initially (since I can seemingly just give it bytes on the go), but that turned out to be mindfudge - especially since Apple's own Audio Queue sample code seems to go off on a magical field trip of OpenGL and needless encapsulation..

I ended up using an AVAudioPlayer during (non-streaming) prototyping; I currently create a WAVE header and add it to the beginning of the PCM data to get AVAudioPlayer to accept it (since it can't take raw PCM)

Obviously that's no use for streaming (WAVE sets the entire file length in the header, so data can't be added on-the-go)..

..essentially: is there a way to just give iPhone OS some PCM bytes and have it play them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枉心 2024-08-28 01:19:52

您应该重新访问 AudioQueue 代码。一旦你去掉所有的废话,你应该有大约 2 页的代码加上一个回调,你可以在其中提供原始 PCM。此回调也与您的主循环同步,因此您甚至不必担心锁定。

You should revisit the AudioQueue code. Once you strip away all the guff you should have about 2 pages of code plus a callback in which you can supply the raw PCM. This callback is also synchronous with your main loop, so you don't even have to worry about locking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文