diff --git a/include/SDL3/SDL_audio.h b/include/SDL3/SDL_audio.h index ac1540bc0..9b8737919 100644 --- a/include/SDL3/SDL_audio.h +++ b/include/SDL3/SDL_audio.h @@ -860,12 +860,13 @@ extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream) /** - * Get the number of sample frames currently queued. + * Get the number of bytes currently queued. * - * Since audio streams can change their input format at any time, even if - * there is still data queued in a different format, this reports the queued - * _sample frames_, so if you queue two stereo samples in float32 format and - * then queue five mono samples in Sint16 format, this will return 6. + * Note that audio streams can change their input format at any time, even if + * there is still data queued in a different format, so the returned byte + * count will not necessarily match the number of _sample frames_ available. + * Users of this API should be aware of format changes they make when feeding + * a stream and plan accordingly. * * Queued data is not converted until it is consumed by * SDL_GetAudioStreamData, so this value should be representative of the exact @@ -878,7 +879,7 @@ extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream) * clamped. * * \param stream The audio stream to query - * \returns the number of sample frames queued. + * \returns the number of bytes queued. * * \threadsafety It is safe to call this function from any thread. * diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index a5be406db..891a425c4 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -660,7 +660,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len) } if (retval == 0) { - stream->total_frames_queued += len / SDL_AUDIO_FRAMESIZE(stream->src_spec); + stream->total_bytes_queued += len; if (stream->put_callback) { const int newavail = SDL_GetAudioStreamAvailable(stream) - prev_available; stream->put_callback(stream->put_callback_userdata, stream, newavail, newavail); @@ -863,7 +863,7 @@ static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int ou SDL_assert(!"Not enough data in queue (read)"); } - stream->total_frames_queued -= output_frames; + stream->total_bytes_queued -= input_bytes; // Even if we aren't currently resampling, we always need to update the history buffer UpdateAudioStreamHistoryBuffer(stream, input_buffer, input_bytes, NULL, 0); @@ -953,7 +953,7 @@ static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int ou if (SDL_ReadFromAudioQueue(stream->queue, input_buffer, input_bytes) != 0) { SDL_assert(!"Not enough data in queue (resample read)"); } - stream->total_frames_queued -= input_frames; + stream->total_bytes_queued -= input_bytes; // Update the history buffer and fill in the left padding UpdateAudioStreamHistoryBuffer(stream, input_buffer, input_bytes, left_padding, padding_bytes); @@ -1124,7 +1124,7 @@ int SDL_GetAudioStreamQueued(SDL_AudioStream *stream) } SDL_LockMutex(stream->lock); - const Uint64 total = stream->total_frames_queued; + const Uint64 total = stream->total_bytes_queued; SDL_UnlockMutex(stream->lock); // if this overflows an int, just clamp it to a maximum. @@ -1142,7 +1142,7 @@ int SDL_ClearAudioStream(SDL_AudioStream *stream) SDL_ClearAudioQueue(stream->queue); SDL_zero(stream->input_spec); stream->resample_offset = 0; - stream->total_frames_queued = 0; + stream->total_bytes_queued = 0; SDL_UnlockMutex(stream->lock); return 0; diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 980dbc565..e0d931606 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -179,7 +179,7 @@ struct SDL_AudioStream float freq_ratio; struct SDL_AudioQueue* queue; - Uint64 total_frames_queued; + Uint64 total_bytes_queued; SDL_AudioSpec input_spec; // The spec of input data currently being processed Sint64 resample_offset;