Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3 example '01-simple-playback': minimum_audio is calculated with input format instead of output format #12403

Closed
nathanvdh opened this issue Feb 26, 2025 · 1 comment
Assignees
Milestone

Comments

@nathanvdh
Copy link

nathanvdh commented Feb 26, 2025

I think this probably also applies to 03-load-wav and 04-multiple-streams.
SDL_GetAudioStreamAvailable() returns

the number of converted/resampled bytes available

that is: the number of bytes after resampling the input to destination/device format.

I expect this is typically not the same as the the generated input 8000hz, 32-bit float mono input. E.g. on my Ubuntu laptop with headphones plugged in its 44100Hz, S16, 2 channel. This example does a comparison that is not apples-to-apples:

    const int minimum_audio = (8000 * sizeof (float)) / 2;  /* 8000 float samples per second. Half of that. */
    if (SDL_GetAudioStreamAvailable(stream) < minimum_audio) {
    ...

I discovered this while doing some network streaming and playback, I kept getting data underflow and injected silence, because I thought my buffers were satisfied when they were not. minimum_audio should be calculated using the device format gotten via a SDL_GetAudioStreamFormat(stream, NULL, &dst_spec).

Edit: I've also just seen SDL_GetAudioStreamQueued(), which returns the amount of queued input data, so that could be used too, instead of SDL_GetAudioStreamAvailable().

@slouken slouken added this to the 3.2.6 milestone Feb 26, 2025
@icculus
Copy link
Collaborator

icculus commented Feb 27, 2025

I was just coming in to say the real bug is we should be using SDL_GetAudioStreamQueued, but I see from your edit that you realized this, too. :)

I'm fixing this up real quick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants