OpenAL - 确定最大来源

发布于 2024-09-02 13:55:29 字数 298 浏览 6 评论 0原文

是否有 API 允许您定义底层声音硬件允许的 OpenAL“源”最大数量?

在互联网上搜索,我发现了 2 个建议:

  • 继续生成 OpenAL 源,直到出现错误。 这“非常糟糕,甚至可能使库崩溃”
  • 然而,FreeSL(OpenAL 包装器)中有一条注释指出,假设您只有 16 个, ;为什么有人会要求更多? (!)

第二个建议甚至被 FreeSL 采纳。

那么,是否有一个通用的 API 来定义支持的同时“语音”数量?

谢谢你的宝贵时间,

比尔

Is there an API that allows you to define the maximum number of OpenAL "sources" allowed by the underlying sound hardware?

Searching the internet, I found 2 recommendations :

  • keep generating OpenAL sources till you get an error. However, there is a note in FreeSL (OpenAL wrapper) stating that this is "very bad and may even crash the library"
  • assume you only have 16; why would anyone ever require more? (!)

The second recommendation is even adopted by FreeSL.

So, is there a common API to define the number of simultaneous "voices" supported?

Thank you for your time,

Bill

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

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

发布评论

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

评论(3

他夏了夏天 2024-09-09 13:55:29

更新:

我找不到方法来确定设备支持的最大源数量,但我想我已经找到了如何确定上下文支持的最大数量(ALC_MONO_SOURCES)。由此可见,上下文支持与其父设备相同的编号。

//error checking omitted for brevity
ALCdevice* device = alcOpenDevice(NULL);
ALCcontext* context = alcCreateContext(device,NULL);
ALCint size;
alcGetIntegerv( device, ALC_ATTRIBUTES_SIZE, 1, &size);
std::vector<ALCint> attrs(size);
alcGetIntegerv( device, ALC_ALL_ATTRIBUTES, size, &attrs[0] );
for(size_t i=0; i<attrs.size(); ++i)
{
   if( attrs[i] == ALC_MONO_SOURCES )
   {
      std::cout << "max mono sources: " << attrs[i+1] << std::endl;
   }
}

在使用库存 OpenAL 驱动程序的 Ubuntu 10.4 上,这将返回 255。


长答案是有点......

基于软件的 OpenAL 驱动程序通常允许无限数量的源。好吧,并不是真正无限,最终你会最大化 CPU 或 RAM。

大多数基于硬件的 OpenAL 驱动程序仅支持与硬件具有的通道一样多的源。现在至少有 16 个,可能有 32 个或更多,但最多可达 256 个。可能有支持更多的声卡,但 256 是我见过的最大的。

在 Windows 上,基于 DirectSound 的驱动程序被任意限制为 31 个(为什么不是 32 个?)源。 DirectSound 已被弃用,所以我不知道这是否仍然适用于 Vista 和 Windows 7。iPhone

支持 32 个源。

我见过一种基于硬件的驱动程序,它是由软件支持的。这意味着它将为每个源提供一个硬件通道,直到它们耗尽为止。然后,它会在软件中混合一些声音,然后再将其从硬件中传送出去。这提供了两全其美的优点,接近无限的资源,同时仍然使用尽可能多的硬件加速。

实际上,如果您使用基于硬件的驱动程序,只需继续创建它们,直到 alGenSources 失败。我听说这在 iPhone 上不起作用。有一些基于 OpenAL 驱动程序的软件会在 alGenSources 失败之前崩溃。

确实应该有一个 API 来检查最大源数和硬件加速的源数。也许扩展中有。

update:

I can't find a way to determine what the maximum number of sources a device supports, but I think I've found how to determine the maximum a context supports(ALC_MONO_SOURCES). It would follow that a context supports the same number as its parent device.

//error checking omitted for brevity
ALCdevice* device = alcOpenDevice(NULL);
ALCcontext* context = alcCreateContext(device,NULL);
ALCint size;
alcGetIntegerv( device, ALC_ATTRIBUTES_SIZE, 1, &size);
std::vector<ALCint> attrs(size);
alcGetIntegerv( device, ALC_ALL_ATTRIBUTES, size, &attrs[0] );
for(size_t i=0; i<attrs.size(); ++i)
{
   if( attrs[i] == ALC_MONO_SOURCES )
   {
      std::cout << "max mono sources: " << attrs[i+1] << std::endl;
   }
}

This returns 255 on Ubuntu 10.4 using the stock OpenAL driver.


The long answer is well kinda...

Software based OpenAL drivers generally allow an infinite number of sources. Well, not really infinite, eventually you'll max out either the CPU or the RAM eventually.

Most hardware based OpenAL drivers only support as many sources as the hardware has channels. Modernly that is at least 16, probably 32 or more but can be as much as 256. There are probably sound cards that support more but 256 is the largest I've ever looked at.

On Windows DirectSound based drivers are arbitrarily limited to 31 (why not 32?) sources. DirectSound has been deprecated so I don't know if this still applies to Vista and Windows 7.

The iPhone supports 32 sources.

I have seen one hardware based driver that was software backed. Meaning it would give each source a hardware channel until they ran out. Then it would mix some of the sounds in software before shipping it off the the hardware. This gives the best of both worlds, near infinite sources, while still using as much hardware acceleration as possible.

In practice if you're using a hardware based driver, just keep creating them until alGenSources fails. I have heard this doesn't work on the iPhone. There a some software based OpenAL drivers that will crash before alGenSources fails.

There really ought to be an API to check the max number of sources and number of sources that are hardware accelerated. Maybe there is in the extensions.

眼眸里的那抹悲凉 2024-09-09 13:55:29

您可以通过alGenSources()创建的源数量与允许同时播放的源数量无关。

iPad 4(我测试过的唯一设备)上,您可以同时播放的最大语音数量为32。如果您尝试播放第 33 个声音,您会在 alSourcePlay() 处收到错误

AL 错误:-1 - AL_INVALID(一般错误)

并且声音不播放。但源可以存在,可以移动,并且可以为其设置各种设置。它只是在其他 32 个播放声音之一播放完毕之前不会播放。

我仅使用循环就在 iPad 4 上成功创建了多达 2048 个源。这并不意味着我可以同时播放 2048 个声音。

所以我的答案是:自己测试硬件平台并编写最大同步 SFX 代码。

The number of sources you can create via alGenSources() has nothing to do with the number of sources allowed to simultaneously play.

On the iPad 4 (the only device I have tested), the maximum number of voices you can have playing simultaneously is 32. If you try to play a 33rd sound, you get an error at alSourcePlay()

AL ERROR: -1 - AL_INVALID (general error)

And the sound doesn't play. But the source can exist, it can move, and have the various settings set for it. it just won't play until one of the other 32 playing sounds finishes playing.

I've successfully created up to 2048 sources on an iPad 4, just using a loop. That doesn't mean I can play 2048 sounds simultaneously.

So my answer is: test the hardware platform and code-in the max simultaneous SFX yourself.

木槿暧夏七纪年 2024-09-09 13:55:29

你可以通过以下方式查询最大源:

ALCint nummono, numstereo;
alcGetIntegerv(device, ALC_MONO_SOURCES, 1, &nummono);
alcGetIntegerv(device, ALC_STEREO_SOURCES, 1, &numstereo);

但这不是标准的,或者在 openAL 1.1 的规范中(可能会在 1.2 上添加),一些驱动程序(openAL 实现)可以回答这个查询,有些则不能,所以如果你幸运的话将得到答案,但如果没有,除了调用 alGenSources() 直到返回错误之外没有其他解决方案。

您应该注意到,某些实现的行为有所不同,据我所知,例如在 Apple iPhone 上,它们可以创建最多 256 个源,但您不能同时播放 256 个源(限制为 64),因此最大源并不总是与 max 相同并发播放。

you can query the maximum source by :

ALCint nummono, numstereo;
alcGetIntegerv(device, ALC_MONO_SOURCES, 1, &nummono);
alcGetIntegerv(device, ALC_STEREO_SOURCES, 1, &numstereo);

but this is not standard or in the spec of openAL 1.1 (probably will be added on 1.2), some driver (openAL implementation) can answer this query and some not, so if you're lucky you will get the answer, but if not, there no other solution than to call alGenSources() until it return error.

and you should notice that, some implementation behave differently, AFAIK for example on Apple iPhone they could create 256 source max, but you can't play 256 source simultaneously (limited to 64), so max source is not always the same thing as max concurrent play.

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