This is probably a very basic question, but I’m struggling with it. I’m trying to generate audio data in code - not load from a file. I want to generate stereo. So I create an audio stream that has 2 channels in the SDL_AudioSpec. I then put samples into it with SDL_PutAudioStreamData, but it doesn’t seem to work right.
I’m assuming the samples are interleaved, so I need to put in one left channel sample, then one right channel sample, then back to left channel. Or is it something else?
My code for putting a single stereo sample is something like this:
uint8_t buff[2] = { 0xFF,0 };
result = SDL_PutAudioStreamData(stream, buf, 2);
(the stream is set up with format SDL_AUDIO_U8 and 2 channels)
If I repeat this infinitely, I expect to hear a tone in one ear, but silence in the other. Instead, I hear a “buzz” in both ears, symmetrically.
I was initially working with a stream with 1 channel, and just feeding it single-byte samples, and that was working correctly - I got the results I expected. But 2 channels seems to break it for me…
So what am I doing wrong here? My guess is that I’m misinterpreting how to feed samples to the stream, but I’ve not been able to find any examples of how to do this. The SDL examples only show how to generate samples for a single channel, and most everything else I found is about playing various files.
This is in C++ and SDL3.