public void enqueue_dequeue() { var rate = 1000; var bufferWrite = new TimeLocatedBuffer(300, rate); var bufferRead = new TimeLocatedBuffer(300, rate); var queue = new SignalRingBuffer(1000, rate) { SizeFixed = false }; var samples = bufferWrite.GetSamples(); for (int i = 0; i < samples.Length; i++) { samples[i] = i; } bufferWrite.SetWritten(samples.Length); queue.Enqueue(bufferWrite); Assert.AreEqual(bufferWrite.WrittenSamples, bufferWrite.Length); Assert.AreEqual(queue.Length, bufferWrite.WrittenSamples); queue.Dequeue(bufferRead); Assert.AreEqual(bufferRead.WrittenSamples, bufferWrite.WrittenSamples); }
public void enqueue_overflow_skip_data2() { var rate = 1000000; var bufferWrite = new TimeLocatedBuffer(rate / 10, rate); var bufferRead = new TimeLocatedBuffer(rate / 10, rate); var queue = new SignalRingBuffer(rate, rate) { SizeFixed = true, IgnoreOverflow = true }; var samples = bufferWrite.GetSamples(); for (int i = 0; i < samples.Length; i++) { samples[i] = i; } for (int i = 0; i < 12; i++) { bufferWrite.SetWritten(samples.Length); queue.Enqueue(bufferWrite); } Assert.AreEqual(queue.Length, queue.Capacity); }
public void enqueue_overflow_skip_data() { var rate = 1000; var bufferWrite = new TimeLocatedBuffer(300, rate); var bufferRead = new TimeLocatedBuffer(300, rate); var queue = new SignalRingBuffer(1000, rate) { SizeFixed = true }; var samples = bufferWrite.GetSamples(); for (int i = 0; i < samples.Length; i++) { samples[i] = i; } bufferWrite.SetWritten(samples.Length); queue.Enqueue(bufferWrite); queue.Enqueue(bufferWrite); queue.Enqueue(bufferWrite); queue.Enqueue(bufferWrite); var queueSizeShouldBe = queue.Capacity; Assert.AreEqual(queueSizeShouldBe, queue.Length); queue.Dequeue(bufferRead); samples = bufferRead.GetSamples(); for (int i = 0; i < samples.Length; i++) { Assert.AreEqual(samples[i], (200 + i) % 300); } queue.Dequeue(bufferRead); samples = bufferRead.GetSamples(); for (int i = 0; i < samples.Length; i++) { Assert.AreEqual(samples[i], (500 + i) % 300); } }
public void RecieveData(TimeLocatedBuffer buf) { if (buf.Length % (_fftSize / 2) != 0) { throw new FFTDataLengthException(); } if (Queue.Length + buf.WrittenSamples >= Queue.Capacity) { GlobalSettings.Instance.Errors.Add(new Error("Data Input: Buffer full. Data loss. Stopping")); GlobalSettings.Instance.StopProcessing(true); } else { Queue.Enqueue(buf); DataAvailable?.Invoke(this, Queue.Length); } }
public void enqueue_exact() { var rate = 1000; var bufferWrite = new TimeLocatedBuffer(1000, rate); var queue = new SignalRingBuffer(1000, rate) { SizeFixed = true }; var samples = bufferWrite.GetSamples(); for (int i = 0; i < samples.Length; i++) { samples[i] = i; } bufferWrite.SetWritten(samples.Length); queue.Enqueue(bufferWrite); Assert.AreEqual(bufferWrite.WrittenSamples, queue.Length); Assert.AreEqual(queue.Length, queue.Capacity); }