Android 声音池问题

发布于 2024-09-26 02:10:24 字数 575 浏览 3 评论 0原文

我在 Android Market 上有一个应用程序,并且一直在使用 SoundPool 类来实现声音效果。我注意到,在 Android API 的所有部分中,这似乎给我带来了最多的问题。例如:

  • HTC Desire 在播放 WAV 文件时出现问题(这会导致其随机锁定)。使用 .ogg 文件修复此问题

  • 在 Droid 上,如果超出 init setup 调用中的通道数:

mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

听筒将锁定。如果你能想象调试的难度!在我没有的手机上。这需要我的客户提供大量无私的帮助。将“4”更改为“16”解决了该问题。我毫不怀疑,如果同时播放 16 个声音,它仍然会崩溃。值得庆幸的是,这种可能性很低。

  • 还在各种设备上随机崩溃。我从一位客户那里收到了一份目录,其中存在与播放声音有关的“堆溢出”错误。

我现在已更改声音管理器以使用 MediaPlayer。目前看来这一切进展顺利。我只是想知道其他开发者是否也遇到过这些问题?

I've got an app on the Android Market and have been using the SoundPool classes for the sound effects. I've noticed that, of all the parts of the Android API, this seems to have caused me the most problems. For example:

  • HTC Desire has problems playing WAV files (this causes it to lock up randomly). Using .ogg files fixes this

  • On the Droid, if you exceed the number of channels in the init setup call:

mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

the handset would lock up. If you can imagine the difficulty in debugging that! On a handset I don't own. It required a lot of selfless help from my customers. Changing the '4' to '16' eliminated the problem. I have no doubt that if 16 sounds were played simultaneously it would still crash. Thankfully the chances of that are low.

  • Also getting random crashes on various devices. I have got a catlog from one of my customers which has 'Heap overflow' errors pertaining to playing sounds.

I have now changed my sound manager to use MediaPlayer. This seems to be working out fine for now. I am just wondering if any other developers are experiencing these problems?

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

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

发布评论

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

评论(1

北凤男飞 2024-10-03 02:10:24

似乎 AudioFlinger 在任何给定时间都可以播放高达 1 Mb 的音频。
如果超过此限制,则会发生堆错误。这个猜测是基于我在 AudioFlinger 源代码中找到的一些代码:

AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) 
     :   RefBase(), 
         mAudioFlinger(audioFlinger), 
         mMemoryDealer(new MemoryDealer(1024*1024)), 
         mPid(pid) 
{ 
     // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer 
} 

还有

size_t size = sizeof(audio_track_cblk_t); 
size_t bufferSize = frameCount*channelCount*sizeof(int16_t); 
if (sharedBuffer == 0) { 
    size += bufferSize; 
} 
mCblkMemory = client->heap()->allocate(size); 
if (mCblkMemory != 0) {
    ...
} else {
    LOGE("not enough memory for AudioTrack size=%u", size); 
    client->heap()->dump("AudioTrack"); 
}

其他人更了解情况吗?

It seems AudioFlinger can have up to 1 Mb worth of audio going on at any given time.
The heap errors occur if this limit is exceeded. This guess is based on some code I found in AudioFlinger source code:

AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) 
     :   RefBase(), 
         mAudioFlinger(audioFlinger), 
         mMemoryDealer(new MemoryDealer(1024*1024)), 
         mPid(pid) 
{ 
     // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer 
} 

And this:

size_t size = sizeof(audio_track_cblk_t); 
size_t bufferSize = frameCount*channelCount*sizeof(int16_t); 
if (sharedBuffer == 0) { 
    size += bufferSize; 
} 
mCblkMemory = client->heap()->allocate(size); 
if (mCblkMemory != 0) {
    ...
} else {
    LOGE("not enough memory for AudioTrack size=%u", size); 
    client->heap()->dump("AudioTrack"); 
}

Anyone else better informed?

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