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

Microphone doesnt record on MacOS in Godot 3.5 #64583

Open
Tracked by #76797
vickylance opened this issue Aug 18, 2022 · 10 comments
Open
Tracked by #76797

Microphone doesnt record on MacOS in Godot 3.5 #64583

vickylance opened this issue Aug 18, 2022 · 10 comments

Comments

@vickylance
Copy link

Godot version

3.5.stable

System information

MacOS Monterey, MacBook Pro 16inch, 16GB RAM, M1 Pro

Issue description

This issue is basically to reopen this issue - #35445
As its still reproducable in MacOS in Godot 3.5

As suggested in the above issue thread. I had to change the input rate in "Audio MIDI Setup" app to 44100Mhz to match with that of Godot in macos for it to work.

image

Reason why this workaround is not enough? End users might not know this when the game is shipped.

Steps to reproduce

Try running the reproducable project below. When your mac os audio input is not matching 41100mhz which by default its not and you will get the "AudioUnitRender error -10863" error

Minimal reproduction project

Here is a simple barebones reproducable project
https://github.com/vickylance/godot_audio_record_test

@asmaloney
Copy link
Contributor

Some additional info:

  • "AudioUnitRender error -10863" is kAudioUnitErr_CannotDoInCurrentContext

  • I can reproduce this with macOS 10.14.6 on an iMac.

  • I can confirm that setting audio/mix_rate to what the user has set using Audio MIDI Setup fixes the error.

The project setting should override whatever was set using Audio MIDI Setup, like Apple does with its Logic Pro:

When using an external audio interface with Logic Pro, the sample rate for your interface should adjust automatically to match the sample rate of your project.

We should probably take the Godot setting, try to find the closest available sample rate, and create the audio unit with that. (And perhaps produce a warning about any mismatches.)

@MJacred
Copy link
Contributor

MJacred commented May 20, 2023

Related:

there was Fix for "-50" error from AudioUnitRender which was not merged due to reasons: #41592, might help

@danegraphics
Copy link

danegraphics commented Sep 24, 2023

With the influx of things being made in Godot, this would be good to fix soon.

But in a way where the sampling rate used in Godot can be whatever it needs instead of trying to force external devices to adapt to Godot.

@obvgab
Copy link

obvgab commented Oct 4, 2023

Hey y'all! Happy Hacktoberfest!
I'm looking into this, and have found somewhat of a way to fix this (for macOS, iOS might work the same way, but I haven't tested that yet).


Taking some notes from LosslessSwitcher, we have to tell macOS that we have a preferred sampling rate. I've implemented this by using AudioDeviceSetProperty on the deviceId in audio_driver_coreaudio.cpp. This does seem to silence the error and change the sampling rate:

Before app launch

before

After app launch

after

Unfortunately, it's not perfect. When connecting my AirPods (which can't provide 44.1kHz, only 24kHz) it will give a new error! Since it's a project-level setting, should we provide settings for "preferred" sampling rates, and then have it default to the closest possible? Or should we just provide an error to the user, so they can figure it out?

@danegraphics
Copy link

Keep in mind that there are many common microphones where the sampling rate cannot be changed to 44,100, so the best solution would be to adapt Godot to the sampling rate rather than the other way around.

@obvgab
Copy link

obvgab commented Oct 4, 2023

Sure. Should I go the route of putting a note in the warnings section when there is a mismatch? And also, does Godot already have a method for dynamically changing the mix rate (from GDScript, so the user can manage it explicitly?)

@Calinou
Copy link
Member

Calinou commented Oct 4, 2023

And also, does Godot already have a method for dynamically changing the mix rate (from GDScript, so the user can manage it explicitly?)

Not that I know of, especially for input audio devices. That said, changing output audio device sample rate is also not ideal. Apps shouldn't do this on their own as it can reduce audio quality significantly. If you have your microphone set above 48 kHz (which may be the case with some professional setups), your output audio device may not be able to match it either.

The better solution is to resample the input in real-time (using linear or preferably cubic resampling), so that any input sample rate works with any output sample rate. This will add a bit of latency and CPU cost, but it's worth the usability and quality upgrade.

@obvgab
Copy link

obvgab commented Oct 4, 2023

Sure, I'll look into it.

@Luzzotica
Copy link

I am getting this same error in Godot 4.2 on my MacOS, Ventura 13.6.1

Downloaded audio recording demo here.

Upgraded to Godot 4.2.

Ran the project, errors.

Changing the sample rate in the demo app does not resolve the problem, I must change it in the audio midi application.

Is there any way I can help with this? I feel like this is a pretty big deal. I need audio recording for things in my game (voice chat, talking to an AI, etc), and not having it just a be a plug and play thing is gonna slow me down quite a bit.

@iandoesallthethings
Copy link

iandoesallthethings commented Oct 21, 2024

Still fighting with this issue in 4.2. I've been digging through the docs for a way to read the sample rate of an input source, but AudioServer only provides the string names with no metadata.

It seems like we should ideally be able to just

var mic = AudioServer.get_input_device_list()[0] # Pick from a dropdown menu, yadda yadda
AudioServer.set_mix_rate(mic.mix_rate)

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

No branches or pull requests

8 participants