3 ms·
For audio DSP in a Qt app I have good success with using a lock-free queue (e.g. https://github.com/cameron314/readerwriterqueue https://github.com/cameron314/r
by jcelerier 5y ago
For audio DSP in a Qt app I have good success with using a lock-free queue (e.g. https://github.com/cameron314/readerwriterqueue https://github.com/cameron314/readerwriterqueue) to communicate from / to the UI threads. Code more-or-less looks like
connect(model, &ModelObject::somethingChanged, [=] {
// knead the data structures used for the UI-side data model into something much simpler
// used for the audio engine
audioQueue.push([... data ...] { update the engine with the new data });
});
and conversely from the engine to the UI thread ; Qt signals do not cut it as emitting them allocate, if only a few bytes. (Doing it naively with std::function doesn't cut it either - I use this instead to store these functions: https://github.com/jcelerier/smallfunction/blob/master/smallfun/include/smallfun.hpp https://github.com/jcelerier/smallfunction/blob/master/small... ; also, the audio threads feeds back those functions into the main thread after their execution so that any memory owned by the lambda ends up being freed here and not in the audio thread.)