Add support for SDL's audio driver#109362
Add support for SDL's audio driver#109362kus04e4ek wants to merge 1 commit intogodotengine:masterfrom
Conversation
|
That's quite awesome! :D I have a suggestion, should the driver also report the underlying audio backend when calling |
c63f525 to
04408f5
Compare
Thanks) I think it should, it would probably make the most sense to implement it with |
There was a problem hiding this comment.
This file was created due to the fact that if for whatever reason JoypadSDL fails to initialize, but AudioDriverSDL does initialize, there will still be a way to poll sdl events, it's important because AudioDriverSDL doesn't poll events and if nothing polls events the events array will eventually run out of memory
| rm -f $target/include/build_config/{*.cmake,SDL_build_config_*.h} $target | ||
| rm -f $target/include/SDL3/SDL_{egl,gpu,oldnames,opengl*,test*,vulkan}.h $target | ||
| rm -f $target/include/build_config/{*.cmake,SDL_build_config_*.h} | ||
| rm -f $target/include/SDL3/SDL_{egl,gpu,oldnames,opengl*,test*,vulkan}.h |
There was a problem hiding this comment.
It was probably just a mistake, without this change there will be an attempt to delete $target
| cp -v hidapi/$dir/*.{c,h} $target/hidapi/$dir | ||
| for f in hidapi/$dir/*.{c,h}; do | ||
| [ -e "$f" ] && cp -v $f $target/hidapi/$dir | ||
| done |
There was a problem hiding this comment.
For some reason this fails on my system (Fedora 42), some of the hidapi/$dir$ don't have *.c or *.h files, so I get the cp: cannot stat 'hidapi/hidapi/*.c': No such file or directory error and because it's run like this #!/bin/bash -e, the execution just stops
| void AudioDriver::input_buffer_wrote(unsigned int p_frames) { | ||
| if ((int)input_position < input_buffer.size()) { | ||
| input_position += p_frames; | ||
| if ((int)input_position >= input_buffer.size()) { | ||
| input_position -= input_buffer.size(); | ||
| } | ||
| if ((int)input_size < input_buffer.size()) { | ||
| input_size = MAX(input_size + p_frames, input_buffer.size()); | ||
| } | ||
| } else { | ||
| WARN_PRINT("input_buffer_write: Invalid input_position=" + itos(input_position) + " input_buffer.size()=" + itos(input_buffer.size())); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Just a function to optimize reading from the SDL buffer, instead of writing 1 frame at a time we'll just write the whole SDL buffer and update input_position/input_size after writing
|
Also, another suggestion, should the current audio drivers be removed, i.e. replaced by the SDL ones, in this PR? See Calinou's comment: godotengine/godot-proposals#12908 (comment) EDIT: I just noticed that you already have this in your TODO list 😅
|
It think it's fine to do it in a similar way to how it was done with the
Yeeeeahh, thought it was still important for me to say what I think about it lol |
jfyi, finished this feature in this branch, not really sure if the branch passes all of the tests and haven't really tested it a lot, but it seems to work fine on my linux laptop |
Addresses: godotengine/godot-proposals#12908
Fixes: #98500
Fixes: #82823
Fixes: #30313
Keeping it as a draft until I'll finish the TODO list.
This PR doesn't bring support for the Web platform as the SDL web audio driver functions the same way as Godot's web audio driver pre-#91382, so it'll most likely break web's audio again.
TODO:
After merge (
sdl_audio_extrabranch contains every change marked off in this section):audio/driver/driversetting (here);AudioDriverSDL::get_name()(here);sdl_audioandsdl_joypadbuild options instead of the onesdloption. Not really sure how to tackle it and I don't think it's necessary for this PR;AudioDeviceimplementations that are no longer required. Want to make this after makingAudioDriverSDLfeature-complete (latency and mix rate support) as some projects might depend on these features;Some of these
After mergegoals or all of them can be changed to be included in this PR (especially the ones making the driver feature-complete), curious what y'all think.To check this PR I used slightly modified versions of the demo projects: demos.zip, the driver is set to be SDL and the initialized driver is printed to the console at start, but the
device_changerdemo also has a new buttonUpdate devices, it just updates the list of available devices and if the device currently used got disconnected, the chosen device in the list will change to the new current device