SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Any open sdl audio device seem to prevent windows from sleeping

Open nico-abram opened this issue 1 year ago • 1 comments

Running powercfg /requests on windows while running the sample below prints

SYSTEM:
[DRIVER] Realtek High Definition Audio (HDAUDIO\{REDACTED})
An audio stream is currently in use.

Note: The sample must be ran in a folder containing a sample.wav file such as the ./test/sample.wav in the repo.

This prevents windows from going to sleep. I've tried setting SDL_HINT_VIDEO_ALLOW_SCREENSAVER and pausing via SDL_PauseAudioDevice

I'm not sure if this is intended behaviour or a bug.

#include "SDL.h"

int main() {
    Uint8 *sound;
    Uint32 soundlen;
    SDL_AudioSpec spec;

    SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS);
    SDL_LoadWAV("sample.wav", &spec, &sound, &soundlen);
    
    SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
    SDL_AudioDeviceID device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &spec, NULL, 0);

    SDL_PauseAudioDevice(device, SDL_FALSE);
    SDL_PauseAudioDevice(device, SDL_TRUE);

    while(1) {}
}

nico-abram avatar Apr 22 '24 21:04 nico-abram

"Pausing" the audio device just feeds silence to the hardware, so that definitely won't do it.

I wasn't aware of this behavior on Windows. I'll have to look into it. I'm not sure if it's something we can workaround, short of the app closing the device when not using it.

icculus avatar Apr 22 '24 21:04 icculus