public static Task <float []> Calculate(Soundfile soundfile) { SoundfileValidator.ValidateBasics(soundfile); var centroid = soundfile.GetFrequencyCentroid(); if (centroid is null || centroid.Length == 0) { throw new InvalidOperationException($"{nameof (soundfile)} does not have frequency centroid calculated. Calculate it first."); } return(Task.Run(() => { var count = soundfile.GetSamples().Length / soundfile.FrameLength; var bandwidth = new float [count]; _ = Parallel.For(0, count, (i) => { var singleFrame = soundfile.GetFftPerFrame(i); float sumUp = 0, sumDown = 0; for (int s = 0; s < singleFrame.Length; s++) { sumUp += (s - centroid [i]) * (s - centroid [i]) * singleFrame [s] * singleFrame [s]; sumDown += singleFrame [s] * singleFrame [s]; } var band = sumUp / sumDown; bandwidth [i] = float.IsInfinity(band) || float.IsNaN(band) ? 0 : sumUp / sumDown; }); return bandwidth; })); }
public static Task <float []> Calculate(Soundfile soundfile) { if (!MainWindow.ShowHiddenParameters) { return(Task.Run(() => Array.Empty <float> ())); } SoundfileValidator.ValidateBasics(soundfile); var f1 = soundfile.BEFrequencyStart; var f2 = soundfile.BEFrequencyStop; return(Task.Run(() => { var count = soundfile.GetSamples().Length / soundfile.FrameLength; var csf = new float [count]; _ = Parallel.For(0, count, (i) => { var maxUp = soundfile.GetFftPerFrame(i).Max(f => f * f); double down = 0; for (int s = f1; s < Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length); s++) { down += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s]; } down /= f2 - f1 + 1; var add = (float)(maxUp / down); if (!float.IsNaN(add) && !float.IsInfinity(add)) { csf [i] = add; } }); return csf; })); }
public static Task <float []> Calculate(Soundfile soundfile) { SoundfileValidator.ValidateBasics(soundfile); return(Task.Run(() => { var volume = new float [soundfile.GetSamples().Length / soundfile.FrameLength]; _ = Parallel.For(0, soundfile.GetSamples().Length / soundfile.FrameLength, (i) => { var singleVolume = soundfile.GetFftPerFrame(i); float sum = 0; foreach (var j in singleVolume) { sum += j * j; } volume [i] = (sum / soundfile.FrameLength); }); return volume; })); }
public static Task <float []> Calculate(Soundfile soundfile) { SoundfileValidator.ValidateBasics(soundfile); return(Task.Run(() => { var fc = new float [soundfile.GetSamples().Length / soundfile.FrameLength]; _ = Parallel.For(0, soundfile.GetSamples().Length / soundfile.FrameLength, (i) => { var singleFc = soundfile.GetFftPerFrame(i); float sumUp = 0, sumDown = 0; for (int s = 0; s < singleFc.Length; s++) { sumUp += s * singleFc [s]; sumDown += singleFc [s]; } var cent = sumUp / sumDown; fc [i] = float.IsNaN(cent) || float.IsInfinity(cent) ? 0 : sumUp / sumDown; }); return fc; })); }
public static Task <float []> Calculate(Soundfile soundfile) { if (!MainWindow.ShowHiddenParameters) { return(Task.Run(() => Array.Empty <float> ())); } SoundfileValidator.ValidateBasics(soundfile); var f1 = soundfile.BEFrequencyStart; var f2 = soundfile.BEFrequencyStop; return(Task.Run(() => { var count = soundfile.GetSamples().Length / soundfile.FrameLength; var sfm = new float [count]; _ = Parallel.For(0, count, (i) => { double up = 1, down = 0; var max = Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length); double n = max - f1; for (int s = f1; s < max; s++) { if (soundfile.GetFftPerFrame(i) [s] == 0) { continue; } up *= Math.Pow(soundfile.GetFftPerFrame(i) [s], 2.0 / n); down += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s]; } down /= n; var add = (float)(up / down); if (!float.IsNaN(add) && !float.IsInfinity(add)) { sfm [i] = add; } }); return sfm; })); }
public static Task <float []> Calculate(Soundfile soundfile) { SoundfileValidator.ValidateBasics(soundfile); var f1 = soundfile.BEFrequencyStart; var f2 = soundfile.BEFrequencyStop; return(Task.Run(() => { var count = soundfile.GetSamples().Length / soundfile.FrameLength; var energy = new float [count]; _ = Parallel.For(0, count, (i) => { float sumUp = 0, sumDown = 0; for (int s = f1; s < Math.Min(f2 + 1, soundfile.GetFftPerFrame(i).Length); s++) { sumUp += soundfile.GetFftPerFrame(i) [s] * soundfile.GetFftPerFrame(i) [s]; sumDown++; } energy [i] = sumUp / sumDown; }); return energy; })); }