update sdl Merge commit '4d48f9d23713d94b861da7b5d41baf2a41334994'

This commit is contained in:
2023-08-12 20:17:29 +02:00
215 changed files with 12672 additions and 17114 deletions

View File

@ -15,6 +15,12 @@ if(NOT (MSVC AND SDL_CPU_ARM64))
find_package(OpenGL)
endif()
if(WINDOWS_STORE)
cmake_minimum_required(VERSION 3.19)
# CMP0112: Target file component generator expressions do not add target dependencies.
cmake_policy(SET CMP0112 NEW)
endif()
set(SDL_TEST_EXECUTABLES)
add_library(sdltests_utils OBJECT
@ -24,7 +30,7 @@ target_link_libraries(sdltests_utils PRIVATE SDL3::Headers)
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
set(RESOURCE_FILE_NAMES)
foreach(RESOURCE_FILE ${RESOURCE_FILES})
foreach(RESOURCE_FILE IN LISTS RESOURCE_FILES)
get_filename_component(res_file_name ${RESOURCE_FILE} NAME)
list(APPEND RESOURCE_FILE_NAMES "${res_file_name}")
endforeach()
@ -33,6 +39,14 @@ define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target i
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.")
if(WINDOWS_STORE)
add_library(sdl_test_main_uwp OBJECT main.cpp)
target_link_libraries(sdl_test_main_uwp PRIVATE SDL3::Headers)
target_compile_options(sdl_test_main_uwp PRIVATE "/ZW")
set_source_files_properties(${RESOURCE_FILES} PROPERTIES VS_DEPLOYENT_LOCATION "Assets")
endif()
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
@ -44,13 +58,34 @@ macro(add_sdl_test_executable TARGET)
if(AST_TESTUTILS)
list(APPEND AST_SOURCES $<TARGET_OBJECTS:sdltests_utils>)
endif()
set(EXTRA_SOURCES "")
if(WINDOWS_STORE)
set(uwp_bindir "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.dir")
if(NOT IS_DIRECTORY "${uwp_bindir}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${uwp_bindir}")
endif()
string(REGEX REPLACE "[_]" "" SAFE_TARGET "${TARGET}")
file(GENERATE OUTPUT "${uwp_bindir}/${TARGET}.appxmanifest"
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/uwp/Package.appxmanifest.in"
TARGET "${TARGET}"
)
set_property(SOURCE "${uwp_bindir}/${TARGET}.appxmanifest" PROPERTY VS_DEPLOYMENT_CONTENT 1)
list(APPEND EXTRA_SOURCES
"$<TARGET_OBJECTS:sdl_test_main_uwp>"
"${uwp_bindir}/${TARGET}.appxmanifest"
"uwp/logo-50x50.png"
"uwp/square-44x44.png"
"uwp/square-150x150.png"
"uwp/splash-620x300.png"
)
endif()
if(AST_NEEDS_RESOURCES)
list(APPEND AST_SOURCES ${RESOURCE_FILES})
list(APPEND EXTRA_SOURCES ${RESOURCE_FILES})
endif()
if(ANDROID)
add_library(${TARGET} SHARED ${AST_SOURCES})
add_library(${TARGET} SHARED ${AST_SOURCES} ${EXTRA_SOURCES})
else()
add_executable(${TARGET} ${AST_SOURCES})
add_executable(${TARGET} ${AST_SOURCES} ${EXTRA_SOURCES})
endif()
SDL_AddCommonCompilerFlags(${TARGET})
target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component})
@ -74,6 +109,16 @@ macro(add_sdl_test_executable TARGET)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET})
elseif(WINDOWS_STORE)
# MSVC does build the dependent targets (or POST_BUILD commands) when building an application
# after starting to debug. By copying the resources in a custom target, the files can be copied afterwards.
# FIXME: find out proper way to add assets to UWP package
cmake_minimum_required(VERSION 3.19)
add_custom_target(zzz-resources-copy-${TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${TARGET}>/AppX"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RESOURCE_FILES} "$<TARGET_FILE_DIR:${TARGET}>/AppX"
)
add_dependencies(${TARGET} zzz-resources-copy-${TARGET})
else()
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>)
@ -82,6 +127,12 @@ macro(add_sdl_test_executable TARGET)
# Make sure resource files get installed into macOS/iOS .app bundles.
set_target_properties(${TARGET} PROPERTIES RESOURCE "${RESOURCE_FILES}")
endif()
if(EMSCRIPTEN)
foreach(res IN LISTS RESOURCE_FILES)
get_filename_component(res_name "${res}" NAME)
target_link_options(${TARGET} PRIVATE "SHELL:--embed-file ${res}@${res_name}")
endforeach()
endif()
set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$<TARGET_FILE_DIR:${TARGET}>/$<JOIN:${RESOURCE_FILE_NAMES},$<SEMICOLON>$<TARGET_FILE_DIR:${TARGET}>/>")
endif()
if(AST_BUILD_DEPENDENT)
@ -97,6 +148,21 @@ macro(add_sdl_test_executable TARGET)
elseif(PSP)
target_link_libraries(${TARGET} PRIVATE GL)
endif()
if(WINDOWS_STORE)
target_compile_definitions(${TARGET} PRIVATE "SDL_MAIN_NOIMPL")
set_property(TARGET ${TARGET} PROPERTY WIN32_EXECUTABLE TRUE)
set_property(TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY "${uwp_bindir}")
target_link_options(${TARGET} PRIVATE
-nodefaultlib:vccorlib$<$<CONFIG:Debug>:d>
-nodefaultlib:msvcrt$<$<CONFIG:Debug>:d>
vccorlib$<$<CONFIG:Debug>:d>.lib
msvcrt$<$<CONFIG:Debug>:d>.lib
)
endif()
if(EMSCRIPTEN)
set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html")
endif()
if(OPENGL_FOUND)
target_compile_definitions(${TARGET} PRIVATE HAVE_OPENGL)
@ -119,11 +185,10 @@ endif()
add_sdl_test_executable(checkkeys SOURCES checkkeys.c)
add_sdl_test_executable(checkkeysthreads SOURCES checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS SOURCES loopwave.c)
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES TESTUTILS SOURCES loopwavequeue.c)
add_sdl_test_executable(testsurround SOURCES testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c)
add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c)
add_sdl_test_executable(testaudiostreamdynamicresample SOURCES testaudiostreamdynamicresample.c)
add_sdl_test_executable(testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS SOURCES testaudiostreamdynamicresample.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})
@ -203,6 +268,7 @@ if(Python3_FOUND AND Python3_VERSION VERSION_GREATER_EQUAL "3.2")
endforeach()
endif()
add_sdl_test_executable(testaudio NEEDS_RESOURCES TESTUTILS SOURCES testaudio.c)
add_sdl_test_executable(testfile NONINTERACTIVE SOURCES testfile.c)
add_sdl_test_executable(testcontroller TESTUTILS SOURCES testcontroller.c gamepadutils.c ${gamepad_image_headers})
add_sdl_test_executable(testgeometry TESTUTILS SOURCES testgeometry.c)
@ -212,7 +278,7 @@ if(ANDROID)
target_link_libraries(testgles PRIVATE GLESv1_CM)
endif()
add_sdl_test_executable(testgles2 SOURCES testgles2.c)
add_sdl_test_executable(testgles2_sdf TESTUTILS SOURCES testgles2_sdf.c)
add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES TESTUTILS SOURCES testgles2_sdf.c)
add_sdl_test_executable(testhaptic SOURCES testhaptic.c)
add_sdl_test_executable(testhotplug SOURCES testhotplug.c)
add_sdl_test_executable(testrumble SOURCES testrumble.c)
@ -279,7 +345,6 @@ endif()
if(SDL_DUMMYAUDIO)
set_property(TARGET testaudioinfo PROPERTY SDL_NONINTERACTIVE 1)
set_property(TARGET testsurround PROPERTY SDL_NONINTERACTIVE 1)
endif()
if(SDL_DUMMYVIDEO)
@ -303,6 +368,12 @@ if(OPENGL_FOUND)
endif()
if(EMSCRIPTEN)
set_property(TARGET testshader APPEND_STRING PROPERTY LINK_FLAGS " -sLEGACY_GL_EMULATION")
find_package(Python3 COMPONENTS Interpreter)
if(TARGET Python3::Interpreter)
add_custom_target(serve-sdl-tests
COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/server.py" -d "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if(PSP)

View File

@ -3,7 +3,6 @@ These are test programs for the SDL library:
checkkeys Watch the key events to check the keyboard
loopwave Audio test -- loop playing a WAV file
loopwavequeue Audio test -- loop playing a WAV file with SDL_QueueAudio
testsurround Audio test -- play test tone on each audio channel
testaudioinfo Lists audio device capabilities
testerror Tests multi-threaded error handling

BIN
external/sdl/SDL/test/audiofile.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

67
external/sdl/SDL/test/emscripten/server.py vendored Executable file
View File

@ -0,0 +1,67 @@
#!/usr/bin/env python
# Based on http/server.py from Python
from argparse import ArgumentParser
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
def serve_forever(port: int, ServerClass):
handler = SimpleHTTPRequestHandler
handler.extensions_map = {
".manifest": "text/cache-manifest",
".html": "text/html",
".png": "image/png",
".jpg": "image/jpg",
".svg": "image/svg+xml",
".css": "text/css",
".js": "application/x-javascript",
".wasm": "application/wasm",
"": "application/octet-stream",
}
addr = ("0.0.0.0", port)
HandlerClass = SimpleHTTPRequestHandler
with ServerClass(addr, handler) as httpd:
host, port = httpd.socket.getsockname()[:2]
url_host = f"[{host}]" if ":" in host else host
print(
f"Serving HTTP on {host} port {port} (http://{url_host}:{port}/) ..."
)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
return 0
def main():
parser = ArgumentParser(allow_abbrev=False)
parser.add_argument("port", nargs="?", type=int, default=8080)
parser.add_argument("-d", dest="directory", type=str, default=None)
args = parser.parse_args()
import contextlib
import http.server
import socket
class DualStackServer(http.server.ThreadingHTTPServer):
def server_bind(self):
# suppress exception when protocol is IPv4
with contextlib.suppress(Exception):
self.socket.setsockopt(
socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
return super().server_bind()
def finish_request(self, request, client_address):
self.RequestHandlerClass(request, client_address, self, directory=args.directory)
return serve_forever(
port=args.port,
ServerClass=DualStackServer,
)
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -54,10 +54,10 @@ static const struct
{ 141, 242 }, /* SDL_GAMEPAD_BUTTON_DPAD_LEFT */
{ 211, 242 }, /* SDL_GAMEPAD_BUTTON_DPAD_RIGHT */
{ 257, 199 }, /* SDL_GAMEPAD_BUTTON_MISC1 */
{ 157, 160 }, /* SDL_GAMEPAD_BUTTON_PADDLE1 */
{ 355, 160 }, /* SDL_GAMEPAD_BUTTON_PADDLE2 */
{ 157, 200 }, /* SDL_GAMEPAD_BUTTON_PADDLE3 */
{ 355, 200 }, /* SDL_GAMEPAD_BUTTON_PADDLE4 */
{ 157, 160 }, /* SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 */
{ 355, 160 }, /* SDL_GAMEPAD_BUTTON_LEFT_PADDLE1 */
{ 157, 200 }, /* SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2 */
{ 355, 200 }, /* SDL_GAMEPAD_BUTTON_LEFT_PADDLE2 */
};
/* This is indexed by gamepad element */
@ -397,7 +397,7 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
for (i = 0; i < SDL_arraysize(button_positions); ++i) {
SDL_bool on_front = SDL_TRUE;
if (i >= SDL_GAMEPAD_BUTTON_PADDLE1 && i <= SDL_GAMEPAD_BUTTON_PADDLE4) {
if (i >= SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 && i <= SDL_GAMEPAD_BUTTON_LEFT_PADDLE2) {
on_front = SDL_FALSE;
}
if (on_front == ctx->showing_front) {
@ -560,7 +560,7 @@ void RenderGamepadImage(GamepadImage *ctx)
SDL_GamepadButton button_position = GetRemappedButton(ctx->face_style, (SDL_GamepadButton)i);
SDL_bool on_front = SDL_TRUE;
if (i >= SDL_GAMEPAD_BUTTON_PADDLE1 && i <= SDL_GAMEPAD_BUTTON_PADDLE4) {
if (i >= SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 && i <= SDL_GAMEPAD_BUTTON_LEFT_PADDLE2) {
on_front = SDL_FALSE;
}
if (on_front == ctx->showing_front) {
@ -681,10 +681,10 @@ static const char *gamepad_button_names[] = {
"DPAD Left",
"DPAD Right",
"Misc1",
"Paddle1",
"Paddle2",
"Paddle3",
"Paddle4",
"Right Paddle 1",
"Left Paddle 1",
"Right Paddle 2",
"Left Paddle 2",
"Touchpad",
};
SDL_COMPILE_TIME_ASSERT(gamepad_button_names, SDL_arraysize(gamepad_button_names) == SDL_GAMEPAD_BUTTON_MAX);

BIN
external/sdl/SDL/test/logaudiodev.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -31,10 +31,18 @@ static struct
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
Uint32 soundpos;
} wave;
static SDL_AudioDeviceID device;
static SDL_AudioStream *stream;
static void fillerup(void)
{
if (SDL_GetAudioStreamAvailable(stream) < (int) ((wave.soundlen / 2))) {
SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen);
}
}
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@ -51,6 +59,8 @@ static void
close_audio(void)
{
if (device != 0) {
SDL_DestroyAudioStream(stream);
stream = NULL;
SDL_CloseAudioDevice(device);
device = 0;
}
@ -59,56 +69,33 @@ close_audio(void)
static void
open_audio(void)
{
/* Initialize fillerup() variables */
device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wave.spec, NULL, 0);
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_free(wave.sound);
quit(2);
}
/* Let the audio run */
SDL_PlayAudioDevice(device);
}
#ifndef __EMSCRIPTEN__
static void reopen_audio(void)
{
close_audio();
open_audio();
}
#endif
static void SDLCALL
fillerup(void *unused, Uint8 *stream, int len)
{
Uint8 *waveptr;
int waveleft;
/* Set up the pointers */
waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos;
/* Go! */
while (waveleft <= len) {
SDL_memcpy(stream, waveptr, waveleft);
stream += waveleft;
len -= waveleft;
waveptr = wave.sound;
waveleft = wave.soundlen;
wave.soundpos = 0;
stream = SDL_CreateAndBindAudioStream(device, &wave.spec);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
SDL_CloseAudioDevice(device);
SDL_free(wave.sound);
quit(2);
}
SDL_memcpy(stream, waveptr, len);
wave.soundpos += len;
}
static int done = 0;
#ifdef __EMSCRIPTEN__
static void loop(void)
{
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
if (done) {
emscripten_cancel_main_loop();
} else {
fillerup();
}
}
#endif
@ -162,13 +149,11 @@ int main(int argc, char *argv[])
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
}
wave.spec.callback = fillerup;
/* Show the list of available drivers */
SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
@ -179,8 +164,6 @@ int main(int argc, char *argv[])
open_audio();
SDL_FlushEvents(SDL_EVENT_AUDIO_DEVICE_ADDED, SDL_EVENT_AUDIO_DEVICE_REMOVED);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
@ -191,11 +174,9 @@ int main(int argc, char *argv[])
if (event.type == SDL_EVENT_QUIT) {
done = 1;
}
if ((event.type == SDL_EVENT_AUDIO_DEVICE_ADDED && !event.adevice.iscapture) ||
(event.type == SDL_EVENT_AUDIO_DEVICE_REMOVED && !event.adevice.iscapture && event.adevice.which == device)) {
reopen_audio();
}
}
fillerup();
SDL_Delay(100);
}
#endif

