示例#1
0
        protected static void ImplSquare(ulong[] x, ulong[] zz)
        {
            Interleave.Expand64To128(x[0], zz, 0);
            Interleave.Expand64To128(x[1], zz, 2);
            Interleave.Expand64To128(x[2], zz, 4);

            ulong x3 = x[3];

            zz[6] = Interleave.Expand32to64((uint)x3);
            zz[7] = Interleave.Expand16to32((uint)(x3 >> 32));
        }
示例#2
0
 protected static void ImplSquare(ulong[] x, ulong[] zz)
 {
     Interleave.Expand64To128(x[0], zz, 0);
     Interleave.Expand64To128(x[1], zz, 2);
     Interleave.Expand64To128(x[2], zz, 4);
     Interleave.Expand64To128(x[3], zz, 6);
     Interleave.Expand64To128(x[4], zz, 8);
     Interleave.Expand64To128(x[5], zz, 10);
     Interleave.Expand64To128(x[6], zz, 12);
     Interleave.Expand64To128(x[7], zz, 14);
     Interleave.Expand64To128(x[8], zz, 16);
 }
示例#3
0
文件: Wander.cs 项目: yingted/Myro
        protected override void Start()
        {
            // Listen on the main port for requests and call the appropriate handler.
            Interleave mainInterleave = ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            SubscribeToBumperSensors();
        }
示例#4
0
    public static void Sqrt(ulong[] x, ulong[] z)
    {
        ulong num  = Interleave.Unshuffle(x[0]);
        ulong num2 = Interleave.Unshuffle(x[1]);
        ulong num3 = (num & uint.MaxValue) | (num2 << 32);
        ulong num4 = (ulong)((long)(num >> 32) | ((long)num2 & -4294967296L));

        num  = Interleave.Unshuffle(x[2]);
        num2 = Interleave.Unshuffle(x[3]);
        ulong num5 = (num & uint.MaxValue) | (num2 << 32);
        ulong num6 = (ulong)((long)(num >> 32) | ((long)num2 & -4294967296L));
        ulong num7 = num6 >> 49;
        ulong num8 = (num4 >> 49) | (num6 << 15);

        num6 ^= num4 << 15;
        ulong[] array  = Nat256.CreateExt64();
        int[]   array2 = new int[2]
        {
            39,
            120
        };
        ulong[] array3;
        for (int i = 0; i < array2.Length; i++)
        {
            int     num9   = array2[i] >> 6;
            int     num10  = array2[i] & 0x3F;
            ulong[] array4 = array3 = array;
            int     num11  = num9;
            IntPtr  intPtr = (IntPtr)num11;
            array4[num11] = (array3[(long)intPtr] ^ (num4 << num10));
            ulong[] array5 = array3 = array;
            int     num12  = num9 + 1;
            intPtr        = (IntPtr)num12;
            array5[num12] = (array3[(long)intPtr] ^ ((num6 << num10) | (num4 >> -num10)));
            ulong[] array6 = array3 = array;
            int     num13  = num9 + 2;
            intPtr        = (IntPtr)num13;
            array6[num13] = (array3[(long)intPtr] ^ ((num8 << num10) | (num6 >> -num10)));
            ulong[] array7 = array3 = array;
            int     num14  = num9 + 3;
            intPtr        = (IntPtr)num14;
            array7[num14] = (array3[(long)intPtr] ^ ((num7 << num10) | (num8 >> -num10)));
            ulong[] array8 = array3 = array;
            int     num15  = num9 + 4;
            intPtr        = (IntPtr)num15;
            array8[num15] = (array3[(long)intPtr] ^ (num7 >> -num10));
        }
        Reduce(array, z);
        (array3 = z)[0] = (array3[0] ^ num3);
        (array3 = z)[1] = (array3[1] ^ num5);
    }
示例#5
0
        private static void ScalarMultBase(byte[] k, PointAccum r)
        {
            Precompute();

            PointSetNeutral(r);

            uint[] n = new uint[ScalarUints];
            DecodeScalar(k, 0, n);

            // Recode the scalar into signed-digit form, then group comb bits in each block
            {
                uint c1 = Nat.CAdd(ScalarUints, ~(int)n[0] & 1, n, L, n);   Debug.Assert(c1 == 0);
                uint c2 = Nat.ShiftDownBit(ScalarUints, n, 1U);             Debug.Assert(c2 == (1U << 31));

                for (int i = 0; i < ScalarUints; ++i)
                {
                    n[i] = Interleave.Shuffle2(n[i]);
                }
            }

            PointPrecomp p = new PointPrecomp();

            int cOff = (PrecompSpacing - 1) * PrecompTeeth;

            for (; ;)
            {
                for (int b = 0; b < PrecompBlocks; ++b)
                {
                    uint w    = n[b] >> cOff;
                    int  sign = (int)(w >> (PrecompTeeth - 1)) & 1;
                    int  abs  = ((int)w ^ -sign) & PrecompMask;

                    Debug.Assert(sign == 0 || sign == 1);
                    Debug.Assert(0 <= abs && abs < PrecompPoints);

                    PointLookup(b, abs, p);

                    X25519Field.CSwap(sign, p.ypx_h, p.ymx_h);
                    X25519Field.CNegate(sign, p.xyd);

                    PointAddPrecomp(p, r);
                }

                if ((cOff -= PrecompTeeth) < 0)
                {
                    break;
                }

                PointDouble(r);
            }
        }
