-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
I've been having trouble with programs built using SDL 2.30, where the authors are still on 2.0.20 or some other 2.0 version. Building with their version of SDL (whatever it may be), I am able to build their programs and run them without any sound issues. However, regardless of whether I build SDL from source or get SDL from a package manager (like pacman), their programs produce an incessant clicking sound. After some trial and error, I found that I can get the absolute most basic program to produce this clicking sound when using SDL 2.30, while using SDL 2.0.20 or other versions that the authors are using does not produce this issue for this example program:
#include <SDL.h>
SDL_AudioSpec audio_spec;
void audio_callback(void *userdata, Uint8 *stream, int len) {
// Fill the audio stream with silence
memset(stream, audio_spec.silence, len);
}
int main() {
// Initialize SDL
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
// Handle initialization error
return -1;
}
// Set the audio format (8khz 8-bit mono)
audio_spec.freq = 8000;
audio_spec.format = AUDIO_S8;
audio_spec.channels = 1;
audio_spec.samples = 1024;
audio_spec.callback = audio_callback;
// Open the audio device
if (SDL_OpenAudio(&audio_spec, NULL) < 0) {
// Handle audio device opening error
return -1;
}
// Start playing audio
SDL_PauseAudio(0);
// Wait for some time (or perform other tasks)
SDL_Delay(5000); // Wait for 5 seconds
// Pause audio playback
SDL_PauseAudio(1);
// Close the audio device and quit SDL
SDL_CloseAudio();
SDL_Quit();
return 0;
}
Here are some notes on testing:
- This bug occurs on 3 different computers (though they are all running some form of arch linux)
- The bug occurs whether I use the package or build from source
- Using
AUDIO_S16SYS
or other formats does not produce a clicking sound - Changing the
samples
changes how frequently the clicks occur (greatersamples
= less frequent) - Changing the
freq
changes how frequently the clicks occur and the pitch of the click (higherfreq
= more frequent + higher pitch, 44100 makes the clicks inaudible on my sound hardware (or just to my decayed ears)) - Both overfilling or underfilling the buffer produce the same issue
- Filing the buffer with actual sound will indeed play the sounds, but the clicking still persists over it all.
I can provide more information as needed. I'm aware this may be an arch-specific issue with some dependent library, but I get the feeling it has something to do with the timing of the callback (perhaps it's not firing fast enough? IDK, I'm not familiar with this stuff, sorry)