public static TimeSpan Calculate(IAudioStream s1, Interval i1, IAudioStream s2, Interval i2, ProgressMonitor progressMonitor, out Result result) { if (i1.Length != i2.Length) { throw new ArgumentException("interval lengths do not match"); } s1 = PrepareStream(s1, 11050); s2 = PrepareStream(s2, 11050); IProgressReporter progress = progressMonitor.BeginTask("calculating cross-correlation", true); float seconds = (float)(i1.Length / 10d / 1000 / 1000); int sampleRate = s1.Properties.SampleRate; int n = (int)(seconds * sampleRate); float[] x = new float[n]; float[] y = new float[n]; int maxdelay = (int)(sampleRate * seconds / 4); if (maxdelay * 2 > n) { throw new Exception("maximum delay must be <= half of the interval to be analyzed"); } Debug.WriteLine("CC window: " + seconds + " secs = " + n + " samples"); float[] r = new float[maxdelay * 2]; StreamUtil.ForceReadIntervalSamples(s1, i1, x); StreamUtil.ForceReadIntervalSamples(s2, i2, y); int indexOffset = Calculate(x, y, progress, out result); TimeSpan offset = new TimeSpan((long)(indexOffset / (float)sampleRate * TimeUtil.SECS_TO_TICKS)); Debug.WriteLine("peak offset @ " + offset); progress.Finish(); return(offset); }