swharden / Spectrogram

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

Improve exception message when spectrogram is empty #42

Closed swharden closed 2 years ago

swharden commented 2 years ago

Abhinav e-mailed me indicating this library was throwing a divide-by-zero exception. It turned-out the problem was that it had some audio, but not enough to fill a full FFT column, and getting the bitmap would throw an exception.

itsAbhi650 commented 2 years ago

Well, if you have Integrated width check I there won't be any need to do it manually everytime. Thanks

swharden commented 2 years ago

if you have Integrated width check I there won't be any need to do it manually every time

Yes and no. GetBitmap() returns a Bitmap, so the best I could do is have it check if Width is 0 and return null, but then your program would crash with a null reference exception (and an unhelpful message) if you try to call that object's Save() method.

I think the best behavior here is for GetBitmap() to throw an exception if there is insufficient data, and with e3b6e3f1603c4a2c331cee67fb438202edb47051 I updated the message to more clearly state what the issue was and how to fix it. It is published on NuGet now.

Thank you again for opening this issue!

itsAbhi650 commented 2 years ago

Returning null when insufficient data.. that definitely make sense! and hey your welcome! That is what open source is all about 😄