Skip to content

Commit f7cadcb

Browse files
committed
examples: Use SDL_GetAudioStreamQueued, not SDL_GetAudioStreamAvailable.
The "available" side is at the mercy of whatever format the hardware wants, but we control what we queued. Fixes libsdl-org#12403.
1 parent b3336c5 commit f7cadcb

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

examples/audio/01-simple-playback/simple-playback.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
6969
A sine wave is unchanging audio--easy to stream--but for video games, you'll want
7070
to generate significantly _less_ audio ahead of time! */
7171
const int minimum_audio = (8000 * sizeof (float)) / 2; /* 8000 float samples per second. Half of that. */
72-
if (SDL_GetAudioStreamAvailable(stream) < minimum_audio) {
72+
if (SDL_GetAudioStreamQueued(stream) < minimum_audio) {
7373
static float samples[512]; /* this will feed 512 samples each frame until we get to our maximum. */
7474
int i;
7575

examples/audio/03-load-wav/load-wav.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
8282
We're being lazy here, but if there's less than the entire wav file left to play,
8383
just shove a whole copy of it into the queue, so we always have _tons_ of
8484
data queued for playback. */
85-
if (SDL_GetAudioStreamAvailable(stream) < (int)wav_data_len) {
85+
if (SDL_GetAudioStreamQueued(stream) < (int)wav_data_len) {
8686
/* feed more data to the stream. It will queue at the end, and trickle out as the hardware needs more data. */
8787
SDL_PutAudioStreamData(stream, wav_data, wav_data_len);
8888
}

examples/audio/04-multiple-streams/multiple-streams.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
104104
/* If less than a full copy of the audio is queued for playback, put another copy in there.
105105
This is overkill, but easy when lots of RAM is cheap. One could be more careful and
106106
queue less at a time, as long as the stream doesn't run dry. */
107-
if (SDL_GetAudioStreamAvailable(sounds[i].stream) < ((int) sounds[i].wav_data_len)) {
107+
if (SDL_GetAudioStreamQueued(sounds[i].stream) < ((int) sounds[i].wav_data_len)) {
108108
SDL_PutAudioStreamData(sounds[i].stream, sounds[i].wav_data, (int) sounds[i].wav_data_len);
109109
}
110110
}

0 commit comments

Comments
 (0)