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

Allow WASAPI multi-channel microphone input #99875

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fire
Copy link
Member

@fire fire commented Nov 30, 2024

Salvaging #96947

Support multi-channel microphone input by downmixing to stereo

  • Enhanced the WASAPI audio driver to support microphones with any number of channels.

  • This modification ensures compatibility with a broader range of multi-channel microphones, allowing for more versatile input handling in Godot.

} 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);
Copy link
Member Author

@fire fire Nov 30, 2024

Choose a reason for hiding this comment

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

Why is this an integer?

Copy link
Member

Choose a reason for hiding this comment

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

Why sample is an integer?

Support multi-channel microphone input by downmixing to stereo
- Enhanced the WASAPI audio driver to support microphones with any number of channels.
- This modification ensures compatibility with a broader range of multi-channel microphones, allowing for more versatile input handling in Godot.

Co-Authored-By: Shatyuka <shatyuka@qq.com>
@fire fire force-pushed the vsk-multi-audio-input-4.4 branch from 79ef794 to 6ad97f7 Compare December 2, 2024 10:43
@fire
Copy link
Member Author

fire commented Dec 2, 2024

I have a microphone with two audio inputs (outputs) https://zoomcorp.com/en/ca/handheld-recorders/handheld-recorders/h3-vr-360-audio-recorder/ but still need to set up to test this.

@@ -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;
Copy link
Member

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.

Suggested change
int32_t l = 0, r = 0;
int32_t left = 0;
int32_t right = 0;

} 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);
Copy link
Member

Choose a reason for hiding this comment

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

Why sample is an integer?

Comment on lines +866 to +870
if (ch % 2 == 0) {
r += sample;
} else {
l += sample;
}
Copy link
Member

Choose a reason for hiding this comment

The 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.

@Sheppowed
Copy link

Came from #99989, I'm glad to see that people are trying to find a solution to this problem. I don't know enough about this area to be able to help, but I'll be the first to give you some feedback 👍

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

Successfully merging this pull request may close these issues.

5 participants