I'm writing an old-school game engine in C and SDL2. I'm designing the audio portion now. Instead of playing .wav samples and the like for sound, I want to implement a sound generator, kind of like a SID chip in software (if you're familiar with the Commodore 64).
Here is my initialization code for setting up the sound device:
void initialize_audio(void) {
SDL_AudioSpec want, have;
SDL_memset(&want, 0, sizeof(want)); //initializes the 'want' struct
want.freq = 44100;
want.format = AUDIO_U8; // 8-bit sound
want.channels = 1; // 1 = mono, 2 = stereo
want.samples = 2048; // how to decide on this? must be power of 2
want.callback = my_callback_function;
// capture global audio_device_id here
audio_device_id = SDL_OpenAudioDevice(
NULL, // choose best device based on 'want' struct
0, // want a playback device, not a recording device
&want,
&have,
SDL_AUDIO_ALLOW_FORMAT_CHANGE);
}
My question is (or what I need help with): I'm not sure what to ask for in terms of the buffer size in the audio device (the 'samples' parameter). I know this will effect how often SDL calls my callback function to feed more audio data into the sound device's buffer.
My guess is to keep it as small as a number as I can afford to do. The smaller the number here, the more frequently the callback function gets called, but I'm not sure what benefit this would give me.