View File

@ -1,183 +0,0 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Program to load a wave file and loop playing it using SDL sound queueing */
#include <stdlib.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#include "testutils.h"
static struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
} wave;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
static int done = 0;
static void poked(int sig)
{
done = 1;
}
static SDL_AudioDeviceID g_audio_id = 0;
static void loop(void)
{
#ifdef __EMSCRIPTEN__
if (done || (SDL_GetAudioDeviceStatus(g_audio_id) != SDL_AUDIO_PLAYING)) {
emscripten_cancel_main_loop();
} else
#endif
{
/* The device from SDL_OpenAudio() is always device #1. */
const Uint32 queued = SDL_GetQueuedAudioSize(g_audio_id);
SDL_Log("Device has %u bytes queued.\n", (unsigned int)queued);
if (queued <= 8192) { /* time to requeue the whole thing? */
if (SDL_QueueAudio(g_audio_id, wave.sound, wave.soundlen) == 0) {
SDL_Log("Device queued %u more bytes.\n", (unsigned int)wave.soundlen);
} else {
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int)wave.soundlen, SDL_GetError());
}
}
}
}
int main(int argc, char *argv[])
{
int i;
char *filename = NULL;
SDLTest_CommonState *state;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (!filename) {
filename = argv[i];
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = { "[sample.wav]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
filename = GetResourceFilename(filename, "sample.wav");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
}
wave.spec.callback = NULL; /* we'll push audio. */
#ifdef HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
(void)signal(SIGHUP, poked);
#endif
(void)signal(SIGINT, poked);
#ifdef SIGQUIT
(void)signal(SIGQUIT, poked);
#endif
(void)signal(SIGTERM, poked);
#endif /* HAVE_SIGNAL_H */
/* Initialize fillerup() variables */
g_audio_id = SDL_OpenAudioDevice(NULL, 0, &wave.spec, NULL, 0);
if (!g_audio_id) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_free(wave.sound);
quit(2);
}
/*static x[99999]; SDL_QueueAudio(1, x, sizeof (x));*/
/* Let the audio run */
SDL_PlayAudioDevice(g_audio_id);
done = 0;
/* Note that we stuff the entire audio buffer into the queue in one
shot. Most apps would want to feed it a little at a time, as it
plays, but we're going for simplicity here. */
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done && (SDL_GetAudioDeviceStatus(g_audio_id) == SDL_AUDIO_PLAYING)) {
loop();
SDL_Delay(100); /* let it play for a while. */
}
#endif
/* Clean up on signal */
SDL_CloseAudioDevice(g_audio_id);
SDL_free(wave.sound);
SDL_free(filename);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;
}

BIN
external/sdl/SDL/test/physaudiodev.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
external/sdl/SDL/test/soundboard.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
external/sdl/SDL/test/speaker.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -0,0 +1,8 @@
The .bmp files used by testaudio.c were made by AlDraw:
https://linktr.ee/AlexDraw
They may be distributed as public domain files!

