-
Notifications
You must be signed in to change notification settings - Fork 267
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
SDL3 Support #1478
SDL3 Support #1478
Conversation
Add SDL3 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that was quick. Thanks a lot! I've only got one comment below. Before merging it, I'll adapt the Window CI pipeline in the next days, to make it compile with SDL3 support.
Add SDL3 to Windows CI
Update sources
Fix callback
Remove .DS_Store
Fix init SDL3 subsystem
Fix SDL3 linking
Fix for finding SDL3 config and components
Remove SDL3_VERSION not defined check
Remove GetSDL3VersionFromHeaders
Fix init subsystem
Fix return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the review findings. It's getting into shape. I found a few more minor issues.
src/drivers/fluid_sdl3.c
Outdated
static void | ||
SDLAudioCallback(void *data, SDL_AudioStream *stream, int add_len, int len) | ||
{ | ||
void *buffer = malloc(len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory allocation during audio playback is not real-time friendly. Is it possible to calculate the maximum len
beforehand and use it to preallocate the biggest possible buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it to additional len as buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry, I think you misunderstood me. I was asking to get rid of the malloc
from the callback and instead allocate the buffer in new_fluid_sdl3_audio_driver
. Also note that dev->write_ptr
takes the number of samples (audio frames) to synthesize, not the buffer length in bytes. See here for an example:
https://github.com/libsdl-org/SDL/blob/be991239d9bc6df06b0ca7a9ae9dbb7251e93c12/examples/audio/02-simple-playback-callback/simple-playback-callback.c#L25-L34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced the malloc with a static buffer and for dev->write_ptr I use the buffer length divided by dev->frame_size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's a static buffer, you may remove the check for NULL in the same function since it generates a warning:
if (buffer == NULL)
{
return;
}
The actual warning:
fluidsynth/src/drivers/fluid_sdl3.c:165:13: warning: comparison of array 'buffer' equal to a null pointer is always false [-Wtautological-pointer-compare]
if (buffer == NULL)
^~~~~~ ~~~~
On the topic of warnings, the following call also triggers a -Wsign-compare
warning on clang:
fluidsynth/src/drivers/fluid_sdl3.c:163:19: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
buf_len = SDL_min(add_len, SDL_arraysize(buffer));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry for nit-picking again. But you cannot use a buffer with a constant size. The size of the buffer must depend on audio.period-size
that you've read in new_fluid_sdl3_audio_driver
, otherwise there's no point in reading that setting. I suppose allocating a buffer size of period-size * frame_size
would be reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer got updated to this.
I've added period_size to the dev structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to malloc since the buffer can't be preallocated.
I have put the buffer inside the dev structure.
I have put the creation of the buffer in new_fluid_sdl3_audio_driver and the destruction of the buffer inside delete_fluid_sdl3_audio_driver.
@FtZPetruska I quickly smashed together a Windows CI build that works with SDL3. Even when resolving the cmake issues mentioned above, all the unit tests will be failing because of missing DLL - presumably SDL3.dll, e.g. here The unit tests inherit their link dependencies from the object lib
This would carry over all add_library(SDL3::SDL3-shared SHARED IMPORTED)
set_target_properties(SDL3::SDL3-shared
PROPERTIES
INTERFACE_LINK_LIBRARIES "SDL3::Headers"
IMPORTED_IMPLIB "${_sdl3_implib}"
IMPORTED_LOCATION "${_sdl3_dll}"
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
INTERFACE_SDL3_SHARED "ON"
COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
INTERFACE_SDL_VERSION "SDL3"
) Is my understanding correct? And why isn't |
This SDL3 target looks properly set up:
What is most likely happening is that all the DLLs need to be copied to the same directory as the test executable. In CMake >=3.21 it can be done with: add_custom_command(TARGET ${_test} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${_test}> $<TARGET_FILE_DIR:${_test}>
COMMAND_EXPAND_LISTS
) Otherwise, if you know about the lists of DLLs needed, you can just use: add_custom_command(TARGET ${_test} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:SDL3::SDL3>
$<TARGET_FILE:other::dependency>
...
$<TARGET_FILE_DIR:${_test}>
) Also on the topic of CI, you may be interested in this Github Action: https://github.com/libsdl-org/setup-sdl |
Remove version check
Remove version check
Fix to work with buffer
Set SDL3 standard on
Add SDL3 to unit tests
Fix SDL3 no malloc
Fix target link libraries
Fix Windows CI with SDL3 on x86 and with MinGW
Fix dependencies
Fix buffer and SDL_min
Fix SDL3 playback
It is working! `fluidsynth /Users/andyvand/Downloads/fluidsynth/sf2/VintageDreamsWaves-v2.sf2 /Users/andyvand/Downloads/opentyrian2000/extras/music40.mid -a sdl3 fluidsynth: warning: Sample 'SineWave': ROM sample ignored |
Update buffer
Fix SDL buffer length
Fix MinGW compile
Revert to malloc for buffer
Buffer check
Ok, thanks so far. I'll merge this to a feature branch and will take care of the correct buffer allocation and fixing the CI build. |
Add SDL3 support