Пример #1
0
        public void TestStreamChunky()
        {
            const int sliverSize = 4; // 4 floats = 16 bytes
            const int floatNumSlices = 11; // 11 slices per buffer, to test various cases
            const int biggestChunk = 5; // max size of slice to copy in middle loop
            BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(sliverSize * floatNumSlices, 1, sizeof(float));

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

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

            float f = 0;
            float[] tinyBuffer = new float[biggestChunk * sliverSize];
            for (int i = 0; i < 100; i++) {
                for (int c = 1; c <= 5; c++) {
                    for (int j = 0; j < c; j++) {
                        tinyBuffer[j * sliverSize] = f;
                        tinyBuffer[j * sliverSize + 1] = f + 0.25f;
                        tinyBuffer[j * sliverSize + 2] = f + 0.5f;
                        tinyBuffer[j * sliverSize + 3] = f + 0.75f;
                        f++;
                    }
                    Slice<Sample, float> tempSlice = new Slice<Sample, float>(
                        new Buf<float>(-2, tinyBuffer), 0, c, sliverSize);
                    stream.Append(tempSlice);
                }
            }

            // Now after this we will need a verification loop.
            BufferAllocator<float> bigBufferAllocator = new BufferAllocator<float>(sliverSize * 1024, 1, sizeof(float));
            DenseSampleFloatStream bigStream = new DenseSampleFloatStream(0, bigBufferAllocator, sliverSize);

            stream.CopyTo(stream.DiscreteInterval, bigStream);

            HoloDebug.Assert(Verify4SliceFloatStream(stream, 0) == 1500);
            HoloDebug.Assert(Verify4SliceFloatStream(bigStream, 0) == 1500);

            DenseSampleFloatStream stream2 = new DenseSampleFloatStream(0, bufferAllocator, sliverSize);
            bigStream.CopyTo(bigStream.DiscreteInterval, stream2);

            HoloDebug.Assert(Verify4SliceFloatStream(stream2, 0) == 1500);
        }
Пример #2
0
        public void TestStreamAppending()
        {
            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, sliverSize);

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

            unsafe {
                fixed (float* f = buffer) {
                    IntPtr pf = new IntPtr(f);

                    stream.Append(floatNumSlices, pf);
                }
            }

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

            HoloDebug.Assert(Verify4SliceFloatStream(stream, 0) == 11);

            // clear original buffer to test copying back into it
            for (int i = 0; i < buffer.Length; i++) {
                buffer[i] = 0;
            }

            unsafe {
                fixed (float* f = buffer) {
                    IntPtr pf = new IntPtr(f);
                    stream.CopyTo(stream.DiscreteInterval, pf);
                }
            }

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

            HoloDebug.Assert(Verify4SliceFloatStream(stream2, 0) == 11);
        }