-
Notifications
You must be signed in to change notification settings - Fork 20
sound_level creates a sample buffer every time #53
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
Comments
Same issue elsewhere: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/blob/511f55ca17a742a5249540d92fa97e66a4226887/adafruit_circuitplayground/bluefruit.py#L90-L91 I've not done a comprehensive survey on this. |
Fixing self._sample typo in sound_level #53
Looks like this got solved (at least in part) by PR #54, is this fixed now? Or is it worth specifically calling |
I do believe this is resolved by #54. I've submitted a similar fix into the circuitplayground repo and I checked the bundle for any other instances of |
The code checks if
self._sample
has been initialised and then assigns a new buffer toself._samples
(note plural!). It looks like a typo which wasn't picked up by linting as_sample
is used for playing sounds over tiny speaker.Adafruit_CircuitPython_CLUE/adafruit_clue.py
Lines 815 to 816 in 670355e
This causes a new buffer to be created on each read of the
sound_level
property. This doesn't leak but it is inefficient and may cause problems for applications with a small amount of (fragmented) remaining memory...Once this is fixed, a single read of
sound_level
may be beneficial at the start of a program that's tight on memory or encounteringMemoryError: memory allocation failed, allocating 640 bytes
exceptions later whensound_level
is used repeatedly. This approach aligns with the advice in Adafruit Learn: Memory-saving tips for CircuitPython: Memory: Reducing fragmentation.The text was updated successfully, but these errors were encountered: