Skip to content

Commit dd54c7e

Browse files
committed
SFF: deprecate
resolves #44
1 parent 3828e2f commit dd54c7e

File tree

5 files changed

+21
-150
lines changed

5 files changed

+21
-150
lines changed

README.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -153,58 +153,6 @@ Bitmap bmp = sg.GetBitmapMel(melSizePoints: 250);
153153
bmp.Save("halMel.png", ImageFormat.Png);
154154
```
155155

156-
## Spectrogram File Format (SFF)
157-
158-
The Spectrogram library has methods which can read and write SFF files, a file format specifically designed for storing spectrogram data. SFF files contain 2D spectrogram data (repeated FFTs) with a [small header](dev/sff) describing the audio and FFT settings suitable for deriving scale information.
159-
160-
SFF files store `double` values (8-byte floating-point data) which is far superior to saving spectrograms as indexed color images (which represent intensity with a single `byte` per pixel).
161-
162-
SFF files be saved using `Complex` data format (with real and imaginary values for each point) to faithfully represent the FFT output, or `double` format to represent magnitude (with an optional pre-conversion to Decibels to represent power).
163-
164-
### Create SFF Files with C#
165-
166-
This example creates a spectrogram but saves it using the SFF file format instead of saving it as an image. The SFF file can then be read in any language.
167-
168-
```cs
169-
(double[] audio, int sampleRate) = ReadWavMono("hal.wav");
170-
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 700, maxFreq: 2000);
171-
sg.Add(audio);
172-
sg.SaveData("hal.sff");
173-
```
174-
175-
### Display SFF Files with C#
176-
Spectrogram data can be loaded from SFF files to facilitate rapid recall of data which can otherwise be resource-intensive to calculate. Spectrogram's `SFF` module facilitates this operation and has methods which can directly convert spectrograms to Bitmaps with options to customize the colormap, intensity, and Decibel scaling.
177-
178-
![](dev/sff/SffViewer/screenshot.png)
179-
180-
A simple SFF file viewer has been added to [dev/sff](dev/sff) and serves as a demonstration of how the `SFF` module can be used to generate spectrogram images from SFF files.
181-
182-
### Read SFF Files with Python
183-
A Python module to read SFF files has been created (in [dev/sff/python](dev/sff/python)) which allows Spectrograms created by this library and stored in SFF format to be loaded as 2D numpy arrays in Python.
184-
185-
This example demonstrates how the SFF file created in the previous C# example can be loaded into Python and displayed with matplotlib. This example has a few lines related to styling omitted for brevity, but the full Python demo can be found in [dev/sff/python](dev/sff/python).
186-
187-
```python
188-
import matplotlib.pyplot as plt
189-
import sffLib
190-
191-
# load spectrogram data as a 2D numpy array
192-
sf = sffLib.SpectrogramFile("hal.sff")
193-
194-
# display the spectrogram as a pseudocolor mesh
195-
plt.pcolormesh(freqs, times, sf.values)
196-
plt.colorbar()
197-
plt.show()
198-
```
199-
200-
![](dev/sff/python/hal.sff.png)
201-
202-
## Resources
203-
* [FftSharp](https://github.com/swharden/FftSharp) - the module which actually performs the FFT and related transformations
204-
* [MP3Sharp](https://github.com/ZaneDubya/MP3Sharp) - a library I use to read MP3 files during testing
205-
* [FSKview](https://github.com/swharden/FSKview) - a real-time spectrogram for viewing frequency-shift-keyed (FSK) signals from audio transmitted over radio frequency.
206-
* [NAudio](https://github.com/naudio/NAudio) - an open source .NET library which makes it easy to get samples from the microphone or sound card in real time
207-
208156
## Read data from a WAV File
209157

210158
You should customize your file-reading method to suit your specific application. I frequently use the NAudio package to read data from WAV and MP3 files. This function reads audio data from a mono WAV file and will be used for the examples on this page.

src/Spectrogram.Tests/FileFormat.cs

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/Spectrogram/SFF.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
namespace Spectrogram
1010
{
11-
// Spectrogram File Format reader/writer
11+
[Obsolete("The SFF file format is obsolete. " +
12+
"Users are encouraged to write their own IO routines specific to their application. "+
13+
"To get a copy of the original SFF reader/writer see https://github.com/swharden/Spectrogram/issues/44",
14+
error: true)]
1215
public class SFF
1316
{
1417
public readonly byte VersionMajor = 1;

src/Spectrogram/SpectrogramGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ public Bitmap GetBitmapMax(double intensity = 1, bool dB = false, double dBScale
350350
return Image.GetBitmap(ffts2, Colormap, intensity, dB, dBScale, roll, NextColumnIndex);
351351
}
352352

353+
[Obsolete("The SFF file format is obsolete. " +
354+
"Users are encouraged to write their own IO routines specific to their application. " +
355+
"To get a copy of the original SFF reader/writer see https://github.com/swharden/Spectrogram/issues/44",
356+
error: true)]
353357
/// <summary>
354358
/// Export spectrogram data using the Spectrogram File Format (SFF)
355359
/// </summary>

src/Spectrogram/Tools.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace Spectrogram
77
{
88
public static class Tools
99
{
10+
[Obsolete("The SFF file format is obsolete. " +
11+
"Users are encouraged to write their own IO routines specific to their application. " +
12+
"To get a copy of the original SFF reader/writer see https://github.com/swharden/Spectrogram/issues/44",
13+
error: true)]
1014
/// <summary>
1115
/// Collapse the 2D spectrogram into a 1D array (mean power of each frequency)
1216
/// </summary>
@@ -31,6 +35,11 @@ public static double[] SffMeanFFT(SFF sff, bool dB = false)
3135
return mean;
3236
}
3337

38+
39+
[Obsolete("The SFF file format is obsolete. " +
40+
"Users are encouraged to write their own IO routines specific to their application. " +
41+
"To get a copy of the original SFF reader/writer see https://github.com/swharden/Spectrogram/issues/44",
42+
error: true)]
3443
/// <summary>
3544
/// Collapse the 2D spectrogram into a 1D array (mean power of each time point)
3645
/// </summary>
@@ -48,6 +57,10 @@ public static double[] SffMeanPower(SFF sff, bool dB = false)
4857
return power;
4958
}
5059

60+
[Obsolete("The SFF file format is obsolete. " +
61+
"Users are encouraged to write their own IO routines specific to their application. " +
62+
"To get a copy of the original SFF reader/writer see https://github.com/swharden/Spectrogram/issues/44",
63+
error: true)]
5164
public static double GetPeakFrequency(SFF sff, bool firstFftOnly = false)
5265
{
5366
double[] freqs = firstFftOnly ? sff.Ffts[0] : SffMeanFFT(sff, false);

0 commit comments

Comments
 (0)