private int AdjustPitchMark(WAVSound sound, int nominalPitchMarkIndex, int adjustmentIndexRange) //, double relativePeakThreshold, double energyComputationTimeRange)
        {
            int        absoluteMaximum = Math.Abs(sound.Samples[0][nominalPitchMarkIndex]);
            int        threshold       = (int)Math.Round(relativePeakThreshold * absoluteMaximum);
            List <int> indicesOfLocalMaximaAboveThreshold = sound.GetIndicesOfLocalExtremaAboveThreshold(nominalPitchMarkIndex, adjustmentIndexRange, adjustmentIndexRange, threshold);
            int        adjustedPitchMarkIndex             = nominalPitchMarkIndex; //  sound.GetSampleIndexAtTime(timeOfAbsoluteMaximum); // Fallback value.
            double     minimumPreviousEnergy       = double.MaxValue;
            int        energyComputationIndexRange = (int)Math.Round(energyComputationTimeRange * sound.SampleRate);

            for (int ii = 0; ii < indicesOfLocalMaximaAboveThreshold.Count; ii++)
            {
                int indexOfLocalMaximumAboveThreshold = indicesOfLocalMaximaAboveThreshold[ii];
                int energyComputationEndIndex         = indexOfLocalMaximumAboveThreshold - 1;
                if (energyComputationEndIndex >= sound.Samples[0].Count)
                {
                    energyComputationEndIndex = sound.Samples[0].Count - 1;
                }
                int energyComputationStartIndex = indexOfLocalMaximumAboveThreshold - energyComputationIndexRange;
                if (energyComputationStartIndex < 0)
                {
                    energyComputationStartIndex = 0;
                }
                double localEnergy = sound.GetLocalEnergy(energyComputationStartIndex, energyComputationEndIndex);
                if (localEnergy < minimumPreviousEnergy)
                {
                    minimumPreviousEnergy  = localEnergy;
                    adjustedPitchMarkIndex = indexOfLocalMaximumAboveThreshold;
                }
            }
            return(adjustedPitchMarkIndex);
        }