示例#6
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            return(command.Id switch
            {
                TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
                TokenType.Concat => Concat.Apply(clips),
                TokenType.Crop => Crop.Apply(command, clips),
                TokenType.Filter => Filter.Apply(command, clips),
                TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips),
                TokenType.Legato => Legato.Apply(clips),
                TokenType.Mask => Mask.Apply(command, clips),
                TokenType.Monophonize => Monophonize.Apply(clips),
                TokenType.Padding => Padding.Apply(command, clips),
                TokenType.Quantize => Quantize.Apply(command, clips),
                TokenType.Ratchet => Ratchet.Apply(command, clips),
                TokenType.Relength => Relength.Apply(command, clips),
                TokenType.Remap => Remap.Apply(command, clips),
                TokenType.Resize => Resize.Apply(command, clips),
                TokenType.Scale => Scale.Apply(command, clips),
                TokenType.Scan => Scan.Apply(command, clips),
                TokenType.SetLength => SetLength.Apply(command, clips),
                TokenType.SetPitch => SetPitch.Apply(command, clips),
                TokenType.SetRhythm => SetRhythm.Apply(command, clips),
                TokenType.Shuffle => Shuffle.Apply(command, clips),
                TokenType.Skip => Skip.Apply(command, clips),
                TokenType.Slice => Slice.Apply(command, clips),
                TokenType.Take => Take.Apply(command, clips),
                TokenType.Transpose => Transpose.Apply(command, clips),
                TokenType.VelocityScale => VelocityScale.Apply(command, clips),
                TokenType.InterleaveEvent => ((Func <ProcessResultArray <Clip> >)(() =>
                {
                    var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                    if (!success)
                    {
                        return new ProcessResultArray <Clip>(msg);
                    }

                    options.Mode = InterleaveMode.Event;
                    return Interleave.Apply(options, targetMetadata, clips);
                }))(),
                _ => new ProcessResultArray <Clip>($"Unsupported command {command.Id}")
            });
示例#7
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong num  = Interleave.Unshuffle(x[0]);
            ulong num2 = Interleave.Unshuffle(x[1]);
            ulong num3 = (num & 0xFFFFFFFFu) | (num2 << 32);
            ulong num4 = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);

            num  = Interleave.Unshuffle(x[2]);
            num2 = Interleave.Unshuffle(x[3]);
            ulong num5 = (num & 0xFFFFFFFFu) | (num2 << 32);
            ulong num6 = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);
            ulong num7 = num6 >> 49;
            ulong num8 = (num4 >> 49) | (num6 << 15);

            num6 ^= num4 << 15;
            ulong[] array  = Nat256.CreateExt64();
            int[]   array2 = new int[2] {
                39, 120
            };
            ulong[] array3;
            for (int i = 0; i < array2.Length; i++)
            {
                int     num9   = array2[i] >> 6;
                int     num10  = array2[i] & 0x3F;
                ulong[] array4 = (array3 = array);
                global::System.IntPtr intPtr = (global::System.IntPtr)num9;
                array4[num9] = array3[(long)intPtr] ^ (num4 << num10);
                ulong[] array5 = (array3 = array);
                int     num11  = num9 + 1;
                intPtr        = (global::System.IntPtr)num11;
                array5[num11] = array3[(long)intPtr] ^ ((num6 << num10) | (num4 >> -num10));
                ulong[] array6 = (array3 = array);
                int     num12  = num9 + 2;
                intPtr        = (global::System.IntPtr)num12;
                array6[num12] = array3[(long)intPtr] ^ ((num8 << num10) | (num6 >> -num10));
                ulong[] array7 = (array3 = array);
                int     num13  = num9 + 3;
                intPtr        = (global::System.IntPtr)num13;
                array7[num13] = array3[(long)intPtr] ^ ((num7 << num10) | (num8 >> -num10));
                ulong[] array8 = (array3 = array);
                int     num14  = num9 + 4;
                intPtr        = (global::System.IntPtr)num14;
                array8[num14] = array3[(long)intPtr] ^ (num7 >> -num10);
            }
            Reduce(array, z);
            (array3 = z)[0] = array3[0] ^ num3;
            (array3 = z)[1] = array3[1] ^ num5;
        }