1069
external/sdl/SDL/test/testaudio.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -22,13 +22,14 @@
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
static SDL_AudioSpec spec;
static SDL_AudioDeviceID devid_in = 0;
static SDL_AudioDeviceID devid_out = 0;
static SDL_AudioStream *stream_in = NULL;
static SDL_AudioStream *stream_out = NULL;
static int done = 0;
static void loop(void)
{
const SDL_AudioDeviceID devid_in = SDL_GetAudioStreamBinding(stream_in);
const SDL_AudioDeviceID devid_out = SDL_GetAudioStreamBinding(stream_out);
SDL_bool please_quit = SDL_FALSE;
SDL_Event e;
@ -42,17 +43,18 @@ static void loop(void)
} else if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (e.button.button == 1) {
SDL_PauseAudioDevice(devid_out);
SDL_PlayAudioDevice(devid_in);
SDL_ResumeAudioDevice(devid_in);
}
} else if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) {
if (e.button.button == 1) {
SDL_PauseAudioDevice(devid_in);
SDL_PlayAudioDevice(devid_out);
SDL_FlushAudioStream(stream_in); /* so no samples are held back for resampling purposes. */
SDL_ResumeAudioDevice(devid_out);
}
}
}
if (SDL_GetAudioDeviceStatus(devid_in) == SDL_AUDIO_PLAYING) {
if (!SDL_IsAudioDevicePaused(devid_in)) {
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
@ -60,13 +62,26 @@ static void loop(void)
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Feed any new data we captured to the output stream. It'll play when we unpause the device. */
while (!please_quit && (SDL_GetAudioStreamAvailable(stream_in) > 0)) {
Uint8 buf[1024];
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));
if (br < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError());
please_quit = 1;
} else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError());
please_quit = 1;
}
}
if (please_quit) {
/* stop playing back, quit. */
SDL_Log("Shutting down.\n");
SDL_PauseAudioDevice(devid_in);
SDL_CloseAudioDevice(devid_in);
SDL_PauseAudioDevice(devid_out);
SDL_CloseAudioDevice(devid_out);
SDL_DestroyAudioStream(stream_in);
SDL_DestroyAudioStream(stream_out);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
@ -77,28 +92,18 @@ static void loop(void)
done = 1;
return;
}
/* Note that it would be easier to just have a one-line function that
calls SDL_QueueAudio() as a capture device callback, but we're
trying to test the API, so we use SDL_DequeueAudio() here. */
while (SDL_TRUE) {
Uint8 buf[1024];
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof(buf));
SDL_QueueAudio(devid_out, buf, br);
if (br < sizeof(buf)) {
break;
}
}
}
int main(int argc, char **argv)
{
/* (NULL means "open default device.") */
const char *devname = NULL;
SDL_AudioSpec wanted;
int devcount;
int i;
SDL_AudioDeviceID *devices;
SDLTest_CommonState *state;
SDL_AudioSpec outspec;
SDL_AudioSpec inspec;
SDL_AudioDeviceID device;
SDL_AudioDeviceID want_device = SDL_AUDIO_DEVICE_DEFAULT_CAPTURE;
const char *devname = NULL;
int i;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
@ -121,7 +126,7 @@ int main(int argc, char **argv)
}
}
if (consumed <= 0) {
static const char *options[] = { "[driver_name]", NULL };
static const char *options[] = { "[device_name]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
@ -145,19 +150,20 @@ int main(int argc, char **argv)
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devcount = SDL_GetNumAudioDevices(SDL_TRUE);
for (i = 0; i < devcount; i++) {
SDL_Log(" Capture device #%d: '%s'\n", i, SDL_GetAudioDeviceName(i, SDL_TRUE));
devices = SDL_GetAudioCaptureDevices(NULL);
for (i = 0; devices[i] != 0; i++) {
char *name = SDL_GetAudioDeviceName(devices[i]);
SDL_Log(" Capture device #%d: '%s'\n", i, name);
if (devname && (SDL_strcmp(devname, name) == 0)) {
want_device = devices[i];
}
SDL_free(name);
}
SDL_zero(wanted);
wanted.freq = 44100;
wanted.format = SDL_AUDIO_F32SYS;
wanted.channels = 1;
wanted.samples = 4096;
wanted.callback = NULL;
SDL_zero(spec);
if (devname && (want_device == SDL_AUDIO_DEVICE_DEFAULT_CAPTURE)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Didn't see a capture device named '%s', using the system default instead.\n", devname);
devname = NULL;
}
/* DirectSound can fail in some instances if you open the same hardware
for both capture and output and didn't open the output end first,
@ -166,24 +172,42 @@ int main(int argc, char **argv)
circumstances. */
SDL_Log("Opening default playback device...\n");
devid_out = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wanted, &spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
if (!devid_out) {
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &outspec);
stream_out = SDL_CreateAndBindAudioStream(device, &outspec);
if (!stream_out) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_Log("Opening capture device %s%s%s...\n",
devname ? "'" : "",
devname ? devname : "[[default]]",
devname ? "'" : "");
devid_in = SDL_OpenAudioDevice(devname, SDL_TRUE, &spec, &spec, 0);
if (!devid_in) {
device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec);
stream_in = SDL_CreateAndBindAudioStream(device, &inspec);
if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_SetAudioStreamFormat(stream_in, NULL, &outspec); /* make sure we output at the playback format. */
SDL_Log("Ready! Hold down mouse or finger to record!\n");
@ -198,11 +222,7 @@ int main(int argc, char **argv)
}
#endif
/* SDL_DestroyRenderer(renderer); */
/* SDL_DestroyWindow(window); */
/* SDL_Quit(); */
/* SDLTest_CommonDestroyState(state); */
SDLTest_CommonDestroyState(state);
return 0;
}

View File

@ -31,9 +31,6 @@ static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
static int posindex = 0;
static Uint32 positions[64];
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
@ -48,31 +45,6 @@ quit(int rc)
}
}
static void SDLCALL
fillerup(void *_pos, Uint8 *stream, int len)
{
Uint32 pos = *((Uint32 *)_pos);
Uint8 *waveptr;
int waveleft;
/* Set up the pointers */
waveptr = sound + pos;
waveleft = soundlen - pos;
/* Go! */
while (waveleft <= len) {
SDL_memcpy(stream, waveptr, waveleft);
stream += waveleft;
len -= waveleft;
waveptr = sound;
waveleft = soundlen;
pos = 0;
}
SDL_memcpy(stream, waveptr, len);
pos += len;
*((Uint32 *)_pos) = pos;
}
static int done = 0;
static void poked(int sig)
@ -97,28 +69,35 @@ static void iteration(void)
done = 1;
}
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_ADDED) {
int index = e.adevice.which;
int iscapture = e.adevice.iscapture;
const char *name = SDL_GetAudioDeviceName(index, iscapture);
const SDL_AudioDeviceID which = (SDL_AudioDeviceID ) e.adevice.which;
const SDL_bool iscapture = e.adevice.iscapture ? SDL_TRUE : SDL_FALSE;
char *name = SDL_GetAudioDeviceName(which);
if (name != NULL) {
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
SDL_Log("New %s audio device at id %u: %s", devtypestr(iscapture), (unsigned int)which, name);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
devtypestr(iscapture), (unsigned int)index, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device, id %u, but failed to get the name: %s",
devtypestr(iscapture), (unsigned int)which, SDL_GetError());
continue;
}
if (!iscapture) {
positions[posindex] = 0;
spec.userdata = &positions[posindex++];
spec.callback = fillerup;
dev = SDL_OpenAudioDevice(name, 0, &spec, NULL, 0);
dev = SDL_OpenAudioDevice(which, &spec);
if (!dev) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError());
} else {
SDL_AudioStream *stream;
SDL_Log("Opened '%s' as %u\n", name, (unsigned int)dev);
SDL_PlayAudioDevice(dev);
stream = SDL_CreateAndBindAudioStream(dev, &spec);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create/bind an audio stream to %u ('%s'): %s", (unsigned int) dev, name, SDL_GetError());
SDL_CloseAudioDevice(dev);
}
/* !!! FIXME: laziness, this used to loop the audio, but we'll just play it once for now on each connect. */
SDL_PutAudioStreamData(stream, sound, soundlen);
SDL_FlushAudioStream(stream);
/* !!! FIXME: this is leaking the stream for now. We'll wire it up to a dictionary or whatever later. */
}
}
SDL_free(name);
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_REMOVED) {
dev = (SDL_AudioDeviceID)e.adevice.which;
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int)dev);
@ -194,7 +173,7 @@ int main(int argc, char *argv[])
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == NULL) {
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
}

View File

@ -14,29 +14,30 @@
#include <SDL3/SDL_test.h>
static void
print_devices(int iscapture)
print_devices(SDL_bool iscapture)
{
SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture);
int n = 0;
SDL_AudioDeviceID *devices = iscapture ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
if (n == -1) {
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
if (devices == NULL) {
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
} else if (n == 0) {
SDL_Log(" No %s devices found.\n\n", typestr);
} else {
int i;
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
for (i = 0; i < n; i++) {
const char *name = SDL_GetAudioDeviceName(i, iscapture);
char *name = SDL_GetAudioDeviceName(devices[i]);
if (name != NULL) {
SDL_Log(" %d: %s\n", i, name);
SDL_free(name);
} else {
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
}
if (SDL_GetAudioDeviceSpec(i, iscapture, &spec) == 0) {
if (SDL_GetAudioDeviceFormat(devices[i], &spec) == 0) {
SDL_Log(" Sample Rate: %d\n", spec.freq);
SDL_Log(" Channels: %d\n", spec.channels);
SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
@ -44,11 +45,11 @@ print_devices(int iscapture)
}
SDL_Log("\n");
}
SDL_free(devices);
}
int main(int argc, char **argv)
{
char *deviceName = NULL;
SDL_AudioSpec spec;
int i;
int n;
@ -88,24 +89,22 @@ int main(int argc, char **argv)
SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
print_devices(0);
print_devices(1);
print_devices(SDL_FALSE);
print_devices(SDL_TRUE);
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default output): %s\n", SDL_GetError());
} else {
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Default Output Device:\n");
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_CAPTURE, &spec) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default capture): %s\n", SDL_GetError());
} else {
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Default Capture Device:\n");
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
@ -115,3 +114,4 @@ int main(int argc, char **argv)
SDLTest_CommonDestroyState(state);
return 0;
}

View File

