OpenAL initialization problem, iPod only (?)

白昼怎懂夜的黑 提交于 2019-12-11 01:35:31

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4201220/openal-initialization-problem-ipod-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!