当前位置: 首页>>代码示例>>C#>>正文


C# Interval.SubintervalStartingAt方法代码示例

本文整理汇总了C#中Interval.SubintervalStartingAt方法的典型用法代码示例。如果您正苦于以下问题:C# Interval.SubintervalStartingAt方法的具体用法?C# Interval.SubintervalStartingAt怎么用?C# Interval.SubintervalStartingAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interval的用法示例。


在下文中一共展示了Interval.SubintervalStartingAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestStreamSlicing

        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);
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:47,代码来源:UnitTest1.cs

示例2: TestStreamShutting

        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);
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:72,代码来源:UnitTest1.cs


注:本文中的Interval.SubintervalStartingAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。