Example #1
0
        protected override Task <double> Frequency(double t, int n, int channel)
        {
            var isThisFeature = featureChooser.IsFeature(n, nameof(FeatureProbabilityModel.Frequency));

            if (!isThisFeature)
            {
                return(Task.FromResult(pulseFrequency.Quiescent));
            }
            var section = sectionsProvider.Section(n);

            var topFrequency = topFrequencyCache.GetOrAdd(section, CreateTopFrequency);
            var frequency    = featureProvider.FeatureValue(t, n, pulseFrequency.Quiescent, topFrequency);

            return(Task.FromResult(frequency));
        }
        private Task <double> EvaluateCarrierFrequency(double t, int n, string carrierFrequencyString)
        {
            var script = scripts.GetOrAdd(carrierFrequencyString, CarrierFrequenyExpression.Parse);
            var p      = new CarrierFrequencyExpressionParams
            {
                t = t,
                T = metadata.TrackLength.TotalSeconds,
                v = featureProvider.FeatureValue(t, n, 0, 1)
            };

            script.setArgumentValue(nameof(CarrierFrequencyExpressionParams.t), p.t);
            script.setArgumentValue(nameof(CarrierFrequencyExpressionParams.T), p.T);
            script.setArgumentValue(nameof(CarrierFrequencyExpressionParams.v), p.v);
            var result = script.calculate();

            return(Task.FromResult(result));
        }
Example #3
0
        private double Wetness(double t, int n)
        {
            if (wetness == null)
            {
                return(0);
            }

            if (sections == null)
            {
                return(wetness.Maximum);
            }

            // rise in a sin^2 fashion from MinWetness to MaxWetness
            var section = sectionsProvider.Section(n);

            var maxForSection = maxWetnessForSectionCache.GetOrAdd(section, s =>
            {
                var numSections = sectionsProvider.NumSections();
                var progression = (double)s / Math.Max(1, numSections - 1); // <= 1
                var max         = randomizer.ProportionAlong(wetness.Variation, progression,
                                                             wetness.Minimum, wetness.Maximum);
                return(max);
            });

            double value;

            if (wetness.LinkToFeature)
            {
                var isThisFeature = featureChooser.IsFeature(n, nameof(FeatureProbabilityModel.Wetness));
                value = isThisFeature ?
                        featureProvider.FeatureValue(t, n, wetness.Minimum, maxForSection)
                    : wetness.Minimum;
            }
            else
            {
                value = maxForSection;
            }

            return(value);
        }