I am working on an audio processing tool that I would like to build using TPL Dataflow.
The Data flow itself will consist of audio samples being passed between sound processing blocks. Those samples will typically be a few Kb in size (float[]
/byte[]
with 1k to 4k elements).
The data flow is thus a simple pipeline which looks like this:
SourceBlock<byte[]>
-> TransformBlock<byte[], float[]>
-> TransformBlock<float[], float[]>
-> ...
Some of the blocks can work purely "in place", ie by mutating the input data, while other have to create new samples. The processing time of each block can vary depending on the data in input.
I don't want to allocate new arrays all the time and rely on the garbage collector to take care of object recycling. I want to benefit from concurrent execution of the blocks and thus don't want to restrict the chain to process data sequentially (in which case I wouldn't need TPL anyway). I don't need processing blocks to run concurrent processing (I am fine with at most one process per block at any given time).
What would be the best scheme to control the number of samples in the pipeline at a given time and recycle samples/arrays no longer used ?