예제 #1
0
        /// <summary>
        /// Update the internal state from a user parameter.
        /// </summary>
        /// <param name="outErrorInfo">The possible <see cref="ErrorInfo"/> that was generated.</param>
        /// <param name="parameter">The user parameter.</param>
        /// <param name="poolMapper">The mapper to use.</param>
        /// <param name="behaviourContext">The behaviour context.</param>
        public void UpdateParameters(out ErrorInfo outErrorInfo, ref VoiceInParameter parameter, ref PoolMapper poolMapper, ref BehaviourContext behaviourContext)
        {
            InUse  = parameter.InUse;
            Id     = parameter.Id;
            NodeId = parameter.NodeId;

            UpdatePlayState(parameter.PlayState);

            SrcQuality = parameter.SrcQuality;

            Priority      = parameter.Priority;
            SortingOrder  = parameter.SortingOrder;
            SampleRate    = parameter.SampleRate;
            SampleFormat  = parameter.SampleFormat;
            ChannelsCount = parameter.ChannelCount;
            Pitch         = parameter.Pitch;
            Volume        = parameter.Volume;
            parameter.BiquadFilters.AsSpan().CopyTo(BiquadFilters.AsSpan());
            WaveBuffersCount = parameter.WaveBuffersCount;
            WaveBuffersIndex = parameter.WaveBuffersIndex;

            if (behaviourContext.IsFlushVoiceWaveBuffersSupported())
            {
                FlushWaveBufferCount += parameter.FlushWaveBufferCount;
            }

            MixId = parameter.MixId;

            if (behaviourContext.IsSplitterSupported())
            {
                SplitterId = parameter.SplitterId;
            }
            else
            {
                SplitterId = Constants.UnusedSplitterId;
            }

            parameter.ChannelResourceIds.AsSpan().CopyTo(ChannelResourceIds.AsSpan());

            DecodingBehaviour behaviour = DecodingBehaviour.Default;

            if (behaviourContext.IsDecodingBehaviourFlagSupported())
            {
                behaviour = parameter.DecodingBehaviourFlags;
            }

            DecodingBehaviour = behaviour;

            if (parameter.ResetVoiceDropFlag)
            {
                VoiceDropFlag = false;
            }

            if (ShouldUpdateParameters(ref parameter))
            {
                DataSourceStateUnmapped = !poolMapper.TryAttachBuffer(out outErrorInfo, ref DataSourceStateAddressInfo, parameter.DataSourceStateAddress, parameter.DataSourceStateSize);
            }
            else
            {
                outErrorInfo = new ErrorInfo();
            }
        }
예제 #2
0
        public static void Resample(Span <float> outputBuffer, ReadOnlySpan <short> inputBuffer, float ratio, ref float fraction, int sampleCount, SampleRateConversionQuality srcQuality, bool needPitch)
        {
            switch (srcQuality)
            {
            case SampleRateConversionQuality.Default:
                ResampleDefaultQuality(outputBuffer, inputBuffer, ratio, ref fraction, sampleCount, needPitch);
                break;

            case SampleRateConversionQuality.Low:
                ResampleLowQuality(outputBuffer, inputBuffer, ratio, ref fraction, sampleCount);
                break;

            case SampleRateConversionQuality.High:
                ResampleHighQuality(outputBuffer, inputBuffer, ratio, ref fraction, sampleCount);
                break;

            default:
                throw new NotImplementedException($"{srcQuality}");
            }
        }
예제 #3
0
        private static (float, float) GetCostByFormat(uint sampleCount, SampleFormat format, SampleRateConversionQuality quality)
        {
            Debug.Assert(sampleCount == 160 || sampleCount == 240);

            switch (format)
            {
            case SampleFormat.PcmInt16:
                switch (quality)
                {
                case SampleRateConversionQuality.Default:
                    if (sampleCount == 160)
                    {
                        return(6329.44f, 427.52f);
                    }

                    return(7853.28f, 710.14f);

                case SampleRateConversionQuality.High:
                    if (sampleCount == 160)
                    {
                        return(8049.42f, 371.88f);
                    }

                    return(10138.84f, 610.49f);

                case SampleRateConversionQuality.Low:
                    if (sampleCount == 160)
                    {
                        return(5062.66f, 423.43f);
                    }

                    return(5810.96f, 676.72f);

                default:
                    throw new NotImplementedException($"{format} {quality}");
                }

            case SampleFormat.PcmFloat:
                switch (quality)
                {
                case SampleRateConversionQuality.Default:
                    if (sampleCount == 160)
                    {
                        return(7845.25f, 2310.4f);
                    }

                    return(10090.9f, 3490.9f);

                case SampleRateConversionQuality.High:
                    if (sampleCount == 160)
                    {
                        return(9446.36f, 2308.91f);
                    }

                    return(12520.85f, 3480.61f);

                case SampleRateConversionQuality.Low:
                    if (sampleCount == 160)
                    {
                        return(9446.36f, 2308.91f);
                    }

                    return(12520.85f, 3480.61f);

                default:
                    throw new NotImplementedException($"{format} {quality}");
                }

            case SampleFormat.Adpcm:
                switch (quality)
                {
                case SampleRateConversionQuality.Default:
                    if (sampleCount == 160)
                    {
                        return(7913.81f, 1827.66f);
                    }

                    return(9736.70f, 2756.37f);

                case SampleRateConversionQuality.High:
                    if (sampleCount == 160)
                    {
                        return(9607.81f, 1829.29f);
                    }

                    return(12154.38f, 2731.31f);

                case SampleRateConversionQuality.Low:
                    if (sampleCount == 160)
                    {
                        return(6517.48f, 1824.61f);
                    }

                    return(7929.44f, 2732.15f);

                default:
                    throw new NotImplementedException($"{format} {quality}");
                }

            default:
                throw new NotImplementedException($"{format}");
            }
        }