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

Misc fixes for light mode #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xyzzy42
Copy link
Contributor

@xyzzy42 xyzzy42 commented Mar 18, 2021

There is race when switching between normal and light mode. Fix this.

If light mode is set in the config file, the app will start in normal anyway and then switch to light mode after processing a bit of audio. This is annoying and can be fixed so it starts in the correct mode to begin with.

xyzzy42 added 2 commits March 17, 2021 19:50
When light mode is toggled, it's possible for the buffer pointer or
timestamp to get messed up if it happens while the callback is running.

The callback will read the current values when it starts, then light
mode switch resets them to zero, and then when the callback finishes it
updates them based on the original values, effectvely undoing to reset
to zero.

This doesn't cause a crash, but it does mean the timestamp isn't quite
right.  It also will cause problems if any code wants to process the
audio data as it arrives.

It could cause a single callback to be processed with the incorrect high
pass filter.

The easiest way to fix this is to pause the input stream while doing the
mode switch.  It could be fixed by making the entire callback a critical
section or having the mode switch done asyncrounsly via the callback,
but this makes the callback more complex and adds overhead.  It seems
better to add the extra work to the mode switch rather than the
callback, since the former is a rare operation that isn't performance
critical while the latter is.
This way settings that affect audio can be read in before audio starts.

Since the config file is now read before starting audio, it is possible
to start in light or normal mode as configured.

If light mode was configured, then previously audio would be started in
normal mode and then immediatly switch to light mode after processing a
few callbacks.
@xyzzy42 xyzzy42 force-pushed the trentpi/misc-lightmode-fixes branch from e641a1b to 4282a1c Compare April 18, 2021 23:57
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.

1 participant