ошибка цикла openAL - PullRequest
       19

ошибка цикла openAL

2 голосов
/ 02 июля 2011

я пытаюсь воспроизвести зацикленный звук в openGL / SDL с openAL, но когда я его называю, он просто зацикливается бесконечно и застревает в начале, я даже не представлял, как это исправить, поэтому я пришел сюда, надеясь, что кто-то знает, вот мой кодкак я называю 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 и инициализирую песню из цикла игрыи без потока это играет хорошо, но внутри цикла и с потоком или без него я получаю ошибку, которую я пытался описать: S

...