openAL循环周期错误

时间:2011-07-01 20:21:48

标签: c++ sdl openal

我试图用OpenAL在openGL / SDL中播放循环声音,但是当我把它称为无限循环并且它在开始时卡住我不知道如何解决这个问题所以我来到这里希望some1知道我的代码我怎么称呼openAL

SDL_Thread * AudioBG;

    bool Init(void)
    {
     m_Music->LoadFile("Sonido/BGSP.wav",true);
    }

    int MusicThread(void *arg)//Creating the Thread
    {
       arg+=0;
        for(;;)
        {
            m_Music->PlaySound();
        }
        return 0;
    }

void Draw()//this is my cycle of the game
{
    gui->Draw(x,y,z);

    AudioBG = SDL_CreateThread(Music,NULL);

}

这是我的班级Sound.cpp

Sound::Sound()
{
    Device = alcOpenDevice((ALCchar*)"DirectSound3D");
    Context = alcCreateContext(Device,NULL);
    alcMakeContextCurrent(Context);
    alGetError();
}

Sound::~Sound()
{
    Context = alcGetCurrentContext();
    Device = alcGetContextsDevice(Context);
    alcMakeContextCurrent(NULL);
    alcDestroyContext(Context);
    alcCloseDevice(Device);
}

void Sound::LoadFile(char archivo[40],bool looping)
{
    ALboolean loop;
    loop = looping;
    alutLoadWAVFile(archivo,&alFormatBuffer,
                    (void **)&alBuffer,
                    (ALsizei *)&alBufferLen,
                    &alFreqBuffer,&loop);

    alGenSources(1,&this->alSource);
    alGenBuffers(1,&alSampleSet);
    alBufferData(alSampleSet,alFormatBuffer,alBuffer,alBufferLen,alFreqBuffer);
    alSourcei(this->alSource,AL_BUFFER,alSampleSet);

    alutUnloadWAV(alFormatBuffer,alBuffer,alBufferLen,alFreqBuffer);

    alSourcef(this->alSource,AL_PITCH,1.0f);

    alSourcef(this->alSource,AL_GAIN,1.0f);

    if(looping)
    alSourcei(this->alSource,AL_LOOPING,AL_TRUE);
    else
    alSourcei(this->alSource,AL_LOOPING,AL_FALSE);
}

void Sound::Direction(float x,float y,float z,float vx,float vy,float vz)
{
    alSource3f(this->alSource,AL_POSITION,x,y,z);
    alSource3f(this->alSource,AL_VELOCITY,vx,vy,vz);
}

void Sound::RelativeSound()
{
    alSourcei(this->alSource,AL_SOURCE_RELATIVE,AL_TRUE);
}

void Sound::PlaySound()
{
    alSourcePlay(this->alSource);
}

我真的失去了...如果我调用函数LoadFile并将游戏循环中的歌曲初始化并且没有线程它可以很好地播放但在循环内部有或没有线程我得到了我试图描述的错误:小号

0 个答案:

没有答案