/// <summary>
        /// Scans segment of audio channel to find damaged samples
        /// and repai them
        /// </summary>
        /// <param name="audioData"></param>
        /// <param name="segmentStart"></param>
        /// <param name="segmentEnd"></param>
        /// <param name="progress"></param>
        /// <param name="cpuCore"></param>
        private static void ScanSegment(
            AudioData audioData,
            int segmentStart,
            int segmentEnd,
            IProgress <double> progress,
            int cpuCore)
        {
            var lastProcessedSample = 0;

            // cycle to check every sample
            for (var index = segmentStart; index < segmentEnd; index++)
            {
                // only core #0 reports progress
                if (cpuCore == 0)
                {
                    ThrottledReportProgress(progress, index, segmentEnd);
                }

                if (index <= lastProcessedSample || !ClickDetector.IsSampleSuspicious(
                        audioData,
                        index))
                {
                    continue;
                }

                var maxLength = HelperCalculator.GetMaxLength(audioData, index);
                var result    = ClickLengthFinder.FindLengthOfClick(
                    audioData,
                    index,
                    maxLength,
                    lastProcessedSample);

                if (!result.Success)
                {
                    continue;
                }

                ClickRepairer.Repair(audioData, result.Position, result.Length);
                audioData.AddClickToList(new AudioClick(
                                             result.Position,
                                             result.Length,
                                             HelperCalculator.CalculateDetectionLevel(audioData, result.Position),
                                             audioData,
                                             audioData.GetCurrentChannelType()));

                lastProcessedSample = result.Position + result.Length + 1;
            }
        }
        private static FixResult TryToFix(
            AudioData audioData,
            int index,
            int maxLength,
            int minLength)
        {
            var result = new FixResult
            {
                Success  = false,
                Position = index,
                Length   = minLength,
                ErrSum   = float.MaxValue
            };

            ClickRepairer.Repair(audioData, index, minLength);

            while (result.Length < maxLength)
            {
                ClickRepairer.Repair(audioData, index + result.Length, 1);
                result.Length++;

                if (!SeveralSamplesInARowAreSuspicious(
                        audioData, index + result.Length, 3))
                {
                    result.ErrSum = CalcErrSum(
                        audioData, index + result.Length, 4);

                    // if click fixed
                    if (result.ErrSum < 0.01F) //0.005F //0.03F
                    {
                        result.Success = true;
                        break;
                    }
                }
            }

            return(result);
        }