public double Linterp(int window, double frequency)
        {
            int lowerBound = freqs.BinarySearchLowerBound(frequency);

            if (lowerBound == -1)
            {
                return(spectralValues[window, 0]);
            }

            if (lowerBound == freqs.Length - 1)
            {
                return(spectralValues[window, lowerBound]);
            }

            return(GeneralMath.Lerp(
                       spectralValues[window, lowerBound],
                       spectralValues[window, lowerBound + 1],
                       (frequency - freqs[lowerBound]) / (freqs[lowerBound + 1] - freqs[lowerBound])));
        }
Esempio n. 2
0
 void ILerpAction <Image> .CallAction(float t)
 {
     imageColor.a = GeneralMath.Lerp(initialAlpha, finalAlpha, t);
     image.color  = imageColor;
 }
Esempio n. 3
0
        public static void GetLevelOffset(
            double level,
            out double levelOffsetL,
            out double levelOffsetR,
            Source source = Source.Custom)
        {
            List <CalibrationPoint> points;

            switch (source)
            {
            case Source.InProgress:
                if (inProgressCalibration == null || inProgressCalibration.Count == 0)
                {
                    goto case Source.Results;
                }
                points = inProgressCalibration;
                break;

            case Source.Results:
                if (resultsCalibration == null || resultsCalibration.Count == 0)
                {
                    goto case Source.Custom;
                }
                points = resultsCalibration;
                break;

            case Source.Custom:
                if (customCalibration == null || customCalibration.Count == 0)
                {
                    goto case Source.Default;
                }
                points = customCalibration;
                break;

            case Source.Default:
                levelOffsetL = 0.0;
                levelOffsetR = 0.0;
                return;

            default:
                Debug.LogError($"Unexpected Source: {source}");
                goto case Source.Default;
            }

            if (points.Count == 1)
            {
                levelOffsetL = points[0].levelOffsetL;
                levelOffsetR = points[0].levelOffsetR;
                return;
            }

            //If the requested level is before the first or after the last, use its assocaited offset
            if (level <= points[0].levelIn)
            {
                levelOffsetL = points[0].levelOffsetL;
                levelOffsetR = points[0].levelOffsetR;
                return;
            }

            //Else, we will LERP between the surrounding offsets
            for (int index = 0; index < points.Count - 1; index++)
            {
                if (level >= points[index].levelIn && level < points[index + 1].levelIn)
                {
                    levelOffsetL = GeneralMath.Lerp(points[index].levelOffsetL,
                                                    points[index + 1].levelOffsetL,
                                                    (level - points[index].levelIn) / (points[index + 1].levelIn - points[index].levelIn));

                    levelOffsetR = GeneralMath.Lerp(points[index].levelOffsetR,
                                                    points[index + 1].levelOffsetR,
                                                    (level - points[index].levelIn) / (points[index + 1].levelIn - points[index].levelIn));

                    return;
                }
            }

            //Else, we return the last value
            levelOffsetL = points[points.Count - 1].levelOffsetL;
            levelOffsetR = points[points.Count - 1].levelOffsetR;
        }
Esempio n. 4
0
        public ChorusEffector(
            IBGCStream stream,
            double minDelay     = 0.040,
            double maxDelay     = 0.060,
            double rate         = 0.25,
            DelayType delayType = DelayType.Sine,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough)
            : base(stream)
        {
            int adjustmentSamples = (int)Math.Round(SamplingRate / rate);

            adjustments = new int[Channels * adjustmentSamples];

            double centerDelay    = 0.5 * (maxDelay + minDelay);
            double delayAmplitude = 0.5 * (maxDelay - minDelay);

            switch (delayType)
            {
            case DelayType.Sine:
                for (int samp = 0; samp < adjustmentSamples; samp++)
                {
                    for (int chan = 0; chan < Channels; chan++)
                    {
                        adjustments[samp * Channels + chan] = (int)Math.Round(stream.SamplingRate * (centerDelay + delayAmplitude * Math.Sin(2.0 * Math.PI * samp / adjustmentSamples)));
                    }
                }
                break;

            case DelayType.Triangle:
            {
                int peakSample   = adjustmentSamples / 4;
                int valleySample = 3 * peakSample;

                for (int samp = 0; samp < adjustmentSamples; samp++)
                {
                    double triangleValue;
                    if (samp < peakSample)
                    {
                        //Initial Rise
                        triangleValue = GeneralMath.Lerp(0, 1.0, samp / (double)peakSample);
                    }
                    else if (samp < valleySample)
                    {
                        triangleValue = GeneralMath.Lerp(1.0, -1.0, (samp - peakSample) / (double)(valleySample - peakSample));
                    }
                    else
                    {
                        triangleValue = GeneralMath.Lerp(-1.0, 0.0, (samp - valleySample) / (double)(adjustmentSamples - valleySample));
                    }


                    for (int chan = 0; chan < Channels; chan++)
                    {
                        adjustments[samp * Channels + chan] = (int)Math.Round(stream.SamplingRate * (centerDelay + delayAmplitude * triangleValue));
                    }
                }
            }
            break;

            default:
                throw new StreamCompositionException($"Unexpected DelayType: {delayType}");
            }


            adjIndexA = 0;
            adjIndexB = adjustments.Length / 2;

            int maxAdjustment = adjustments.Max();

            bufferSize = Math.Max(MIN_BUFFER_SIZE, Channels * maxAdjustment.CeilingToPowerOfTwo());

            newBuffer = new float[bufferSize];
            oldBuffer = new float[bufferSize];

            this.rmsBehavior = rmsBehavior;

            channelSampleAdjustment = (int)Math.Ceiling(maxDelay * stream.SamplingRate);

            if (stream.ChannelSamples == int.MaxValue)
            {
                ChannelSamples = int.MaxValue;
                TotalSamples   = int.MaxValue;
            }
            else
            {
                ChannelSamples = stream.ChannelSamples + channelSampleAdjustment;
                TotalSamples   = Channels * ChannelSamples;
            }
        }