Jump to content
  • Advertisement
Sign in to follow this  

OpenAL - Source doesn't start playing

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've tested OpenAL a little, but in the beginning I found some strange behavior. When I start playing a looped sound like this:
It starts to play only very rarely. But when I tried this, it worked pretty well:
SDL_Delay(100); // important as well
alSourcef (Source, AL_GAIN,     0.5      );
alSourcef (Source, AL_PITCH,     0.5      );
alSourcef (Source, AL_GAIN,     1.0      );
alSourcef (Source, AL_PITCH,     1.0      );
Do you have an explanation for this? I can't get it. Thanks. PS: I'm amazed with OpenAL despite I started with it only a few moments now. It's so high-level that I must ask if it is not for a price of speed. And how about licensing under Windows and Linux? Lets say when using it in commercial development? I didn't bother studying the whole Creative Labs license when installing the SDK, so if you dont' mind answering this as well... This is my initialization (pseudo)code (taken almost directly from a tutorial):
alutInit(NULL, 0);

// Position of the source sound.
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };

// Velocity of the source sound.
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };

// Position of the Listener.
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };

// Velocity of the Listener.
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };

// Orientation of the Listener. (first 3 elements are "at", second 3 are "up")
// Also note that these should be units of '1'.
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };

Buffer = alutCreateBufferFromFile ("somewav.wav");

// Bind the buffer with the source.

alGenSources(1, &Source);

alSourcei (Source, AL_BUFFER,   Buffer   );
alSourcef (Source, AL_PITCH,    1.0      );
alSourcef (Source, AL_GAIN,     1.0      );
alSourcefv(Source, AL_POSITION, SourcePos);
alSourcefv(Source, AL_VELOCITY, SourceVel);

alSourcei (Source, AL_LOOPING,  1     );

alListenerfv(AL_POSITION,    ListenerPos);
alListenerfv(AL_VELOCITY,    ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);

Share this post

Link to post
Share on other sites

My looping sounds start with no problems, so I looked for differences in your code as compared to mine. A difference I found was the code used to load a wav.

Although alutLoadWAVFile() is considered deprecated, it works great for me.

unsigned int Source;
char* alBuffer;
long alBufferLen;
ALsizei alFreqBuffer;
ALboolean loop;
ALenum alFormatBuffer;
unsigned int alSampleSet;

alGenSources(1, &Source);
alGenBuffers(1, &alSampleSet);
alBufferData(alSampleSet, alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);
alSourcei(Source, AL_BUFFER, alSampleSet);
alutUnloadWAV(alFormatBuffer, alBuffer, alBufferLen, alFreqBuffer);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!