再次关于 SoundPool 的内存问题

发布于 2024-09-30 18:58:16 字数 615 浏览 2 评论 0原文

我知道 SoundPool 的目的是处理小型效果器之类的声音,并且我确保我想要按某个顺序一一播放的 4 个声音剪辑足够小。

我使用 ogg 质量 0,剪辑大小为 35kb、14kb、21kb 和 23kb,压缩音频总计 92kb。我不知道如何估计未压缩的大小,但应该不会很多,对吧?

因此,当我按顺序播放 4 个声音时,前 9 次效果很好(9 个序列 x 4 个声音),但开始导致其中一个声音的 9 个序列出现内存问题。当我开始看到错误时,它总是序列 9。

处理这个问题的最佳方法是什么?我有一些想法:

1)进一步压缩声音(ogg 质量 -1 和单声道而不是立体声)

2)使用 SoundPool.load 和 SoundPool.unload 不断卸载和加载声音

3)随时释放和重新创建 soundPool

实例我还能做些什么吗?尴尬的是android api无法处理这么小的剪辑。我想知道人们如何创建具有大量音效的游戏...

错误看起来像这样:

ERROR/AudioFlinger(35):没有足够的内存用于AudioTrack size=1048640 调试/MemoryDe​​aler(35):AudioTrack(0x25018,大小=1048576)

I am aware that SoundPool was intended to handle small fx like sounds and I made sure my 4 sound clips which I want to play one by one in some sequence are small enough.

I used ogg quality 0 and clips are 35kb, 14kb, 21kb and 23kb totaling 92kb of compressed audio. I have no idea how to estimate what the uncompressed size would be, but it should not be a lot, right?

So when I play 4 sounds in sequence, it works well for first 9 times (9 sequences x 4 sounds) but starts to cause memory issues on the nines sequence for one of the sounds. It is always sequence 9 when I start to see error.

What is the best way to handle that? I have a few ideas:

1) compress sounds even more (ogg quality -1 and mono instead of stereo)

2) unload and load sounds constantly using SoundPool.load and SoundPool.unload

3) release and recreate soundPool instance time from time

Is there anything else I can do? It is embarrassing that android api cannot handle so small clips. I wonder how people create games with a lot of sound effects...

Errors look like that:

ERROR/AudioFlinger(35): not enough memory for AudioTrack size=1048640
DEBUG/MemoryDealer(35): AudioTrack (0x25018,size=1048576)

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

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

发布评论

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

评论(2

筑梦 2024-10-07 18:58:16

看来我能够解决我的问题:

1)将我的声音剪辑从 44khz 降采样到 22khz。未压缩的大小被削减了一半(我想出了如何估计未压缩的声音大小 - 将剪辑导出为未压缩的 wav)。我使用了不错的开源工具 Audacity

2)更多地修剪声音以减少持续时间

3)将 try/catch 放在 play() 周围以防万一(当它尝试播放声音但不能播放时,它确实会捕获错误)

It seems I was able to resolve my issue after:

1) downsampled my sound clips from 44 to 22khz. Uncompressed size was cut in half (I figured how to estimate uncompressed sound size - export your clip to uncompressed wav). I used nice open source tool Audacity

2) trim the sounds more to reduce duration

3) put try/catch around play() just in case (it does catch errors when it try to play the sound but cannot)

海的爱人是光 2024-10-07 18:58:16

这看起来很奇怪。 SoundPool 在加载音频剪辑时应该将它们扩展到内存中,并且一旦加载,我不希望您以后遇到内存问题。当我遇到内存问题时,都是在一开始的时候,而不是后来。您确定稍后不会加载更多声音吗?

为了回答您的其他问题,有些游戏使用 JET Player 和 MIDI 声音而不是 SoundPool。 Android SDK 中的 JetBoy 示例程序是如何在应用程序中执行此类声音工作的一个很好的示例。

That seems odd. SoundPool should be expanding your audio clips into memory when it loads them, and once loaded I wouldn't expect you to run into memory issues later. When I've run into memory issues it was right at the beginning, not later on. You sure you're not loading more sounds later on?

To answer your other question, some games use JET Player and MIDI sounds instead of SoundPool. The JetBoy sample program that comes in the Android SDK is a great example of how to do this type of sound work in an app.

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