示例#8
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong[] numArray = Nat192.Create64();
            ulong   num      = Interleave.Unshuffle(x[0]);
            ulong   num2     = Interleave.Unshuffle(x[1]);
            ulong   num3     = (num & 0xffffffffL) | (num2 << 0x20);

            numArray[0] = (num >> 0x20) | (num2 & 18_446_744_069_414_584_320L);
            num         = Interleave.Unshuffle(x[2]);
            ulong num4 = num & 0xffffffffL;

            numArray[1] = num >> 0x20;
            Multiply(numArray, ROOT_Z, z);
            z[0] ^= num3;
            z[1] ^= num4;
        }
示例#9
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong num  = Interleave.Unshuffle(x[0]);
            ulong num2 = Interleave.Unshuffle(x[1]);
            ulong num3 = (num & 0xFFFFFFFFu) | (num2 << 32);
            ulong num4 = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);

            num = Interleave.Unshuffle(x[2]);
            ulong num5 = (num & 0xFFFFFFFFu) ^ (x[3] << 32);
            ulong num6 = num >> 32;

            z[0] = num3 ^ (num4 << 8);
            z[1] = num5 ^ (num6 << 8) ^ (num4 >> 56) ^ (num4 << 33);
            z[2] = (num6 >> 56) ^ (num6 << 33) ^ (num4 >> 31);
            z[3] = num6 >> 31;
        }
示例#10
0
    public static void Sqrt(ulong[] x, ulong[] z)
    {
        ulong num  = Interleave.Unshuffle(x[0]);
        ulong num2 = Interleave.Unshuffle(x[1]);
        ulong num3 = (num & uint.MaxValue) | (num2 << 32);
        ulong num4 = (ulong)((long)(num >> 32) | ((long)num2 & -4294967296L));

        num = Interleave.Unshuffle(x[2]);
        ulong num5 = (num & uint.MaxValue) ^ (x[3] << 32);
        ulong num6 = num >> 32;

        z[0] = (num3 ^ (num4 << 8));
        z[1] = (num5 ^ (num6 << 8) ^ (num4 >> 56) ^ (num4 << 33));
        z[2] = ((num6 >> 56) ^ (num6 << 33) ^ (num4 >> 31));
        z[3] = num6 >> 31;
    }
示例#11
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong num  = Interleave.Unshuffle(x[0]);
            ulong num2 = Interleave.Unshuffle(x[1]);
            ulong num3 = (num & 0xffffffffL) | (num2 << 0x20);
            ulong num4 = (num >> 0x20) | (num2 & 18_446_744_069_414_584_320L);

            num = Interleave.Unshuffle(x[2]);
            ulong num5 = (num & 0xffffffffL) ^ (x[3] << 0x20);
            ulong num6 = num >> 0x20;

            z[0] = num3 ^ (num4 << 8);
            z[1] = ((num5 ^ (num6 << 8)) ^ (num4 >> 0x38)) ^ (num4 << 0x21);
            z[2] = ((num6 >> 0x38) ^ (num6 << 0x21)) ^ (num4 >> 0x1f);
            z[3] = num6 >> 0x1f;
        }
示例#12
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong[] array = Nat192.Create64();
            ulong   num   = Interleave.Unshuffle(x[0]);
            ulong   num2  = Interleave.Unshuffle(x[1]);
            ulong   num3  = (num & 0xFFFFFFFFu) | (num2 << 32);

            array[0] = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);
            num      = Interleave.Unshuffle(x[2]);
            ulong num4 = num & 0xFFFFFFFFu;

            array[1] = num >> 32;
            Multiply(array, ROOT_Z, z);
            ulong[] array2;
            (array2 = z)[0] = array2[0] ^ num3;
            (array2 = z)[1] = array2[1] ^ num4;
        }
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong u0, u1;

            u0 = Interleave.Unshuffle(x[0]); u1 = Interleave.Unshuffle(x[1]);
            ulong e0 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);
            ulong c0 = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);

            u0 = Interleave.Unshuffle(x[2]);
            ulong e1 = (u0 & 0x00000000FFFFFFFFUL) ^ (x[3] << 32);
            ulong c1 = (u0 >> 32);

            z[0] = e0 ^ (c0 << 8);
            z[1] = e1 ^ (c1 << 8) ^ (c0 >> 56) ^ (c0 << 33);
            z[2] = (c1 >> 56) ^ (c1 << 33) ^ (c0 >> 31);
            z[3] = (c1 >> 31);
        }
示例#14
0
        internal static void Square(ulong[] x, ulong[] z)
        {
            ulong[] t = new ulong[4];
            Interleave.Expand64To128Rev(x[0], t, 0);
            Interleave.Expand64To128Rev(x[1], t, 2);

            ulong z0 = t[0], z1 = t[1], z2 = t[2], z3 = t[3];

            z1 ^= z3 ^ (z3 >> 1) ^ (z3 >> 2) ^ (z3 >> 7);
//          z2 ^=      (z3 << 63) ^ (z3 << 62) ^ (z3 << 57);
            z2 ^= (z3 << 62) ^ (z3 << 57);

            z0 ^= z2 ^ (z2 >> 1) ^ (z2 >> 2) ^ (z2 >> 7);
            z1 ^= (z2 << 63) ^ (z2 << 62) ^ (z2 << 57);

            z[0] = z0;
            z[1] = z1;
        }
