[openal] Problem putting Windows system to sleep while OpenAL is initialized but idle

Kirk Baker kbaker at camerabits.com
Thu Jul 14 19:38:55 EDT 2016


Our desktop application uses the OpenAL-soft libraries to play sounds asynchronously on Mac OS X and Windows.  Our needs for sound are relatively simple—we just need to queue up sounds and play them, stop them when the user tires of hearing the sounds, etc.

OpenAL works great for our needs but some users on Windows are reporting that shortly after our application starts up and until it quits, they cannot put their system to sleep.  This happens regardless of them playing sounds.  Our application initializes OpenAL on startup via:

	// Init OpenAL
	ALenum			error;
	ALCcontext		*newContext = NULL;
	ALCdevice		*newDevice = NULL;

	// Create a new OpenAL Device
	// Pass NULL to specify the system’s default output device
	newDevice = alcOpenDevice(NULL);
	if (newDevice != NULL) {
		// Create a new OpenAL Context
		// The new context will render to the OpenAL Device just created
		newContext = alcCreateContext(newDevice, 0);
		if (newContext != NULL) {
			// Make the new context the Current OpenAL Context

			// Create the OpenAL Source Object
			alGenSources(1, &gSource);
			if ((error = alGetError()) != AL_NO_ERROR) {
				FIELDLOG("Error generating audio sources!");
			// 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 };

			alSourcefv(gSource, AL_POSITION, SourcePos);
			alSourcefv(gSource, AL_VELOCITY, SourceVel);
			alSourcef(gSource, AL_PITCH, 1.0f);
			alSourcef(gSource, AL_GAIN, 1.0f);
			alSourcei(gSource, AL_LOOPING, AL_FALSE);

			// 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")
			ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };

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

			ms_playerSingleton = this;

The above is fairly straightforward, I expect.  Is there some way for us to "pause" OpenAL such that it won't deny system sleep?  On Windows, powercfg -requests shows
[DRIVER] Realtek High Definition Audio (HDAUDIO \ FUNC_01 & VEN_10EC & DEV_0889 & SUBSYS_1458A022 & REV_1000 \ 4 & 36360a8e & 0 & 0201)
An audio stream is currently in use.

I am guessing that as soon as we initialize as above, an audio stream is started up and mixes in silence, keeping things ready for low-latency playback.  If we could "pause" this when our app is switched out, or when a system sleep event raises, or when we know we're not trying to play sounds then I'd expect the system to be able to sleep.



Kirk A. Baker
Senior Software Engineer
Camera Bits, Inc.

More information about the openal mailing list