试图在OpenAL中玩一些东西,但它永远不会超出AL_INITIAL状态

时间:2011-04-26 20:28:50

标签: c++ openal

我正在尝试使用OpenAl播放音频文件,但它实际上并没有播放任何内容。当我在调用alSourcePlay后检查音频文件是否正在播放时,状态仍为AL_INITIAL。

这是我播放音频的地方:

// Make sure the audio source ident is valid and usable
if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID])
    return false;

int sourceAudioState = 0;

if(!alIsSource(mAudioSources[audioID]) == AL_TRUE) return false;

alGetError();
// Are we currently playing the audio source?
alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );

if ( sourceAudioState == AL_PLAYING )
{
    printf("Currently playing!\n");
    if ( forceRestart )
        stopAudio( audioID );
    else
        return false; // Not forced, so we don't do anything
}
alSourcePlay( mAudioSources[ audioID ] );
if ( checkALError( "playAudio::alSourcePlay: ") )
    return false;
alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );
printState(sourceAudioState);
if(sourceAudioState == AL_PLAYING)
{
    printf("Now playing!\n\n");
}
return true;

mAudioSources是由alGenBuffers创建的缓冲区数组。该文件加载

mAudioBuffers[bufferID] = alutCreateBufferFromFile(filename.c_str());

这不会导致alGetError出错。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

alutCreateBufferFromFile不会导致alGetError出错。您必须使用alutGetError(请注意前缀alut而不是al)。如果alutCreateBufferFromFile失败,它将返回AL_NONE这是一个有效的缓冲区:NULL缓冲区将无法播放。

查看ALUT documentation有关alutGetError以及OpenAL Specs的信息。