Пример #1
0
        public void TestLimitedBufferingStream()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float[] tempBuffer = AllocateSmall4FloatArray(20, sliverSize);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, 5);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-7, tempBuffer), 0, 11, sliverSize));
            HoloDebug.Assert(stream.DiscreteDuration == 5);
            Slice<Sample, float> slice = stream.GetNextSliceAt(stream.DiscreteInterval);
            HoloDebug.Assert(slice[0, 0] == 6f);

            stream.Append(new Slice<Sample, float>(new Buf<float>(-8, tempBuffer), 11, 5, sliverSize));
            HoloDebug.Assert(stream.DiscreteDuration == 5);
            HoloDebug.Assert(stream.InitialTime == 11);
            slice = stream.GetNextSliceAt(stream.DiscreteInterval);
            HoloDebug.Assert(slice[0, 0] == 11f);
        }
Пример #2
0
 static float Verify4SliceFloatStream(DenseSampleFloatStream stream, float f)
 {
     Interval<Sample> interval = stream.DiscreteInterval;
     while (!interval.IsEmpty) {
         Slice<Sample, float> nextSlice = stream.GetNextSliceAt(interval);
         for (int i = 0; i < (int)nextSlice.Duration; i++) {
             HoloDebug.Assert(nextSlice[i, 0] == f);
             HoloDebug.Assert(nextSlice[i, 1] == f + 0.25f);
             HoloDebug.Assert(nextSlice[i, 2] == f + 0.5f);
             HoloDebug.Assert(nextSlice[i, 3] == f + 0.75f);
             f++;
         }
         interval = interval.SubintervalStartingAt(nextSlice.Duration);
     }
     return f;
 }
Пример #3
0
        public void TestStreamShutting()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float continuousDuration = 2.4f;
            int discreteDuration = (int)Math.Round(continuousDuration + 1);
            float[] buffer = AllocateSmall4FloatArray(discreteDuration, sliverSize);
            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, useContinuousLoopingMapper: true);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-5, buffer), sliverSize));

            // OK, time to get this fractional business right.
            stream.Shut((ContinuousDuration)continuousDuration);
            HoloDebug.Assert(stream.IsShut);

            // now test looping
            Interval<Sample> interval = new Interval<Sample>(0, 10);
            // we expect this to be [0, 1, 2, 0, 1, 0, 1, 2, 0, 1]
            // or rather, [0>3], [0>2], [0>3], [0>2]
            Slice<Sample, float> slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 2);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 2);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            HoloDebug.Assert(interval.IsEmpty);

            DenseSampleFloatStream stream2 = new DenseSampleFloatStream(0, bufferAllocator, sliverSize, useContinuousLoopingMapper: false);
            stream2.Append(new Slice<Sample, float>(new Buf<float>(-5, buffer), sliverSize));
            stream2.Shut((ContinuousDuration)continuousDuration);
            interval = new Interval<Sample>(0, 10);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[1, 0] == 1f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 3);
            HoloDebug.Assert(slice[0, 0] == 0f);
            HoloDebug.Assert(slice[2, 0] == 2f);

            interval = interval.SubintervalStartingAt(slice.Duration);
            slice = stream2.GetNextSliceAt(interval);
            HoloDebug.Assert(slice.Duration == 1);
            HoloDebug.Assert(slice[0, 0] == 0f);
        }
Пример #4
0
        public void TestStreamSlicing()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

            float[] buffer = AllocateSmall4FloatArray(floatNumSlices * 2, sliverSize);

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            stream.Append(new Slice<Sample, float>(new Buf<float>(-4, buffer), sliverSize));

            // test getting slices from existing stream
            Slice<Sample, float> beforeFirst = stream.GetNextSliceAt(new Interval<Sample>((-2), 4));
            // should return slice with duration 2
            HoloDebug.Assert(beforeFirst.Duration == 2);

            Slice<Sample, float> afterLast = stream.GetNextSliceAt(new Interval<Sample>(19, 5));
            HoloDebug.Assert(afterLast.Duration == 3);

            // now get slice across the buffer boundary, verify it is split as expected
            Interval<Sample> splitInterval = new Interval<Sample>(7, 8);
            Slice<Sample, float> beforeSplit = stream.GetNextSliceAt(splitInterval);
            HoloDebug.Assert(beforeSplit.Duration == 4);

            Slice<Sample, float> afterSplit = stream.GetNextSliceAt(splitInterval.SubintervalStartingAt(beforeSplit.Duration));
            HoloDebug.Assert(afterSplit.Duration == beforeSplit.Duration);
            float lastBefore = beforeSplit[3, 0];
            float firstAfter = afterSplit[0, 0];
            HoloDebug.Assert(lastBefore + 1 == firstAfter);

            float[] testStrideCopy = new float[] {
                0, 0, 1, 1, 0, 0,
                0, 0, 2, 2, 0, 0,
            };

            stream.AppendSliver(testStrideCopy, 2, 2, 6, 2);

            Slice<Sample, float> lastSliver = stream.GetNextSliceAt(new Interval<Sample>(22, 1));
            HoloDebug.Assert(lastSliver.Duration == 1);
            HoloDebug.Assert(lastSliver[0, 0] == 1f);
            HoloDebug.Assert(lastSliver[0, 1] == 1f);
            HoloDebug.Assert(lastSliver[0, 2] == 2f);
            HoloDebug.Assert(lastSliver[0, 3] == 2f);

            Slice<Sample, float> firstSlice = stream.GetNextSliceAt(new Interval<Sample>(-2, 100));
            HoloDebug.Assert(firstSlice.Duration == 11);
        }
Пример #5
0
        public void TestStream()
        {
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(FloatNumSlices * 2048, 1, sizeof(float));

            DenseSampleFloatStream stream = new DenseSampleFloatStream(0, bufferAllocator, FloatSliverSize);

            HoloDebug.Assert(stream.DiscreteDuration == 0);

            var interval = new Interval<Sample>(0, 10);
            Slice<Sample, float> firstSlice = stream.GetNextSliceAt(interval);
            HoloDebug.Assert(firstSlice.IsEmpty());

            // Now let's fill a float array...
            float[] buffer = new float[FloatNumSlices * FloatSliverSize];
            Duration<Sample> floatNumSlicesDuration = FloatNumSlices;
            Slice<Sample, float> tempSlice = new Slice<Sample, float>(new Buf<float>(-1, buffer), FloatSliverSize);
            PopulateFloatSlice(tempSlice);

            // now append in chunks
            stream.Append(tempSlice.SubsliceOfDuration(tempSlice.Duration / 2));
            stream.Append(tempSlice.SubsliceStartingAt(tempSlice.Duration / 2));

            HoloDebug.Assert(stream.InitialTime == 0);
            HoloDebug.Assert(stream.DiscreteDuration == FloatNumSlices);

            Slice<Sample, float> theSlice = stream.GetNextSliceAt(stream.DiscreteInterval);

            VerifySlice(theSlice);
            HoloDebug.Assert(theSlice.Duration == floatNumSlicesDuration);
        }