Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void Test_SFF_Linear()
        {
            (double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav");
            int fftSize = 1 << 12;
            var spec    = new SpectrogramGenerator(sampleRate, fftSize, stepSize: 700, maxFreq: 2000);

            spec.SetWindow(FftSharp.Window.Hanning(fftSize / 3)); // sharper window than typical
            spec.Add(audio);
            spec.SaveData("../../../../../dev/sff/hal.sff");

            var spec2 = new SFF("../../../../../dev/sff/hal.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);
        }
Beispiel #3
0
        public void Test_Make_CommonColormaps()
        {
            (double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav");
            int fftSize = 1 << 12;
            var spec    = new SpectrogramGenerator(sampleRate, fftSize, stepSize: 700, maxFreq: 2000);

            spec.SetWindow(FftSharp.Window.Hanning(fftSize / 3)); // sharper window than typical
            spec.Add(audio);

            // delete old colormap files
            foreach (var filePath in System.IO.Directory.GetFiles("../../../../../dev/graphics/", "hal-*.png"))
            {
                System.IO.File.Delete(filePath);
            }

            foreach (var cmap in Colormap.GetColormaps())
            {
                spec.SetColormap(cmap);
                spec.SaveImage($"../../../../../dev/graphics/hal-{cmap.Name}.png");
                Debug.WriteLine($"![](dev/graphics/hal-{cmap.Name}.png)");
            }
        }