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

[macOS/iOS] Use hardware sampling rates for audio I/O. #88628

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

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Feb 21, 2024

Instead of "max_rate" from the project settings, use preferred OS values, since API can work only with the limited set of values depending on device.

Fixes #58180

TODO:

  • I'm not sure if changes in the AudioStreamPlaybackMicrophone are sufficient to correctly resample it.
  • We should track device changes and adjust sampling rates accordingly, but I'm not sure if Godot audio subsystem is capable of handling sampling rate changes.

@kus04e4ek
Copy link
Contributor

kus04e4ek commented Mar 15, 2024

I'm still new to the Godot's source code, so take everything I say with a grain of salt.

I'm not sure if changes in the AudioStreamPlaybackMicrophone are sufficient to correctly resample it.

They look like they are. AudioStreamPlaybackMicrophone is a child of AudioStreamPlaybackResampled, AudioStreamPlaybackResampled::mix calls _mix_internal and it uses get_stream_sampling_rate and AudioDriver::get_mix_rate to correctly resample audio.

I'm not sure if Godot audio subsystem is capable of handling sampling rate changes.

Since audio generation is happening only in a callback by the current output device and uses AudioDriver::get_mix_rate to resample all of the audio, as long as AudioDriver::get_mix_rate returns the correct mix rate for the current output device and AudioDriver::get_capture_mix_rate returns the correct mix rate for the input device that last wrote to the buffer everything should be fine (AudioDriverCoreAudio::output_callback, then AudioDriver::audio_server_process, then AudioServer::_driver_process, then AudioServer::_mix_step, then playback->stream_playback->mix or AudioStreamPlaybackResampled::mix)

@@ -97,6 +97,7 @@ class AudioDriver {
virtual Error init() = 0;
virtual void start() = 0;
virtual int get_mix_rate() const = 0;
virtual int get_capture_mix_rate() const { return get_mix_rate(); };
Copy link
Contributor

@kus04e4ek kus04e4ek Mar 16, 2024

Choose a reason for hiding this comment

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

get_input_mix_rate is probably a better name. See #69120

@AThousandShips AThousandShips mentioned this pull request Mar 29, 2024
Closed
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.

macOS audio recording error: input_callback: AudioUnitRender failed, code: -10863
2 participants