/// <summary> /// Replace output sample at position with prediction and /// sets prediction error sample to zero /// </summary> /// <param name="audioData"></param> /// <param name="position"></param> /// <param name="lenght"></param> public static float Repair(AudioData audioData, int position, int lenght) { for (var index = position; index < position + lenght; index++) { audioData.SetPredictionErr(index, 0.001F); audioData.SetOutputSample( index, CalcBurgPred(audioData, index) ); } for (var index = position + lenght; index < position + lenght + 5; index++) { audioData.SetPredictionErr( index, CalcBurgPred(audioData, index) - audioData.GetOutputSample(index)); } var historyLengthSamples = audioData.AudioProcessingSettings.HistoryLengthSamples; HelperCalculator.CalculateErrorAverageCpu( audioData, position - historyLengthSamples, position + lenght + historyLengthSamples, historyLengthSamples); return(HelperCalculator.CalculateDetectionLevel(audioData, position)); }
/// <summary> /// Scans channel to find damaged samples /// </summary> /// <param name="audioData"></param> /// <param name="progress"></param> /// <param name="status"></param> /// <returns></returns> private static async Task ProcessChannelAsync( AudioData audioData, IProgress <double> progress, IProgress <string> status) { var historyLengthSamples = audioData.AudioProcessingSettings.HistoryLengthSamples; SetStatus(audioData, status, "preprocessing"); if (audioData.CurrentChannelIsPreprocessed()) { // if prediction errors were previously calculated audioData.RestoreCurrentChannelPredErrors(); } else { CalculateBurgPredictionErrCpu(audioData, progress); audioData.SetCurrentChannelIsPreprocessed(); audioData.BackupCurrentChannelPredErrors(); } for (var index = 0; index < historyLengthSamples + 16; index++) { audioData.SetErrorAverage(index, 0.001F); } HelperCalculator.CalculateErrorAverageCpu( audioData, historyLengthSamples, audioData.LengthSamples(), historyLengthSamples); status.Report(""); // copies input samples to output before scanning for (var index = 0; index < audioData.LengthSamples(); index++) { audioData.SetOutputSample(index, audioData.GetInputSample(index)); } SetStatus(audioData, status, "scanning"); await Task.Run(() => ScanAudioAsync(audioData, progress)); status.Report(""); }