Skip to content
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

synthio: Add Synthesizer.note_state #8186

Merged
merged 5 commits into from
Jul 21, 2023
Merged

Conversation

jepler
Copy link
Member

@jepler jepler commented Jul 20, 2023

This enables the specific use case of checking whether a note's release phase has ended, but is also potentially useful to implement a sort of "voice stealing" algorithm in Python code, which can take account of the note's envelope state as well as other factors specific to the program.

@todbot your comment on this would be appreciated

jepler added 4 commits July 20, 2023 13:16
This enables the specific use case of checking whether a note's release
phase has ended, but is also potentially useful to implement a sort of
"voice stealing" algorithm in Python code, which can take account of
the note's envelope state as well as other factors specific to the
program.
... by the disassembly just below

This was tripped up because in exactly the right conditions some qstr
could be of the form 'xx 63' and make the expression `\.\+63` match
something other than what was intended.

This test was re-worked upstream for mpy version 6 so it'll be a conflict
to resolve when we get to that. :-/
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for the size fix too.

@todbot
Copy link

todbot commented Jul 21, 2023

This addition is really neat! Both items returned in synth.note_info() are handy. Here's the quick test I used; it maxes out all synthio voices while printing their note_info (and makes a nice distorty wall of sound). https://gist.github.com/todbot/e1e954889e47fafa7ef14429c53e2c2d

Am I correct that:

  • The amplitude value returned is the same as Note.amplitude
  • If it returns (None,0.0), synthio is done with that Note object

A few things I noticed:

  • The whole system degrades if you ask it about a bunch of Note objects it doesn't know about
  • I got some hard crashes with ear-splitting static a few times. Was that me just badgering USB too fast or is the note_info() call kinda costly?

@tannewt
Copy link
Member

tannewt commented Jul 21, 2023

@jepler is out today and Monday so I'm going to merge this as-is to get the size fix. He can make a follow up PR if needed. Thanks for the feedback @todbot.

@tannewt tannewt merged commit 9e22850 into adafruit:main Jul 21, 2023
@jepler
Copy link
Member Author

jepler commented Jul 24, 2023

The Note.amplitude another value that is multiplied together with the envelope's current value to give an overall note loudness, so the two values are different. (A Note's panning is yet another factor into the overall note loudness)

Each note_state call does a linear search through the (typically) 12 note slots. If a note is found in an early slot it takes a bit less time, while if it's a note that is not playing or was never playing it takes the greatest amount of time.

Bulk printing of data can cause glitches, because during USB CDC console writes the background tasks can't run. (and with a displayio display it's even worse because the whole time a display is being background-updated, the audiobackground task is also blocked)

However, I don't know why this would lead to a hardfault. If you have a hardfault please try to minimize the test case and file an issue.

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

Successfully merging this pull request may close these issues.

3 participants