godot icon indicating copy to clipboard operation
godot copied to clipboard

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

Open bruvzg opened this issue 1 year ago • 1 comments

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

Fixes https://github.com/godotengine/godot/issues/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.

Edit: I corrected a typo in "mix_rate". - @adamscott

bruvzg avatar Feb 21 '24 12:02 bruvzg

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)

kus04e4ek avatar Mar 15 '24 11:03 kus04e4ek

Thanks!

Repiteo avatar Oct 30 '24 00:10 Repiteo