Skip to content

Solve possible long-lived allocator issue vs synthio #8082

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

Closed
jepler opened this issue Jun 13, 2023 · 4 comments
Closed

Solve possible long-lived allocator issue vs synthio #8082

jepler opened this issue Jun 13, 2023 · 4 comments

Comments

@jepler
Copy link

jepler commented Jun 13, 2023

CircuitPython version

8.2.0-beta.1

Code/REPL

# see forum thread

Behavior

when some synthio objects (particularly the Synthesizer itself?) are imported, synthio breaks.

these objects refer to each other in complicated ways, e.g., AudioOut -> Synthesizer -> Note -> LFO

If one of these objects is moved (made long-lived) it would break the relationships.

At the same time, Notes in particular are not conceptually "long lived", so the usual thing we've done (e.g., with UART, which frequently is pointed to by an interrupt handler object) of initially allocating as long-lived is not a great solution.

This may be a cause of https://forums.adafruit.com/viewtopic.php?t=202163 -- I saw and ignored something similar during testing.

A workaround that still lets the "create audio player", "create synthesizer" object etc code to be re-used is to place a FUNCTION for creating the object in the import, instead of creating the object itself there.

Description

No response

Additional information

No response

@jepler jepler added the bug label Jun 13, 2023
@tannewt tannewt added the audio label Jun 13, 2023
@tannewt tannewt added this to the 8.x.x milestone Jun 13, 2023
@todbot
Copy link

todbot commented Jun 14, 2023

Looks like the issue noted in the forum post has been resolved so I think this issue could be closed?

@jepler
Copy link
Author

jepler commented Jun 14, 2023

I'd like to leave it for now. I was wrong about it being the cause of the user's problem, but there's a real problem here which can arise when you do something like

# go_audio.py
speaker = I2SAudioOut(...)
synth = Synthio(...)
speaker.play(synth)
# code.py
from go_audio import synth
synth.press(...)

which I believe is because of long-lived objects; the "synth" that is played on "speaker" is not the same "synth" that is imported from code.py, and so things don't work.

@jepler
Copy link
Author

jepler commented Jun 21, 2023

This is a facet of #2687

@jepler jepler modified the milestones: 8.x.x, Long term Jun 21, 2023
@dhalbert
Copy link
Collaborator

Fixed by #8281, which removed long-lived allocations, and so removed objects moving around after creation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants