View Single Post
Old 06-21-2015, 12:40 PM   #9
Human being with feelings
Tale's Avatar
Join Date: Jul 2008
Location: The Netherlands
Posts: 2,985

Well, I don't think your code does that, because a FIFO (first in first out) queue has a head (where you first started adding samples) and a tail (where you will add the next block of samples). If you "remove" samples from a FIFO queue, then you will have to either a) move your head pointer, or b) actually move elements within the queue. Your code seems to do neither.

Originally Posted by mviljamaa View Post
1. The host sends 63 samples, so add them to the input queue.
4. The host sends 63 samples, so add them to the input queue.
Here I mean add samples to the tail (end) of the queue.

Originally Posted by mviljamaa View Post
5. Process 64 samples (63 from step 1 + 1 from step 4), remove these from the input queue
8. Output 63 samples, and remove these from the output queue.
Here i mean remove a number of samples (but not all!) from the head (beginning) of the queue. This would require memmove() or similar to move elements within the queue (although a smart implementation might just update the queue head pointer, like with a circular buffer).

The reason you should use a queue, and you can't just use a normal circular buffer, is that the host might send you way more samples than your internal buffer can fit. Also, by the time that you are ready to output a large number of samples, the host might send you a very small number of samples, which means you can only output a small number of samples (and so you can't output all samples in the queue). Hence the input and output "buffers" should be totaly asynchronous (i.e. either can grow or shrink independently of the other, and of the also variable host buffer size).

Anyway, I would suggest replacing your internal input and output buffers with some sort of queue, e.g. WDL_Queue (#include "WDL/queue.h"), or perhaps std::queue. If you have trouble with the implementation, then I guess I could code you an example.
Martinic Kee Bass - Scanner Vibrato - Elka Panther - Tale's JSFX Pack

Last edited by Tale; 06-25-2015 at 04:35 PM. Reason: Fixed typos, meh.
Tale is offline   Reply With Quote