Example #1
0
        public (bool succes, double value) CalculateFrequency(List <SoundPoint> values, int step, int start, int k, int size, float precision,
                                                              int dimensions, bool useMedian, bool useRandomValues)
        {
            if (dimensions * k + start > values.Count)
            {
                return(false, double.NegativeInfinity);
            }

            if (dimensions * k + start > start + size)
            {
                return(false, double.NegativeInfinity);
            }

            if (start + size > values.Count)
            {
                return(false, double.NegativeInfinity);
            }

            var valuesToTest = new List <List <SoundPoint> >();

            for (var i = dimensions * k + start; i < start + size; i += step)
            {
                var temp = new List <SoundPoint>();
                for (var j = 0; j < dimensions; j++)
                {
                    temp.Add(values[i - j * k]);
                }

                valuesToTest.Add(temp);
            }

            var comparer         = new SoundPointComparer(precision);
            var distances        = new List <long>();
            var indexForDistance = 0;

            for (var i = 0; i < 20; i++)
            {
                var index    = useRandomValues ? _random.Next(0, Math.Min(100, valuesToTest.Count)) : indexForDistance;
                var distance = GetDistance(valuesToTest, index, comparer);
                if (distance.success)
                {
                    distances.Add(distance.value);
                }

                indexForDistance += 5;
            }

            if (distances.Count == 0)
            {
                return(false, double.PositiveInfinity);
            }
            var calculated = useMedian ? GetMedian(distances) : distances.Average();

            return(true, 1d / calculated * SampleRate);
        }
Example #2
0
        private (bool success, long value) GetDistance(List <List <SoundPoint> > values, int startIndex,
                                                       SoundPointComparer comparer)
        {
            if (startIndex >= values.Count)
            {
                return(false, long.MaxValue);
            }
            var first = values[startIndex];

            startIndex += 30;
            for (; startIndex < values.Count; startIndex++)
            {
                if (first.SequenceEqual(values[startIndex], comparer))
                {
                    break;
                }
            }

            if (startIndex >= values.Count)
            {
                return(false, long.MaxValue);
            }
            return(true, values[startIndex][0].Time - first[0].Time);
        }