示例#15
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong num  = Interleave.Unshuffle(x[0]);
            ulong num2 = Interleave.Unshuffle(x[1]);
            ulong num3 = (num & 0xFFFFFFFFu) | (num2 << 32);
            ulong num4 = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);

            num  = Interleave.Unshuffle(x[2]);
            num2 = Interleave.Unshuffle(x[3]);
            ulong num5 = (num & 0xFFFFFFFFu) | (num2 << 32);
            ulong num6 = (num >> 32) | (num2 & 0xFFFFFFFF00000000uL);
            ulong num7 = num6 >> 27;

            num6 ^= (num4 >> 27) | (num6 << 37);
            num4 ^= num4 << 37;
            ulong[] array  = Nat256.CreateExt64();
            int[]   array2 = new int[3];
            RuntimeHelpers.InitializeArray((global::System.Array)array2, (RuntimeFieldHandle) /*OpCode not supported: LdMemberToken*/);
            int[]   array3 = array2;
            ulong[] array4;
            for (int i = 0; i < array3.Length; i++)
            {
                int     num8   = array3[i] >> 6;
                int     num9   = array3[i] & 0x3F;
                ulong[] array5 = (array4 = array);
                global::System.IntPtr intPtr = (global::System.IntPtr)num8;
                array5[num8] = array4[(long)intPtr] ^ (num4 << num9);
                ulong[] array6 = (array4 = array);
                int     num10  = num8 + 1;
                intPtr        = (global::System.IntPtr)num10;
                array6[num10] = array4[(long)intPtr] ^ ((num6 << num9) | (num4 >> -num9));
                ulong[] array7 = (array4 = array);
                int     num11  = num8 + 2;
                intPtr        = (global::System.IntPtr)num11;
                array7[num11] = array4[(long)intPtr] ^ ((num7 << num9) | (num6 >> -num9));
                ulong[] array8 = (array4 = array);
                int     num12  = num8 + 3;
                intPtr        = (global::System.IntPtr)num12;
                array8[num12] = array4[(long)intPtr] ^ (num7 >> -num9);
            }
            Reduce(array, z);
            (array4 = z)[0] = array4[0] ^ num3;
            (array4 = z)[1] = array4[1] ^ num5;
        }
示例#16
0
    public void TestInterleaveTimeRangesAndCounts()
    {
        var clip1 = new Clip(4, true)
        {
            Notes = new SortedList <NoteEvent>()
            {
                new NoteEvent(60, 0, 4, 100)
            }
        };
        var clip2 = new Clip(4, true)
        {
            Notes = new SortedList <NoteEvent>()
            {
                new NoteEvent(62, 0, 4, 100)
            }
        };
        var options = new InterleaveOptions
        {
            Ranges  = new decimal[] { 2, 1 },
            Repeats = new int[] { 1, 2 },
            Mode    = InterleaveMode.Time
        };

        var resultObj = Interleave.Apply(options, new ClipMetaData(), clip1, clip2);

        Assert.IsTrue(resultObj.Success);
        Assert.IsTrue(resultObj.Result.Length == 1);
        var result = resultObj.Result[0];

        Assert.AreEqual(16, result.Length);
        Assert.AreEqual(12, result.Notes.Count);
        Assert.AreEqual(60, result.Notes[0].Pitch);
        Assert.AreEqual(2, result.Notes[0].Duration);
        Assert.AreEqual(62, result.Notes[1].Pitch);
        Assert.AreEqual(1, result.Notes[1].Duration);
        Assert.AreEqual(62, result.Notes[2].Pitch);
        Assert.AreEqual(1, result.Notes[2].Duration);
        Assert.AreEqual(60, result.Notes[3].Pitch);
        Assert.AreEqual(2, result.Notes[3].Duration);
        Assert.AreEqual(62, result.Notes[4].Pitch);
        Assert.AreEqual(1, result.Notes[4].Duration);
        Assert.AreEqual(62, result.Notes[5].Pitch);
        Assert.AreEqual(1, result.Notes[5].Duration);
    }
