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

SpectrogramGenerator: Support initializing with an existing list #36

Closed swharden closed 3 years ago

swharden commented 3 years ago

Content originally posted by @shirok1 in #33:


The loss of possibility to DIRECTLY use the reference of an external List<double>

The way you design this generator is for continuous or even real-time spectro drawing. In this case, make List<double> newAudio read-only, init as an empty one and .AddRange() later is the best solution. However, in my case, I need to use SG to generate the spectro for only once. Which means that as the Bitmap is generated, both the audio in ReadWAV and the newAudio in SG will immediately become garbage.

The Solution I come up with is this: An addition Optional Argument to init newAudio. It keeps the forward compatibility, but also enable me to prevent meaningless object creation (and later Grow into the same size as audio, which is the real problem). image