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
A synth without threads
Moderators: MattKingUSA, khz
-
- Established Member
- Posts: 2347
- Joined: Mon Jul 01, 2013 8:13 am
- Has thanked: 9 times
- Been thanked: 466 times
Re: A synth without threads
That only work when you are the only one. as soon the PC get some work to do, it explode.
And, usual there is one thread for audio/midi, one for the GUI and one worker thread (were you call read or such stuff).
On most modern PC's that will leave at least one Core untouched for other stuff to do.
The question which remain is: why would you do that all in one thread? What advance should it have?
And, usual there is one thread for audio/midi, one for the GUI and one worker thread (were you call read or such stuff).
On most modern PC's that will leave at least one Core untouched for other stuff to do.
The question which remain is: why would you do that all in one thread? What advance should it have?
On the road again.
Re: A synth without threads
The first motivation for single-threading was: simpler code. No mutexes, no synchronisation, everything predictable. The fact that such a small audio buffer was possible came as an extra bonus.
I think that a real GUI can operate also in this setup. In my projects the GUI always runs in the main thread. I posted this question to investigate whether I was inventing the wheel again, or not.
Wouter Boeke
I think that a real GUI can operate also in this setup. In my projects the GUI always runs in the main thread. I posted this question to investigate whether I was inventing the wheel again, or not.
Wouter Boeke
-
- Established Member
- Posts: 2347
- Joined: Mon Jul 01, 2013 8:13 am
- Has thanked: 9 times
- Been thanked: 466 times
Re: A synth without threads
So you are doing plain ALSA, I guess.wboe wrote: ↑Sat Dec 05, 2020 5:50 pm The first motivation for single-threading was: simpler code. No mutexes, no synchronisation, everything predictable. The fact that such a small audio buffer was possible came as an extra bonus.
I think that a real GUI can operate also in this setup. In my projects the GUI always runs in the main thread. I posted this question to investigate whether I was inventing the wheel again, or not.
Wouter Boeke
As I said, as long you are alone, your approve may work, but, there is a reason why open-mp was developed, and why developers prefer a multi threading approve.
Keep in mind, development is not about code, it is about data and it's handing.
On the road again.