Skip to content

Commit ab81058

Browse files
HaukanesAksel Haukanesswharden
authored
Support non integer sample rate. (#60)
* Support non integer sample rate. * Update SpectrogramGenerator.cs --------- Co-authored-by: Aksel Haukanes <[email protected]> Co-authored-by: Scott W Harden <[email protected]>
1 parent 44ef4fe commit ab81058

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Spectrogram/Settings.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Spectrogram
66
{
77
class Settings
88
{
9-
public readonly int SampleRate;
9+
public readonly double SampleRate;
1010

1111
// vertical information
1212
public readonly int FftSize;
@@ -29,7 +29,7 @@ class Settings
2929
public readonly double StepOverlapFrac;
3030
public readonly double StepOverlapSec;
3131

32-
public Settings(int sampleRate, int fftSize, int stepSize, double minFreq, double maxFreq, int offsetHz)
32+
public Settings(double sampleRate, int fftSize, int stepSize, double minFreq, double maxFreq, int offsetHz)
3333
{
3434
static bool IsPowerOfTwo(int x) => ((x & (x - 1)) == 0) && (x > 0);
3535

@@ -45,7 +45,7 @@ public Settings(int sampleRate, int fftSize, int stepSize, double minFreq, doubl
4545
// vertical
4646
minFreq = Math.Max(minFreq, 0);
4747
FreqNyquist = sampleRate / 2;
48-
HzPerPixel = (double)sampleRate / fftSize;
48+
HzPerPixel = sampleRate / fftSize;
4949
PxPerHz = (double)fftSize / sampleRate;
5050
FftIndex1 = (minFreq == 0) ? 0 : (int)(minFreq / HzPerPixel);
5151
FftIndex2 = (maxFreq >= FreqNyquist) ? fftSize / 2 : (int)(maxFreq / HzPerPixel);

src/Spectrogram/SpectrogramGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SpectrogramGenerator
5656
/// <summary>
5757
/// Number of samples per second
5858
/// </summary>
59-
public int SampleRate { get => Settings.SampleRate; }
59+
public double SampleRate { get => Settings.SampleRate; }
6060

6161
/// <summary>
6262
/// Number of samples to step forward after each FFT is processed.
@@ -218,7 +218,7 @@ public List<double[]> GetMelFFTs(int melBinCount)
218218

219219
var fftsMel = new List<double[]>();
220220
foreach (var fft in FFTs)
221-
fftsMel.Add(FftSharp.Mel.Scale(fft, SampleRate, melBinCount));
221+
fftsMel.Add(FftSharp.Mel.Scale(fft, (int)SampleRate, melBinCount));
222222

223223
return fftsMel;
224224
}

0 commit comments

Comments
 (0)