forked from swharden/Spectrogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickstart.cs
More file actions
44 lines (38 loc) · 1.43 KB
/
Quickstart.cs
File metadata and controls
44 lines (38 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using NUnit.Framework;
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace Spectrogram.Tests
{
public class Quickstart
{
[Test]
public void Test_Quickstart_Hal()
{
(int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/cant-do-that-44100.wav");
int fftSize = 4096;
var spec = new Spectrogram(sampleRate, fftSize, stepSize: 500, maxFreq: 3000);
spec.Add(audio);
spec.SaveImage("../../../../../dev/graphics/hal.png", intensity: .2);
Console.WriteLine(spec);
}
[Test]
public void Test_Quickstart_Handel()
{
double[] audio = Mp3.Read("../../../../../data/Handel - Air and Variations.mp3");
int sampleRate = 44100;
int fftSize = 16384;
int targetWidthPx = 3000;
int stepSize = audio.Length / targetWidthPx;
var spec = new Spectrogram(sampleRate, fftSize, stepSize, maxFreq: 2200);
spec.Add(audio);
spec.SaveImage("../../../../../dev/spectrogram-song.jpg", intensity: 5, dB: true);
Console.WriteLine(spec);
/*
Spectrogram (2993, 817)
Vertical (817 px): 0 - 2,199 Hz, FFT size: 16,384 samples, 2.69 Hz/px
Horizontal (2993 px): 2.96 min, window: 0.37 sec, step: 0.06 sec, overlap: 84%
*/
}
}
}