OpenAL 初始化问题,仅限 iPod(?)

发布于 2024-10-03 09:03:55 字数 1351 浏览 4 评论 0原文

我在使用 OpenAL 时遇到了一个问题,该问题似乎只出现在 iPod 硬件上,奇怪的是它工作正常,但现在却不行了。

我正在设置音频会话:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, 
sizeof(UInt32), &audioRouteOverride);

AudioSessionSetActive(YES);

并初始化 OpenAL:

device = alcOpenDevice(NULL);
if (!device) {
    NSLog(@"Could not open default OpenAL device.");
    return NO;
}

context = alcCreateContext(device, 0);
if (!context) {
    NSLog(@"Failed to create OpenAL context for default device.");
    return NO;
}

BOOL success = alcMakeContextCurrent(context);  // fails here
if (!success) {
    NSLog(@"Failed to set current OpenAL context.");
    return NO;

输出为:

AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
2010-10-27 10:51:09.261 FinchTestProject[239:307] Failed to set current OpenAL context.

所以 alcMakeContextCurrent 函数返回 false,我不确定为什么。音频并不是我的专长,我找不到太多这方面的信息,所以你们能给我的任何帮助将不胜感激。

谢谢!

编辑:我发现如果我颠倒初始化的顺序 - 也就是说,如果我初始化 OpenAL 然后初始化 AudioSession,它就可以工作......尽管这是我之前的顺序并且它不起作用,所以有些有趣肯定正在发生;此外,它仍然不适用于旧版本的 iOS

I'm having a problem with OpenAL that only seems to occur with iPod hardware, and the odd thing is that it was working fine, and now it's not.

I'm setting up the audio session:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, 
sizeof(UInt32), &audioRouteOverride);

AudioSessionSetActive(YES);

And initializing OpenAL:

device = alcOpenDevice(NULL);
if (!device) {
    NSLog(@"Could not open default OpenAL device.");
    return NO;
}

context = alcCreateContext(device, 0);
if (!context) {
    NSLog(@"Failed to create OpenAL context for default device.");
    return NO;
}

BOOL success = alcMakeContextCurrent(context);  // fails here
if (!success) {
    NSLog(@"Failed to set current OpenAL context.");
    return NO;

The output is:

AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
2010-10-27 10:51:09.261 FinchTestProject[239:307] Failed to set current OpenAL context.

So alcMakeContextCurrent function is returning false, and I'm not sure why. Audio is not really my expertise, and I can't find much information on this, so any help you guys can give me would be appreciated.

Thanks!

EDIT: I've found if I reverse the order of initialization- that is if I initialize OpenAL and then the AudioSession, it works... although this is the order I had it in before and it wasn't working, so something funny is definitely going on; also, it still doesn't work with older versions of iOS

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

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

发布评论

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

评论(2

给妤﹃绝世温柔 2024-10-10 09:03:55

初始化的逆序似乎可以正常工作,先是 OpenAL,然后是 AudioSession

Reverse order of initialization seems to work ok, OpenAL then AudioSession

黄昏下泛黄的笔记 2024-10-10 09:03:55

只是一个大胆的猜测:

第一代 iPod touch 没有扬声器。因此,也许您无法覆盖到不存在的扬声器的音频路由。

编辑:哦,只有最新的(第 4 代)iPod touch 具有内置麦克风。所有其他版本都需要插入耳机(带麦克风)才能录音。也许这就是它突然停止工作的原因,耳机被移除了。

Just a wild guess:

The 1st generation iPod touch doesn't have a speaker. So perhaps you cannot override the audio route to a non-existent speaker.

Edit: Oh, and only the latest (4th gen) iPod touch has a microphone built in. All other generations require that the headphones (with microphone) be plugged in to record. Maybe that's why it stopped working all of sudden, the headphones were removed.

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