示例#1
0
        public void TestClear()
        {
            RingBuffer <float> rbf = new RingBuffer <float>(3);

            Assert.IsTrue(rbf.IsEmpty);
            Assert.IsFalse(rbf.IsFull);

            Assert.IsTrue(rbf.Enqueue(1.5f));
            Assert.IsTrue(rbf.Enqueue(2.5f));
            Assert.IsTrue(rbf.Enqueue(3.5f));

            Assert.IsFalse(rbf.IsEmpty);
            Assert.IsTrue(rbf.IsFull);
            Assert.AreEqual(3, rbf.Count);

            rbf.Clear();

            Assert.IsTrue(rbf.IsEmpty);
            Assert.IsFalse(rbf.IsFull);
            Assert.AreEqual(0, rbf.Count);
        }
示例#2
0
            public void SetSampleRates(decimal fps, int hz)
            {
                if (m_FPS == fps && m_sampleRate == hz)
                {
                    return;
                }

                // If either fps or hz changed, we must reallocate these buffers.
                m_scratch = new float[(int)(hz / fps)];
                m_stereo  = new float[(int)(hz / fps * 2)];

                // Here only hz matters.
                if (hz != m_sampleRate)
                {
                    m_leftChannel  = new RingBuffer <float>(hz * kSizeInSeconds);
                    m_rightChannel = new RingBuffer <float>(hz * kSizeInSeconds);
                }

                m_FPS        = fps;
                m_sampleRate = hz;
            }
示例#3
0
        public void TestCopyFromWrapped()
        {
            RingBuffer <float> r1 = new RingBuffer <float>(3);
            RingBuffer <float> r2 = new RingBuffer <float>(10);
            RingBuffer <float> r3 = new RingBuffer <float>(1);

            Assert.IsTrue(r1.Enqueue(1.5f, true));
            Assert.IsTrue(r1.Enqueue(2.5f, true));
            Assert.IsTrue(r1.Enqueue(3.5f, true));
            Assert.IsTrue(r1.Enqueue(4.5f, true));
            Assert.IsTrue(r1.Enqueue(5.5f, true));
            Assert.IsTrue(r1.Enqueue(6.5f, true));
            Assert.IsTrue(r1.Enqueue(7.5f, true));
            Assert.IsTrue(r1.Enqueue(8.5f, true));

            r2.CopyFrom(r1);
            r3.CopyFrom(r2);

            Assert.AreEqual(r1.IsFull, r2.IsFull);
            Assert.AreEqual(r1.IsEmpty, r2.IsEmpty);
            Assert.AreEqual(r1[0], r2[0]);
            Assert.AreEqual(r1[1], r2[1]);
            Assert.AreEqual(r1[2], r2[2]);

            Assert.AreEqual(r3.IsFull, r2.IsFull);
            Assert.AreEqual(r3.IsEmpty, r2.IsEmpty);
            Assert.AreEqual(r3[0], r2[0]);
            Assert.AreEqual(r3[1], r2[1]);
            Assert.AreEqual(r3[2], r2[2]);

            r2.Clear();

            Assert.AreEqual(r3.IsFull, r1.IsFull);
            Assert.AreEqual(r3.IsEmpty, r1.IsEmpty);
            Assert.AreEqual(r3[0], r1[0]);
            Assert.AreEqual(r3[1], r1[1]);
            Assert.AreEqual(r3[2], r1[2]);
        }
示例#4
0
        public void TestGetRange()
        {
            RingBuffer <float> r1 = new RingBuffer <float>(3);

            Assert.IsTrue(r1.Enqueue(4.5f));
            Assert.IsTrue(r1.Enqueue(1.5f));
            Assert.IsTrue(r1.Enqueue(2.5f));
            Assert.IsTrue(r1.Enqueue(3.5f, true));

            float[] v1 = new float[1];
            r1.GetRange(ref v1);
            Assert.AreEqual(1.5f, v1[0]);

            float[] v2 = new float[2];
            r1.GetRange(ref v2);
            Assert.AreEqual(1.5f, v2[0]);
            Assert.AreEqual(2.5f, v2[1]);

            float[] v3 = new float[3];
            r1.GetRange(ref v3);
            Assert.AreEqual(1.5f, v3[0]);
            Assert.AreEqual(2.5f, v3[1]);
            Assert.AreEqual(3.5f, v3[2]);

            r1.GetRange(ref v2, 1, 2);
            Assert.AreEqual(2.5f, v2[0]);
            Assert.AreEqual(3.5f, v2[1]);

            r1.GetRange(ref v1, 1, 1);
            Assert.AreEqual(2.5f, v1[0]);

            r1.GetRange(ref v1, 2, 1);
            Assert.AreEqual(3.5f, v1[0]);

            r1.GetRange(ref v1, 0, 1);
            Assert.AreEqual(1.5f, v1[0]);
        }
示例#5
0
        public void TestEnumerators()
        {
            RingBuffer <float> r1 = new RingBuffer <float>(3);

            Assert.IsTrue(r1.Enqueue(4.5f));
            Assert.IsTrue(r1.Enqueue(1.5f));
            Assert.IsTrue(r1.Enqueue(2.5f));
            Assert.IsTrue(r1.Enqueue(3.5f, true));

            using (var e1 = r1.GetEnumerator()) {
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }

            using (var e1 = r1.GetEnumerator(0, 3)) {
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }

            using (var e1 = r1.GetEnumerator(1, 2)) {
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsTrue(e1.MoveNext());
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }

            using (var e1 = r1.GetEnumerator(2, 1)) {
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(3.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }

            using (var e1 = r1.GetEnumerator(1, 1)) {
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(2.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }

            using (var e1 = r1.GetEnumerator(0, 1)) {
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
                e1.Reset();
                Assert.AreEqual(1.5, e1.Current);
                Assert.IsFalse(e1.MoveNext());
            }
        }
示例#6
0
 public void Dispose()
 {
     m_owner = null;
 }