|
|
|
|
|
by saltcured
2562 days ago
|
|
Something like a filter chain for an audio stream is truly the textbook candidate for pipelined concurrency. Conceptually, there are no events or conditional branching. Just a methodical iteration over input samples, in order, producing output samples also in order. Whatever you can calculate sequentially like: while True:
buf0 = input.recv()
buf1 = filter1(buf0)
buf2 = filter2(buf1)
buf3 = filter3(buf2)
output.send(buf3)
can instead be written as a set of concurrent worker loops.Each worker is dedicated to running a specific filter function, so its internal state remains local to that one worker. Only the intermediate sample buffers get relayed between the workers, usually via a low-latency asynchronous queue or similar data structure. If a particular filter function is a little slow, the next stage will simply block on its input receive step until the slow stage can perform the send. (Edited to try to fix pseudo code block) |
|