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_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_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 bool InitBuffer(int queueSamples = -1, int bufferSamples = -1) { try { if (Queue == null || Queue.Samplerate != Samplerate || (queueSamples >= 0 && Queue.Capacity < queueSamples)) { Queue = new SignalRingBuffer(queueSamples < 0 ? GlobalSettings.Instance.RingBufferSize(Samplerate) : queueSamples, Samplerate); } if (Buffer == null || Buffer.Samplerate != Samplerate || (bufferSamples >= 0 && Buffer.Length < bufferSamples)) { Buffer = TimeLocatedBuffer.Default(Samplerate); } return(true); } catch (Exception e) { GlobalSettings.Instance.Errors.Add(new Error($"InitBuffer of {Parent.Name}: {e}")); return(false); } }
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); }
internal void LoadBuffer(SignalRingBuffer buf) { Queue.LoadState(buf); }
public void InitBuffer() { Queue = new SignalRingBuffer(GlobalSettings.Instance.RingBufferSize(_samplerate), _samplerate); }