public void CalcBurgPred_SinusoidalInput_ReturnsPrediction() { const int historyLength = 512; var inputAudio = new float[historyLength + 1]; for (var i = 0; i < inputAudio.Length; i++) { inputAudio[i] = (float)Math.Sin(2 * Math.PI * i / (historyLength / 5.2)); } AudioData audioData = new AudioDataMono(inputAudio); for (var index = 0; index < audioData.LengthSamples(); index++) { audioData.SetOutputSample( index, audioData.GetInputSample(index)); } var prediction = ClickRepairer.CalcBurgPred( audioData, historyLength); Assert.AreEqual( prediction, inputAudio[inputAudio.Length - 1], 0.000001); }
public void FindLengthOfClick_DamagedSinusoidalInput_ReturnsLength(int shift) { const int historyLength = 512; const int signalLength = 5 * historyLength; const int damageLength = 10; var damageStartPosition = signalLength / 2 + shift; var inputAudio = new float[signalLength]; for (var index = 0; index < inputAudio.Length; index++) { inputAudio[index] = (float)Math.Sin(2 * Math.PI * index / (historyLength / 5.2)); } for (var index = damageStartPosition; index < damageStartPosition + damageLength; index++) { inputAudio[index] = 0; } AudioData audioData = new AudioDataMono(inputAudio); for (var index = historyLength; index < audioData.LengthSamples() - historyLength; index++) { audioData.SetOutputSample( index, audioData.GetInputSample(index)); var prediction = ClickRepairer.CalcBurgPred( audioData, index); audioData.SetPredictionErr(index, prediction - audioData.GetInputSample(index)); } HelperCalculator.CalculateErrorAverageCpu( audioData, historyLength, audioData.LengthSamples(), historyLength); audioData.SetCurrentChannelIsPreprocessed(); audioData.BackupCurrentChannelPredErrors(); var result = ClickLengthFinder.FindLengthOfClick(audioData, damageStartPosition, 250, 0); Assert.AreEqual(damageLength, result.Length, 1); }
public async Task AudioInputOutputSaveLoadTest() { var taskProgress = new Progress <double>(); var taskStatus = new Progress <string>(); var audioInputOutput = new AudioInputOutput(); await audioInputOutput.Init(taskProgress); var audioLength = 44100; var inputAudio = new float[audioLength]; for (var i = 0; i < inputAudio.Length; i++) { inputAudio[i] = (float)Math.Sin(2 * Math.PI * i / ((float)audioLength / 5)); } var audioData = new AudioDataMono(inputAudio); for (var index = 0; index < audioData.LengthSamples(); index++) { audioData.SetOutputSample( index, audioData.GetInputSample(index)); } audioInputOutput.SetAudioData(audioData); var testFolder = KnownFolders.MusicLibrary; var audioOutputFile = await testFolder.GetFileAsync("test.wav"); if (audioOutputFile != null) { await audioInputOutput.SaveAudioToFile(audioOutputFile, taskStatus); } }