Skip to content

Commit d8eb877

Browse files
committed
NuGet: use new readme format
1 parent 61908eb commit d8eb877

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/Spectrogram/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
**Spectrogram is a .NET library for creating frequency spectrograms from pre-recorded signals, streaming data, or microphone audio from the sound card.** Spectrogram uses FFT algorithms and window functions provided by the [FftSharp](https://github.com/swharden/FftSharp) project, and it targets .NET Standard so it can be used in .NET Framework and .NET Core projects.
2+
3+
[![](https://raw.githubusercontent.com/swharden/Spectrogram/master/dev/graphics/hal-spectrogram.png)](https://github.com/swharden/Spectrogram)
4+
5+
## Quickstart
6+
7+
```cs
8+
(double[] audio, int sampleRate) = ReadWavMono("hal.wav");
9+
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 500, maxFreq: 3000);
10+
sg.Add(audio);
11+
sg.SaveImage("hal.png");
12+
```
13+
14+
This example generates the image at the top of the page.
15+
16+
17+
## How to Read a WAV File
18+
19+
There are many excellent libraries that read audio files. Consult the documentation _for those libraries_ to learn how to do this well. Here's an example method I use to read audio values from mono WAV files using the NAudio package:
20+
21+
```cs
22+
(double[] audio, int sampleRate) ReadWavMono(string filePath, double multiplier = 16_000)
23+
{
24+
using var afr = new NAudio.Wave.AudioFileReader(filePath);
25+
int sampleRate = afr.WaveFormat.SampleRate;
26+
int bytesPerSample = afr.WaveFormat.BitsPerSample / 8;
27+
int sampleCount = (int)(afr.Length / bytesPerSample);
28+
int channelCount = afr.WaveFormat.Channels;
29+
var audio = new List<double>(sampleCount);
30+
var buffer = new float[sampleRate * channelCount];
31+
int samplesRead = 0;
32+
while ((samplesRead = afr.Read(buffer, 0, buffer.Length)) > 0)
33+
audio.AddRange(buffer.Take(samplesRead).Select(x => x * multiplier));
34+
return (audio.ToArray(), sampleRate);
35+
}
36+
```

src/Spectrogram/Spectrogram.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ Release Notes: https://github.com/swharden/Spectrogram/releases</PackageReleaseN
2222
<PackageReference Include="FftSharp" Version="1.0.8" />
2323
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
2424
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.8.64" Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'" />
25-
<None Include="icon.png">
26-
<Pack>True</Pack>
27-
<PackagePath></PackagePath>
28-
</None>
25+
<None Include="icon.png" Pack="true" PackagePath="\" />
26+
<None Include="README.md" Pack="true" PackagePath="\" />
2927
</ItemGroup>
3028

3129
</Project>

0 commit comments

Comments
 (0)