5

我知道 SoundPool 旨在处理类似声音的小型 fx,并且我确保我想按某个顺序一个一个播放的 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不能处理这么小的剪辑。我想知道人们如何制作具有大量音效的游戏...

错误看起来像这样:

错误/AudioFlinger(35): AudioTrack 内存不足 size=1048640 DEBUG/MemoryDe​​aler(35): AudioTrack (0x25018,size=1048576)

4

2 回答 2

2

之后我似乎能够解决我的问题:

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

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

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

于 2010-11-05T13:52:24.683 回答
0

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.

于 2010-11-05T02:13:07.033 回答