Esempio n. 1
0
        public void G711ComparisonTest()
        {
            for (int i = short.MinValue; i <= short.MaxValue; i++)
            {
                Assert.AreEqual(G711.LinearToULaw((byte)i), G711.LinearToULawFast((byte)i));
            }

            for (int i = byte.MinValue; i <= byte.MaxValue; i++)
            {
                Assert.AreEqual(G711.ULawToLinear((byte)i), G711.ULawToLinearFast((byte)i));
            }
        }
Esempio n. 2
0
        public void G711LinearToULawPerformanceComparison()
        {
            const int innerIterations = 10000;
            var       input           = new short[_audioFormat.SamplesPerFrame];
            var       rnd             = new Random();

            for (int i = 0; i < input.Length; i++)
            {
                input[i] = (short)rnd.Next(short.MinValue, short.MaxValue);
            }

            var calculationElapsed = new TimeSpan();
            var lookupElapsed      = new TimeSpan();

            for (int i = 0; i < 10; i++)
            {
                var start = DateTime.Now;
                for (int j = 0; j < innerIterations; j++)
                {
                    foreach (short k in input)
                    {
                        var encoded = G711.LinearToULaw(k);
                    }
                }
                calculationElapsed += DateTime.Now - start;

                start = DateTime.Now;
                for (int j = 0; j < innerIterations; j++)
                {
                    foreach (short k in input)
                    {
                        var encoded = G711.LinearToULawFast(k);
                    }
                }
                lookupElapsed += DateTime.Now - start;
            }
            ClientLogger.Debug("CalculationElapsed: {0}; LookupElapsed: {1}", calculationElapsed.TotalMilliseconds, lookupElapsed.TotalMilliseconds);
        }