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

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Feb 21, 2024

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 #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

@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)

servers/audio_server.h Outdated Show resolved Hide resolved
@AThousandShips AThousandShips mentioned this pull request Mar 29, 2024
Closed
@bruvzg bruvzg force-pushed the i_have_no_idea_what_im_doing branch from 37cb3f2 to 0dbbe0e Compare October 7, 2024 08:27
@bruvzg bruvzg marked this pull request as ready for review October 7, 2024 09:01
@bruvzg bruvzg requested review from a team as code owners October 7, 2024 09:01
@bruvzg bruvzg force-pushed the i_have_no_idea_what_im_doing branch from 0dbbe0e to cbe7903 Compare October 7, 2024 09:14
@adamscott adamscott modified the milestones: 4.x, 4.4 Oct 7, 2024
Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

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

Tested out the mic record demo and it works flawlessly.

The code looks good too. So I'm giving it my thumbs up.

Great job, @bruvzg !

drivers/coreaudio/audio_driver_coreaudio.mm Outdated Show resolved Hide resolved
drivers/coreaudio/audio_driver_coreaudio.mm Outdated Show resolved Hide resolved
drivers/coreaudio/audio_driver_coreaudio.mm Outdated Show resolved Hide resolved
drivers/coreaudio/audio_driver_coreaudio.mm Outdated Show resolved Hide resolved
servers/audio_server.h Outdated Show resolved Hide resolved
@bruvzg bruvzg force-pushed the i_have_no_idea_what_im_doing branch from cbe7903 to b0c4dee Compare October 7, 2024 14:32
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

Just needs a rebase & this'll be good to go!

@bruvzg bruvzg force-pushed the i_have_no_idea_what_im_doing branch from b0c4dee to c8609f4 Compare October 25, 2024 16:32
@Repiteo Repiteo merged commit 73830b3 into godotengine:master Oct 30, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 30, 2024

Thanks!

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
5 participants