-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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 WASAPI multi-channel microphone input #99875
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -849,7 +849,7 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { | |
|
||
// fixme: Only works for floating point atm | ||
for (UINT32 j = 0; j < num_frames_available; j++) { | ||
int32_t l, r; | ||
int32_t l = 0, r = 0; | ||
|
||
if (flags & AUDCLNT_BUFFERFLAGS_SILENT) { | ||
l = r = 0; | ||
|
@@ -859,6 +859,26 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { | |
r = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * 2 + 1); | ||
} else if (ad->audio_input.channels == 1) { | ||
l = r = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j); | ||
} else if (ad->audio_input.channels >= 2) { | ||
int channels = ad->audio_input.channels; | ||
for (int ch = 0; ch < channels - 1; ch++) { | ||
int32_t sample = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * channels + ch); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this an integer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
if (ch % 2 == 0) { | ||
r += sample; | ||
} else { | ||
l += sample; | ||
} | ||
Comment on lines
+866
to
+870
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I know, the assumption is naive. Like, depending on the number of channels, sometimes it's left, right, or even center. |
||
} | ||
int32_t last_sample = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * channels + (channels - 1)); | ||
r += last_sample; | ||
if (channels % 2 != 0) { | ||
l += last_sample; | ||
l /= ((channels + 1) / 2); | ||
r /= ((channels + 1) / 2); | ||
} else { | ||
l /= (channels / 2); | ||
r /= (channels / 2); | ||
} | ||
} else { | ||
l = r = 0; | ||
ERR_PRINT("WASAPI: unsupported channel count in microphone!"); | ||
|
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.
It's super rare in the codebase to initialize multiple variables on the same line. And they are single letter variables too. We could take this opportunity to rename them.