public void Test_SFF_Mel() { (double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav"); int fftSize = 1 << 12; var spec = new SpectrogramGenerator(sampleRate, fftSize, stepSize: 700); var window = new FftSharp.Windows.Hanning(); spec.SetWindow(window.Create(fftSize / 3)); // sharper window than typical spec.Add(audio); Bitmap bmp = spec.GetBitmapMel(250); bmp.Save("../../../../../dev/sff/halMel.png", System.Drawing.Imaging.ImageFormat.Png); spec.SaveData("../../../../../dev/sff/halMel.sff", melBinCount: 250); var spec2 = new SFF("../../../../../dev/sff/halMel.sff"); Assert.AreEqual(spec.SampleRate, spec2.SampleRate); Assert.AreEqual(spec.StepSize, spec2.StepSize); Assert.AreEqual(spec.Width, spec2.Width); Assert.AreEqual(spec.FftSize, spec2.FftSize); Assert.AreEqual(spec.NextColumnIndex, spec2.FftFirstIndex); Assert.AreEqual(spec.Height, spec2.Height); Assert.AreEqual(spec.OffsetHz, spec2.OffsetHz); }
public void BuildSpectrogram(string _wavPath) { double[] audio; int sampleRate; (audio, sampleRate) = ReadWAV(_wavPath); var sg = new SpectrogramGenerator(sampleRate, fftSize: FFTSize, stepSize: FFTStepSize, maxFreq: MaxFrequency); //sg.SetFixedWidth(SpectrogramWidth); sg.Add(audio); sg.SetColormap(ImageColormap); //sg.SetFixedWidth(1024); var bmp = sg.GetBitmapMel(melBinCount: 103, dB: true, dBScale: 10); bmp.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg); //sg.SaveImage(ImagePath, dB: true, dBScale: 10); }
public void Test_MelSpectrogram_MelScale() { (double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav"); int fftSize = 4096; var sg = new SpectrogramGenerator(sampleRate, fftSize, stepSize: 500); sg.Add(audio); Bitmap bmpMel = sg.GetBitmapMel(250); bmpMel.Save("../../../../../dev/graphics/halMel-MelScale.png", ImageFormat.Png); Bitmap bmpRaw = sg.GetBitmap(); Bitmap bmpCropped = new Bitmap(bmpRaw.Width, bmpMel.Height); using (Graphics gfx = Graphics.FromImage(bmpCropped)) { gfx.DrawImage(bmpRaw, 0, bmpMel.Height - bmpRaw.Height); } bmpCropped.Save("../../../../../dev/graphics/halMel-LinearCropped.png", ImageFormat.Png); }