示例#17
0
    public static ProcessResult <Clip[]> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
    {
        var clips = new Clip[incomingClips.Length];

        for (var i = 0; i < incomingClips.Length; i++)
        {
            clips[i] = new Clip(incomingClips[i]);
        }

        return(command.Id switch
        {
            TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
            TokenType.Concat => Concat.Apply(clips),
            TokenType.Crop => Crop.Apply(command, clips),
            TokenType.Echo => Echo.Apply(command, clips),
            TokenType.Extract => Take.Apply(command, clips, true),
            TokenType.Filter => Filter.Apply(command, clips),
            TokenType.Invert => Invert.Apply(command, clips),
            TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.NotSpecified),
            TokenType.InterleaveEvent => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.Event),
            TokenType.Legato => Legato.Apply(clips),
            TokenType.Loop => Loop.Apply(command, clips),
            TokenType.Mask => Mask.Apply(command, clips),
            TokenType.Monophonize => Monophonize.Apply(clips),
            TokenType.Padding => Padding.Apply(command, clips),
            TokenType.Quantize => Quantize.Apply(command, clips),
            TokenType.Ratchet => Ratchet.Apply(command, clips),
            TokenType.Relength => Relength.Apply(command, clips),
            TokenType.Remap => Remap.Apply(command, clips),
            TokenType.Resize => Resize.Apply(command, clips),
            TokenType.Scale => Scale.Apply(command, clips),
            TokenType.Scan => Scan.Apply(command, clips),
            TokenType.SetLength => SetLength.Apply(command, clips),
            TokenType.SetPitch => SetPitch.Apply(command, clips),
            TokenType.SetRhythm => SetRhythm.Apply(command, clips),
            TokenType.Shuffle => Shuffle.Apply(command, clips),
            TokenType.Skip => Skip.Apply(command, clips),
            TokenType.Slice => Slice.Apply(command, clips),
            TokenType.Take => Take.Apply(command, clips),
            TokenType.Transpose => Transpose.Apply(command, clips),
            TokenType.VelocityScale => VelocityScale.Apply(command, clips),
            _ => new ProcessResult <Clip[]>($"Unsupported command {command.Id}")
        });
示例#18
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new ChrUm6OrientationSensorState();
                _state.ChrUm6OrientationSensorConfig          = new ChrUm6OrientationSensorConfig();
                _state.ChrUm6OrientationSensorConfig.CommPort = 0;

                SaveState(_state);
            }
            else
            {
                // Clear old Chr readings
                _state.Quaternion = null;
            }

            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            if (_state.ChrUm6OrientationSensorConfig == null)
            {
                _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig();
            }

            // Publish the service to the local Node Directory
            DirectoryInsert();

            _chrConnection = new ChrConnection(_state.ChrUm6OrientationSensorConfig, _chrDataPort);

            SpawnIterator(ConnectToChrUm6OrientationSensor);

            // Listen on the main port for requests and call the appropriate handler.
            Interleave mainInterleave = ActivateDsspOperationHandlers();

            mainInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup(
                                                          Arbiter.Receive <short[]>(true, _chrDataPort, DataReceivedHandler),
                                                          Arbiter.Receive <Exception>(true, _chrDataPort, ExceptionHandler),
                                                          Arbiter.Receive <string>(true, _chrDataPort, MessageHandler)
                                                          ),
                                                      new ConcurrentReceiverGroup()));

            //base.Start(); -- can't have it here, we already started mainInterleave and added to directory via DirectoryInsert
        }
示例#19
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong[] array  = Nat576.Create64();
            ulong[] array2 = Nat576.Create64();
            int     num    = 0;

            for (int i = 0; i < 4; i++)
            {
                ulong num2 = Interleave.Unshuffle(x[num++]);
                ulong num3 = Interleave.Unshuffle(x[num++]);
                array[i]  = (num2 & 0xFFFFFFFFu) | (num3 << 32);
                array2[i] = (num2 >> 32) | (num3 & 0xFFFFFFFF00000000uL);
            }
            ulong num4 = Interleave.Unshuffle(x[num]);

            array[4]  = num4 & 0xFFFFFFFFu;
            array2[4] = num4 >> 32;
            Multiply(array2, ROOT_Z, z);
            Add(z, array, z);
        }
示例#20
0
    public void TestInterleaveEventCount()
    {
        var clip1 = new Clip(4, true)
        {
            Notes = new SortedList <NoteEvent>()
            {
                new NoteEvent(60, 0, 1, 100),
                new NoteEvent(60, 1, 1, 100),
                new NoteEvent(60, 2, 1, 100),
                new NoteEvent(60, 3, 1, 100)
            }
        };
        var clip2 = new Clip(4, true)
        {
            Notes = new SortedList <NoteEvent>()
            {
                new NoteEvent(62, 0, 1, 100),
                new NoteEvent(62, 1, 1, 100),
                new NoteEvent(62, 2, 1, 100),
                new NoteEvent(62, 3, 1, 100)
            }
        };
        var options = new InterleaveOptions
        {
            Mode = InterleaveMode.Event
        };
        var resultObj = Interleave.Apply(options, new ClipMetaData(), clip1, clip2);

        Assert.IsTrue(resultObj.Success);
        Assert.IsTrue(resultObj.Result.Length == 1);
        var clip = resultObj.Result[0];

        Assert.AreEqual(8m, clip.Length);
        for (var i = 0; i < 8; i++)
        {
            Console.WriteLine($"{clip.Notes[i].Start} {clip.Notes[i].Pitch}");
            Assert.AreEqual(i % 2 == 0 ? 60 : 62, clip.Notes[i].Pitch);
            Assert.AreEqual(i, clip.Notes[i].Start);
            Assert.AreEqual(1, clip.Notes[0].Duration);
        }
    }