@ -15,108 +15,176 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
#include "testutils.h"
static void SDLCALL audio_callback(void *userdata, Uint8 * stream, int len)
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#include <stdlib.h>
#define SLIDER_WIDTH_PERC 500.f / 600.f
#define SLIDER_HEIGHT_PERC 100.f / 480.f
static int done;
static SDLTest_CommonState *state;
static int multiplier = 100;
static SDL_FRect slider_area;
static SDL_FRect slider_fill_area;
static SDL_AudioSpec spec;
static SDL_AudioStream *stream;
static Uint8 *audio_buf = NULL;
static Uint32 audio_len = 0;
static void loop(void)
{
SDL_AudioStream *audiostream = (SDL_AudioStream *) userdata;
SDL_memset(stream, 0, len);
SDL_GetAudioStreamData(audiostream, stream, len);
int i;
SDL_Event e;
int newmultiplier = multiplier;
while (SDL_PollEvent(&e)) {
SDLTest_CommonEvent(state, &e, &done);
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
if (e.type == SDL_EVENT_MOUSE_MOTION) {
if (e.motion.state & SDL_BUTTON_LMASK) {
const SDL_FPoint p = { e.motion.x, e.motion.y };
if (SDL_PointInRectFloat(&p, &slider_area)) {
const float w = SDL_roundf(p.x - slider_area.x);
slider_fill_area.w = w;
newmultiplier = ((int) ((w / slider_area.w) * 800.0f)) - 400;
}
}
}
}
if (multiplier != newmultiplier) {
SDL_AudioSpec newspec;
char title[64];
int newfreq = spec.freq;
multiplier = newmultiplier;
if (multiplier == 0) {
SDL_snprintf(title, sizeof (title), "Drag the slider: Normal speed");
} else if (multiplier < 0) {
SDL_snprintf(title, sizeof (title), "Drag the slider: %.2fx slow", (-multiplier / 100.0f) + 1.0f);
} else {
SDL_snprintf(title, sizeof (title), "Drag the slider: %.2fx fast", (multiplier / 100.0f) + 1.0f);
}
for (i = 0; i < state->num_windows; i++) {
SDL_SetWindowTitle(state->windows[i], title);
}
/* this math sucks, but whatever. */
if (multiplier < 0) {
newfreq = spec.freq + (int) ((spec.freq * (multiplier / 400.0f)) * 0.75f);
} else if (multiplier > 0) {
newfreq = spec.freq + (int) (spec.freq * (multiplier / 100.0f));
}
/* SDL_Log("newfreq=%d multiplier=%d\n", newfreq, multiplier); */
SDL_memcpy(&newspec, &spec, sizeof (spec));
newspec.freq = newfreq;
SDL_SetAudioStreamFormat(stream, &newspec, NULL);
}
/* keep it looping. */
if (SDL_GetAudioStreamAvailable(stream) < ((int) (audio_len / 2))) {
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
}
for (i = 0; i < state->num_windows; i++) {
SDL_SetRenderDrawColor(state->renderers[i], 0, 0, 255, 255);
SDL_RenderClear(state->renderers[i]);
SDL_SetRenderDrawColor(state->renderers[i], 0, 0, 0, 255);
SDL_RenderFillRect(state->renderers[i], &slider_area);
SDL_SetRenderDrawColor(state->renderers[i], 255, 0, 0, 255);
SDL_RenderFillRect(state->renderers[i], &slider_fill_area);
SDL_RenderPresent(state->renderers[i]);
}
}
int main(int argc, char *argv[])
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_bool done = SDL_FALSE;
const SDL_FRect slider_area = { (640 - 500) / 2, (480 - 100) / 2, 500, 100 };
SDL_FRect slider_fill_area = slider_area;
int multiplier = 100;
SDL_AudioSpec spec;
Uint8 *audio_buf = NULL;
Uint32 audio_len = 0;
SDL_AudioStream *stream;
SDL_AudioDeviceID device;
char *filename = NULL;
int i;
int rc;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
window = SDL_CreateWindow("Drag the slider: Normal speed", 640, 480, 0);
renderer = SDL_CreateRenderer(window, NULL, 0);
SDL_LoadWAV("sample.wav", &spec, &audio_buf, &audio_len);
stream = SDL_CreateAudioStream(spec.format, spec.channels, spec.freq, spec.format, spec.channels, spec.freq);
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
spec.callback = audio_callback;
spec.userdata = stream;
device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &spec, NULL, 0);
SDL_PlayAudioDevice(device);
slider_fill_area.w /= 2;
while (!done) {
SDL_Event e;
int newmultiplier = multiplier;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
done = 1;
} else if (e.type == SDL_EVENT_KEY_DOWN) {
if (e.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
}
} else if (e.type == SDL_EVENT_MOUSE_MOTION) {
if (e.motion.state & SDL_BUTTON_LMASK) {
const SDL_FPoint p = { e.motion.x, e.motion.y };
if (SDL_PointInRectFloat(&p, &slider_area)) {
const float w = SDL_roundf(p.x - slider_area.x);
slider_fill_area.w = w;
newmultiplier = ((int) ((w / slider_area.w) * 800.0f)) - 400;
}
}
}
}
if (multiplier != newmultiplier) {
char title[64];
int newfreq = spec.freq;
multiplier = newmultiplier;
if (multiplier == 0) {
SDL_snprintf(title, sizeof (title), "Drag the slider: Normal speed");
} else if (multiplier < 0) {
SDL_snprintf(title, sizeof (title), "Drag the slider: %.2fx slow", (-multiplier / 100.0f) + 1.0f);
} else {
SDL_snprintf(title, sizeof (title), "Drag the slider: %.2fx fast", (multiplier / 100.0f) + 1.0f);
}
SDL_SetWindowTitle(window, title);
/* this math sucks, but whatever. */
if (multiplier < 0) {
newfreq = spec.freq + (int) ((spec.freq * (multiplier / 400.0f)) * 0.75f);
} else if (multiplier > 0) {
newfreq = spec.freq + (int) (spec.freq * (multiplier / 100.0f));
}
/* SDL_Log("newfreq=%d multiplier=%d\n", newfreq, multiplier); */
SDL_LockAudioDevice(device);
SDL_SetAudioStreamFormat(stream, spec.format, spec.channels, newfreq, spec.format, spec.channels, spec.freq);
SDL_UnlockAudioDevice(device);
}
/* keep it looping. */
if (SDL_GetAudioStreamAvailable(stream) < (1024 * 100)) {
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
}
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderFillRect(renderer, &slider_area);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &slider_fill_area);
SDL_RenderPresent(renderer);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO | SDL_INIT_VIDEO);
if (state == NULL) {
return 1;
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_CloseAudioDevice(device);
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (!filename) {
filename = argv[i];
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = { "[sample.wav]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
slider_area.x = state->window_w * (1.f - SLIDER_WIDTH_PERC) / 2;
slider_area.y = state->window_h * (1.f - SLIDER_HEIGHT_PERC) / 2;
slider_area.w = SLIDER_WIDTH_PERC * state->window_w;
slider_area.h = SLIDER_HEIGHT_PERC * state->window_h;
slider_fill_area = slider_area;
slider_fill_area.w /= 2;
/* Load the SDL library */
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
filename = GetResourceFilename(filename, "sample.wav");
rc = SDL_LoadWAV(filename, &spec, &audio_buf, &audio_len);
SDL_free(filename);
if (rc < 0) {
SDL_Log("Failed to load '%s': %s", filename, SDL_GetError());
SDL_Quit();
return 1;
}
for (i = 0; i < state->num_windows; i++) {
SDL_SetWindowTitle(state->windows[i], "Drag the slider: Normal speed");
}
stream = SDL_CreateAudioStream(&spec, &spec);
SDL_PutAudioStreamData(stream, audio_buf, audio_len);
SDL_BindAudioStream(state->audio_id, stream);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
SDL_DestroyAudioStream(stream);
SDL_free(audio_buf);
SDLTest_CommonQuit(state);
SDL_Quit();
return 0;
}

View File

@ -38,6 +38,7 @@ static void audioTearDown(void *arg)
SDLTest_AssertPass("Cleanup of test files completed");
}
#if 0 /* !!! FIXME: maybe update this? */
/* Global counter for callback invocation */
static int g_audio_testCallbackCounter;
@ -51,6 +52,7 @@ static void SDLCALL audio_testCallback(void *userdata, Uint8 *stream, int len)
g_audio_testCallbackCounter++;
g_audio_testCallbackLength += len;
}
#endif
static SDL_AudioDeviceID g_audio_id = -1;
@ -176,28 +178,22 @@ static int audio_initOpenCloseQuitAudio(void *arg)
desired.freq = 22050;
desired.format = SDL_AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = audio_testCallback;
desired.userdata = NULL;
case 1:
/* Set custom desired spec */
desired.freq = 48000;
desired.format = SDL_AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = audio_testCallback;
desired.userdata = NULL;
break;
}
/* Call Open (maybe multiple times) */
for (k = 0; k <= j; k++) {
result = SDL_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
if (k == 0) {
g_audio_id = result;
}
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0), call %d", j, k + 1);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d), call %d", j, k + 1);
SDLTest_AssertCheck(result > 0, "Verify return value; expected: > 0, got: %d", result);
}
@ -230,11 +226,9 @@ static int audio_initOpenCloseQuitAudio(void *arg)
*/
static int audio_pauseUnpauseAudio(void *arg)
{
int iMax;
int i, j /*, k, l*/;
int result;
int i, iMax, j, k, l;
int totalDelay;
int pause_on;
int originalCounter;
const char *audioDriver;
SDL_AudioSpec desired;
@ -269,9 +263,6 @@ static int audio_pauseUnpauseAudio(void *arg)
desired.freq = 22050;
desired.format = SDL_AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = audio_testCallback;
desired.userdata = NULL;
break;
case 1:
@ -279,18 +270,16 @@ static int audio_pauseUnpauseAudio(void *arg)
desired.freq = 48000;
desired.format = SDL_AUDIO_F32SYS;
desired.channels = 2;
desired.samples = 2048;
desired.callback = audio_testCallback;
desired.userdata = NULL;
break;
}
/* Call Open */
g_audio_id = SDL_OpenAudioDevice(NULL, 0, &desired, NULL, 0);
g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
result = g_audio_id;
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(NULL, 0, desired_spec_%d, NULL, 0)", j);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d)", j);
SDLTest_AssertCheck(result > 0, "Verify return value; expected > 0 got: %d", result);
#if 0 /* !!! FIXME: maybe update this? */
/* Start and stop audio multiple times */
for (l = 0; l < 3; l++) {
SDLTest_Log("Pause/Unpause iteration: %d", l + 1);
@ -300,14 +289,13 @@ static int audio_pauseUnpauseAudio(void *arg)
g_audio_testCallbackLength = 0;
/* Un-pause audio to start playing (maybe multiple times) */
pause_on = 0;
for (k = 0; k <= j; k++) {
SDL_PlayAudioDevice(g_audio_id);
SDLTest_AssertPass("Call to SDL_PlayAudioDevice(g_audio_id), call %d", k + 1);
}
/* Wait for callback */
totalDelay = 0;
int totalDelay = 0;
do {
SDL_Delay(10);
totalDelay += 10;
@ -317,7 +305,7 @@ static int audio_pauseUnpauseAudio(void *arg)
/* Pause audio to stop playing (maybe multiple times) */
for (k = 0; k <= j; k++) {
pause_on = (k == 0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
const int pause_on = (k == 0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999);
if (pause_on) {
SDL_PauseAudioDevice(g_audio_id);
SDLTest_AssertPass("Call to SDL_PauseAudioDevice(g_audio_id), call %d", k + 1);
@ -328,10 +316,11 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/* Ensure callback is not called again */
originalCounter = g_audio_testCallbackCounter;
const int originalCounter = g_audio_testCallbackCounter;
SDL_Delay(totalDelay + 10);
SDLTest_AssertCheck(originalCounter == g_audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, g_audio_testCallbackCounter);
}
#endif
/* Call Close */
SDL_CloseAudioDevice(g_audio_id);
@ -358,51 +347,34 @@ static int audio_pauseUnpauseAudio(void *arg)
*/
static int audio_enumerateAndNameAudioDevices(void *arg)
{
int t, tt;
int i, n, nn;
const char *name, *nameAgain;
int t;
int i, n;
char *name;
SDL_AudioDeviceID *devices = NULL;
/* Iterate over types: t=0 output device, t=1 input/capture device */
for (t = 0; t < 2; t++) {
/* Get number of devices. */
n = SDL_GetNumAudioDevices(t);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
devices = (t) ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Capture" : "Output", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* Variation of non-zero type */
if (t == 1) {
tt = t + SDLTest_RandomIntegerInRange(1, 10);
nn = SDL_GetNumAudioDevices(tt);
SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
nn = SDL_GetNumAudioDevices(-tt);
SDLTest_AssertCheck(n == nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
}
/* List devices. */
if (n > 0) {
SDLTest_AssertCheck(devices != NULL, "Validate devices is not NULL if n > 0");
for (i = 0; i < n; i++) {
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
name = SDL_GetAudioDeviceName(devices[i]);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i)", i);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i) is not NULL", i);
if (name != NULL) {
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
if (t == 1) {
/* Also try non-zero type */
tt = t + SDLTest_RandomIntegerInRange(1, 10);
nameAgain = SDL_GetAudioDeviceName(i, tt);
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
if (nameAgain != NULL) {
SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain) == 0,
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
i, t, i, tt);
}
}
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i) is not empty, got: '%s'", i, name);
SDL_free(name);
}
}
}
SDL_free(devices);
}
return TEST_COMPLETED;
@ -416,42 +388,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
*/
static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
{
int t;
int i, j, no, nc;
const char *name;
/* Get number of devices. */
no = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
nc = SDL_GetNumAudioDevices(1);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
/* Invalid device index when getting name */
for (t = 0; t < 2; t++) {
/* Negative device index */
i = SDLTest_RandomIntegerInRange(-10, -1);
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
/* Device index past range */
for (j = 0; j < 3; j++) {
i = (t) ? nc + j : no + j;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
/* Capture index past capture range but within output range */
if ((no > 0) && (no > nc) && (t == 1)) {
i = no - 1;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
}
return TEST_COMPLETED;
return TEST_COMPLETED; /* nothing in here atm since these interfaces changed in SDL3. */
}
/**
@ -532,8 +469,7 @@ static int audio_buildAudioStream(void *arg)
spec1.format = SDL_AUDIO_S16LSB;
spec1.channels = 2;
spec1.freq = 22050;
stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
spec1.format, spec1.channels, spec1.freq);
stream = SDL_CreateAudioStream(&spec1, &spec1);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec1)");
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDL_DestroyAudioStream(stream);
@ -545,8 +481,7 @@ static int audio_buildAudioStream(void *arg)
spec2.format = SDL_AUDIO_S16LSB;
spec2.channels = 2;
spec2.freq = 44100;
stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
SDL_DestroyAudioStream(stream);
@ -564,8 +499,7 @@ static int audio_buildAudioStream(void *arg)
spec2.format = g_audioFormats[ii];
spec2.channels = g_audioChannels[jj];
spec2.freq = g_audioFrequencies[kk];
stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
@ -646,8 +580,7 @@ static int audio_buildAudioStreamNegative(void *arg)
spec2.freq = 0;
}
SDLTest_Log("%s", message);
stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(spec1 ==> spec2)");
SDLTest_AssertCheck(stream == NULL, "Verify stream value; expected: NULL, got: %p", (void *)stream);
error = SDL_GetError();
@ -669,16 +602,7 @@ static int audio_buildAudioStreamNegative(void *arg)
*/
static int audio_getAudioStatus(void *arg)
{
SDL_AudioStatus result;
/* Check current audio status */
result = SDL_GetAudioDeviceStatus(g_audio_id);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus(g_audio_id)");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
return TEST_COMPLETED;
return TEST_COMPLETED; /* no longer a thing in SDL3. */
}
/**
@ -688,57 +612,7 @@ static int audio_getAudioStatus(void *arg)
*/
static int audio_openCloseAndGetAudioStatus(void *arg)
{
SDL_AudioStatus result;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = SDL_AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
if (id > 0) {
/* Check device audio status */
result = SDL_GetAudioDeviceStatus(id);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED,
"Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i",
SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
return TEST_COMPLETED; /* not a thing in SDL3. */
}
/**
@ -749,60 +623,7 @@ static int audio_openCloseAndGetAudioStatus(void *arg)
*/
static int audio_lockUnlockOpenAudioDevice(void *arg)
{
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = SDL_AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
if (id > 0) {
/* Lock to protect callback */
SDL_LockAudioDevice(id);
SDLTest_AssertPass("SDL_LockAudioDevice(%" SDL_PRIu32 ")", id);
/* Simulate callback processing */
SDL_Delay(10);
SDLTest_Log("Simulate callback processing - delay");
/* Unlock again */
SDL_UnlockAudioDevice(id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%" SDL_PRIu32 ")", id);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
return TEST_COMPLETED; /* not a thing in SDL3 */
}
/**
@ -862,8 +683,7 @@ static int audio_convertAudio(void *arg)
spec2.channels = g_audioChannels[jj];
spec2.freq = g_audioFrequencies[kk];
stream = SDL_CreateAudioStream(spec1.format, spec1.channels, spec1.freq,
spec2.format, spec2.channels, spec2.freq);
stream = SDL_CreateAudioStream(&spec1, &spec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i ==> format[%i]=%s(%i),channels[%i]=%i,freq[%i]=%i)",
i, g_audioFormatsVerbose[i], spec1.format, j, spec1.channels, k, spec1.freq, ii, g_audioFormatsVerbose[ii], spec2.format, jj, spec2.channels, kk, spec2.freq);
SDLTest_AssertCheck(stream != NULL, "Verify stream value; expected: != NULL, got: %p", (void *)stream);
@ -936,59 +756,7 @@ static int audio_convertAudio(void *arg)
*/
static int audio_openCloseAudioDeviceConnected(void *arg)
{
int result = -1;
int i;
int count;
const char *device;
SDL_AudioDeviceID id;
SDL_AudioSpec desired, obtained;
/* Get number of devices. */
count = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
if (count > 0) {
for (i = 0; i < count; i++) {
/* Get device name */
device = SDL_GetAudioDeviceName(i, 0);
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
if (device == NULL) {
return TEST_ABORTED;
}
/* Set standard desired spec */
desired.freq = 22050;
desired.format = SDL_AUDIO_S16SYS;
desired.channels = 2;
desired.samples = 4096;
desired.callback = audio_testCallback;
desired.userdata = NULL;
/* Open device */
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
SDLTest_AssertCheck(id > 0, "Validate device ID; expected: > 0, got: %" SDL_PRIu32, id);
if (id > 0) {
/* TODO: enable test code when function is available in SDL3 */
#ifdef AUDIODEVICECONNECTED_DEFINED
/* Get connected status */
result = SDL_AudioDeviceConnected(id);
SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
#endif
SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
/* Close device again */
SDL_CloseAudioDevice(id);
SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
}
}
} else {
SDLTest_Log("No devices to test with");
}
return TEST_COMPLETED;
return TEST_COMPLETED; /* not a thing in SDL3. */
}
static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64 freq, const double phase)
@ -1040,6 +808,7 @@ static int audio_resampleLoss(void *arg)
const int len_in = frames_in * (int)sizeof(float);
const int len_target = frames_target * (int)sizeof(float);
SDL_AudioSpec tmpspec1, tmpspec2;
Uint64 tick_beg = 0;
Uint64 tick_end = 0;
int i = 0;
@ -1056,7 +825,13 @@ static int audio_resampleLoss(void *arg)
SDLTest_AssertPass("Test resampling of %i s %i Hz %f phase sine wave from sampling rate of %i Hz to %i Hz",
spec->time, spec->freq, spec->phase, spec->rate_in, spec->rate_out);
stream = SDL_CreateAudioStream(SDL_AUDIO_F32, 1, spec->rate_in, SDL_AUDIO_F32, 1, spec->rate_out);
tmpspec1.format = SDL_AUDIO_F32;
tmpspec1.channels = 1;
tmpspec1.freq = spec->rate_in;
tmpspec2.format = SDL_AUDIO_F32;
tmpspec2.channels = 1;
tmpspec2.freq = spec->rate_out;
stream = SDL_CreateAudioStream(&tmpspec1, &tmpspec2);
SDLTest_AssertPass("Call to SDL_CreateAudioStream(SDL_AUDIO_F32, 1, %i, SDL_AUDIO_F32, 1, %i)", spec->rate_in, spec->rate_out);
SDLTest_AssertCheck(stream != NULL, "Expected SDL_CreateAudioStream to succeed.");
if (stream == NULL) {

View File

@ -95,11 +95,11 @@ static void RWopsTearDown(void *arg)
* \sa SDL_RWseek
* \sa SDL_RWread
*/
static void testGenericRWopsValidations(SDL_RWops *rw, int write)
static void testGenericRWopsValidations(SDL_RWops *rw, SDL_bool write)
{
char buf[sizeof(RWopsHelloWorldTestString)];
Sint64 i;
Sint64 s;
size_t s;
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
/* Clear buffer */
@ -116,7 +116,7 @@ static void testGenericRWopsValidations(SDL_RWops *rw, int write)
if (write) {
SDLTest_AssertCheck(s == sizeof(RWopsHelloWorldTestString) - 1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
} else {
SDLTest_AssertCheck(s == -1, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
SDLTest_AssertCheck(s == 0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
}
/* Test seek to random position */
@ -133,7 +133,7 @@ static void testGenericRWopsValidations(SDL_RWops *rw, int write)
s = SDL_RWread(rw, buf, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWread succeeded");
SDLTest_AssertCheck(
s == (size_t)(sizeof(RWopsHelloWorldTestString) - 1),
s == (sizeof(RWopsHelloWorldTestString) - 1),
"Verify result from SDL_RWread, expected %i, got %i",
(int)(sizeof(RWopsHelloWorldTestString) - 1),
(int)s);
@ -242,7 +242,7 @@ static int rwops_testMem(void *arg)
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY, rw->type);
/* Run generic tests */
testGenericRWopsValidations(rw, 1);
testGenericRWopsValidations(rw, SDL_TRUE);
/* Close */
result = SDL_RWclose(rw);
@ -277,7 +277,7 @@ static int rwops_testConstMem(void *arg)
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %" SDL_PRIu32, SDL_RWOPS_MEMORY_RO, rw->type);
/* Run generic tests */
testGenericRWopsValidations(rw, 0);
testGenericRWopsValidations(rw, SDL_FALSE);
/* Close handle */
result = SDL_RWclose(rw);
@ -324,7 +324,7 @@ static int rwops_testFileRead(void *arg)
#endif
/* Run generic tests */
testGenericRWopsValidations(rw, 0);
testGenericRWopsValidations(rw, SDL_FALSE);
/* Close handle */
result = SDL_RWclose(rw);
@ -371,7 +371,7 @@ static int rwops_testFileWrite(void *arg)
#endif
/* Run generic tests */
testGenericRWopsValidations(rw, 1);
testGenericRWopsValidations(rw, SDL_TRUE);
/* Close handle */
result = SDL_RWclose(rw);
@ -437,7 +437,7 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
/* Read/seek from memory */
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
SDLTest_AssertPass("Call to SDL_RWFromMem()");
rv_mem = (size_t)SDL_RWread(rwops_mem, buffer_mem, size * 6);
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size * 6);
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size * 6);
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
@ -448,7 +448,7 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
/* Read/see from file */
rwops_file = SDL_RWFromFile(RWopsAlphabetFilename, "r");
SDLTest_AssertPass("Call to SDL_RWFromFile()");
rv_file = (size_t)SDL_RWread(rwops_file, buffer_file, size * 6);
rv_file = SDL_RWread(rwops_file, buffer_file, size * 6);
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size * 6);
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
@ -477,15 +477,14 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
*
* \sa SDL_RWFromFile
* \sa SDL_RWClose
* \sa SDL_ReadBE16
* \sa SDL_WriteBE16
* \sa SDL_ReadU16BE
* \sa SDL_WriteU16BE
*/
static int rwops_testFileWriteReadEndian(void *arg)
{
SDL_RWops *rw;
Sint64 result;
int mode;
size_t objectsWritten;
Uint16 BE16value;
Uint32 BE32value;
Uint64 BE64value;
@ -498,6 +497,7 @@ static int rwops_testFileWriteReadEndian(void *arg)
Uint16 LE16test;
Uint32 LE32test;
Uint64 LE64test;
SDL_bool bresult;
int cresult;
for (mode = 0; mode < 3; mode++) {
@ -545,24 +545,24 @@ static int rwops_testFileWriteReadEndian(void *arg)
}
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteBE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteBE32(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteBE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteBE64(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteBE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE16(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteLE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE32(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteLE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
objectsWritten = SDL_WriteLE64(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteLE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int)objectsWritten);
bresult = SDL_WriteU16BE(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteU16BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
bresult = SDL_WriteU32BE(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteU32BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
bresult = SDL_WriteU64BE(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteU64BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
bresult = SDL_WriteU16LE(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteU16LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
bresult = SDL_WriteU32LE(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteU32LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
bresult = SDL_WriteU64LE(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteU64LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object written, expected: SDL_TRUE, got: SDL_FALSE");
/* Test seek to start */
result = SDL_RWseek(rw, 0, SDL_RW_SEEK_SET);
@ -570,24 +570,30 @@ static int rwops_testFileWriteReadEndian(void *arg)
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int)result);
/* Read test data */
BE16test = SDL_ReadBE16(rw);
SDLTest_AssertPass("Call to SDL_ReadBE16()");
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
BE32test = SDL_ReadBE32(rw);
SDLTest_AssertPass("Call to SDL_ReadBE32()");
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64()");
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
LE16test = SDL_ReadLE16(rw);
SDLTest_AssertPass("Call to SDL_ReadLE16()");
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
LE32test = SDL_ReadLE32(rw);
SDLTest_AssertPass("Call to SDL_ReadLE32()");
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64()");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
bresult = SDL_ReadU16BE(rw, &BE16test);
SDLTest_AssertPass("Call to SDL_ReadU16BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(BE16test == BE16value, "Validate object read from SDL_ReadU16BE, expected: %hu, got: %hu", BE16value, BE16test);
bresult = SDL_ReadU32BE(rw, &BE32test);
SDLTest_AssertPass("Call to SDL_ReadU32BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(BE32test == BE32value, "Validate object read from SDL_ReadU32BE, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, BE32value, BE32test);
bresult = SDL_ReadU64BE(rw, &BE64test);
SDLTest_AssertPass("Call to SDL_ReadU64BE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(BE64test == BE64value, "Validate object read from SDL_ReadU64BE, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, BE64value, BE64test);
bresult = SDL_ReadU16LE(rw, &LE16test);
SDLTest_AssertPass("Call to SDL_ReadU16LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(LE16test == LE16value, "Validate object read from SDL_ReadU16LE, expected: %hu, got: %hu", LE16value, LE16test);
bresult = SDL_ReadU32LE(rw, &LE32test);
SDLTest_AssertPass("Call to SDL_ReadU32LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(LE32test == LE32value, "Validate object read from SDL_ReadU32LE, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, LE32value, LE32test);
bresult = SDL_ReadU64LE(rw, &LE64test);
SDLTest_AssertPass("Call to SDL_ReadU64LE()");
SDLTest_AssertCheck(bresult == SDL_TRUE, "Validate object read, expected: SDL_TRUE, got: SDL_FALSE");
SDLTest_AssertCheck(LE64test == LE64value, "Validate object read from SDL_ReadU64LE, expected: %" SDL_PRIu64 ", got: %" SDL_PRIu64, LE64value, LE64test);
/* Close handle */
cresult = SDL_RWclose(rw);

View File

@ -197,30 +197,34 @@ static int stdlib_snprintf(void *arg)
{
static struct
{
int precision;
float value;
const char *expected_f;
const char *expected_g;
} f_and_g_test_cases[] = {
{ 100.0f, "100.000000", "100" },
{ -100.0f, "-100.000000", "-100" },
{ 100.75f, "100.750000", "100.75" },
{ -100.75f, "-100.750000", "-100.75" },
{ ((100 * 60 * 1000) / 1001) / 100.0f, "59.939999", "59.94" },
{ -((100 * 60 * 1000) / 1001) / 100.0f, "-59.939999", "-59.94" },
{ ((100 * 120 * 1000) / 1001) / 100.0f, "119.879997", "119.88" },
{ -((100 * 120 * 1000) / 1001) / 100.0f, "-119.879997", "-119.88" },
{ 9.9999999f, "10.000000", "10" },
{ -9.9999999f, "-10.000000", "-10" },
{ 6, 100.0f, "100.000000", "100" },
{ 6, -100.0f, "-100.000000", "-100" },
{ 6, 100.75f, "100.750000", "100.75" },
{ 6, -100.75f, "-100.750000", "-100.75" },
{ 6, ((100 * 60 * 1000) / 1001) / 100.0f, "59.939999", "59.94" },
{ 6, -((100 * 60 * 1000) / 1001) / 100.0f, "-59.939999", "-59.94" },
{ 6, ((100 * 120 * 1000) / 1001) / 100.0f, "119.879997", "119.88" },
{ 6, -((100 * 120 * 1000) / 1001) / 100.0f, "-119.879997", "-119.88" },
{ 6, 0.9999999f, "1.000000", "1" },
{ 6, -0.9999999f, "-1.000000", "-1" },
{ 5, 9.999999f, "10.00000", "10" },
{ 5, -9.999999f, "-10.00000", "-10" },
};
int i;
for (i = 0; i < SDL_arraysize(f_and_g_test_cases); ++i) {
float value = f_and_g_test_cases[i].value;
int prec = f_and_g_test_cases[i].precision;
result = SDL_snprintf(text, sizeof(text), "%f", value);
predicted = SDL_snprintf(NULL, 0, "%f", value);
result = SDL_snprintf(text, sizeof(text), "%.*f", prec, value);
predicted = SDL_snprintf(NULL, 0, "%.*f", prec, value);
expected = f_and_g_test_cases[i].expected_f;
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", %g)", value);
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.5f\", %g)", value);
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);

View File

@ -15,6 +15,7 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title)
SDL_Window *window;
int w, h;
SDL_WindowFlags flags;
SDL_bool needs_renderer = SDL_FALSE;
/* Standard window */
w = SDLTest_RandomIntegerInRange(320, 1024);
@ -25,6 +26,35 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title)
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d)", w, h, flags);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
* This is required for the mouse/keyboard grab tests to pass.
*/
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
needs_renderer = SDL_TRUE;
} else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
/* Try to detect if the x11 driver is running under XWayland */
const char *session_type = SDL_getenv("XDG_SESSION_TYPE");
if (session_type && SDL_strcasecmp(session_type, "wayland") == 0) {
needs_renderer = SDL_TRUE;
}
}
if (needs_renderer) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0);
if (renderer) {
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop.
*/
SDL_Delay(100);
} else {
SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland");
}
}
return window;
}
@ -1629,6 +1659,11 @@ cleanup:
*
* Especially useful when run on a multi-monitor system with different DPI scales per monitor,
* to test that the window size is maintained when moving between monitors.
*
* As the Wayland windowing protocol does not allow application windows to control their position in the
* desktop space, coupled with the general asynchronous nature of Wayland compositors, the positioning
* tests don't work in windowed mode and are unreliable in fullscreen mode, thus are disabled when using
* the Wayland video driver. All that can be done is check that the windows are the expected size.
*/
static int video_setWindowCenteredOnDisplay(void *arg)
{
@ -1640,6 +1675,7 @@ static int video_setWindowCenteredOnDisplay(void *arg)
int displayNum;
int result;
SDL_Rect display0, display1;
SDL_bool video_driver_is_wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
displays = SDL_GetDisplays(&displayNum);
if (displays) {
@ -1682,18 +1718,45 @@ static int video_setWindowCenteredOnDisplay(void *arg)
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */
if (video_driver_is_wayland) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0);
if (renderer) {
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop.
*/
SDL_Delay(100);
} else {
SDLTest_Log("Unable to create a renderer, tests may fail under Wayland");
}
}
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetDisplayForWindow(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Enter fullscreen desktop */
SDL_SetWindowPosition(window, x, y);
result = SDL_SetWindowFullscreen(window, SDL_TRUE);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
@ -1702,11 +1765,19 @@ static int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Leave fullscreen desktop */
result = SDL_SetWindowFullscreen(window, SDL_FALSE);
@ -1717,11 +1788,19 @@ static int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Center on display yVariation, and check window properties */
@ -1737,11 +1816,19 @@ static int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Clean up */
destroyVideoSuiteTestWindow(window);

View File

@ -131,10 +131,10 @@ static int s_arrBindingOrder[] = {
SDL_GAMEPAD_ELEMENT_INVALID,
/* Paddle sequence */
SDL_GAMEPAD_BUTTON_PADDLE1,
SDL_GAMEPAD_BUTTON_PADDLE2,
SDL_GAMEPAD_BUTTON_PADDLE3,
SDL_GAMEPAD_BUTTON_PADDLE4,
SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1,
SDL_GAMEPAD_BUTTON_LEFT_PADDLE1,
SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2,
SDL_GAMEPAD_BUTTON_LEFT_PADDLE2,
SDL_GAMEPAD_ELEMENT_INVALID,
};
@ -749,13 +749,13 @@ static const char *GetBindingInstruction(void)
return "Press the D-Pad right";
case SDL_GAMEPAD_BUTTON_MISC1:
return "Press the bottom center button (Share/Capture)";
case SDL_GAMEPAD_BUTTON_PADDLE1:
case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1:
return "Press the upper paddle under your right hand";
case SDL_GAMEPAD_BUTTON_PADDLE2:
case SDL_GAMEPAD_BUTTON_LEFT_PADDLE1:
return "Press the upper paddle under your left hand";
case SDL_GAMEPAD_BUTTON_PADDLE3:
case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2:
return "Press the lower paddle under your right hand";
case SDL_GAMEPAD_BUTTON_PADDLE4:
case SDL_GAMEPAD_BUTTON_LEFT_PADDLE2:
return "Press the lower paddle under your left hand";
case SDL_GAMEPAD_BUTTON_TOUCHPAD:
return "Press down on the touchpad";
@ -1024,7 +1024,7 @@ static SDL_bool ShowingFront(void)
int i;
/* Show the back of the gamepad if the paddles are being held or bound */
for (i = SDL_GAMEPAD_BUTTON_PADDLE1; i <= SDL_GAMEPAD_BUTTON_PADDLE4; ++i) {
for (i = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1; i <= SDL_GAMEPAD_BUTTON_LEFT_PADDLE2; ++i) {
if (SDL_GetGamepadButton(controller->gamepad, (SDL_GamepadButton)i) == SDL_PRESSED ||
binding_element == i) {
showing_front = SDL_FALSE;

View File

@ -19,8 +19,9 @@
#include <emscripten/emscripten.h>
#endif
#include <SDL3/SDL_test_common.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test_common.h>
#define NUM_OBJECTS 100

View File

@ -55,7 +55,7 @@ rwops_error_quit(unsigned line, SDL_RWops *rwops)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
if (rwops) {
rwops->close(rwops); /* This calls SDL_DestroyRW(rwops); */
SDL_RWclose(rwops); /* This calls SDL_DestroyRW(rwops); */
}
cleanup();
SDLTest_CommonDestroyState(state);
@ -126,25 +126,25 @@ int main(int argc, char *argv[])
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab");
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
unlink(FBASENAME2);
SDL_Log("test2 OK\n");
@ -155,110 +155,110 @@ int main(int argc, char *argv[])
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->write(rwops, "1234567", 7)) {
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (-1 != rwops->read(rwops, test_buf, 1)) {
if (0 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
}
rwops->close(rwops);
SDL_RWclose(rwops);
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exist */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->read(rwops, test_buf, 7)) {
if (7 != SDL_RWread(rwops, test_buf, 7)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1)) {
if (0 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1000)) {
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
}
if (27 != rwops->read(rwops, test_buf, 30)) {
if (27 != SDL_RWread(rwops, test_buf, 30)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
if (-1 != rwops->write(rwops, test_buf, 1)) {
if (0 != SDL_RWwrite(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops); /* readonly mode */
}
rwops->close(rwops);
SDL_RWclose(rwops);
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->write(rwops, "1234567", 7)) {
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->read(rwops, test_buf, 1)) {
if (1 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->read(rwops, test_buf, 7)) {
if (7 != SDL_RWread(rwops, test_buf, 7)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1)) {
if (0 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1000)) {
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
}
if (27 != rwops->read(rwops, test_buf, 30)) {
if (27 != SDL_RWread(rwops, test_buf, 30)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
SDL_Log("test3 OK\n");
/* test 4: same in r+ mode */
@ -266,50 +266,50 @@ int main(int argc, char *argv[])
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->write(rwops, "1234567", 7)) {
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->read(rwops, test_buf, 1)) {
if (1 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (20 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
if (20 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->read(rwops, test_buf, 7)) {
if (7 != SDL_RWread(rwops, test_buf, 7)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1)) {
if (0 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1000)) {
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
if (0 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
}
if (27 != rwops->read(rwops, test_buf, 30)) {
if (27 != SDL_RWread(rwops, test_buf, 30)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
SDL_Log("test4 OK\n");
/* test5 : append mode */
@ -317,56 +317,56 @@ int main(int argc, char *argv[])
if (rwops == NULL) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (10 != rwops->write(rwops, "1234567890", 10)) {
if (10 != SDL_RWwrite(rwops, "1234567890", 10)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->write(rwops, "1234567", 7)) {
if (7 != SDL_RWwrite(rwops, "1234567", 7)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->read(rwops, test_buf, 1)) {
if (1 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (20 + 27 != rwops->seek(rwops, -7, SDL_RW_SEEK_END)) {
if (20 + 27 != SDL_RWseek(rwops, -7, SDL_RW_SEEK_END)) {
RWOP_ERR_QUIT(rwops);
}
if (7 != rwops->read(rwops, test_buf, 7)) {
if (7 != SDL_RWread(rwops, test_buf, 7)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1)) {
if (0 != SDL_RWread(rwops, test_buf, 1)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->read(rwops, test_buf, 1000)) {
if (0 != SDL_RWread(rwops, test_buf, 1000)) {
RWOP_ERR_QUIT(rwops);
}
if (27 != rwops->seek(rwops, -27, SDL_RW_SEEK_CUR)) {
if (27 != SDL_RWseek(rwops, -27, SDL_RW_SEEK_CUR)) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, SDL_RW_SEEK_SET)) {
if (0 != SDL_RWseek(rwops, 0L, SDL_RW_SEEK_SET)) {
RWOP_ERR_QUIT(rwops);
}
if (30 != rwops->read(rwops, test_buf, 30)) {
if (30 != SDL_RWread(rwops, test_buf, 30)) {
RWOP_ERR_QUIT(rwops);
}
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
SDL_RWclose(rwops);
SDL_Log("test5 OK\n");
cleanup();
SDLTest_CommonDestroyState(state);

View File

@ -108,7 +108,7 @@ static int unifont_init(const char *fontname)
Uint8 hexBuffer[65];
Uint32 numGlyphs = 0;
int lineNumber = 1;
Sint64 bytesRead;
size_t bytesRead;
SDL_RWops *hexFile;
const size_t unifontGlyphSize = UNIFONT_NUM_GLYPHS * sizeof(struct UnifontGlyph);
const size_t unifontTextureSize = UNIFONT_NUM_TEXTURES * state->num_windows * sizeof(void *);
@ -150,11 +150,6 @@ static int unifont_init(const char *fontname)
Uint32 codepoint;
bytesRead = SDL_RWread(hexFile, hexBuffer, 9);
if (bytesRead < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "error SDL_RWread\n");
return -1;
}
if (numGlyphs > 0 && bytesRead == 0) {
break; /* EOF */
}
@ -196,9 +191,7 @@ static int unifont_init(const char *fontname)
return -1;
}
if ((size_t)bytesRead < (33 - bytesOverread)) {
if (bytesRead < (33 - bytesOverread)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
return -1;
}

View File

@ -27,85 +27,57 @@ static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
typedef struct
{
SDL_AudioDeviceID dev;
int soundpos;
SDL_AtomicInt done;
} callback_data;
/* these have to be in globals so the Emscripten port can see them in the mainloop. :/ */
static SDL_AudioDeviceID device = 0;
static SDL_AudioStream *stream = NULL;
static callback_data cbd[64];
static void SDLCALL
play_through_once(void *arg, Uint8 *stream, int len)
{
callback_data *cbdata = (callback_data *)arg;
Uint8 *waveptr = sound + cbdata->soundpos;
int waveleft = soundlen - cbdata->soundpos;
int cpy = len;
if (cpy > waveleft) {
cpy = waveleft;
}
SDL_memcpy(stream, waveptr, cpy);
len -= cpy;
cbdata->soundpos += cpy;
if (len > 0) {
stream += cpy;
SDL_memset(stream, spec.silence, len);
SDL_AtomicSet(&cbdata->done, 1);
}
}
#ifdef __EMSCRIPTEN__
static void loop(void)
{
if (SDL_AtomicGet(&cbd[0].done)) {
emscripten_cancel_main_loop();
SDL_PauseAudioDevice(cbd[0].dev);
SDL_CloseAudioDevice(cbd[0].dev);
if (SDL_GetAudioStreamAvailable(stream) == 0) {
SDL_Log("done.");
SDL_CloseAudioDevice(device);
SDL_DestroyAudioStream(stream);
SDL_free(sound);
SDL_Quit();
emscripten_cancel_main_loop();
}
}
#endif
static void
test_multi_audio(int devcount)
test_multi_audio(SDL_AudioDeviceID *devices, int devcount)
{
int keep_going = 1;
SDL_AudioStream **streams = NULL;
int i;
#ifdef __ANDROID__
#ifdef __ANDROID__ /* !!! FIXME: maybe always create a window, in the SDLTest layer, so these #ifdefs don't have to be here? */
SDL_Event event;
/* Create a Window to get fully initialized event processing for testing pause on Android. */
SDL_CreateWindow("testmultiaudio", 320, 240, 0);
#endif
if (devcount > 64) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
devcount);
devcount = 64;
}
spec.callback = play_through_once;
for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0);
SDL_Log("playing on device #%d: ('%s')...", i, devname);
char *devname = SDL_GetAudioDeviceName(devices[i]);
SDL_memset(&cbd[0], '\0', sizeof(callback_data));
spec.userdata = &cbd[0];
cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[0].dev == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
SDL_Log("Playing on device #%d of %d: id=%u, name='%s'...", i, devcount, (unsigned int) devices[i], devname);
device = SDL_OpenAudioDevice(devices[i], &spec);
if (device == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s", SDL_GetError());
} else if ((stream = SDL_CreateAndBindAudioStream(device, &spec)) == NULL) { /* we can reuse these, but we'll just make one each time for now. */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Audio stream creation failed: %s", SDL_GetError());
SDL_CloseAudioDevice(device);
} else {
SDL_PlayAudioDevice(cbd[0].dev);
SDL_PutAudioStreamData(stream, sound, soundlen);
SDL_FlushAudioStream(stream);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!SDL_AtomicGet(&cbd[0].done)) {
while (SDL_GetAudioStreamAvailable(stream) > 0) {
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)) {
@ -113,61 +85,77 @@ test_multi_audio(int devcount)
#endif
SDL_Delay(100);
}
SDL_PauseAudioDevice(cbd[0].dev);
#endif
SDL_Log("done.\n");
SDL_CloseAudioDevice(cbd[0].dev);
SDL_Log("done.");
SDL_CloseAudioDevice(device);
SDL_DestroyAudioStream(stream);
}
SDL_free(devname);
stream = NULL;
}
SDL_memset(cbd, '\0', sizeof(cbd));
SDL_Log("playing on all devices...\n");
for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0);
spec.userdata = &cbd[i];
cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[i].dev == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError());
}
}
for (i = 0; i < devcount; i++) {
if (cbd[i].dev) {
SDL_PlayAudioDevice(cbd[i].dev);
}
}
while (keep_going) {
keep_going = 0;
/* note that Emscripten currently doesn't run this part (but maybe only has a single audio device anyhow?) */
SDL_Log("Playing on all devices...\n");
streams = (SDL_AudioStream **) SDL_calloc(devcount, sizeof (SDL_AudioStream *));
if (!streams) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
for (i = 0; i < devcount; i++) {
if ((cbd[i].dev) && (!SDL_AtomicGet(&cbd[i].done))) {
keep_going = 1;
char *devname = SDL_GetAudioDeviceName(devices[i]);
device = SDL_OpenAudioDevice(devices[i], &spec);
if (device == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d of %d (id=%u, name='%s') failed: %s\n", i, devcount, (unsigned int) devices[i], devname, SDL_GetError());
}
SDL_free(devname);
devices[i] = device; /* just replace the physical device ID with the newly-opened logical device ID. */
if (device) {
SDL_PauseAudioDevice(device); /* hold while we set up all the streams. */
streams[i] = SDL_CreateAndBindAudioStream(device, &spec);
if (streams[i] == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Audio stream creation failed for device %d of %d: %s", i, devcount, SDL_GetError());
} else {
SDL_PutAudioStreamData(streams[i], sound, soundlen);
SDL_FlushAudioStream(streams[i]);
}
}
}
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)) {
/* try to start all the devices about the same time. SDL does not guarantee sync across physical devices. */
for (i = 0; i < devcount; i++) {
if (devices[i]) {
SDL_ResumeAudioDevice(devices[i]);
}
}
while (keep_going) {
keep_going = 0;
for (i = 0; i < devcount; i++) {
if (streams[i] && (SDL_GetAudioStreamAvailable(streams[i]) > 0)) {
keep_going = 1;
}
}
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)) {}
#endif
SDL_Delay(100);
}
#ifndef __EMSCRIPTEN__
for (i = 0; i < devcount; i++) {
if (cbd[i].dev) {
SDL_PauseAudioDevice(cbd[i].dev);
SDL_CloseAudioDevice(cbd[i].dev);
SDL_Delay(100);
}
for (i = 0; i < devcount; i++) {
SDL_CloseAudioDevice(devices[i]);
SDL_DestroyAudioStream(streams[i]);
}
SDL_free(streams);
}
SDL_Log("All done!\n");
#endif
}
int main(int argc, char **argv)
{
SDL_AudioDeviceID *devices = NULL;
int devcount = 0;
int i;
char *filename = NULL;
@ -212,20 +200,21 @@ int main(int argc, char **argv)
filename = GetResourceFilename(filename, "sample.wav");
devcount = SDL_GetNumAudioDevices(0);
if (devcount < 1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
devices = SDL_GetAudioOutputDevices(&devcount);
if (devices == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!");
} else {
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == NULL) {
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename,
SDL_GetError());
} else {
test_multi_audio(devcount);
test_multi_audio(devices, devcount);
SDL_free(sound);
}
}
SDL_free(devices);
SDL_free(filename);
SDL_Quit();
@ -233,3 +222,4 @@ int main(int argc, char **argv)
return 0;
}

View File

@ -3,8 +3,15 @@
#ifdef TEST_NATIVE_COCOA
#include <AvailabilityMacros.h>
#include <Cocoa/Cocoa.h>
#ifndef MAC_OS_X_VERSION_10_12
static const unsigned int NSWindowStyleMaskTitled = NSTitledWindowMask;
static const unsigned int NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask;
static const unsigned int NSWindowStyleMaskClosable = NSClosableWindowMask;
#endif
static void *CreateWindowCocoa(int w, int h);
static void DestroyWindowCocoa(void *window);
@ -29,7 +36,7 @@ static void *CreateWindowCocoa(int w, int h)
rect.size.height = h;
rect.origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - rect.origin.y - rect.size.height;
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
[nswindow makeKeyAndOrderFront:nil];

View File

@ -22,12 +22,11 @@ static void log_usage(char *progname, SDLTest_CommonState *state) {
int main(int argc, char **argv)
{
SDL_AudioSpec spec;
SDL_AudioSpec cvtspec;
SDL_AudioStream *stream = NULL;
Uint8 *dst_buf = NULL;
Uint32 len = 0;
Uint8 *data = NULL;
int cvtfreq = 0;
int cvtchans = 0;
int bitsize = 0;
int blockalign = 0;
int avgbytes = 0;
@ -49,6 +48,8 @@ int main(int argc, char **argv)
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_zero(cvtspec);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
@ -65,14 +66,14 @@ int main(int argc, char **argv)
consumed = 1;
} else if (argpos == 2) {
char *endp;
cvtfreq = (int)SDL_strtoul(argv[i], &endp, 0);
cvtspec.freq = (int)SDL_strtoul(argv[i], &endp, 0);
if (endp != argv[i] && *endp == '\0') {
argpos++;
consumed = 1;
}
} else if (argpos == 3) {
char *endp;
cvtchans = (int)SDL_strtoul(argv[i], &endp, 0);
cvtspec.channels = (int)SDL_strtoul(argv[i], &endp, 0);
if (endp != argv[i] && *endp == '\0') {
argpos++;
consumed = 1;
@ -100,14 +101,14 @@ int main(int argc, char **argv)
goto end;
}
if (SDL_LoadWAV(file_in, &spec, &data, &len) == NULL) {
if (SDL_LoadWAV(file_in, &spec, &data, &len) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", file_in, SDL_GetError());
ret = 3;
goto end;
}
if (SDL_ConvertAudioSamples(spec.format, spec.channels, spec.freq, data, len,
spec.format, cvtchans, cvtfreq, &dst_buf, &dst_len) < 0) {
cvtspec.format = spec.format;
if (SDL_ConvertAudioSamples(&spec, data, len, &cvtspec, &dst_buf, &dst_len) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to convert samples: %s\n", SDL_GetError());
ret = 4;
goto end;
@ -122,22 +123,22 @@ int main(int argc, char **argv)
}
bitsize = SDL_AUDIO_BITSIZE(spec.format);
blockalign = (bitsize / 8) * cvtchans;
avgbytes = cvtfreq * blockalign;
blockalign = (bitsize / 8) * cvtspec.channels;
avgbytes = cvtspec.freq * blockalign;
SDL_WriteLE32(io, 0x46464952); /* RIFF */
SDL_WriteLE32(io, dst_len + 36);
SDL_WriteLE32(io, 0x45564157); /* WAVE */
SDL_WriteLE32(io, 0x20746D66); /* fmt */
SDL_WriteLE32(io, 16); /* chunk size */
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
SDL_WriteLE16(io, cvtchans); /* channels */
SDL_WriteLE32(io, cvtfreq); /* sample rate */
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
SDL_WriteLE16(io, blockalign); /* block align */
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
SDL_WriteLE32(io, 0x61746164); /* data */
SDL_WriteLE32(io, dst_len); /* size */
SDL_WriteU32LE(io, 0x46464952); /* RIFF */
SDL_WriteU32LE(io, dst_len + 36);
SDL_WriteU32LE(io, 0x45564157); /* WAVE */
SDL_WriteU32LE(io, 0x20746D66); /* fmt */
SDL_WriteU32LE(io, 16); /* chunk size */
SDL_WriteU16LE(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
SDL_WriteU16LE(io, cvtspec.channels); /* channels */
SDL_WriteU32LE(io, cvtspec.freq); /* sample rate */
SDL_WriteU32LE(io, avgbytes); /* average bytes per second */
SDL_WriteU16LE(io, blockalign); /* block align */
SDL_WriteU16LE(io, bitsize); /* significant bits per sample */
SDL_WriteU32LE(io, 0x61746164); /* data */
SDL_WriteU32LE(io, dst_len); /* size */
SDL_RWwrite(io, dst_buf, dst_len);
if (SDL_RWclose(io) == -1) {

View File

@ -96,20 +96,23 @@ static SDL_bool is_lfe_channel(int channel_index, int channel_count)
return (channel_count == 3 && channel_index == 2) || (channel_count >= 6 && channel_index == 3);
}
static void SDLCALL fill_buffer(void *unused, Uint8 *stream, int len)
static void SDLCALL fill_buffer(SDL_AudioStream *stream, int len, void *unused)
{
Sint16 *buffer = (Sint16 *)stream;
int samples = len / sizeof(Sint16);
const int samples = len / sizeof(Sint16);
Sint16 *buffer = NULL;
static int total_samples = 0;
int i;
SDL_memset(stream, 0, len);
/* This can happen for a short time when switching devices */
if (active_channel == total_channels) {
return;
}
buffer = (Sint16 *) SDL_calloc(samples, sizeof(Sint16));
if (!buffer) {
return; /* oh well. */
}
/* Play a sine wave on the active channel only */
for (i = active_channel; i < samples; i += total_channels) {
float time = (float)total_samples++ / SAMPLE_RATE_HZ;
@ -134,12 +137,18 @@ static void SDLCALL fill_buffer(void *unused, Uint8 *stream, int len)
break;
}
}
SDL_PutAudioStreamData(stream, buffer, samples * sizeof (Sint16));
SDL_free(buffer);
}
int main(int argc, char *argv[])
{
int i;
SDL_AudioDeviceID *devices = NULL;
SDLTest_CommonState *state;
int devcount = 0;
int i;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
@ -168,38 +177,58 @@ int main(int argc, char *argv[])
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
for (i = 0; i < SDL_GetNumAudioDevices(0); i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0);
devices = SDL_GetAudioOutputDevices(&devcount);
if (!devices) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioOutputDevices() failed: %s\n", SDL_GetError());
devcount = 0;
}
SDL_Log("Available audio devices:");
for (i = 0; i < devcount; i++) {
SDL_Log("%s", SDL_GetAudioDeviceName(devices[i]));
}
for (i = 0; i < devcount; i++) {
SDL_AudioStream *stream = NULL;
char *devname = SDL_GetAudioDeviceName(devices[i]);
int j;
SDL_AudioSpec spec;
SDL_AudioDeviceID dev;
if (SDL_GetAudioDeviceSpec(i, 0, &spec) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioSpec() failed: %s\n", SDL_GetError());
SDL_Log("Testing audio device: %s\n", devname);
SDL_free(devname);
if (SDL_GetAudioDeviceFormat(devices[i], &spec) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioDeviceFormat() failed: %s\n", SDL_GetError());
continue;
}
SDL_Log(" (%d channels)\n", spec.channels);
spec.freq = SAMPLE_RATE_HZ;
spec.format = SDL_AUDIO_S16SYS;
spec.samples = 4096;
spec.callback = fill_buffer;
dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
dev = SDL_OpenAudioDevice(devices[i], &spec);
if (dev == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDevice() failed: %s\n", SDL_GetError());
continue;
}
SDL_Log("Testing audio device: %s (%d channels)\n", devname, spec.channels);
stream = SDL_CreateAndBindAudioStream(dev, &spec);
if (stream == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateAndBindAudioStream() failed: %s\n", SDL_GetError());
SDL_CloseAudioDevice(dev);
continue;
}
/* These are used by the fill_buffer callback */
total_channels = spec.channels;
active_channel = 0;
SDL_PlayAudioDevice(dev);
SDL_SetAudioStreamGetCallback(stream, fill_buffer, NULL);
for (j = 0; j < total_channels; j++) {
int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
const int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
SDL_Log("Playing %d Hz test tone on channel: %s\n", sine_freq, get_channel_name(j, total_channels));
@ -212,8 +241,11 @@ int main(int argc, char *argv[])
}
SDL_CloseAudioDevice(dev);
SDL_DestroyAudioStream(stream);
}
SDL_free(devices);
SDL_Quit();
return 0;
}

BIN
external/sdl/SDL/test/trashcan.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="mp uap">
<Identity Name="5a2cfb51-9dcf-4830-81e5-49472403b04d"
Publisher="O=libsdl.org"
Version="1.0.0.0" />
<mp:PhoneIdentity
PhoneProductId="5a2cfb51-9dcf-4830-81e5-49472403b04d"
PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>$<TARGET_PROPERTY:NAME></DisplayName>
<PublisherDisplayName>libsdl.org</PublisherDisplayName>
<Logo>logo-50x50.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily
Name="Windows.Universal"
MinVersion="10.0.0.0"
MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App"
Executable="$<TARGET_PROPERTY:NAME>.exe"
EntryPoint="$<TARGET_PROPERTY:NAME>.App">
<uap:VisualElements
DisplayName="$<TARGET_PROPERTY:NAME>"
Description="$<TARGET_PROPERTY:NAME>"
BackgroundColor="#FFFFFF"
Square150x150Logo="square-150x150.png"
Square44x44Logo="square-44x44.png">
<uap:SplashScreen Image="splash-620x300.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="microphone" />
</Capabilities>
</Package>

BIN
external/sdl/SDL/test/uwp/logo-50x50.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB