Beispiel #1
0
        private static double GetAverage(List <byte[]> sampleList, int start = 0)
        {
            long sum         = 0;
            long totalLength = 0;

            for (int j = start; j < sampleList.Count; j++)             // (byte[] samples in sampleList)
            {
                byte[] samples = sampleList[j];
                var    shorts  = new short[samples.Length / 2];
                Buffer.BlockCopy(samples, 0, shorts, 0, samples.Length);

                totalLength += shorts.Length;
                sum          = shorts.Aggregate(sum, (current, t) => current + Math.Abs((int)t));
            }
            return(sum / (double)totalLength);
        }
Beispiel #2
0
        private static double GetRMS(IList <byte[]> sampleList, int start = 0)
        {
            long sum         = 0;
            long totalLength = 0;

            for (int j = start; j < sampleList.Count; j++)             // foreach (byte[] samples in sampleList)
            {
                byte[] samples = sampleList[j];
                var    shorts  = new short[samples.Length / 2];
                Buffer.BlockCopy(samples, 0, shorts, 0, samples.Length);

                totalLength += shorts.Length;
                sum          = shorts.Aggregate(sum, (current, t) => current + (t * t));
            }
            double average = sum / (double)totalLength;

            return(Math.Sqrt(average));
        }