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)); } }
public void G711ULawToLinearPerformanceComparison() { const int innerIterations = 10000; var input = new byte[_audioFormat.SamplesPerFrame]; var rnd = new Random(); for (int i = 0; i < input.Length; i++) { input[i] = (byte)rnd.Next(byte.MinValue, byte.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 (byte k in input) { var encoded = G711.ULawToLinear(k); } } calculationElapsed += DateTime.Now - start; start = DateTime.Now; for (int j = 0; j < innerIterations; j++) { foreach (byte k in input) { var encoded = G711.ULawToLinearFast(k); } } lookupElapsed += DateTime.Now - start; } ClientLogger.Debug("CalculationElapsed: {0}; LookupElapsed: {1}", calculationElapsed.TotalMilliseconds, lookupElapsed.TotalMilliseconds); }