示例#21
0
        public void A_Flow_using_Join_must_allow_for_interleave_cycle()
        {
            this.AssertAllStagesStopped(() =>
            {
                var source = Source.Single("lonely traveler").MapMaterializedValue(_ => Task.FromResult(""));
                var flow   = Flow.FromGraph(GraphDsl.Create(Sink.First <string>(), (b, sink) =>
                {
                    var interleave = b.Add(Interleave.Create <string>(2, 1));
                    var broadcast  = b.Add(new Broadcast <string>(2, true));

                    b.From(source).To(interleave.In(0));
                    b.From(interleave.Out).To(broadcast.In);
                    b.From(broadcast.Out(0)).To(sink);
                    return(new FlowShape <string, string>(interleave.In(1), broadcast.Out(1)));
                }));

                var t = flow.Join(Flow.Create <string>()).Run(Materializer);
                t.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
                t.Result.Should().Be("lonely traveler");
            }, Materializer);
        }
示例#22
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong[] odd = Nat192.Create64();

            ulong u0, u1;

            u0 = Interleave.Unshuffle(x[0]); u1 = Interleave.Unshuffle(x[1]);
            ulong e0 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);

            odd[0] = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);

            u0 = Interleave.Unshuffle(x[2]);
            ulong e1 = (u0 & 0x00000000FFFFFFFFUL);

            odd[1] = (u0 >> 32);

            Multiply(odd, ROOT_Z, z);

            z[0] ^= e0;
            z[1] ^= e1;
        }
示例#23
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong[] evn = Nat576.Create64(), odd = Nat576.Create64();

            int pos = 0;

            for (int i = 0; i < 4; ++i)
            {
                ulong u0 = Interleave.Unshuffle(x[pos++]);
                ulong u1 = Interleave.Unshuffle(x[pos++]);
                evn[i] = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);
                odd[i] = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);
            }
            {
                ulong u0 = Interleave.Unshuffle(x[pos]);
                evn[4] = (u0 & 0x00000000FFFFFFFFUL);
                odd[4] = (u0 >> 32);
            }

            Multiply(odd, ROOT_Z, z);
            Add(z, evn, z);
        }
示例#24
0
        public static void Sqrt(ulong[] x, ulong[] z)
        {
            ulong u0, u1;

            u0 = Interleave.Unshuffle(x[0]); u1 = Interleave.Unshuffle(x[1]);
            ulong e0 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);
            ulong c0 = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);

            u0 = Interleave.Unshuffle(x[2]); u1 = Interleave.Unshuffle(x[3]);
            ulong e1 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);
            ulong c1 = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);

            ulong c2, c3;

            c3  = (c1 >> 49);
            c2  = (c0 >> 49) | (c1 << 15);
            c1 ^= (c0 << 15);

            ulong[] tt = Nat256.CreateExt64();

            int[] shifts = { 39, 120 };
            for (int i = 0; i < shifts.Length; ++i)
            {
                int w = shifts[i] >> 6, s = shifts[i] & 63;
                Debug.Assert(s != 0);
                tt[w]     ^= (c0 << s);
                tt[w + 1] ^= (c1 << s) | (c0 >> -s);
                tt[w + 2] ^= (c2 << s) | (c1 >> -s);
                tt[w + 3] ^= (c3 << s) | (c2 >> -s);
                tt[w + 4] ^= (c3 >> -s);
            }

            Reduce(tt, z);

            z[0] ^= e0;
            z[1] ^= e1;
        }
示例#25
0
        public override object ToUFEEffect()
        {
            var eff = new Interleave();

            eff.LineWidth       = _Thickness;
            eff.LineOrientation = _Lines ?  LineLocationType.VERTICAL :  LineLocationType.HORIZONTAL;
            switch (_DirectionWay)
            {
            case DirectionWays.BottomCorners: eff.Direction = EffectDirectionType.LOWCORNERS; break;

            case DirectionWays.BottomLeftTopRight: eff.Direction = EffectDirectionType.LOWLEFT_UPRIGHT; break;

            case DirectionWays.InOut: eff.Direction = EffectDirectionType.IN_OUT; break;

            case DirectionWays.LeftRight: eff.Direction = EffectDirectionType.LEFT_RIGHT; break;

            case DirectionWays.TopBottom: eff.Direction = EffectDirectionType.UP_DOWN; break;

            case DirectionWays.TopCorners: eff.Direction = EffectDirectionType.UPCENTER; break;

            case DirectionWays.TopLeftBottomRight: eff.Direction = EffectDirectionType.UPLEFT_LOWRIGHT; break;
            }
            return(eff);
        }
