A synth without threads
Posted: Sat Dec 05, 2020 4:21 pm
Hi,
Has somebody ever tried to make a synth (or some other instrument) without using threads? Usually there is at least one thread for the audio and one e.g. for the midi keyboard.
I tied to do it in a single-threaded program, and it worked. The audio buffer that was needed in normal threaded programs is 512 frames (on my Linux box, no RT, sample rate 44100 Hz), but now it appeared that 128 frames was enough. That's a very low latency.
The trick is to use sytem call read(), with parameter O_RDONLY | O_NONBLOCK. The audio loop is blocking on Alsa function snd_pcm_writei().
This should be a well-known design method, but I never saw it yet.
Wouter Boeke
Has somebody ever tried to make a synth (or some other instrument) without using threads? Usually there is at least one thread for the audio and one e.g. for the midi keyboard.
I tied to do it in a single-threaded program, and it worked. The audio buffer that was needed in normal threaded programs is 512 frames (on my Linux box, no RT, sample rate 44100 Hz), but now it appeared that 128 frames was enough. That's a very low latency.
The trick is to use sytem call read(), with parameter O_RDONLY | O_NONBLOCK. The audio loop is blocking on Alsa function snd_pcm_writei().
This should be a well-known design method, but I never saw it yet.
Wouter Boeke