Example #1
0
        /// <summary>
        /// Update the <see cref="SplitterState"/> from user parameter.
        /// </summary>
        /// <param name="context">The splitter context.</param>
        /// <param name="parameter">The user parameter.</param>
        /// <param name="input">The raw input data after the <paramref name="parameter"/>.</param>
        public void Update(SplitterContext context, ref SplitterInParameter parameter, ReadOnlySpan <byte> input)
        {
            ClearLinks();

            int destinationCount;

            if (context.IsBugFixed)
            {
                destinationCount = parameter.DestinationCount;
            }
            else
            {
                destinationCount = Math.Min(context.GetDestinationCountPerStateForCompatibility(), parameter.DestinationCount);
            }

            if (destinationCount > 0)
            {
                ReadOnlySpan <int> destinationIds = MemoryMarshal.Cast <byte, int>(input);

                Memory <SplitterDestination> destination = context.GetDestinationMemory(destinationIds[0]);

                SetDestination(ref destination.Span[0]);

                DestinationCount = destinationCount;

                for (int i = 1; i < destinationCount; i++)
                {
                    Memory <SplitterDestination> nextDestination = context.GetDestinationMemory(destinationIds[i]);

                    destination.Span[0].Link(ref nextDestination.Span[0]);
                    destination = nextDestination;
                }
            }

            Debug.Assert(parameter.Id == Id);

            if (parameter.Id == Id)
            {
                SampleRate       = parameter.SampleRate;
                HasNewConnection = true;
            }
        }
Example #2
0
        /// <summary>
        /// Update one or multiple <see cref="SplitterState"/> from user parameters.
        /// </summary>
        /// <param name="inputHeader">The splitter header.</param>
        /// <param name="input">The raw data after the splitter header.</param>
        private void UpdateState(ref SplitterInParameterHeader inputHeader, ref ReadOnlySpan <byte> input)
        {
            for (int i = 0; i < inputHeader.SplitterCount; i++)
            {
                SplitterInParameter parameter = MemoryMarshal.Read <SplitterInParameter>(input);

                Debug.Assert(parameter.IsMagicValid());

                if (parameter.IsMagicValid())
                {
                    if (parameter.Id >= 0 && parameter.Id < _splitters.Length)
                    {
                        ref SplitterState splitter = ref GetState(parameter.Id);

                        splitter.Update(this, ref parameter, input.Slice(Unsafe.SizeOf <SplitterInParameter>()));
                    }

                    input = input.Slice(0x1C + (int)parameter.DestinationCount * 4);
                }
            }