=====================================================
| Buffering Technique used in DSEnc by Dark Avenger |
-----------------------------------------------------
|website: http://dsenc.freeyellow.com               |
|  email: aacleech@gmx.net                          |
-----------------------------------------------------

The naive way to do buffering is to make 6 read and one write buffers. Of course the write buffer has to be of double the size, since it is the one holding a stereo pcm whereas the other just hold mono pcms. It would look something like this:

ch0 ############## (left)
ch1 ############## (center)
ch2 ############## (right)
ch3 ############## (rearleft)
ch4 ############## (rearright)
ch5 ############## (LFE)

out ----------------------------

Since I want to put the reads and writes into a separate thread so that the programme can compute and transfer data to/from HD at the same time, a problem arises here. All buffers will be empty/full the same time, so all the transfers will be done at the same time and the programme cannot compute anymore since there is no computable data in memory.

So the next step was to divide the original buffer into two chunks so that while one chunk is processed the next one can be filled/emptied:

ch0 ####### ####### (left)
ch1 ####### ####### (center)
ch2 ####### ####### (right)
ch3 ####### ####### (rearleft)
ch4 ####### ####### (rearright)
ch5 ####### ####### (LFE)

out -------------- --------------

Here again arises the problem that all chunks will be empty/full at the same time, so I initally fill the buffers to different amounts. The difference is 1/7 chunk size:

ch0 ------# ####### (left)
ch1 -----## ####### (center)
ch2 ----### ####### (right)
ch3 ---#### ####### (rearleft)
ch4 --##### ####### (rearright)
ch5 -###### ####### (LFE)

out -------------- --------------

After processing e.g. 3/7 chunks it looks like this:

ch0 ####### --##### (left)
ch1 ####### -###### (center)
ch2 ------- ####### (right)     <- read demand on first chunk!
ch3 ------# ####### (rearleft)
ch4 -----## ####### (rearright)
ch5 ----### ####### (LFE)

out ######-------- --------------



So now after every 1/7 chunk processing only one read (write) command appears, when one chunk will be filled/emptied. I think it is a somewhat efficient buffer management, at least my multi-threaded version of DSEnc seems to be quite fast. This is the buffering technique I used in DSEnc V1.

The new buffering technique will be explained soon.