Sign in to follow this  


Recommended Posts

I am having a problem when playing back a wav file using OpenAL AND alut to load it, when the sound starts there is a loud corrupt sound then the actuall playback, if it is on loop then the strange sound is only at the beginning not on every loop. it may also be a system problem(ubuntu) any ideas? or would I be better off using fmod? or some other libary? I use alutInit(0,0); to start it up then the folowing class to play sounds

bool sound::init(std::string filename)

    alGenBuffers(1, &m_soundID);
    alGenSources(1, &m_sourceID);

    float SourcePos[] = { 0.0, 0.0, 0.0 };
    float SourceVel[] = { 0.0, 0.0, 0.0 };

    float ListenerPos[] = { 0.0, 0.0, 0.0 };
    float ListenerVel[] = { 0.0, 0.0, 0.0 };
    float ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };

    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;

    alutLoadWAVFile((ALbyte*)filename.c_str(), &format, &data, &size, &freq, &loop);
    alBufferData(m_soundID, format, data, size, freq);
    alutUnloadWAV(format, data, size, freq);

    //m_soundID = alutCreateBufferFromFile (filename.c_str());

    alSourcei (m_sourceID, AL_BUFFER,   m_soundID);
    alSourcef (m_sourceID, AL_PITCH,    1.0f     );
    alSourcef (m_sourceID, AL_GAIN,     1.0f     );
    alSourcefv(m_sourceID, AL_POSITION, SourcePos);
    alSourcefv(m_sourceID, AL_VELOCITY, SourceVel);
    alSourcei (m_sourceID, AL_LOOPING,  AL_TRUE );

void sound::play()

void sound::stop()

void sound::distroy()
    alDeleteSources(1, &m_sourceID);
    alDeleteBuffers(1, &m_soundID);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this