Skip to content

Commit 43c84ed

Browse files
committed
SFF.GetPixelInfo()
1 parent 21f588e commit 43c84ed

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Spectrogram/SFF.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class SFF
2727
public int OffsetHz { get; private set; }
2828
public int MelBinCount { get; private set; }
2929
public bool Decibels { get; private set; }
30+
public bool IsMel { get { return MelBinCount > 0; } }
3031

3132
// FFT details
3233
public int FftHeight { get { return Ffts[0].Length; } }
@@ -220,5 +221,20 @@ public void Save(string filePath)
220221
// write file to disk
221222
File.WriteAllBytes(filePath, fileBytes);
222223
}
224+
225+
public (double timeSec, double freqHz, double magRms) GetPixelInfo(int x, int y)
226+
{
227+
double timeSec = (double)x * StepSize / SampleRate;
228+
229+
double maxFreq = SampleRate / 2;
230+
double maxMel = FftSharp.Transform.MelFromFreq(maxFreq);
231+
double frac = (FftHeight - y) / (double)FftHeight;
232+
double freq = IsMel ? FftSharp.Transform.MelToFreq(frac * maxMel) : frac * maxFreq;
233+
234+
double mag = double.NaN;
235+
try { mag = Ffts[x][FftHeight - y - 1]; } catch { }
236+
237+
return (timeSec, freq, mag);
238+
}
223239
}
224240
}

0 commit comments

Comments
 (0)