swharden / Spectrogram

.NET library for creating spectrograms (visual representations of frequency spectrum over time)
https://nuget.org/packages/Spectrogram
MIT License
315 stars 57 forks source link

Spectrogram renders as solid color. #28

Closed TheDJPHD closed 4 years ago

TheDJPHD commented 4 years ago

Hello, I am learning about Spectrograms and I would like to use this library to view spectrograms for the GTZAN music data set, which is a bunch of 30-second wav files at 22050hz.

Whenever I Add() the song, which I read in using Spectrogram.WavFile.ReadMono(), and then produce the image, it is always comes out as a straight blue/purple image, depending on the ColorMap.

I must be creating my spectrogram incorrectly, or something is wrong with my audio, though, I am confident my audio arrays are full of data. I even save them back to wav files and play them from my program.

I guess a solid color bitmap would mean that every frequency is the same for the whole song.

I am attaching one audio file here: SongSample.zip

Please let me know if you can help. Thank you, James

swharden commented 4 years ago

Hi @TheDJPHD, I am very sorry it took this long to get back to you! This issue slipped off my radar and I just noticed it again this morning. I'm guessing you figured this out or moved on, but just in case someone ends up here after Googling I thought I'd share the answer:

(int sampleRate, double[] audio) = Spectrogram.WavFile.ReadMono("blues.00001.wav");
var spec = new Spectrogram.Spectrogram(sampleRate, fftSize: 1024, stepSize: 800);
spec.Add(audio);
spec.SaveImage("test.png", intensity: 2);

image