示例#26
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                //initialize state
                _state           = new ScribblerState();
                _state.ComPort   = 0;
                _state.RobotName = null;

                //motors initially stopped
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;

                SaveState(_state);
            }

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            //open Scribbler Communications port
            if (ConnectToScribbler())
            {
                // Listen for a single Serial port request with an acknowledgement
                Activate(Arbiter.ReceiveWithIterator <SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler));

                PollTimer           = new System.Timers.Timer();
                PollTimer.Interval  = TimerDelay;
                PollTimer.AutoReset = true;
                PollTimer.Elapsed  += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed);
                PollTimer.Start();


                //play startup tone
                PlayToneBody startTone = new PlayToneBody(200, 1000, 2000);
                _mainPort.Post(new PlayTone(startTone));

                //debug
                //ScribblerCommand cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.GET_INFO);
                //SendScribblerCommand sendcmd = new SendScribblerCommand(cmd);
                //_scribblerComPort.Post(sendcmd);


                //fix state
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;
                _state.LEDLeft    = false;
                _state.LEDRight   = false;
                _state.LEDCenter  = false;
            }
            else
            {
                //no scribbler found. Open state page for manual settings.
                //OpenServiceInBrowser();
            }


            // Listen on the main port for requests and call the appropriate handler.
            Interleave mainInterleave = ActivateDsspOperationHandlers();

            //for HttpPost
            _httpUtilities = DsspHttpUtilitiesService.Create(Environment);

            // Publish the service to the local Node Directory
            DirectoryInsert();

            //add custom handlers to interleave
            mainInterleave.CombineWith(new Interleave(
                                           new TeardownReceiverGroup(),
                                           new ExclusiveReceiverGroup(
                                               Arbiter.ReceiveWithIterator <SetMotors>(true, _mainPort, SetMotorHandler),
                                               Arbiter.ReceiveWithIterator <SetLED>(true, _mainPort, SetLEDHandler),
                                               Arbiter.ReceiveWithIterator <SetAllLEDs>(true, _mainPort, SetAllLEDsHandler),
                                               Arbiter.ReceiveWithIterator <PlayTone>(true, _mainPort, PlayToneHandler),
                                               Arbiter.ReceiveWithIterator <SetName>(true, _mainPort, SetNameHandler),
                                               Arbiter.ReceiveWithIterator <ScribblerResponseMessage>(true, _mainPort, ScribblerResponseHandler)
                                               ),
                                           new ConcurrentReceiverGroup()
                                           ));
        }
示例#27
0
 protected static void ImplSquare(ulong[] x, ulong[] zz)
 {
     Interleave.Expand64To128(x[0], zz, 0);
     Interleave.Expand64To128(x[1], zz, 2);
 }
示例#28
0
 public Interleave( State.Single left, State.Single right, State.Single join, bool textToLeft, Interleave next )
 {
     this.Left = left;
     this.Right = right;
     this.Join = join;
     this.Next = next;
     this.TextToLeft = textToLeft;
 }
示例#29
0
 protected static void ImplSquare(ulong[] x, ulong[] zz)
 {
     Interleave.Expand64To128(x[0], zz, 0);
     Interleave.Expand64To128(x[1], zz, 2);
     zz[4] = (ulong)Interleave.Expand8to16((uint)x[2]);
 }
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            InitializeState();

            // Set up the reliable port using DSS forwarder to ensure exception and timeout conversion to fault.
            _reliableMainPort = ServiceForwarder<NxtBrickOperations>(this.ServiceInfo.Service);

            // Make the service visible immediately
            DirectoryInsert();

            // Handle some handlers all the time -- even during initialization and exclusive handlers.
            Activate<ITask>(
                Arbiter.ReceiveWithIterator<Get>(true, _internalMainPort, GetHandler),
                Arbiter.Receive<HttpGet>(true, _internalMainPort, HttpGetHandler),
                Arbiter.Receive<DsspDefaultLookup>(true, _internalMainPort, base.DefaultLookupHandler),
                Arbiter.ReceiveWithIterator<LegoSensorUpdate>(true, _internalMainPort, LegoSensorUpdateHandler)
               );

            // Start initializing the communications service
            DsspResponsePort<CreateResponse> nxtCommunicationResponse = CreateNxtCommunicationService();

            // Activate on all operations.
            // Operations which require a connection to the hardware will throw a fault.
            Interleave initializationInterleave = new Interleave(
                new TeardownReceiverGroup(
                    Arbiter.ReceiveWithIterator<CreateResponse>(false, nxtCommunicationResponse, ServiceInitialization),
                    Arbiter.ReceiveWithIterator<DsspDefaultDrop>(false, _internalMainPort, DropHandler)
                ),
                new ExclusiveReceiverGroup(
                    Arbiter.ReceiveWithIterator<AttachAndSubscribe>(true, _internalMainPort, AttachAndSubscribeHandler),
                    Arbiter.ReceiveWithIterator<ReserveDevicePort>(true, _internalMainPort, ReserveDevicePortHandler),
                    Arbiter.ReceiveWithIterator<Subscribe>(true, _internalMainPort, SubscribeHandler),
                    Arbiter.ReceiveWithIterator<Detach>(true, _internalMainPort, DetachHandler),
                    Arbiter.ReceiveWithIterator <AdjustPollingFrequency>(true, _internalMainPort, AdjustPollingFrequencyHandler)
                ),
                new ConcurrentReceiverGroup());

            // Wait on this interleave until a CreateResponse is posted to nxtCommunicationResponse port.
            Activate(initializationInterleave);

            // Set up a seperate interleave which processes I2C Commands one at a time.
            Activate(new Interleave(
                new ExclusiveReceiverGroup(
                    Arbiter.ReceiveWithIterator<SendLowSpeedCommand>(true, _internalI2CPort, I2cLowSpeedCommandHandler)),
                new ConcurrentReceiverGroup()));
        }
