开发者

openAL looping cycle error

im trying to play a looping sound in openGL/SDL with openAL but when im calling it its just looping infinitely and its stuck at the start ive got no idea how to fix this so i came here hoping some1 knows heres my code of how im calling 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);

}

this is my class 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);
}

im really lost... if i call the function LoadFile and in开发者_如何学Pythonitialize the song out of the game loop and without a thread it plays well but inside the loop and with or without the thread im getting the error i tried to describe :S

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