-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Usage Improvements #33
Conversation
…to match the eventual size of `audio`
…an external `List<double>`
I tried but don't know where to add explanation for the additional optional argument in readme.md (supposed to be something like shortcuts? |
@swharden pls merge this... |
I've been focusing the last few days on https://github.com/ScottPlot/ScottPlot/issues and https://github.com/ScottPlot/ScottPlot/pulls but I'll try to get to this by the end of the day 👍 |
Hi @shirok1, thank you for your PR! I reviewed its content and will begin working on it now. The original comment/PR conflated at least 3 distinct issues. I opened 3 issues to track progress toward each and edited your original comment to link to those issues. I hope you find this acceptable 👍 I'll refactor this PR to address just the IEnumerable suggestion (#35) and merge it in, then work on the other two issues separately. |
This reverts commit 6640625.
Uses Python's scipy.io.wavfile as a source of truth. swharden#33 swharden#34
Regarding topic 1, I added new tests to verify that ReadWAV is functioning as expected. I used Python's scipy.io.wavfile and GoldWave to confirm the lengths of WAV files in the data folder. Spectrogram/src/Spectrogram.Tests/AudioFileTests.cs Lines 13 to 25 in 448282f
I think the misunderstanding is that if the data is two channels, it will return an array with data from both channels in the array. Perhaps it's simply twice as large as you expected because of this? |
Makes it more explicit that this sample function only works with mono WAV files. #33
Thank you for your work on manually splitting it into 3 issues! Therefor my commits will be much clarified.
The garbage is generated when the array is |
Long story short, I am developing a WPF app using this library as a use-and-throw-away spectrogram generator. After noticing an unreasonably high memory usage,
EDIT: @shirok1's original comment/PR addressed multiple independent topics and @swharden edited it to add expandable sections and link to individual issue pages.
1. Bug: ReadWAV returns wrong sample count (#34)
1. Wrong
sampleCount
expression inReadWAV
(readme.md)I guess this
sampleCount
is an estimation of the final size of theList<double> audio
. However, 253296 is 64 times smaller than 16210944. So the most reasonable explanation is/8
is a typo of*8
.This "typo" causes the birth of garbage twice as large as the
audio
itself.2. Feature: SpectrogramGenerator.Add() should accept IEnumerable (#35)
2. An unnecessary type requirement in signature of
sg.Add()
List<double>.AddRange
accepts anIEnumerable<double>
as the parameter. However,sg.Add()
asks for an explicitdouble[]
, which means that I can't directly use theList<double>
but have to do a.ToArray()
first, which obvious will waste the memory as large as theaudio
itself.3. Feature: Support initializing with an existing List (#36)
3. 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 theBitmap
is generated, both theaudio
inReadWAV
and thenewAudio
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 laterGrow
into the same size asaudio
, which is the real problem).4. Question: How to use the debugger
P.S. I tried to add a breakpoint directly in the "Definition", but this is shown.Could you tell me the right way to do this?
Hopefully this PR be merged and a new version of Nuget package be released. May you have a wonderful day!