示例#31
0
文件: Scribbler.cs 项目: yingted/Myro
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                //initialize state
                _state           = new ScribblerState();
                _state.ComPort   = 0;
                _state.RobotName = null;

                //motors initially stopped
                _state.MotorLeft  = 100;
                _state.MotorRight = 100;

                //_state.LightLeftConfig = new SensorConfig();
                //_state.LightRightConfig = new SensorConfig();
                //_state.LightCenterConfig = new SensorConfig();

                SaveState(_state);
            }

            // Listen on the main port for requests and call the appropriate handler.
            Interleave mainInterleave = ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            //open Scribbler Communications port
            if (ConnectToScribbler())
            {
                // Listen for a single Serial port request with an acknowledgement
                Activate(Arbiter.ReceiveWithIterator <SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler));


                //add custom handlers to interleave
                mainInterleave.CombineWith(new Interleave(
                                               new TeardownReceiverGroup(),
                                               new ExclusiveReceiverGroup(
                                                   Arbiter.ReceiveWithIterator <SetMotor>(true, _mainPort, SetMotorHandler),
                                                   Arbiter.ReceiveWithIterator <SetLED>(true, _mainPort, SetLEDHandler),
                                                   Arbiter.ReceiveWithIterator <PlayTone>(true, _mainPort, PlayToneHandler),
                                                   //Arbiter.ReceiveWithIterator<ConfigureSensor>(true, _mainPort, ConfigureSensorHandler),
                                                   Arbiter.ReceiveWithIterator <SetName>(true, _mainPort, SetNameHandler)
                                                   ),
                                               new ConcurrentReceiverGroup()
                                               ));


                PollTimer           = new System.Timers.Timer();
                PollTimer.Interval  = TimerDelay;
                PollTimer.AutoReset = true;
                PollTimer.Elapsed  += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed);
                PollTimer.Start();


                //play startup tone
                PlayToneBody startTone = new PlayToneBody(200, 1000, 2000);
                PlayTone     sendcmd   = new PlayTone();
                sendcmd.Body = startTone;
                _mainPort.Post(sendcmd);
            }
        }
 protected static void ImplSquare(ulong[] x, ulong[] zz)
 {
     Interleave.Expand64To128(x, 0, 4, zz, 0);
     zz[8] = Interleave.Expand32to64((uint)x[4]);
 }
示例#33
0
 private void subscribeCamera(CameraInfo argCi)
 {
     // Subscribe to the simulator camera, using a handler
     // that will only update the GUI if this camera is
     // selected (because there is currently no way to 
     // unsubscribe from a camera.
     //if (ci.Camera.IsRealTimeCamera)
     //{
     CameraInfo ci = argCi;
     ci.Port = new Port<System.Drawing.Bitmap>();
     ci.Camera.Subscribe(ci.Port);
     Interleave interleave = new Interleave(new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup());
     interleave.CombineWith(
         new Interleave(new ExclusiveReceiverGroup(
             Arbiter.Receive(true, ci.Port,
             delegate(System.Drawing.Bitmap inbmp)
             {
                 if (interleave.PendingExclusiveCount <= 1 && curCamera == ci)
                     if (DateTime.Now.Subtract(lastFrameTime).Milliseconds >= frameInterval)
                     {
                         lastFrameTime = DateTime.Now;
                         updateImageDisplay(inbmp);
                     }
             })),
         new ConcurrentReceiverGroup()));
     Arbiter.Activate(throttledQueue, interleave);
     //}
     //else
     //{
     //    // If it's not a real time camera, we have to start a loop
     //    // to query it
     //    new Thread(new ThreadStart(delegate()
     //    {
     //        var resultPort = new PortSet<System.Drawing.Bitmap, Exception>();
     //        while (shouldStay)
     //        {
     //            if (curCamera == ci)
     //            {
     //                // The throttledQueue has only 1 thread, so concurrent execution
     //                // will not happen here if the updateImageDisplay handler cannot
     //                // keep up with the rate at which we're querying frames.
     //                ci.Camera.CaptureScene(System.Drawing.Imaging.ImageFormat.Bmp, resultPort);
     //                Arbiter.Activate(throttledQueue, Arbiter.Choice(resultPort,
     //                    updateImageDisplay,
     //                    delegate(Exception e)
     //                    {
     //                        Console.WriteLine(e);
     //                    }));
     //            }
     //            Thread.Sleep(frameInterval);
     //        }
     //    })).Start();
     //}
 }