-
Notifications
You must be signed in to change notification settings - Fork 138
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
Allow larger values of MAX_MIXINPUTS #396
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the change, left a few comments, and agree the performance impact shouldn't be a concern.
under the current model PRs are opened against the unstable
branch, merged there, then unstable
is merged to main
on the tagging of a release. I intend to change this, but for now I'll change your PR to be against unstable
src/rtl_airband.h
Outdated
unsigned int inputs_todo; | ||
unsigned int input_mask; | ||
int inputs_todo[MAX_MIXINPUTS] = {0}; | ||
int input_mask[MAX_MIXINPUTS] = {0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two variables will only have one of two values (0 or 1) so instead of using int
how about an array of bools?
src/mixer.cpp
Outdated
RESET_BIT(mixer->input_mask, input_idx); | ||
if(mixer->input_mask == 0) { | ||
mixer->input_mask[input_idx] = 0; | ||
for (int i = 0; i < MAX_MIXINPUTS; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding up the count, how about a bool has_some_input = false
then set to true
if anything in the array is true
. the vast majority of the time the first input will be active, so adding a && has_some_input == false
to the loop condition would mean it only goes through once most of the time
src/mixer.cpp
Outdated
@@ -169,7 +174,7 @@ void *mixer_thread(void *param) { | |||
for(int j = 0; j < mixer->input_count; j++) { | |||
mixinput_t *input = mixer->inputs + j; | |||
pthread_mutex_lock(&input->mutex); | |||
if(IS_SET(mixer->inputs_todo & mixer->input_mask, j) && input->ready) { | |||
if((mixer->inputs_todo[j] & mixer->input_mask[j]) && input->ready) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont think the binary and between inputs_todo
and mixer->input_mask
is necessary, once the arrays are bools this just becomes
if((mixer->inputs_todo[j] & mixer->input_mask[j]) && input->ready) { | |
if(mixer->inputs_todo[j] && mixer->input_mask[j] && input->ready) { |
src/mixer.cpp
Outdated
mixer->enabled = true; | ||
debug_print("ampfactor=%.1f ampl=%.1f ampr=%.1f\n", mixer->inputs[i].ampfactor, mixer->inputs[i].ampl, mixer->inputs[i].ampr); | ||
return(mixer->input_count++); | ||
} | ||
|
||
void mixer_disable_input(mixer_t *mixer, int input_idx) { | ||
int mixer_sum = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a mix of spacing with the rest of the file (tabs vs spaces) here and a few other places
src/mixer.cpp
Outdated
} | ||
pthread_mutex_unlock(&input->mutex); | ||
} | ||
|
||
if((mixer->inputs_todo & mixer->input_mask) == 0 || mixer->interval == 0) { // all good inputs handled or last interval passed | ||
unprocessed_mixer_count = 0; | ||
for(int k = 0; k < MAX_MIXINPUTS; k++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can also be replaced with a bool rather than counting
src/mixer.cpp
Outdated
if((mixer->inputs_todo & mixer->input_mask) == 0 || mixer->interval == 0) { // all good inputs handled or last interval passed | ||
unprocessed_mixer_count = 0; | ||
for(int k = 0; k < MAX_MIXINPUTS; k++) { | ||
unprocessed_mixer_count = unprocessed_mixer_count + ( mixer->inputs_todo[k] & mixer->input_mask[k]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another binary and
src/mixer.cpp
Outdated
RESET_BIT(mixer->input_mask, input_idx); | ||
if(mixer->input_mask == 0) { | ||
mixer->input_mask[input_idx] = 0; | ||
for (int i = 0; i < MAX_MIXINPUTS; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can go up to mixer->input_count
rather than MAX_MIXINPUTS
(check other places as well)
src/mixer.cpp
Outdated
debug_bulk_print("mixerinput: %lu.%lu %lu int=%d inp_unhandled=0x%02x inp_mask=0x%02x\n", | ||
te.tv_sec, (unsigned long) te.tv_usec, (te.tv_sec - ts.tv_sec) * 1000000UL + te.tv_usec - ts.tv_usec, | ||
mixer->interval, mixer->inputs_todo, mixer->input_mask); | ||
for(int k = 0; k < mixer->input_count; k++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems less than ideal. these debug printouts are already quite verbose, adding another line for each mixer input with the only difference being mixer->inputs_todo[k]
, mixer->input_mask[k]
is a lot more output. How about generating a single string that has the list of true / false for each, and including that once?
@cdknox NOTE - I changed the PR baseline to |
Fair points and thanks for the feedback! I believe I addressed all of them now and it looks like I was able to get the rebasing done appropriately for the review (apologies for missing it should have been done against unstable). Python is my native language so what I came up with for the formatting is not the most elegant I'm sure, but it does appear to be functional. It's a string of 0s and 1s with the leftmost index being the 0th input and counting up from there. I've included a couple examples at the bottom, one with 13 inputs and one with 47 (after having compiled with an increased MAX_MIXINPUTS of 64). mixer_thread(): mixerinput: 1690435113.452584 27 int=1 inp_unhandled=0000000000000 inp_mask=1111111111111 mixer_thread(): mixerinput: 1690435113.452557 93 int=1 inp_unhandled=00000000000000000000000000000000000000000000000 inp_mask=11111111111111111111111111111111111111111111111 |
awesome, thanks! There are a few more minor tweaks and rather than going back and forth I'll just make them. If im unable to push to your fork I'll do it as a new PR. |
@cdknox how high are you looking at setting |
there is a request to increase the value in #401 |
re: the small changes, all good if you want to make them or I can if it'd make your life easier, I believe you should have access to commit to the branch, but if there's something setting I need to change otherwise just let me know. re: |
Opened a new PR based on these changes #408 that removes the upper bound, closing this PR |
Removed the bit logic in favor of an array based approach to allow more inputs to a mixer than address size would allow.
Certainly more comparisons, but I've been running it for a while with no issues it seems.
I appreciate the work!