codesimian
Class CDQ

java.lang.Object
  extended by codesimian.CDQ
All Implemented Interfaces:
ContinuousDQueue

public class CDQ
extends java.lang.Object
implements ContinuousDQueue

the default continuous double queue. Add pairs of size and value. Remove any size (range 0 (exclusive) to total size (inclusive)) and get a weighted sum of the values at that range.

This is useful for asynchronous floating-point streams that must communicate, like microphone and speaker buffers.

WARNING: this class is implemented as a linked list of pairs of double, so its inefficient. It would be much faster to use 1 double[] array with 2 indexs per sample. But the linked list should be fast enough for audio.


Nested Class Summary
static class CDQ.Doubles
          its inefficient (but easy to code) to use a class for each data point instead of 2 array indexs
 
Constructor Summary
CDQ()
           
 
Method Summary
 void cdqAdd(double value, double size)
          increases cdqSize()
 double cdqRemove(double size)
          size <= cdqSize().
 double cdqSize()
          how many doubles in this micQueue
static void main(java.lang.String[] s)
          tests this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CDQ

public CDQ()
Method Detail

cdqAdd

public void cdqAdd(double value,
                   double size)
Description copied from interface: ContinuousDQueue
increases cdqSize()

Specified by:
cdqAdd in interface ContinuousDQueue

cdqRemove

public double cdqRemove(double size)
Description copied from interface: ContinuousDQueue
size <= cdqSize(). Removes the range 0 to size, decreasing cdqSize(), and returns the average value in that range.

Specified by:
cdqRemove in interface ContinuousDQueue

cdqSize

public double cdqSize()
Description copied from interface: ContinuousDQueue
how many doubles in this micQueue

Specified by:
cdqSize in interface ContinuousDQueue

main

public static void main(java.lang.String[] s)
tests this class. prints to standard-out. It should print exeption every time size tries to become negative. The values should oscillate in a sine wave between -1 and 1, and the sizes average 1.0 and range from 0.0 to 10.0. But the last value should be approximately 1000. You should not see more than a few consecutive equal numbers.