I initialize my OpenAL source in sequence like this:
ALCcontext *_mContext;
ALCdevice *_mDevice;
ALuint _mSourceID;
alcOpenDevice(NULL);
_mContext = alcCreateContext();
alcMakeContextCurrent(_mContext);
alGenSources(1, &_mSourceID);
alSourcei(_mSourceID, ALLOOPING, AL_FALSE);
alSourcei(_mSourceID, AL_SOURCE_TYPE, AL_STREAMING);
alSourcef(_mSourceIDm AL_GAIN, (ALfloat)1.0);
alSpeedOfSound(1.0F);
The error orrurred at alSourcei(_mSourceID, AL_SOURCE_TYPE, AL_STREAMING)
. Error code 40962.
What happened? Why is failed to set the source type? Please help me. Thank you at advance!
Error code 40962 is AL_INVALID_ENUM (see al.h).
The OpenAL spec (http://www.openal.org/documentation/openal-1.1-specification.pdf) has a section on AL_SOURCE_TYPE (p34).
AL_SOURCE_TYPE is a read-only property indicating whether a source is ready to queue buffers, ready to use a static buffer, or is in an undetermined state where it can be used for either streaming or static playback.
The issue is that you are trying to set AL_SOURCE_TYPE when it is a read only parameter.
- Source is Streaming if one or more Buffers have been attached using alSourceQueueBuffers
The source type will set to streaming if you queue more than 1 buffer to the source.