Audio input and output together?

Hey there!

I am trying to add SDL2 as an audio backend to my toy ANSI C framework… currently I have Jack support set up in a way I am familiar with: one callback, with access to input and output buffers.

I have successfully set up either input or output callbacks in SDL2, but I’m not sure what the proper way to have a combined one (or even just parallel input and output buffers safely in one scope would be :frowning:

I’ve experimented with using the dequeue API to pull input bytes within the output callback… it seemed to work but doesn’t feel very ideomatic to say the least!

Would very much appreciate some advice from anyone who has succesfully implemented an input > process > output audio program in SDL2!


It wouldn’t be unreasonable to skip both callbacks and use the audio queue feature on both ends in a loop. Whenever SDL_DequeueAudio() gives you more data from a capture device, process it and then SDL_QueueAudio() your processed results on an output device.

This also has the benefit of keeping all your efforts in a single thread that you can control in a tight loop, regardless of what SDL is doing behind the scenes, so it’s less mental acrobatics necessary for you.



Thanks Ryan thats a great suggestion! I guess that’s the sorta in-depth use-case those queue functions are provided for :slight_smile:

1 Like