Hello all,
I am developing an application that uses sound output. It does not continously play audio, but only in certain situations. I am initialising audio like this (simplified without error handling):
SDL_AudioStream* Audio_Output_Stream = NULL;
SDL_AudioSpec request = {SDL_AUDIO_S16BE, 2, 44100};
SDL_InitSubSystem(SDL_INIT_AUDIO);
Audio_Output_Stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &request, NULL, NULL);
When audio data is available, I play it with these function calls:
SDL_ClearAudioStream(Audio_Output_Stream);
SDL_PutAudioStreamData(Audio_Output_Stream, data, len);
SDL_ClearAudioStream(Audio_Output_Stream)
is called once when audio output starts. SDL_PutAudio_StreamData(Audio_Output_Stream)
is called periodically with chunks of up to 2048 bytes.
Now my question is: Do I need to call SDL_FlushAudioStream(Audio_Output_Stream)
after last chunk of data was passed to the stream?
It seems that some data is stuck in the queue otherwise. If I call SDL_GetAudioStreamQueued(Audio_Output_Stream)
before starting to play (before SDL_ClearAudioStream(Audio_Output_Stream)
) it reports 28 or 32 bytes of data being queued, even if there was a long period of time between last call of SDL_PutAudioStreamData(Audio_Output_Stream, data, len)
.
This is with SDL3. Is there an equivalent to SDL_FlushAudioStream()
in SDL2?