Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -16,8 +16,8 @@ AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: AllDefinitions AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine AlwaysBreakTemplateDeclarations: MultiLine
@@ -35,7 +35,7 @@ BraceWrapping:
AfterUnion: true AfterUnion: true
AfterExternBlock: false AfterExternBlock: false
BeforeElse: false BeforeElse: false
BeforeWhile: true BeforeWhile: false
IndentBraces: false IndentBraces: false
SplitEmptyFunction: true SplitEmptyFunction: true
SplitEmptyRecord: true SplitEmptyRecord: true
@@ -48,7 +48,7 @@ IncludeBlocks: Preserve
# clang-format version 4.0 through 12.0: # clang-format version 4.0 through 12.0:
#SortIncludes: false #SortIncludes: false
# clang-format version 13.0+: # clang-format version 13.0+:
#SortIncludes: Never SortIncludes: Never
# No length limit, in case it breaks macros, you can # No length limit, in case it breaks macros, you can
# disable it with /* clang-format off/on */ comments # disable it with /* clang-format off/on */ comments
@@ -62,7 +62,8 @@ IndentGotoLabels: true
IndentPPDirectives: None IndentPPDirectives: None
IndentExternBlock: NoIndent IndentExternBlock: NoIndent
SpaceAfterCStyleCast: true PointerAlignment: Right
SpaceAfterCStyleCast: false
SpacesInCStyleCastParentheses: false SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false SpacesInConditionalStatement: false
SpacesInContainerLiterals: true SpacesInContainerLiterals: true

View File

@@ -0,0 +1,32 @@
#!/bin/sh
cd "$(dirname $0)/../src"
echo "Running clang-format in $(pwd)"
find . -regex '.*\.[chm]p*' -exec clang-format -i {} \;
# Revert third-party code
git checkout \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
libm \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
video/arm \
video/khronos \
video/x11/edid-parse.c \
video/yuv2rgb
clang-format -i hidapi/SDL_hidapi.c
# Revert generated code
git checkout dynapi/SDL_dynapi_overrides.h
git checkout dynapi/SDL_dynapi_procs.h
git checkout render/metal/SDL_shaders_metal_*.h
echo "clang-format complete!"

View File

@@ -44,7 +44,7 @@
/* Initialization/Cleanup routines */ /* Initialization/Cleanup routines */
#if !SDL_TIMERS_DISABLED #if !SDL_TIMERS_DISABLED
# include "timer/SDL_timer_c.h" #include "timer/SDL_timer_c.h"
#endif #endif
#if SDL_VIDEO_DRIVER_WINDOWS #if SDL_VIDEO_DRIVER_WINDOWS
extern int SDL_HelperWindowCreate(void); extern int SDL_HelperWindowCreate(void);
@@ -87,8 +87,8 @@ SDL_NORETURN void SDL_ExitProcess(int exitcode)
ExitProcess here that will never be reached but make MingW happy. */ ExitProcess here that will never be reached but make MingW happy. */
ExitProcess(exitcode); ExitProcess(exitcode);
#elif defined(__EMSCRIPTEN__) #elif defined(__EMSCRIPTEN__)
emscripten_cancel_main_loop(); /* this should "kill" the app. */ emscripten_cancel_main_loop(); /* this should "kill" the app. */
emscripten_force_exit(exitcode); /* this should "kill" the app. */ emscripten_force_exit(exitcode); /* this should "kill" the app. */
exit(exitcode); exit(exitcode);
#elif defined(__HAIKU__) /* Haiku has _Exit, but it's not marked noreturn. */ #elif defined(__HAIKU__) /* Haiku has _Exit, but it's not marked noreturn. */
_exit(exitcode); _exit(exitcode);
@@ -99,7 +99,6 @@ SDL_NORETURN void SDL_ExitProcess(int exitcode)
#endif #endif
} }
/* The initialized subsystems */ /* The initialized subsystems */
#ifdef SDL_MAIN_NEEDED #ifdef SDL_MAIN_NEEDED
static SDL_bool SDL_MainIsReady = SDL_FALSE; static SDL_bool SDL_MainIsReady = SDL_FALSE;
@@ -107,11 +106,10 @@ static SDL_bool SDL_MainIsReady = SDL_FALSE;
static SDL_bool SDL_MainIsReady = SDL_TRUE; static SDL_bool SDL_MainIsReady = SDL_TRUE;
#endif #endif
static SDL_bool SDL_bInMainQuit = SDL_FALSE; static SDL_bool SDL_bInMainQuit = SDL_FALSE;
static Uint8 SDL_SubsystemRefCount[ 32 ]; static Uint8 SDL_SubsystemRefCount[32];
/* Private helper to increment a subsystem's ref counter. */ /* Private helper to increment a subsystem's ref counter. */
static void static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
{ {
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255)); SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
@@ -121,8 +119,7 @@ SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
} }
/* Private helper to decrement a subsystem's ref counter. */ /* Private helper to decrement a subsystem's ref counter. */
static void static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
{ {
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) { if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
@@ -131,8 +128,7 @@ SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
} }
/* Private helper to check if a system needs init. */ /* Private helper to check if a system needs init. */
static SDL_bool static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
{ {
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255)); SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
@@ -140,8 +136,8 @@ SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
} }
/* Private helper to check if a system needs to be quit. */ /* Private helper to check if a system needs to be quit. */
static SDL_bool static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) { {
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem); const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) { if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) {
return SDL_FALSE; return SDL_FALSE;
@@ -153,14 +149,12 @@ SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE; return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
} }
void void SDL_SetMainReady(void)
SDL_SetMainReady(void)
{ {
SDL_MainIsReady = SDL_TRUE; SDL_MainIsReady = SDL_TRUE;
} }
int int SDL_InitSubSystem(Uint32 flags)
SDL_InitSubSystem(Uint32 flags)
{ {
Uint32 flags_initialized = 0; Uint32 flags_initialized = 0;
@@ -182,13 +176,13 @@ SDL_InitSubSystem(Uint32 flags)
flags |= SDL_INIT_JOYSTICK; flags |= SDL_INIT_JOYSTICK;
} }
if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO))) { if ((flags & (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO))) {
/* video or joystick or audio implies events */ /* video or joystick or audio implies events */
flags |= SDL_INIT_EVENTS; flags |= SDL_INIT_EVENTS;
} }
#if SDL_VIDEO_DRIVER_WINDOWS #if SDL_VIDEO_DRIVER_WINDOWS
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) { if ((flags & (SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK))) {
if (SDL_HelperWindowCreate() < 0) { if (SDL_HelperWindowCreate() < 0) {
goto quit_and_error; goto quit_and_error;
} }
@@ -267,9 +261,9 @@ SDL_InitSubSystem(Uint32 flags)
if ((flags & SDL_INIT_JOYSTICK)) { if ((flags & SDL_INIT_JOYSTICK)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) { if (SDL_JoystickInit() < 0) {
goto quit_and_error; goto quit_and_error;
} }
} }
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
flags_initialized |= SDL_INIT_JOYSTICK; flags_initialized |= SDL_INIT_JOYSTICK;
@@ -326,7 +320,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
(void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */ (void)flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
return 0; return 0;
@@ -335,14 +329,12 @@ quit_and_error:
return -1; return -1;
} }
int int SDL_Init(Uint32 flags)
SDL_Init(Uint32 flags)
{ {
return SDL_InitSubSystem(flags); return SDL_InitSubSystem(flags);
} }
void void SDL_QuitSubSystem(Uint32 flags)
SDL_QuitSubSystem(Uint32 flags)
{ {
/* Shut down requested initialized subsystems */ /* Shut down requested initialized subsystems */
#if !SDL_SENSOR_DISABLED #if !SDL_SENSOR_DISABLED
@@ -459,8 +451,7 @@ SDL_WasInit(Uint32 flags)
return initialized; return initialized;
} }
void void SDL_Quit(void)
SDL_Quit(void)
{ {
SDL_bInMainQuit = SDL_TRUE; SDL_bInMainQuit = SDL_TRUE;
@@ -486,7 +477,7 @@ SDL_Quit(void)
/* Now that every subsystem has been quit, we reset the subsystem refcount /* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems. * and the list of initialized subsystems.
*/ */
SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) ); SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
SDL_TLSCleanup(); SDL_TLSCleanup();
@@ -494,13 +485,13 @@ SDL_Quit(void)
} }
/* Get the library version number */ /* Get the library version number */
void void SDL_GetVersion(SDL_version *ver)
SDL_GetVersion(SDL_version * ver)
{ {
static SDL_bool check_hint = SDL_TRUE; static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE; static SDL_bool legacy_version = SDL_FALSE;
if (ver == NULL) { return; if (ver == NULL) {
return;
} }
SDL_VERSION(ver); SDL_VERSION(ver);

View File

@@ -40,8 +40,7 @@
/* The size of the stack buffer to use for rendering assert messages. */ /* The size of the stack buffer to use for rendering assert messages. */
#define SDL_MAX_ASSERT_MESSAGE_STACK 256 #define SDL_MAX_ASSERT_MESSAGE_STACK 256
static SDL_assert_state SDLCALL static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
/* /*
* We keep all triggered assertions in a singly-linked list so we can * We keep all triggered assertions in a singly-linked list so we can
@@ -57,12 +56,10 @@ static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
static void *assertion_userdata = NULL; static void *assertion_userdata = NULL;
#ifdef __GNUC__ #ifdef __GNUC__
static void static void debug_print(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
#endif #endif
static void static void debug_print(const char *fmt, ...)
debug_print(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@@ -70,31 +67,30 @@ debug_print(const char *fmt, ...)
va_end(ap); va_end(ap);
} }
static void SDL_AddAssertionToReport(SDL_assert_data *data) static void SDL_AddAssertionToReport(SDL_assert_data *data)
{ {
/* (data) is always a static struct defined with the assert macros, so /* (data) is always a static struct defined with the assert macros, so
we don't have to worry about copying or allocating them. */ we don't have to worry about copying or allocating them. */
data->trigger_count++; data->trigger_count++;
if (data->trigger_count == 1) { /* not yet added? */ if (data->trigger_count == 1) { /* not yet added? */
data->next = triggered_assertions; data->next = triggered_assertions;
triggered_assertions = data; triggered_assertions = data;
} }
} }
#if defined(__WIN32__) || defined(__GDK__) #if defined(__WIN32__) || defined(__GDK__)
#define ENDLINE "\r\n" #define ENDLINE "\r\n"
#else #else
#define ENDLINE "\n" #define ENDLINE "\n"
#endif #endif
static int SDL_RenderAssertMessage(char *buf, size_t buf_len, const SDL_assert_data *data) { static int SDL_RenderAssertMessage(char *buf, size_t buf_len, const SDL_assert_data *data)
{
return SDL_snprintf(buf, buf_len, return SDL_snprintf(buf, buf_len,
"Assertion failure at %s (%s:%d), triggered %u %s:" ENDLINE " '%s'", "Assertion failure at %s (%s:%d), triggered %u %s:" ENDLINE " '%s'",
data->function, data->filename, data->linenum, data->function, data->filename, data->linenum,
data->trigger_count, (data->trigger_count == 1) ? "time" : "times", data->trigger_count, (data->trigger_count == 1) ? "time" : "times",
data->condition data->condition);
);
} }
static void SDL_GenerateAssertionReport(void) static void SDL_GenerateAssertionReport(void)
@@ -124,7 +120,6 @@ static void SDL_GenerateAssertionReport(void)
} }
} }
/* This is not declared in any header, although it is shared between some /* This is not declared in any header, although it is shared between some
parts of SDL, because we don't want anything calling it without an parts of SDL, because we don't want anything calling it without an
extremely good reason. */ extremely good reason. */
@@ -134,9 +129,8 @@ extern void SDL_ExitProcess(int exitcode);
#endif #endif
extern SDL_NORETURN void SDL_ExitProcess(int exitcode); extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
static void SDL_AbortAssertion (void); static void SDL_AbortAssertion(void);
#pragma aux SDL_AbortAssertion aborts; #pragma aux SDL_AbortAssertion aborts;
#endif #endif
static SDL_NORETURN void SDL_AbortAssertion(void) static SDL_NORETURN void SDL_AbortAssertion(void)
@@ -145,21 +139,20 @@ static SDL_NORETURN void SDL_AbortAssertion(void)
SDL_ExitProcess(42); SDL_ExitProcess(42);
} }
static SDL_assert_state SDLCALL static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
{ {
const char *envr; const char *envr;
SDL_assert_state state = SDL_ASSERTION_ABORT; SDL_assert_state state = SDL_ASSERTION_ABORT;
SDL_Window *window; SDL_Window *window;
SDL_MessageBoxData messagebox; SDL_MessageBoxData messagebox;
SDL_MessageBoxButtonData buttons[] = { SDL_MessageBoxButtonData buttons[] = {
{ 0, SDL_ASSERTION_RETRY, "Retry" }, { 0, SDL_ASSERTION_RETRY, "Retry" },
{ 0, SDL_ASSERTION_BREAK, "Break" }, { 0, SDL_ASSERTION_BREAK, "Break" },
{ 0, SDL_ASSERTION_ABORT, "Abort" }, { 0, SDL_ASSERTION_ABORT, "Abort" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
SDL_ASSERTION_IGNORE, "Ignore" }, SDL_ASSERTION_IGNORE, "Ignore" },
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
SDL_ASSERTION_ALWAYS_IGNORE, "Always Ignore" } SDL_ASSERTION_ALWAYS_IGNORE, "Always Ignore" }
}; };
int selected; int selected;
@@ -168,7 +161,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
size_t buf_len = sizeof(stack_buf); size_t buf_len = sizeof(stack_buf);
int len; int len;
(void) userdata; /* unused in default handler. */ (void)userdata; /* unused in default handler. */
/* Assume the output will fit... */ /* Assume the output will fit... */
len = SDL_RenderAssertMessage(message, buf_len, data); len = SDL_RenderAssertMessage(message, buf_len, data);
@@ -213,7 +206,7 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} else if (SDL_strcmp(envr, "always_ignore") == 0) { } else if (SDL_strcmp(envr, "always_ignore") == 0) {
return SDL_ASSERTION_ALWAYS_IGNORE; return SDL_ASSERTION_ALWAYS_IGNORE;
} else { } else {
return SDL_ASSERTION_ABORT; /* oh well. */ return SDL_ASSERTION_ABORT; /* oh well. */
} }
} }
@@ -247,8 +240,9 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} else { } else {
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
/* This is nasty, but we can't block on a custom UI. */ /* This is nasty, but we can't block on a custom UI. */
for ( ; ; ) { for (;;) {
SDL_bool okay = SDL_TRUE; SDL_bool okay = SDL_TRUE;
/* *INDENT-OFF* */ /* clang-format off */
char *buf = (char *) EM_ASM_INT({ char *buf = (char *) EM_ASM_INT({
var str = var str =
UTF8ToString($0) + '\n\n' + UTF8ToString($0) + '\n\n' +
@@ -259,12 +253,14 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} }
return allocate(intArrayFromString(reply), 'i8', ALLOC_NORMAL); return allocate(intArrayFromString(reply), 'i8', ALLOC_NORMAL);
}, message); }, message);
/* *INDENT-ON* */ /* clang-format on */
if (SDL_strcmp(buf, "a") == 0) { if (SDL_strcmp(buf, "a") == 0) {
state = SDL_ASSERTION_ABORT; state = SDL_ASSERTION_ABORT;
/* (currently) no break functionality on Emscripten #if 0 /* (currently) no break functionality on Emscripten */
} else if (SDL_strcmp(buf, "b") == 0) { } else if (SDL_strcmp(buf, "b") == 0) {
state = SDL_ASSERTION_BREAK; */ state = SDL_ASSERTION_BREAK;
#endif
} else if (SDL_strcmp(buf, "r") == 0) { } else if (SDL_strcmp(buf, "r") == 0) {
state = SDL_ASSERTION_RETRY; state = SDL_ASSERTION_RETRY;
} else if (SDL_strcmp(buf, "i") == 0) { } else if (SDL_strcmp(buf, "i") == 0) {
@@ -282,11 +278,11 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
} }
#elif defined(HAVE_STDIO_H) #elif defined(HAVE_STDIO_H)
/* this is a little hacky. */ /* this is a little hacky. */
for ( ; ; ) { for (;;) {
char buf[32]; char buf[32];
fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : "); fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
fflush(stderr); fflush(stderr);
if (fgets(buf, sizeof (buf), stdin) == NULL) { if (fgets(buf, sizeof(buf), stdin) == NULL) {
break; break;
} }
@@ -322,7 +318,6 @@ SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
return state; return state;
} }
SDL_assert_state SDL_assert_state
SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file, SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
int line) int line)
@@ -337,13 +332,13 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
assertion_mutex = SDL_CreateMutex(); assertion_mutex = SDL_CreateMutex();
if (assertion_mutex == NULL) { if (assertion_mutex == NULL) {
SDL_AtomicUnlock(&spinlock); SDL_AtomicUnlock(&spinlock);
return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
} }
} }
SDL_AtomicUnlock(&spinlock); SDL_AtomicUnlock(&spinlock);
if (SDL_LockMutex(assertion_mutex) < 0) { if (SDL_LockMutex(assertion_mutex) < 0) {
return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
} }
#endif #endif
@@ -357,13 +352,14 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
SDL_AddAssertionToReport(data); SDL_AddAssertionToReport(data);
assertion_running++; assertion_running++;
if (assertion_running > 1) { /* assert during assert! Abort. */ if (assertion_running > 1) { /* assert during assert! Abort. */
if (assertion_running == 2) { if (assertion_running == 2) {
SDL_AbortAssertion(); SDL_AbortAssertion();
} else if (assertion_running == 3) { /* Abort asserted! */ } else if (assertion_running == 3) { /* Abort asserted! */
SDL_ExitProcess(42); SDL_ExitProcess(42);
} else { } else {
while (1) { /* do nothing but spin; what else can you do?! */ } while (1) { /* do nothing but spin; what else can you do?! */
}
} }
} }
@@ -371,21 +367,20 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
state = assertion_handler(data, assertion_userdata); state = assertion_handler(data, assertion_userdata);
} }
switch (state) switch (state) {
{ case SDL_ASSERTION_ALWAYS_IGNORE:
case SDL_ASSERTION_ALWAYS_IGNORE: state = SDL_ASSERTION_IGNORE;
state = SDL_ASSERTION_IGNORE; data->always_ignore = 1;
data->always_ignore = 1; break;
break;
case SDL_ASSERTION_IGNORE: case SDL_ASSERTION_IGNORE:
case SDL_ASSERTION_RETRY: case SDL_ASSERTION_RETRY:
case SDL_ASSERTION_BREAK: case SDL_ASSERTION_BREAK:
break; /* macro handles these. */ break; /* macro handles these. */
case SDL_ASSERTION_ABORT: case SDL_ASSERTION_ABORT:
SDL_AbortAssertion(); SDL_AbortAssertion();
/*break; ...shouldn't return, but oh well. */ /*break; ...shouldn't return, but oh well. */
} }
assertion_running--; assertion_running--;
@@ -397,7 +392,6 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
return state; return state;
} }
void SDL_AssertionsQuit(void) void SDL_AssertionsQuit(void)
{ {
#if SDL_ASSERT_LEVEL > 0 #if SDL_ASSERT_LEVEL > 0
@@ -432,7 +426,7 @@ void SDL_ResetAssertionReport(void)
SDL_assert_data *next = NULL; SDL_assert_data *next = NULL;
SDL_assert_data *item; SDL_assert_data *item;
for (item = triggered_assertions; item != NULL; item = next) { for (item = triggered_assertions; item != NULL; item = next) {
next = (SDL_assert_data *) item->next; next = (SDL_assert_data *)item->next;
item->always_ignore = SDL_FALSE; item->always_ignore = SDL_FALSE;
item->trigger_count = 0; item->trigger_count = 0;
item->next = NULL; item->next = NULL;

View File

@@ -24,10 +24,10 @@
typedef struct SDL_DataQueuePacket typedef struct SDL_DataQueuePacket
{ {
size_t datalen; /* bytes currently in use in this packet. */ size_t datalen; /* bytes currently in use in this packet. */
size_t startpos; /* bytes currently consumed in this packet. */ size_t startpos; /* bytes currently consumed in this packet. */
struct SDL_DataQueuePacket *next; /* next item in linked list. */ struct SDL_DataQueuePacket *next; /* next item in linked list. */
Uint8 data[SDL_VARIABLE_LENGTH_ARRAY]; /* packet data */ Uint8 data[SDL_VARIABLE_LENGTH_ARRAY]; /* packet data */
} SDL_DataQueuePacket; } SDL_DataQueuePacket;
struct SDL_DataQueue struct SDL_DataQueue
@@ -35,12 +35,11 @@ struct SDL_DataQueue
SDL_DataQueuePacket *head; /* device fed from here. */ SDL_DataQueuePacket *head; /* device fed from here. */
SDL_DataQueuePacket *tail; /* queue fills to here. */ SDL_DataQueuePacket *tail; /* queue fills to here. */
SDL_DataQueuePacket *pool; /* these are unused packets. */ SDL_DataQueuePacket *pool; /* these are unused packets. */
size_t packet_size; /* size of new packets */ size_t packet_size; /* size of new packets */
size_t queued_bytes; /* number of bytes of data in the queue. */ size_t queued_bytes; /* number of bytes of data in the queue. */
}; };
static void static void SDL_FreeDataQueueList(SDL_DataQueuePacket *packet)
SDL_FreeDataQueueList(SDL_DataQueuePacket *packet)
{ {
while (packet) { while (packet) {
SDL_DataQueuePacket *next = packet->next; SDL_DataQueuePacket *next = packet->next;
@@ -49,13 +48,12 @@ SDL_FreeDataQueueList(SDL_DataQueuePacket *packet)
} }
} }
/* this all expects that you managed thread safety elsewhere. */ /* this all expects that you managed thread safety elsewhere. */
SDL_DataQueue * SDL_DataQueue *
SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack) SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
{ {
SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue)); SDL_DataQueue *queue = (SDL_DataQueue *)SDL_malloc(sizeof(SDL_DataQueue));
if (queue == NULL) { if (queue == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
@@ -69,7 +67,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
queue->packet_size = packetlen; queue->packet_size = packetlen;
for (i = 0; i < wantpackets; i++) { for (i = 0; i < wantpackets; i++) {
SDL_DataQueuePacket *packet = (SDL_DataQueuePacket *) SDL_malloc(sizeof (SDL_DataQueuePacket) + packetlen); SDL_DataQueuePacket *packet = (SDL_DataQueuePacket *)SDL_malloc(sizeof(SDL_DataQueuePacket) + packetlen);
if (packet) { /* don't care if this fails, we'll deal later. */ if (packet) { /* don't care if this fails, we'll deal later. */
packet->datalen = 0; packet->datalen = 0;
packet->startpos = 0; packet->startpos = 0;
@@ -82,8 +80,7 @@ SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
return queue; return queue;
} }
void void SDL_FreeDataQueue(SDL_DataQueue *queue)
SDL_FreeDataQueue(SDL_DataQueue *queue)
{ {
if (queue) { if (queue) {
SDL_FreeDataQueueList(queue->head); SDL_FreeDataQueueList(queue->head);
@@ -92,11 +89,10 @@ SDL_FreeDataQueue(SDL_DataQueue *queue)
} }
} }
void void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
{ {
const size_t packet_size = queue ? queue->packet_size : 1; const size_t packet_size = queue ? queue->packet_size : 1;
const size_t slackpackets = (slack + (packet_size-1)) / packet_size; const size_t slackpackets = (slack + (packet_size - 1)) / packet_size;
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
SDL_DataQueuePacket *prev = NULL; SDL_DataQueuePacket *prev = NULL;
size_t i; size_t i;
@@ -132,11 +128,10 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
queue->pool = NULL; queue->pool = NULL;
} }
SDL_FreeDataQueueList(packet); /* free extra packets */ SDL_FreeDataQueueList(packet); /* free extra packets */
} }
static SDL_DataQueuePacket * static SDL_DataQueuePacket *AllocateDataQueuePacket(SDL_DataQueue *queue)
AllocateDataQueuePacket(SDL_DataQueue *queue)
{ {
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
@@ -148,7 +143,7 @@ AllocateDataQueuePacket(SDL_DataQueue *queue)
queue->pool = packet->next; queue->pool = packet->next;
} else { } else {
/* Have to allocate a new one! */ /* Have to allocate a new one! */
packet = (SDL_DataQueuePacket *) SDL_malloc(sizeof (SDL_DataQueuePacket) + queue->packet_size); packet = (SDL_DataQueuePacket *)SDL_malloc(sizeof(SDL_DataQueuePacket) + queue->packet_size);
if (packet == NULL) { if (packet == NULL) {
return NULL; return NULL;
} }
@@ -157,7 +152,7 @@ AllocateDataQueuePacket(SDL_DataQueue *queue)
packet->datalen = 0; packet->datalen = 0;
packet->startpos = 0; packet->startpos = 0;
packet->next = NULL; packet->next = NULL;
SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0)); SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
if (queue->tail == NULL) { if (queue->tail == NULL) {
queue->head = packet; queue->head = packet;
@@ -168,12 +163,10 @@ AllocateDataQueuePacket(SDL_DataQueue *queue)
return packet; return packet;
} }
int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
int
SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
{ {
size_t len = _len; size_t len = _len;
const Uint8 *data = (const Uint8 *) _data; const Uint8 *data = (const Uint8 *)_data;
const size_t packet_size = queue ? queue->packet_size : 0; const size_t packet_size = queue ? queue->packet_size : 0;
SDL_DataQueuePacket *orighead; SDL_DataQueuePacket *orighead;
SDL_DataQueuePacket *origtail; SDL_DataQueuePacket *origtail;
@@ -197,9 +190,9 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
if (packet == NULL) { if (packet == NULL) {
/* uhoh, reset so we've queued nothing new, free what we can. */ /* uhoh, reset so we've queued nothing new, free what we can. */
if (origtail == NULL) { if (origtail == NULL) {
packet = queue->head; /* whole queue. */ packet = queue->head; /* whole queue. */
} else { } else {
packet = origtail->next; /* what we added to existing queue. */ packet = origtail->next; /* what we added to existing queue. */
origtail->next = NULL; origtail->next = NULL;
origtail->datalen = origlen; origtail->datalen = origlen;
} }
@@ -207,7 +200,7 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
queue->tail = origtail; queue->tail = origtail;
queue->pool = NULL; queue->pool = NULL;
SDL_FreeDataQueueList(packet); /* give back what we can. */ SDL_FreeDataQueueList(packet); /* give back what we can. */
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
} }
@@ -227,7 +220,7 @@ size_t
SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
{ {
size_t len = _len; size_t len = _len;
Uint8 *buf = (Uint8 *) _buf; Uint8 *buf = (Uint8 *)_buf;
Uint8 *ptr = buf; Uint8 *ptr = buf;
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
@@ -245,14 +238,14 @@ SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
len -= cpy; len -= cpy;
} }
return (size_t) (ptr - buf); return (size_t)(ptr - buf);
} }
size_t size_t
SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len) SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
{ {
size_t len = _len; size_t len = _len;
Uint8 *buf = (Uint8 *) _buf; Uint8 *buf = (Uint8 *)_buf;
Uint8 *ptr = buf; Uint8 *ptr = buf;
SDL_DataQueuePacket *packet; SDL_DataQueuePacket *packet;
@@ -271,7 +264,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
queue->queued_bytes -= cpy; queue->queued_bytes -= cpy;
len -= cpy; len -= cpy;
if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */ if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */
queue->head = packet->next; queue->head = packet->next;
SDL_assert((packet->next != NULL) || (packet == queue->tail)); SDL_assert((packet->next != NULL) || (packet == queue->tail));
packet->next = queue->pool; packet->next = queue->pool;
@@ -282,10 +275,10 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0)); SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
if (queue->head == NULL) { if (queue->head == NULL) {
queue->tail = NULL; /* in case we drained the queue entirely. */ queue->tail = NULL; /* in case we drained the queue entirely. */
} }
return (size_t) (ptr - buf); return (size_t)(ptr - buf);
} }
size_t size_t
@@ -313,7 +306,7 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
packet = queue->head; packet = queue->head;
if (packet) { if (packet) {
const size_t avail = queue->packet_size - packet->datalen; const size_t avail = queue->packet_size - packet->datalen;
if (len <= avail) { /* we can use the space at end of this packet. */ if (len <= avail) { /* we can use the space at end of this packet. */
void *retval = packet->data + packet->datalen; void *retval = packet->data + packet->datalen;
packet->datalen += len; packet->datalen += len;
queue->queued_bytes += len; queue->queued_bytes += len;
@@ -334,4 +327,3 @@ SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -52,4 +52,3 @@ void *SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len);
#endif /* SDL_dataqueue_h_ */ #endif /* SDL_dataqueue_h_ */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -24,8 +24,7 @@
#include "SDL_error_c.h" #include "SDL_error_c.h"
int int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
/* Ignore call if invalid format pointer was passed */ /* Ignore call if invalid format pointer was passed */
if (fmt != NULL) { if (fmt != NULL) {
@@ -33,7 +32,7 @@ SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
int result; int result;
SDL_error *error = SDL_GetErrBuf(); SDL_error *error = SDL_GetErrBuf();
error->error = 1; /* mark error as valid */ error->error = 1; /* mark error as valid */
va_start(ap, fmt); va_start(ap, fmt);
result = SDL_vsnprintf(error->str, error->len, fmt, ap); result = SDL_vsnprintf(error->str, error->len, fmt, ap);
@@ -51,7 +50,6 @@ SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
} }
} }
if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) { if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
/* If we are in debug mode, print out the error message */ /* If we are in debug mode, print out the error message */
SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", error->str); SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", error->str);
@@ -69,15 +67,13 @@ SDL_GetError(void)
return error->error ? error->str : ""; return error->error ? error->str : "";
} }
void void SDL_ClearError(void)
SDL_ClearError(void)
{ {
SDL_GetErrBuf()->error = 0; SDL_GetErrBuf()->error = 0;
} }
/* Very common errors go here */ /* Very common errors go here */
int int SDL_Error(SDL_errorcode code)
SDL_Error(SDL_errorcode code)
{ {
switch (code) { switch (code) {
case SDL_ENOMEM: case SDL_ENOMEM:
@@ -96,8 +92,7 @@ SDL_Error(SDL_errorcode code)
} }
#ifdef TEST_ERROR #ifdef TEST_ERROR
int int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
char buffer[BUFSIZ + 1]; char buffer[BUFSIZ + 1];
@@ -112,7 +107,6 @@ main(int argc, char *argv[])
} }
#endif #endif
char * char *
SDL_GetErrorMsg(char *errstr, int maxlen) SDL_GetErrorMsg(char *errstr, int maxlen)
{ {

View File

@@ -20,8 +20,6 @@
*/ */
#include "SDL_internal.h" #include "SDL_internal.h"
/* convert the guid to a printable string */ /* convert the guid to a printable string */
void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID) void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
{ {
@@ -32,7 +30,7 @@ void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
return; return;
} }
for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) { for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; i++) {
/* each input byte writes 2 ascii chars, and might write a null byte. */ /* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */ /* If we don't have room for next input byte, stop */
unsigned char c = guid.data[i]; unsigned char c = guid.data[i];
@@ -71,7 +69,7 @@ static unsigned char nibble(unsigned char c)
SDL_GUID SDL_GUIDFromString(const char *pchGUID) SDL_GUID SDL_GUIDFromString(const char *pchGUID)
{ {
SDL_GUID guid; SDL_GUID guid;
int maxoutputbytes= sizeof(guid); int maxoutputbytes = sizeof(guid);
size_t len = SDL_strlen(pchGUID); size_t len = SDL_strlen(pchGUID);
Uint8 *p; Uint8 *p;
size_t i; size_t i;
@@ -82,8 +80,8 @@ SDL_GUID SDL_GUIDFromString(const char *pchGUID)
SDL_memset(&guid, 0x00, sizeof(guid)); SDL_memset(&guid, 0x00, sizeof(guid));
p = (Uint8 *)&guid; p = (Uint8 *)&guid;
for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) { for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i += 2, p++) {
*p = (nibble((unsigned char)pchGUID[i]) << 4) | nibble((unsigned char)pchGUID[i+1]); *p = (nibble((unsigned char)pchGUID[i]) << 4) | nibble((unsigned char)pchGUID[i + 1]);
} }
return guid; return guid;

View File

@@ -22,17 +22,18 @@
#include "SDL_hints_c.h" #include "SDL_hints_c.h"
/* Assuming there aren't many hints set and they aren't being queried in /* Assuming there aren't many hints set and they aren't being queried in
critical performance paths, we'll just use linked lists here. critical performance paths, we'll just use linked lists here.
*/ */
typedef struct SDL_HintWatch { typedef struct SDL_HintWatch
{
SDL_HintCallback callback; SDL_HintCallback callback;
void *userdata; void *userdata;
struct SDL_HintWatch *next; struct SDL_HintWatch *next;
} SDL_HintWatch; } SDL_HintWatch;
typedef struct SDL_Hint { typedef struct SDL_Hint
{
char *name; char *name;
char *value; char *value;
SDL_HintPriority priority; SDL_HintPriority priority;
@@ -66,7 +67,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
} }
if (hint->value != value && if (hint->value != value &&
(value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) { (value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
for (entry = hint->callbacks; entry; ) { for (entry = hint->callbacks; entry;) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
entry->callback(entry->userdata, name, hint->value, value); entry->callback(entry->userdata, name, hint->value, value);
@@ -111,7 +112,7 @@ SDL_ResetHint(const char *name)
if ((env == NULL && hint->value != NULL) || if ((env == NULL && hint->value != NULL) ||
(env != NULL && hint->value == NULL) || (env != NULL && hint->value == NULL) ||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) { (env != NULL && SDL_strcmp(env, hint->value) != 0)) {
for (entry = hint->callbacks; entry; ) { for (entry = hint->callbacks; entry;) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
entry->callback(entry->userdata, name, hint->value, env); entry->callback(entry->userdata, name, hint->value, env);
@@ -127,8 +128,7 @@ SDL_ResetHint(const char *name)
return SDL_FALSE; return SDL_FALSE;
} }
void void SDL_ResetHints(void)
SDL_ResetHints(void)
{ {
const char *env; const char *env;
SDL_Hint *hint; SDL_Hint *hint;
@@ -139,7 +139,7 @@ SDL_ResetHints(void)
if ((env == NULL && hint->value != NULL) || if ((env == NULL && hint->value != NULL) ||
(env != NULL && hint->value == NULL) || (env != NULL && hint->value == NULL) ||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) { (env != NULL && SDL_strcmp(env, hint->value) != 0)) {
for (entry = hint->callbacks; entry; ) { for (entry = hint->callbacks; entry;) {
/* Save the next entry in case this one is deleted */ /* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next; SDL_HintWatch *next = entry->next;
entry->callback(entry->userdata, hint->name, hint->value, env); entry->callback(entry->userdata, hint->name, hint->value, env);
@@ -195,8 +195,7 @@ SDL_GetHintBoolean(const char *name, SDL_bool default_value)
return SDL_GetStringBoolean(hint, default_value); return SDL_GetStringBoolean(hint, default_value);
} }
void void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
{ {
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry; SDL_HintWatch *entry;
@@ -257,8 +256,7 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
callback(userdata, name, value, value); callback(userdata, name, value, value);
} }
void void SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
{ {
SDL_Hint *hint; SDL_Hint *hint;
SDL_HintWatch *entry, *prev; SDL_HintWatch *entry, *prev;
@@ -294,7 +292,7 @@ void SDL_ClearHints(void)
SDL_free(hint->name); SDL_free(hint->name);
SDL_free(hint->value); SDL_free(hint->value);
for (entry = hint->callbacks; entry; ) { for (entry = hint->callbacks; entry;) {
SDL_HintWatch *freeable = entry; SDL_HintWatch *freeable = entry;
entry = entry->next; entry = entry->next;
SDL_free(freeable); SDL_free(freeable);

View File

@@ -40,9 +40,14 @@
#define SDL_VARIABLE_LENGTH_ARRAY #define SDL_VARIABLE_LENGTH_ARRAY
#endif #endif
#define SDL_MAX_SMALL_ALLOC_STACKSIZE 128 #define SDL_MAX_SMALL_ALLOC_STACKSIZE 128
#define SDL_small_alloc(type, count, pisstack) ( (*(pisstack) = ((sizeof(type)*(count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type*)SDL_malloc(sizeof(type)*(count))) ) #define SDL_small_alloc(type, count, pisstack) ((*(pisstack) = ((sizeof(type) * (count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type *)SDL_malloc(sizeof(type) * (count))))
#define SDL_small_free(ptr, isstack) if ((isstack)) { SDL_stack_free(ptr); } else { SDL_free(ptr); } #define SDL_small_free(ptr, isstack) \
if ((isstack)) { \
SDL_stack_free(ptr); \
} else { \
SDL_free(ptr); \
}
#include "dynapi/SDL_dynapi.h" #include "dynapi/SDL_dynapi.h"
@@ -68,97 +73,96 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#if defined(HAVE_STDLIB_H) #if defined(HAVE_STDLIB_H)
# include <stdlib.h> #include <stdlib.h>
#elif defined(HAVE_MALLOC_H) #elif defined(HAVE_MALLOC_H)
# include <malloc.h> #include <malloc.h>
#endif #endif
#if defined(HAVE_STDDEF_H) #if defined(HAVE_STDDEF_H)
# include <stddef.h> #include <stddef.h>
#endif #endif
#if defined(HAVE_STDARG_H) #if defined(HAVE_STDARG_H)
# include <stdarg.h> #include <stdarg.h>
#endif #endif
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# ifdef HAVE_MEMORY_H #ifdef HAVE_MEMORY_H
# include <memory.h> #include <memory.h>
# endif #endif
# include <string.h> #include <string.h>
#endif #endif
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
# include <strings.h> #include <strings.h>
#endif #endif
#ifdef HAVE_WCHAR_H #ifdef HAVE_WCHAR_H
# include <wchar.h> #include <wchar.h>
#endif #endif
#if defined(HAVE_INTTYPES_H) #if defined(HAVE_INTTYPES_H)
# include <inttypes.h> #include <inttypes.h>
#elif defined(HAVE_STDINT_H) #elif defined(HAVE_STDINT_H)
# include <stdint.h> #include <stdint.h>
#endif #endif
#ifdef HAVE_CTYPE_H #ifdef HAVE_CTYPE_H
# include <ctype.h> #include <ctype.h>
#endif #endif
#ifdef HAVE_MATH_H #ifdef HAVE_MATH_H
# include <math.h> #include <math.h>
#endif #endif
#ifdef HAVE_FLOAT_H #ifdef HAVE_FLOAT_H
# include <float.h> #include <float.h>
#endif #endif
/* If you run into a warning that O_CLOEXEC is redefined, update the SDL configuration header for your platform to add HAVE_O_CLOEXEC */ /* If you run into a warning that O_CLOEXEC is redefined, update the SDL configuration header for your platform to add HAVE_O_CLOEXEC */
#ifndef HAVE_O_CLOEXEC #ifndef HAVE_O_CLOEXEC
#define O_CLOEXEC 0 #define O_CLOEXEC 0
#endif #endif
/* A few #defines to reduce SDL footprint. /* A few #defines to reduce SDL footprint.
Only effective when library is statically linked. Only effective when library is statically linked.
You have to manually edit this file. */ You have to manually edit this file. */
#ifndef SDL_LEAN_AND_MEAN #ifndef SDL_LEAN_AND_MEAN
#define SDL_LEAN_AND_MEAN 0 #define SDL_LEAN_AND_MEAN 0
#endif #endif
/* Optimized functions from 'SDL_blit_0.c' /* Optimized functions from 'SDL_blit_0.c'
- blit with source BitsPerPixel < 8, palette */ - blit with source BitsPerPixel < 8, palette */
#ifndef SDL_HAVE_BLIT_0 #ifndef SDL_HAVE_BLIT_0
#define SDL_HAVE_BLIT_0 !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_0 !SDL_LEAN_AND_MEAN
#endif #endif
/* Optimized functions from 'SDL_blit_1.c' /* Optimized functions from 'SDL_blit_1.c'
- blit with source BytesPerPixel == 1, palette */ - blit with source BytesPerPixel == 1, palette */
#ifndef SDL_HAVE_BLIT_1 #ifndef SDL_HAVE_BLIT_1
#define SDL_HAVE_BLIT_1 !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_1 !SDL_LEAN_AND_MEAN
#endif #endif
/* Optimized functions from 'SDL_blit_A.c' /* Optimized functions from 'SDL_blit_A.c'
- blit with 'SDL_BLENDMODE_BLEND' blending mode */ - blit with 'SDL_BLENDMODE_BLEND' blending mode */
#ifndef SDL_HAVE_BLIT_A #ifndef SDL_HAVE_BLIT_A
#define SDL_HAVE_BLIT_A !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_A !SDL_LEAN_AND_MEAN
#endif #endif
/* Optimized functions from 'SDL_blit_N.c' /* Optimized functions from 'SDL_blit_N.c'
- blit with COLORKEY mode, or nothing */ - blit with COLORKEY mode, or nothing */
#ifndef SDL_HAVE_BLIT_N #ifndef SDL_HAVE_BLIT_N
#define SDL_HAVE_BLIT_N !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_N !SDL_LEAN_AND_MEAN
#endif #endif
/* Optimized functions from 'SDL_blit_N.c' /* Optimized functions from 'SDL_blit_N.c'
- RGB565 conversion with Lookup tables */ - RGB565 conversion with Lookup tables */
#ifndef SDL_HAVE_BLIT_N_RGB565 #ifndef SDL_HAVE_BLIT_N_RGB565
#define SDL_HAVE_BLIT_N_RGB565 !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_N_RGB565 !SDL_LEAN_AND_MEAN
#endif #endif
/* Optimized functions from 'SDL_blit_AUTO.c' /* Optimized functions from 'SDL_blit_AUTO.c'
- blit with modulate color, modulate alpha, any blending mode - blit with modulate color, modulate alpha, any blending mode
- scaling or not */ - scaling or not */
#ifndef SDL_HAVE_BLIT_AUTO #ifndef SDL_HAVE_BLIT_AUTO
#define SDL_HAVE_BLIT_AUTO !SDL_LEAN_AND_MEAN #define SDL_HAVE_BLIT_AUTO !SDL_LEAN_AND_MEAN
#endif #endif
/* Run-Length-Encoding /* Run-Length-Encoding
- SDL_SetColorKey() called with SDL_RLEACCEL flag */ - SDL_SetColorKey() called with SDL_RLEACCEL flag */
#ifndef SDL_HAVE_RLE #ifndef SDL_HAVE_RLE
#define SDL_HAVE_RLE !SDL_LEAN_AND_MEAN #define SDL_HAVE_RLE !SDL_LEAN_AND_MEAN
#endif #endif
/* Software SDL_Renderer /* Software SDL_Renderer
@@ -166,14 +170,14 @@
- *not* general blitting functions - *not* general blitting functions
- {blend,draw}{fillrect,line,point} internal functions */ - {blend,draw}{fillrect,line,point} internal functions */
#ifndef SDL_VIDEO_RENDER_SW #ifndef SDL_VIDEO_RENDER_SW
#define SDL_VIDEO_RENDER_SW !SDL_LEAN_AND_MEAN #define SDL_VIDEO_RENDER_SW !SDL_LEAN_AND_MEAN
#endif #endif
/* YUV formats /* YUV formats
- handling of YUV surfaces - handling of YUV surfaces
- blitting and conversion functions */ - blitting and conversion functions */
#ifndef SDL_HAVE_YUV #ifndef SDL_HAVE_YUV
#define SDL_HAVE_YUV !SDL_LEAN_AND_MEAN #define SDL_HAVE_YUV !SDL_LEAN_AND_MEAN
#endif #endif
#include <SDL3/SDL.h> #include <SDL3/SDL.h>

View File

@@ -23,10 +23,9 @@
#include "./SDL_list.h" #include "./SDL_list.h"
/* Push */ /* Push */
int int SDL_ListAdd(SDL_ListNode **head, void *ent)
SDL_ListAdd(SDL_ListNode **head, void *ent)
{ {
SDL_ListNode *node = SDL_malloc(sizeof (*node)); SDL_ListNode *node = SDL_malloc(sizeof(*node));
if (node == NULL) { if (node == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@@ -39,8 +38,7 @@ SDL_ListAdd(SDL_ListNode **head, void *ent)
} }
/* Pop from end as a FIFO (if add with SDL_ListAdd) */ /* Pop from end as a FIFO (if add with SDL_ListAdd) */
void void SDL_ListPop(SDL_ListNode **head, void **ent)
SDL_ListPop(SDL_ListNode **head, void **ent)
{ {
SDL_ListNode **ptr = head; SDL_ListNode **ptr = head;
@@ -54,15 +52,14 @@ SDL_ListPop(SDL_ListNode **head, void **ent)
} }
if (ent) { if (ent) {
*ent = (*ptr)->entry; *ent = (*ptr)->entry;
} }
SDL_free(*ptr); SDL_free(*ptr);
*ptr = NULL; *ptr = NULL;
} }
void void SDL_ListRemove(SDL_ListNode **head, void *ent)
SDL_ListRemove(SDL_ListNode **head, void *ent)
{ {
SDL_ListNode **ptr = head; SDL_ListNode **ptr = head;
@@ -77,8 +74,7 @@ SDL_ListRemove(SDL_ListNode **head, void *ent)
} }
} }
void void SDL_ListClear(SDL_ListNode **head)
SDL_ListClear(SDL_ListNode **head)
{ {
SDL_ListNode *l = *head; SDL_ListNode *l = *head;
*head = NULL; *head = NULL;

View File

@@ -28,7 +28,6 @@ typedef struct SDL_ListNode
struct SDL_ListNode *next; struct SDL_ListNode *next;
} SDL_ListNode; } SDL_ListNode;
int SDL_ListAdd(SDL_ListNode **head, void *ent); int SDL_ListAdd(SDL_ListNode **head, void *ent);
void SDL_ListPop(SDL_ListNode **head, void **ent); void SDL_ListPop(SDL_ListNode **head, void **ent);
void SDL_ListRemove(SDL_ListNode **head, void *ent); void SDL_ListRemove(SDL_ListNode **head, void *ent);

View File

@@ -38,14 +38,13 @@
#include "stdlib/SDL_vacopy.h" #include "stdlib/SDL_vacopy.h"
/* The size of the stack buffer to use for rendering log messages. */ /* The size of the stack buffer to use for rendering log messages. */
#define SDL_MAX_LOG_MESSAGE_STACK 256 #define SDL_MAX_LOG_MESSAGE_STACK 256
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL #define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN #define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO #define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE #define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
typedef struct SDL_LogLevel typedef struct SDL_LogLevel
{ {
@@ -102,8 +101,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
}; };
#endif /* __ANDROID__ */ #endif /* __ANDROID__ */
void void SDL_LogInit(void)
SDL_LogInit(void)
{ {
if (log_function_mutex == NULL) { if (log_function_mutex == NULL) {
/* if this fails we'll try to continue without it. */ /* if this fails we'll try to continue without it. */
@@ -111,8 +109,7 @@ SDL_LogInit(void)
} }
} }
void void SDL_LogQuit(void)
SDL_LogQuit(void)
{ {
SDL_LogResetPriorities(); SDL_LogResetPriorities();
if (log_function_mutex) { if (log_function_mutex) {
@@ -121,8 +118,7 @@ SDL_LogQuit(void)
} }
} }
void void SDL_LogSetAllPriority(SDL_LogPriority priority)
SDL_LogSetAllPriority(SDL_LogPriority priority)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
@@ -134,8 +130,7 @@ SDL_LogSetAllPriority(SDL_LogPriority priority)
SDL_application_priority = priority; SDL_application_priority = priority;
} }
void void SDL_LogSetPriority(int category, SDL_LogPriority priority)
SDL_LogSetPriority(int category, SDL_LogPriority priority)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
@@ -178,8 +173,7 @@ SDL_LogGetPriority(int category)
} }
} }
void void SDL_LogResetPriorities(void)
SDL_LogResetPriorities(void)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
@@ -195,8 +189,7 @@ SDL_LogResetPriorities(void)
SDL_test_priority = DEFAULT_TEST_PRIORITY; SDL_test_priority = DEFAULT_TEST_PRIORITY;
} }
void void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -205,8 +198,7 @@ SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -215,8 +207,7 @@ SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -225,8 +216,7 @@ SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -235,8 +225,7 @@ SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -245,8 +234,7 @@ SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -255,8 +243,7 @@ SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -265,8 +252,7 @@ SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void void SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@@ -276,8 +262,7 @@ SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING
} }
#ifdef __ANDROID__ #ifdef __ANDROID__
static const char * static const char *GetCategoryPrefix(int category)
GetCategoryPrefix(int category)
{ {
if (category < SDL_LOG_CATEGORY_RESERVED1) { if (category < SDL_LOG_CATEGORY_RESERVED1) {
return SDL_category_prefixes[category]; return SDL_category_prefixes[category];
@@ -289,8 +274,7 @@ GetCategoryPrefix(int category)
} }
#endif /* __ANDROID__ */ #endif /* __ANDROID__ */
void void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
{ {
char *message = NULL; char *message = NULL;
char stack_buf[SDL_MAX_LOG_MESSAGE_STACK]; char stack_buf[SDL_MAX_LOG_MESSAGE_STACK];
@@ -342,9 +326,9 @@ SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list
} }
/* Chop off final endline. */ /* Chop off final endline. */
if ((len > 0) && (message[len-1] == '\n')) { if ((len > 0) && (message[len - 1] == '\n')) {
message[--len] = '\0'; message[--len] = '\0';
if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */ if ((len > 0) && (message[len - 1] == '\r')) { /* catch "\r\n", too. */
message[--len] = '\0'; message[--len] = '\0';
} }
} }
@@ -373,9 +357,8 @@ static int consoleAttached = 0;
static HANDLE stderrHandle = NULL; static HANDLE stderrHandle = NULL;
#endif #endif
static void SDLCALL static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message)
const char *message)
{ {
#if defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__) #if defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)
/* Way too many allocations here, urgh */ /* Way too many allocations here, urgh */
@@ -396,34 +379,34 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
if (consoleAttached == 0) { if (consoleAttached == 0) {
attachResult = AttachConsole(ATTACH_PARENT_PROCESS); attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
if (!attachResult) { if (!attachResult) {
attachError = GetLastError(); attachError = GetLastError();
if (attachError == ERROR_INVALID_HANDLE) { if (attachError == ERROR_INVALID_HANDLE) {
/* This is expected when running from Visual Studio */ /* This is expected when running from Visual Studio */
/*OutputDebugString(TEXT("Parent process has no console\r\n"));*/ /*OutputDebugString(TEXT("Parent process has no console\r\n"));*/
consoleAttached = -1; consoleAttached = -1;
} else if (attachError == ERROR_GEN_FAILURE) { } else if (attachError == ERROR_GEN_FAILURE) {
OutputDebugString(TEXT("Could not attach to console of parent process\r\n")); OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
consoleAttached = -1; consoleAttached = -1;
} else if (attachError == ERROR_ACCESS_DENIED) { } else if (attachError == ERROR_ACCESS_DENIED) {
/* Already attached */ /* Already attached */
consoleAttached = 1;
} else {
OutputDebugString(TEXT("Error attaching console\r\n"));
consoleAttached = -1;
}
} else {
/* Newly attached */
consoleAttached = 1; consoleAttached = 1;
} else {
OutputDebugString(TEXT("Error attaching console\r\n"));
consoleAttached = -1;
} }
} else {
/* Newly attached */
consoleAttached = 1;
}
if (consoleAttached == 1) { if (consoleAttached == 1) {
stderrHandle = GetStdHandle(STD_ERROR_HANDLE); stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
if (GetConsoleMode(stderrHandle, &consoleMode) == 0) { if (GetConsoleMode(stderrHandle, &consoleMode) == 0) {
/* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */ /* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */
consoleAttached = 2; consoleAttached = 2;
}
} }
}
} }
#endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__) */ #endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__) */
@@ -431,22 +414,22 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
output = SDL_small_alloc(char, length, &isstack); output = SDL_small_alloc(char, length, &isstack);
SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message); SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
tstr = WIN_UTF8ToString(output); tstr = WIN_UTF8ToString(output);
/* Output to debugger */ /* Output to debugger */
OutputDebugString(tstr); OutputDebugString(tstr);
#if !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__) #if !defined(HAVE_STDIO_H) && !defined(__WINRT__) && !defined(__GDK__)
/* Screen output to stderr, if console was attached. */ /* Screen output to stderr, if console was attached. */
if (consoleAttached == 1) { if (consoleAttached == 1) {
if (!WriteConsole(stderrHandle, tstr, (DWORD) SDL_tcslen(tstr), &charsWritten, NULL)) { if (!WriteConsole(stderrHandle, tstr, (DWORD)SDL_tcslen(tstr), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteConsole\r\n")); OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) { if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n")); OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
}
} }
}
} else if (consoleAttached == 2) { } else if (consoleAttached == 2) {
if (!WriteFile(stderrHandle, output, (DWORD) SDL_strlen(output), &charsWritten, NULL)) { if (!WriteFile(stderrHandle, output, (DWORD)SDL_strlen(output), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteFile\r\n")); OutputDebugString(TEXT("Error calling WriteFile\r\n"));
} }
} }
@@ -464,7 +447,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
} }
#elif defined(__APPLE__) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT)) #elif defined(__APPLE__) && (defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT))
/* Technically we don't need Cocoa/UIKit, but that's where this function is defined for now. /* Technically we don't need Cocoa/UIKit, but that's where this function is defined for now.
*/ */
extern void SDL_NSLog(const char *prefix, const char *text); extern void SDL_NSLog(const char *prefix, const char *text);
{ {
SDL_NSLog(SDL_priority_prefixes[priority], message); SDL_NSLog(SDL_priority_prefixes[priority], message);
@@ -472,17 +455,17 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
} }
#elif defined(__PSP__) || defined(__PS2__) #elif defined(__PSP__) || defined(__PS2__)
{ {
FILE* pFile; FILE *pFile;
pFile = fopen ("SDL_Log.txt", "a"); pFile = fopen("SDL_Log.txt", "a");
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile); fclose(pFile);
} }
#elif defined(__VITA__) #elif defined(__VITA__)
{ {
FILE* pFile; FILE *pFile;
pFile = fopen ("ux0:/data/SDL_Log.txt", "a"); pFile = fopen("ux0:/data/SDL_Log.txt", "a");
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile); fclose(pFile);
} }
#elif defined(__3DS__) #elif defined(__3DS__)
{ {
@@ -503,8 +486,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
#endif #endif
} }
void void SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
{ {
if (callback) { if (callback) {
*callback = SDL_log_function; *callback = SDL_log_function;
@@ -514,8 +496,7 @@ SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
} }
} }
void void SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
{ {
SDL_log_function = callback; SDL_log_function = callback;
SDL_log_userdata = userdata; SDL_log_userdata = userdata;

View File

@@ -20,13 +20,12 @@
*/ */
#include "SDL_internal.h" #include "SDL_internal.h"
#if defined(_MSC_VER) && (_MSC_VER >= 1500) #if defined(_MSC_VER) && (_MSC_VER >= 1500)
#include <intrin.h> #include <intrin.h>
#define HAVE_MSC_ATOMICS 1 #define HAVE_MSC_ATOMICS 1
#endif #endif
#if defined(__MACOS__) /* !!! FIXME: should we favor gcc atomics? */ #if defined(__MACOS__) /* !!! FIXME: should we favor gcc atomics? */
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
#endif #endif
@@ -36,19 +35,20 @@
/* The __atomic_load_n() intrinsic showed up in different times for different compilers. */ /* The __atomic_load_n() intrinsic showed up in different times for different compilers. */
#if defined(__clang__) #if defined(__clang__)
# if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS) #if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have. /* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
It might be in a later NDK or we might need an extra library? --ryan. */ It might be in a later NDK or we might need an extra library? --ryan. */
# if !defined(__ANDROID__) #if !defined(__ANDROID__)
# define HAVE_ATOMIC_LOAD_N 1 #define HAVE_ATOMIC_LOAD_N 1
# endif #endif
# endif #endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
# if (__GNUC__ >= 5) #if (__GNUC__ >= 5)
# define HAVE_ATOMIC_LOAD_N 1 #define HAVE_ATOMIC_LOAD_N 1
# endif #endif
#endif #endif
/* *INDENT-OFF* */ /* clang-format off */
#if defined(__WATCOMC__) && defined(__386__) #if defined(__WATCOMC__) && defined(__386__)
SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int)); SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int));
#define HAVE_WATCOM_ATOMICS #define HAVE_WATCOM_ATOMICS
@@ -73,7 +73,9 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
parm [ecx] [eax] \ parm [ecx] [eax] \
value [eax] \ value [eax] \
modify exact [eax]; modify exact [eax];
#endif /* __WATCOMC__ && __386__ */ #endif /* __WATCOMC__ && __386__ */
/* *INDENT-ON* */ /* clang-format on */
/* /*
If any of the operations are not provided then we must emulate some If any of the operations are not provided then we must emulate some
@@ -105,16 +107,14 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
#if EMULATE_CAS #if EMULATE_CAS
static SDL_SpinLock locks[32]; static SDL_SpinLock locks[32];
static SDL_INLINE void static SDL_INLINE void enterLock(void *a)
enterLock(void *a)
{ {
uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f); uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
SDL_AtomicLock(&locks[index]); SDL_AtomicLock(&locks[index]);
} }
static SDL_INLINE void static SDL_INLINE void leaveLock(void *a)
leaveLock(void *a)
{ {
uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f); uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
@@ -122,7 +122,6 @@ leaveLock(void *a)
} }
#endif #endif
SDL_bool SDL_bool
SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval) SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
{ {
@@ -132,9 +131,9 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
#elif defined(HAVE_WATCOM_ATOMICS) #elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval); return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval); return (SDL_bool)__sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value); return (SDL_bool)OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval); return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
#elif EMULATE_CAS #elif EMULATE_CAS
@@ -149,7 +148,7 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
return retval; return retval;
#else #else
#error Please define your platform. #error Please define your platform.
#endif #endif
} }
@@ -162,10 +161,10 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval); return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(a, oldval, newval); return __sync_bool_compare_and_swap(a, oldval, newval);
#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a); return (SDL_bool)OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t *)a);
#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */ #elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a); return (SDL_bool)OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t *)a);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval); return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval);
#elif EMULATE_CAS #elif EMULATE_CAS
@@ -180,12 +179,11 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
return retval; return retval;
#else #else
#error Please define your platform. #error Please define your platform.
#endif #endif
} }
int int SDL_AtomicSet(SDL_atomic_t *a, int v)
SDL_AtomicSet(SDL_atomic_t *a, int v)
{ {
#ifdef HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value)); SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
@@ -205,7 +203,7 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
#endif #endif
} }
void* void *
SDL_AtomicSetPtr(void **a, void *v) SDL_AtomicSetPtr(void **a, void *v)
{ {
#if defined(HAVE_MSC_ATOMICS) #if defined(HAVE_MSC_ATOMICS)
@@ -225,8 +223,7 @@ SDL_AtomicSetPtr(void **a, void *v)
#endif #endif
} }
int int SDL_AtomicAdd(SDL_atomic_t *a, int v)
SDL_AtomicAdd(SDL_atomic_t *a, int v)
{ {
#ifdef HAVE_MSC_ATOMICS #ifdef HAVE_MSC_ATOMICS
SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value)); SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
@@ -236,9 +233,9 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
#elif defined(HAVE_GCC_ATOMICS) #elif defined(HAVE_GCC_ATOMICS)
return __sync_fetch_and_add(&a->value, v); return __sync_fetch_and_add(&a->value, v);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
int pv = a->value; int pv = a->value;
membar_consumer(); membar_consumer();
atomic_add_int((volatile uint_t*)&a->value, v); atomic_add_int((volatile uint_t *)&a->value, v);
return pv; return pv;
#else #else
int value; int value;
@@ -249,8 +246,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
#endif #endif
} }
int int SDL_AtomicGet(SDL_atomic_t *a)
SDL_AtomicGet(SDL_atomic_t *a)
{ {
#ifdef HAVE_ATOMIC_LOAD_N #ifdef HAVE_ATOMIC_LOAD_N
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST); return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
@@ -298,14 +294,12 @@ SDL_AtomicGetPtr(void **a)
#error This file should be built in arm mode so the mcr instruction is available for memory barriers #error This file should be built in arm mode so the mcr instruction is available for memory barriers
#endif #endif
void void SDL_MemoryBarrierReleaseFunction(void)
SDL_MemoryBarrierReleaseFunction(void)
{ {
SDL_MemoryBarrierRelease(); SDL_MemoryBarrierRelease();
} }
void void SDL_MemoryBarrierAcquireFunction(void)
SDL_MemoryBarrierAcquireFunction(void)
{ {
SDL_MemoryBarrierAcquire(); SDL_MemoryBarrierAcquire();
} }

View File

@@ -24,7 +24,6 @@
#include "../core/windows/SDL_windows.h" #include "../core/windows/SDL_windows.h"
#endif #endif
#if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__) #if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
#include <atomic.h> #include <atomic.h>
#endif #endif
@@ -45,6 +44,7 @@
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
#endif #endif
/* *INDENT-OFF* */ /* clang-format off */
#if defined(__WATCOMC__) && defined(__386__) #if defined(__WATCOMC__) && defined(__386__)
SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock)); SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock));
extern __inline int _SDL_xchg_watcom(volatile int *a, int v); extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
@@ -54,6 +54,7 @@ extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
value [eax] \ value [eax] \
modify exact [eax]; modify exact [eax];
#endif /* __WATCOMC__ && __386__ */ #endif /* __WATCOMC__ && __386__ */
/* *INDENT-ON* */ /* clang-format on */
/* This function is where all the magic happens... */ /* This function is where all the magic happens... */
SDL_bool SDL_bool
@@ -90,39 +91,47 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#elif defined(__WATCOMC__) && defined(__386__) #elif defined(__WATCOMC__) && defined(__386__)
return _SDL_xchg_watcom(lock, 1) == 0; return _SDL_xchg_watcom(lock, 1) == 0;
#elif defined(__GNUC__) && defined(__arm__) && \ #elif defined(__GNUC__) && defined(__arm__) && \
(defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) || \ (defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) || \
defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \ defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \ defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
defined(__ARM_ARCH_5TEJ__)) defined(__ARM_ARCH_5TEJ__))
int result; int result;
#if defined(__RISCOS__) #if defined(__RISCOS__)
if (__cpucap_have_rex()) { if (__cpucap_have_rex()) {
__asm__ __volatile__ ( __asm__ __volatile__(
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r"(result)
: "r"(1), "r"(lock)
: "cc", "memory");
return result == 0; return result == 0;
} }
#endif #endif
__asm__ __volatile__ ( __asm__ __volatile__(
"swp %0, %1, [%2]\n" "swp %0, %1, [%2]\n"
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); : "=&r,&r"(result)
: "r,0"(1), "r,r"(lock)
: "memory");
return result == 0; return result == 0;
#elif defined(__GNUC__) && defined(__arm__) #elif defined(__GNUC__) && defined(__arm__)
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__(
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r"(result)
: "r"(1), "r"(lock)
: "cc", "memory");
return result == 0; return result == 0;
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result; int result;
__asm__ __volatile__( __asm__ __volatile__(
"lock ; xchgl %0, (%1)\n" "lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory"); : "=r"(result)
: "r"(lock), "0"(1)
: "cc", "memory");
return result == 0; return result == 0;
#elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__) #elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
@@ -147,7 +156,9 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
res = SDL_TRUE; res = SDL_TRUE;
} }
// enable interuption // enable interuption
if (oldintr) { EIntr(); } if (oldintr) {
EIntr();
}
return res; return res;
#else #else
#error Please implement for your platform. #error Please implement for your platform.
@@ -155,8 +166,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#endif #endif
} }
void void SDL_AtomicLock(SDL_SpinLock *lock)
SDL_AtomicLock(SDL_SpinLock *lock)
{ {
int iterations = 0; int iterations = 0;
/* FIXME: Should we have an eventual timeout? */ /* FIXME: Should we have an eventual timeout? */
@@ -171,8 +181,7 @@ SDL_AtomicLock(SDL_SpinLock *lock)
} }
} }
void void SDL_AtomicUnlock(SDL_SpinLock *lock)
SDL_AtomicUnlock(SDL_SpinLock *lock)
{ {
#if HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET #if HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
__sync_lock_release(lock); __sync_lock_release(lock);
@@ -185,7 +194,7 @@ SDL_AtomicUnlock(SDL_SpinLock *lock)
*lock = 0; *lock = 0;
#elif defined(__WATCOMC__) && defined(__386__) #elif defined(__WATCOMC__) && defined(__386__)
SDL_CompilerBarrier (); SDL_CompilerBarrier();
*lock = 0; *lock = 0;
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)

File diff suppressed because it is too large Load Diff

View File

@@ -40,11 +40,11 @@
#include "samplerate.h" #include "samplerate.h"
extern SDL_bool SRC_available; extern SDL_bool SRC_available;
extern int SRC_converter; extern int SRC_converter;
extern SRC_STATE* (*SRC_src_new)(int converter_type, int channels, int *error); extern SRC_STATE *(*SRC_src_new)(int converter_type, int channels, int *error);
extern int (*SRC_src_process)(SRC_STATE *state, SRC_DATA *data); extern int (*SRC_src_process)(SRC_STATE *state, SRC_DATA *data);
extern int (*SRC_src_reset)(SRC_STATE *state); extern int (*SRC_src_reset)(SRC_STATE *state);
extern SRC_STATE* (*SRC_src_delete)(SRC_STATE *state); extern SRC_STATE *(*SRC_src_delete)(SRC_STATE *state);
extern const char* (*SRC_src_strerror)(int error); extern const char *(*SRC_src_strerror)(int error);
extern int (*SRC_src_simple)(SRC_DATA *data, int converter_type, int channels); extern int (*SRC_src_simple)(SRC_DATA *data, int converter_type, int channels);
#endif #endif
@@ -54,7 +54,7 @@ extern SDL_AudioFormat SDL_NextAudioFormat(void);
/* Function to calculate the size and silence for a SDL_AudioSpec */ /* Function to calculate the size and silence for a SDL_AudioSpec */
extern Uint8 SDL_SilenceValueForFormat(const SDL_AudioFormat format); extern Uint8 SDL_SilenceValueForFormat(const SDL_AudioFormat format);
extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec); extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec);
/* Choose the audio filter functions below */ /* Choose the audio filter functions below */
extern void SDL_ChooseAudioConverters(void); extern void SDL_ChooseAudioConverters(void);

File diff suppressed because it is too large Load Diff

View File

@@ -21,10 +21,10 @@
/* DO NOT EDIT, THIS FILE WAS GENERATED BY build-scripts/gen_audio_resampler_filter.c */ /* DO NOT EDIT, THIS FILE WAS GENERATED BY build-scripts/gen_audio_resampler_filter.c */
#define RESAMPLER_ZERO_CROSSINGS 5 #define RESAMPLER_ZERO_CROSSINGS 5
#define RESAMPLER_BITS_PER_SAMPLE 16 #define RESAMPLER_BITS_PER_SAMPLE 16
#define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1)) #define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1))
#define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1) #define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1)
static const float ResamplerFilter[RESAMPLER_FILTER_SIZE] = { static const float ResamplerFilter[RESAMPLER_FILTER_SIZE] = {
1.000000000f, 0.999993682f, 0.999974370f, 0.999941289f, 0.999894559f, 1.000000000f, 0.999993682f, 0.999974370f, 0.999941289f, 0.999894559f,
@@ -1059,4 +1059,3 @@ static const float ResamplerFilterDifference[RESAMPLER_FILTER_SIZE] = {
}; };
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@@ -33,9 +33,9 @@
#ifndef _PATH_DEV_DSP #ifndef _PATH_DEV_DSP
#if defined(__NETBSD__) || defined(__OPENBSD__) #if defined(__NETBSD__) || defined(__OPENBSD__)
#define _PATH_DEV_DSP "/dev/audio" #define _PATH_DEV_DSP "/dev/audio"
#else #else
#define _PATH_DEV_DSP "/dev/dsp" #define _PATH_DEV_DSP "/dev/dsp"
#endif #endif
#endif #endif
#ifndef _PATH_DEV_DSP24 #ifndef _PATH_DEV_DSP24
@@ -45,8 +45,7 @@
#define _PATH_DEV_AUDIO "/dev/audio" #define _PATH_DEV_AUDIO "/dev/audio"
#endif #endif
static void static void test_device(const int iscapture, const char *fname, int flags, int (*test)(int fd))
test_device(const int iscapture, const char *fname, int flags, int (*test) (int fd))
{ {
struct stat sb; struct stat sb;
if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) { if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
@@ -64,20 +63,18 @@ test_device(const int iscapture, const char *fname, int flags, int (*test) (int
* information, making this information inaccessible at * information, making this information inaccessible at
* enumeration time * enumeration time
*/ */
SDL_AddAudioDevice(iscapture, fname, NULL, (void *) (uintptr_t) dummyhandle); SDL_AddAudioDevice(iscapture, fname, NULL, (void *)(uintptr_t)dummyhandle);
} }
} }
} }
} }
static int static int test_stub(int fd)
test_stub(int fd)
{ {
return 1; return 1;
} }
static void static void SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*test)(int))
SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*test)(int))
{ {
const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT; const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
const char *audiodev; const char *audiodev;
@@ -96,9 +93,7 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
struct stat sb; struct stat sb;
/* Added support for /dev/sound/\* in Linux 2.4 */ /* Added support for /dev/sound/\* in Linux 2.4 */
if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) && ((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode))) {
&& ((stat(_PATH_DEV_DSP24, &sb) == 0)
&& S_ISCHR(sb.st_mode))) {
audiodev = _PATH_DEV_DSP24; audiodev = _PATH_DEV_DSP24;
} else { } else {
audiodev = _PATH_DEV_DSP; audiodev = _PATH_DEV_DSP;
@@ -118,8 +113,7 @@ SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*
} }
} }
void void SDL_EnumUnixAudioDevices(const int classic, int (*test)(int))
SDL_EnumUnixAudioDevices(const int classic, int (*test)(int))
{ {
SDL_EnumUnixAudioDevices_Internal(SDL_TRUE, classic, test); SDL_EnumUnixAudioDevices_Internal(SDL_TRUE, classic, test);
SDL_EnumUnixAudioDevices_Internal(SDL_FALSE, classic, test); SDL_EnumUnixAudioDevices_Internal(SDL_FALSE, classic, test);

View File

@@ -30,10 +30,10 @@
#ifdef USE_BLOCKING_WRITES #ifdef USE_BLOCKING_WRITES
#define OPEN_FLAGS_OUTPUT O_WRONLY #define OPEN_FLAGS_OUTPUT O_WRONLY
#define OPEN_FLAGS_INPUT O_RDONLY #define OPEN_FLAGS_INPUT O_RDONLY
#else #else
#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK) #define OPEN_FLAGS_OUTPUT (O_WRONLY | O_NONBLOCK)
#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK) #define OPEN_FLAGS_INPUT (O_RDONLY | O_NONBLOCK)
#endif #endif
extern void SDL_EnumUnixAudioDevices(const int classic, int (*test)(int)); extern void SDL_EnumUnixAudioDevices(const int classic, int (*test)(int));

File diff suppressed because it is too large Load Diff

View File

@@ -78,14 +78,12 @@ static const Uint8 mix8[] = {
}; };
/* The volume ranges from 0 - 128 */ /* The volume ranges from 0 - 128 */
#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME) #define ADJUST_VOLUME(s, v) (s = (s * v) / SDL_MIX_MAXVOLUME)
#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128) #define ADJUST_VOLUME_U8(s, v) (s = (((s - 128) * v) / SDL_MIX_MAXVOLUME) + 128)
#define ADJUST_VOLUME_U16(s, v) (s = (((s-32768)*v)/SDL_MIX_MAXVOLUME)+32768) #define ADJUST_VOLUME_U16(s, v) (s = (((s - 32768) * v) / SDL_MIX_MAXVOLUME) + 32768)
void SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format,
void Uint32 len, int volume)
SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
Uint32 len, int volume)
{ {
if (volume == 0) { if (volume == 0) {
return; return;
@@ -94,258 +92,248 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
switch (format) { switch (format) {
case AUDIO_U8: case AUDIO_U8:
{ {
Uint8 src_sample; Uint8 src_sample;
while (len--) { while (len--) {
src_sample = *src; src_sample = *src;
ADJUST_VOLUME_U8(src_sample, volume); ADJUST_VOLUME_U8(src_sample, volume);
*dst = mix8[*dst + src_sample]; *dst = mix8[*dst + src_sample];
++dst; ++dst;
++src; ++src;
}
} }
break; } break;
case AUDIO_S8: case AUDIO_S8:
{ {
Sint8 *dst8, *src8; Sint8 *dst8, *src8;
Sint8 src_sample; Sint8 src_sample;
int dst_sample; int dst_sample;
const int max_audioval = SDL_MAX_SINT8; const int max_audioval = SDL_MAX_SINT8;
const int min_audioval = SDL_MIN_SINT8; const int min_audioval = SDL_MIN_SINT8;
src8 = (Sint8 *) src; src8 = (Sint8 *)src;
dst8 = (Sint8 *) dst; dst8 = (Sint8 *)dst;
while (len--) { while (len--) {
src_sample = *src8; src_sample = *src8;
ADJUST_VOLUME(src_sample, volume); ADJUST_VOLUME(src_sample, volume);
dst_sample = *dst8 + src_sample; dst_sample = *dst8 + src_sample;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*dst8 = dst_sample;
++dst8;
++src8;
} }
*dst8 = dst_sample;
++dst8;
++src8;
} }
break; } break;
case AUDIO_S16LSB: case AUDIO_S16LSB:
{ {
Sint16 src1, src2; Sint16 src1, src2;
int dst_sample; int dst_sample;
const int max_audioval = SDL_MAX_SINT16; const int max_audioval = SDL_MAX_SINT16;
const int min_audioval = SDL_MIN_SINT16; const int min_audioval = SDL_MIN_SINT16;
len /= 2; len /= 2;
while (len--) { while (len--) {
src1 = SDL_SwapLE16(*(Sint16 *)src); src1 = SDL_SwapLE16(*(Sint16 *)src);
ADJUST_VOLUME(src1, volume); ADJUST_VOLUME(src1, volume);
src2 = SDL_SwapLE16(*(Sint16 *)dst); src2 = SDL_SwapLE16(*(Sint16 *)dst);
src += 2; src += 2;
dst_sample = src1 + src2; dst_sample = src1 + src2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(Sint16 *)dst = SDL_SwapLE16(dst_sample);
dst += 2;
} }
*(Sint16 *)dst = SDL_SwapLE16(dst_sample);
dst += 2;
} }
break; } break;
case AUDIO_S16MSB: case AUDIO_S16MSB:
{ {
Sint16 src1, src2; Sint16 src1, src2;
int dst_sample; int dst_sample;
const int max_audioval = SDL_MAX_SINT16; const int max_audioval = SDL_MAX_SINT16;
const int min_audioval = SDL_MIN_SINT16; const int min_audioval = SDL_MIN_SINT16;
len /= 2; len /= 2;
while (len--) { while (len--) {
src1 = SDL_SwapBE16(*(Sint16 *)src); src1 = SDL_SwapBE16(*(Sint16 *)src);
ADJUST_VOLUME(src1, volume); ADJUST_VOLUME(src1, volume);
src2 = SDL_SwapBE16(*(Sint16 *)dst); src2 = SDL_SwapBE16(*(Sint16 *)dst);
src += 2; src += 2;
dst_sample = src1 + src2; dst_sample = src1 + src2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(Sint16 *)dst = SDL_SwapBE16(dst_sample);
dst += 2;
} }
*(Sint16 *)dst = SDL_SwapBE16(dst_sample);
dst += 2;
} }
break; } break;
case AUDIO_U16LSB: case AUDIO_U16LSB:
{ {
Uint16 src1, src2; Uint16 src1, src2;
int dst_sample; int dst_sample;
const int max_audioval = SDL_MAX_SINT16; const int max_audioval = SDL_MAX_SINT16;
const int min_audioval = SDL_MIN_SINT16; const int min_audioval = SDL_MIN_SINT16;
len /= 2; len /= 2;
while (len--) { while (len--) {
src1 = SDL_SwapLE16(*(Uint16 *)src); src1 = SDL_SwapLE16(*(Uint16 *)src);
ADJUST_VOLUME_U16(src1, volume); ADJUST_VOLUME_U16(src1, volume);
src2 = SDL_SwapLE16(*(Uint16 *)dst); src2 = SDL_SwapLE16(*(Uint16 *)dst);
src += 2; src += 2;
dst_sample = src1 + src2 - 32768 * 2; dst_sample = src1 + src2 - 32768 * 2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
dst_sample += 32768;
*(Uint16 *)dst = SDL_SwapLE16(dst_sample);
dst += 2;
} }
dst_sample += 32768;
*(Uint16 *)dst = SDL_SwapLE16(dst_sample);
dst += 2;
} }
break; } break;
case AUDIO_U16MSB: case AUDIO_U16MSB:
{ {
Uint16 src1, src2; Uint16 src1, src2;
int dst_sample; int dst_sample;
const int max_audioval = SDL_MAX_SINT16; const int max_audioval = SDL_MAX_SINT16;
const int min_audioval = SDL_MIN_SINT16; const int min_audioval = SDL_MIN_SINT16;
len /= 2; len /= 2;
while (len--) { while (len--) {
src1 = SDL_SwapBE16(*(Uint16 *)src); src1 = SDL_SwapBE16(*(Uint16 *)src);
ADJUST_VOLUME_U16(src1, volume); ADJUST_VOLUME_U16(src1, volume);
src2 = SDL_SwapBE16(*(Uint16 *)dst); src2 = SDL_SwapBE16(*(Uint16 *)dst);
src += 2; src += 2;
dst_sample = src1 + src2 - 32768 * 2; dst_sample = src1 + src2 - 32768 * 2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
dst_sample += 32768;
*(Uint16 *)dst = SDL_SwapBE16(dst_sample);
dst += 2;
} }
dst_sample += 32768;
*(Uint16 *)dst = SDL_SwapBE16(dst_sample);
dst += 2;
} }
break; } break;
case AUDIO_S32LSB: case AUDIO_S32LSB:
{ {
const Uint32 *src32 = (Uint32 *) src; const Uint32 *src32 = (Uint32 *)src;
Uint32 *dst32 = (Uint32 *) dst; Uint32 *dst32 = (Uint32 *)dst;
Sint64 src1, src2; Sint64 src1, src2;
Sint64 dst_sample; Sint64 dst_sample;
const Sint64 max_audioval = SDL_MAX_SINT32; const Sint64 max_audioval = SDL_MAX_SINT32;
const Sint64 min_audioval = SDL_MIN_SINT32; const Sint64 min_audioval = SDL_MIN_SINT32;
len /= 4; len /= 4;
while (len--) { while (len--) {
src1 = (Sint64) ((Sint32) SDL_SwapLE32(*src32)); src1 = (Sint64)((Sint32)SDL_SwapLE32(*src32));
src32++; src32++;
ADJUST_VOLUME(src1, volume); ADJUST_VOLUME(src1, volume);
src2 = (Sint64) ((Sint32) SDL_SwapLE32(*dst32)); src2 = (Sint64)((Sint32)SDL_SwapLE32(*dst32));
dst_sample = src1 + src2; dst_sample = src1 + src2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(dst32++) = SDL_SwapLE32((Uint32) ((Sint32) dst_sample));
} }
*(dst32++) = SDL_SwapLE32((Uint32)((Sint32)dst_sample));
} }
break; } break;
case AUDIO_S32MSB: case AUDIO_S32MSB:
{ {
const Uint32 *src32 = (Uint32 *) src; const Uint32 *src32 = (Uint32 *)src;
Uint32 *dst32 = (Uint32 *) dst; Uint32 *dst32 = (Uint32 *)dst;
Sint64 src1, src2; Sint64 src1, src2;
Sint64 dst_sample; Sint64 dst_sample;
const Sint64 max_audioval = SDL_MAX_SINT32; const Sint64 max_audioval = SDL_MAX_SINT32;
const Sint64 min_audioval = SDL_MIN_SINT32; const Sint64 min_audioval = SDL_MIN_SINT32;
len /= 4; len /= 4;
while (len--) { while (len--) {
src1 = (Sint64) ((Sint32) SDL_SwapBE32(*src32)); src1 = (Sint64)((Sint32)SDL_SwapBE32(*src32));
src32++; src32++;
ADJUST_VOLUME(src1, volume); ADJUST_VOLUME(src1, volume);
src2 = (Sint64) ((Sint32) SDL_SwapBE32(*dst32)); src2 = (Sint64)((Sint32)SDL_SwapBE32(*dst32));
dst_sample = src1 + src2; dst_sample = src1 + src2;
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(dst32++) = SDL_SwapBE32((Uint32) ((Sint32) dst_sample));
} }
*(dst32++) = SDL_SwapBE32((Uint32)((Sint32)dst_sample));
} }
break; } break;
case AUDIO_F32LSB: case AUDIO_F32LSB:
{ {
const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME); const float fmaxvolume = 1.0f / ((float)SDL_MIX_MAXVOLUME);
const float fvolume = (float) volume; const float fvolume = (float)volume;
const float *src32 = (float *) src; const float *src32 = (float *)src;
float *dst32 = (float *) dst; float *dst32 = (float *)dst;
float src1, src2; float src1, src2;
double dst_sample; double dst_sample;
/* !!! FIXME: are these right? */ /* !!! FIXME: are these right? */
const double max_audioval = 3.402823466e+38F; const double max_audioval = 3.402823466e+38F;
const double min_audioval = -3.402823466e+38F; const double min_audioval = -3.402823466e+38F;
len /= 4; len /= 4;
while (len--) { while (len--) {
src1 = ((SDL_SwapFloatLE(*src32) * fvolume) * fmaxvolume); src1 = ((SDL_SwapFloatLE(*src32) * fvolume) * fmaxvolume);
src2 = SDL_SwapFloatLE(*dst32); src2 = SDL_SwapFloatLE(*dst32);
src32++; src32++;
dst_sample = ((double) src1) + ((double) src2); dst_sample = ((double)src1) + ((double)src2);
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(dst32++) = SDL_SwapFloatLE((float) dst_sample);
} }
*(dst32++) = SDL_SwapFloatLE((float)dst_sample);
} }
break; } break;
case AUDIO_F32MSB: case AUDIO_F32MSB:
{ {
const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME); const float fmaxvolume = 1.0f / ((float)SDL_MIX_MAXVOLUME);
const float fvolume = (float) volume; const float fvolume = (float)volume;
const float *src32 = (float *) src; const float *src32 = (float *)src;
float *dst32 = (float *) dst; float *dst32 = (float *)dst;
float src1, src2; float src1, src2;
double dst_sample; double dst_sample;
/* !!! FIXME: are these right? */ /* !!! FIXME: are these right? */
const double max_audioval = 3.402823466e+38F; const double max_audioval = 3.402823466e+38F;
const double min_audioval = -3.402823466e+38F; const double min_audioval = -3.402823466e+38F;
len /= 4; len /= 4;
while (len--) { while (len--) {
src1 = ((SDL_SwapFloatBE(*src32) * fvolume) * fmaxvolume); src1 = ((SDL_SwapFloatBE(*src32) * fvolume) * fmaxvolume);
src2 = SDL_SwapFloatBE(*dst32); src2 = SDL_SwapFloatBE(*dst32);
src32++; src32++;
dst_sample = ((double) src1) + ((double) src2); dst_sample = ((double)src1) + ((double)src2);
if (dst_sample > max_audioval) { if (dst_sample > max_audioval) {
dst_sample = max_audioval; dst_sample = max_audioval;
} else if (dst_sample < min_audioval) { } else if (dst_sample < min_audioval) {
dst_sample = min_audioval; dst_sample = min_audioval;
}
*(dst32++) = SDL_SwapFloatBE((float) dst_sample);
} }
*(dst32++) = SDL_SwapFloatBE((float)dst_sample);
} }
break; } break;
default: /* If this happens... FIXME! */ default: /* If this happens... FIXME! */
SDL_SetError("SDL_MixAudioFormat(): unknown audio format"); SDL_SetError("SDL_MixAudioFormat(): unknown audio format");
return; return;
} }

View File

@@ -28,11 +28,11 @@
/* !!! FIXME: These are wordy and unlocalized... */ /* !!! FIXME: These are wordy and unlocalized... */
#define DEFAULT_OUTPUT_DEVNAME "System audio output device" #define DEFAULT_OUTPUT_DEVNAME "System audio output device"
#define DEFAULT_INPUT_DEVNAME "System audio capture device" #define DEFAULT_INPUT_DEVNAME "System audio capture device"
/* The SDL audio driver */ /* The SDL audio driver */
typedef struct SDL_AudioDevice SDL_AudioDevice; typedef struct SDL_AudioDevice SDL_AudioDevice;
#define _THIS SDL_AudioDevice *_this #define _THIS SDL_AudioDevice *_this
/* Audio targets should call this as devices are added to the system (such as /* Audio targets should call this as devices are added to the system (such as
a USB headset being plugged in), and should also be called for a USB headset being plugged in), and should also be called for
@@ -62,21 +62,21 @@ extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device);
typedef struct SDL_AudioDriverImpl typedef struct SDL_AudioDriverImpl
{ {
void (*DetectDevices) (void); void (*DetectDevices)(void);
int (*OpenDevice) (_THIS, const char *devname); int (*OpenDevice)(_THIS, const char *devname);
void (*ThreadInit) (_THIS); /* Called by audio thread at start */ void (*ThreadInit)(_THIS); /* Called by audio thread at start */
void (*ThreadDeinit) (_THIS); /* Called by audio thread at end */ void (*ThreadDeinit)(_THIS); /* Called by audio thread at end */
void (*WaitDevice) (_THIS); void (*WaitDevice)(_THIS);
void (*PlayDevice) (_THIS); void (*PlayDevice)(_THIS);
Uint8 *(*GetDeviceBuf) (_THIS); Uint8 *(*GetDeviceBuf)(_THIS);
int (*CaptureFromDevice) (_THIS, void *buffer, int buflen); int (*CaptureFromDevice)(_THIS, void *buffer, int buflen);
void (*FlushCapture) (_THIS); void (*FlushCapture)(_THIS);
void (*CloseDevice) (_THIS); void (*CloseDevice)(_THIS);
void (*LockDevice) (_THIS); void (*LockDevice)(_THIS);
void (*UnlockDevice) (_THIS); void (*UnlockDevice)(_THIS);
void (*FreeDeviceHandle) (void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */ void (*FreeDeviceHandle)(void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */
void (*Deinitialize) (void); void (*Deinitialize)(void);
int (*GetDefaultAudioInfo) (char **name, SDL_AudioSpec *spec, int iscapture); int (*GetDefaultAudioInfo)(char **name, SDL_AudioSpec *spec, int iscapture);
/* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */ /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
@@ -89,7 +89,6 @@ typedef struct SDL_AudioDriverImpl
SDL_bool SupportsNonPow2Samples; SDL_bool SupportsNonPow2Samples;
} SDL_AudioDriverImpl; } SDL_AudioDriverImpl;
typedef struct SDL_AudioDeviceItem typedef struct SDL_AudioDeviceItem
{ {
void *handle; void *handle;
@@ -100,7 +99,6 @@ typedef struct SDL_AudioDeviceItem
struct SDL_AudioDeviceItem *next; struct SDL_AudioDeviceItem *next;
} SDL_AudioDeviceItem; } SDL_AudioDeviceItem;
typedef struct SDL_AudioDriver typedef struct SDL_AudioDriver
{ {
/* * * */ /* * * */
@@ -123,7 +121,6 @@ typedef struct SDL_AudioDriver
SDL_AudioDeviceItem *inputDevices; SDL_AudioDeviceItem *inputDevices;
} SDL_AudioDriver; } SDL_AudioDriver;
/* Define the SDL audio driver structure */ /* Define the SDL audio driver structure */
struct SDL_AudioDevice struct SDL_AudioDevice
{ {
@@ -174,8 +171,8 @@ typedef struct AudioBootStrap
{ {
const char *name; const char *name;
const char *desc; const char *desc;
SDL_bool (*init) (SDL_AudioDriverImpl * impl); SDL_bool (*init)(SDL_AudioDriverImpl *impl);
SDL_bool demand_only; /* 1==request explicitly, or it won't be available. */ SDL_bool demand_only; /* 1==request explicitly, or it won't be available. */
} AudioBootStrap; } AudioBootStrap;
/* Not all of these are available in a given build. Use #ifdefs, etc. */ /* Not all of these are available in a given build. Use #ifdefs, etc. */

File diff suppressed because it is too large Load Diff

View File

@@ -26,14 +26,14 @@
/* Define values for Microsoft WAVE format */ /* Define values for Microsoft WAVE format */
/*******************************************/ /*******************************************/
/* FOURCC */ /* FOURCC */
#define RIFF 0x46464952 /* "RIFF" */ #define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */ #define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */ #define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */ #define LIST 0x5453494c /* "LIST" */
#define BEXT 0x74786562 /* "bext" */ #define BEXT 0x74786562 /* "bext" */
#define JUNK 0x4B4E554A /* "JUNK" */ #define JUNK 0x4B4E554A /* "JUNK" */
#define FMT 0x20746D66 /* "fmt " */ #define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */ #define DATA 0x61746164 /* "data" */
/* Format tags */ /* Format tags */
#define UNKNOWN_CODE 0x0000 #define UNKNOWN_CODE 0x0000
#define PCM_CODE 0x0001 #define PCM_CODE 0x0001
@@ -49,13 +49,13 @@
/* Stores the WAVE format information. */ /* Stores the WAVE format information. */
typedef struct WaveFormat typedef struct WaveFormat
{ {
Uint16 formattag; /* Raw value of the first field in the fmt chunk data. */ Uint16 formattag; /* Raw value of the first field in the fmt chunk data. */
Uint16 encoding; /* Actual encoding, possibly from the extensible header. */ Uint16 encoding; /* Actual encoding, possibly from the extensible header. */
Uint16 channels; /* Number of channels. */ Uint16 channels; /* Number of channels. */
Uint32 frequency; /* Sampling rate in Hz. */ Uint32 frequency; /* Sampling rate in Hz. */
Uint32 byterate; /* Average bytes per second. */ Uint32 byterate; /* Average bytes per second. */
Uint16 blockalign; /* Bytes per block. */ Uint16 blockalign; /* Bytes per block. */
Uint16 bitspersample; /* Currently supported are 8, 16, 24, 32, and 4 for ADPCM. */ Uint16 bitspersample; /* Currently supported are 8, 16, 24, 32, and 4 for ADPCM. */
/* Extra information size. Number of extra bytes starting at byte 18 in the /* Extra information size. Number of extra bytes starting at byte 18 in the
* fmt chunk data. This is at least 22 for the extensible header. * fmt chunk data. This is at least 22 for the extensible header.
@@ -66,11 +66,12 @@ typedef struct WaveFormat
Uint16 validsamplebits; Uint16 validsamplebits;
Uint32 samplesperblock; /* For compressed formats. Can be zero. Actually 16 bits in the header. */ Uint32 samplesperblock; /* For compressed formats. Can be zero. Actually 16 bits in the header. */
Uint32 channelmask; Uint32 channelmask;
Uint8 subformat[16]; /* A format GUID. */ Uint8 subformat[16]; /* A format GUID. */
} WaveFormat; } WaveFormat;
/* Stores information on the fact chunk. */ /* Stores information on the fact chunk. */
typedef struct WaveFact { typedef struct WaveFact
{
/* Represents the state of the fact chunk in the WAVE file. /* Represents the state of the fact chunk in the WAVE file.
* Set to -1 if the fact chunk is invalid. * Set to -1 if the fact chunk is invalid.
* Set to 0 if the fact chunk is not present * Set to 0 if the fact chunk is not present
@@ -101,7 +102,8 @@ typedef struct WaveChunk
} WaveChunk; } WaveChunk;
/* Controls how the size of the RIFF chunk affects the loading of a WAVE file. */ /* Controls how the size of the RIFF chunk affects the loading of a WAVE file. */
typedef enum WaveRiffSizeHint { typedef enum WaveRiffSizeHint
{
RiffSizeNoHint, RiffSizeNoHint,
RiffSizeForce, RiffSizeForce,
RiffSizeIgnoreZero, RiffSizeIgnoreZero,
@@ -110,7 +112,8 @@ typedef enum WaveRiffSizeHint {
} WaveRiffSizeHint; } WaveRiffSizeHint;
/* Controls how a truncated WAVE file is handled. */ /* Controls how a truncated WAVE file is handled. */
typedef enum WaveTruncationHint { typedef enum WaveTruncationHint
{
TruncNoHint, TruncNoHint,
TruncVeryStrict, TruncVeryStrict,
TruncStrict, TruncStrict,
@@ -119,7 +122,8 @@ typedef enum WaveTruncationHint {
} WaveTruncationHint; } WaveTruncationHint;
/* Controls how the fact chunk affects the loading of a WAVE file. */ /* Controls how the fact chunk affects the loading of a WAVE file. */
typedef enum WaveFactChunkHint { typedef enum WaveFactChunkHint
{
FactNoHint, FactNoHint,
FactTruncate, FactTruncate,
FactStrict, FactStrict,
@@ -139,7 +143,7 @@ typedef struct WaveFile
*/ */
Sint64 sampleframes; Sint64 sampleframes;
void *decoderdata; /* Some decoders require extra data for a state. */ void *decoderdata; /* Some decoders require extra data for a state. */
WaveRiffSizeHint riffhint; WaveRiffSizeHint riffhint;
WaveTruncationHint trunchint; WaveTruncationHint trunchint;

View File

@@ -28,17 +28,17 @@
/* Debug */ /* Debug */
#if 0 #if 0
# define LOGI(...) SDL_Log(__VA_ARGS__); #define LOGI(...) SDL_Log(__VA_ARGS__);
#else #else
# define LOGI(...) #define LOGI(...)
#endif #endif
typedef struct AAUDIO_Data typedef struct AAUDIO_Data
{ {
AAudioStreamBuilder *builder; AAudioStreamBuilder *builder;
void *handle; void *handle;
#define SDL_PROC(ret,func,params) ret (*func) params; #define SDL_PROC(ret, func, params) ret(*func) params;
# include "SDL_aaudiofuncs.h" #include "SDL_aaudiofuncs.h"
#undef SDL_PROC #undef SDL_PROC
} AAUDIO_Data; } AAUDIO_Data;
static AAUDIO_Data ctx; static AAUDIO_Data ctx;
@@ -48,28 +48,27 @@ static SDL_AudioDevice *captureDevice = NULL;
static int aaudio_LoadFunctions(AAUDIO_Data *data) static int aaudio_LoadFunctions(AAUDIO_Data *data)
{ {
#define SDL_PROC(ret,func,params) \ #define SDL_PROC(ret, func, params) \
do { \ do { \
data->func = SDL_LoadFunction(data->handle, #func); \ data->func = SDL_LoadFunction(data->handle, #func); \
if (! data->func) { \ if (!data->func) { \
return SDL_SetError("Couldn't load AAUDIO function %s: %s", #func, SDL_GetError()); \ return SDL_SetError("Couldn't load AAUDIO function %s: %s", #func, SDL_GetError()); \
} \ } \
} while (0); } while (0);
#include "SDL_aaudiofuncs.h" #include "SDL_aaudiofuncs.h"
#undef SDL_PROC #undef SDL_PROC
return 0; return 0;
} }
void aaudio_errorCallback( AAudioStream *stream, void *userData, aaudio_result_t error ); void aaudio_errorCallback(AAudioStream *stream, void *userData, aaudio_result_t error);
void aaudio_errorCallback( AAudioStream *stream, void *userData, aaudio_result_t error ) void aaudio_errorCallback(AAudioStream *stream, void *userData, aaudio_result_t error)
{ {
LOGI( "SDL aaudio_errorCallback: %d - %s", error, ctx.AAudio_convertResultToText( error ) ); LOGI("SDL aaudio_errorCallback: %d - %s", error, ctx.AAudio_convertResultToText(error));
} }
#define LIB_AAUDIO_SO "libaaudio.so" #define LIB_AAUDIO_SO "libaaudio.so"
static int static int aaudio_OpenDevice(_THIS, const char *devname)
aaudio_OpenDevice(_THIS, const char *devname)
{ {
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
SDL_bool iscapture = this->iscapture; SDL_bool iscapture = this->iscapture;
@@ -92,7 +91,7 @@ aaudio_OpenDevice(_THIS, const char *devname)
audioDevice = this; audioDevice = this;
} }
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden)); this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, (sizeof *this->hidden));
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -114,11 +113,11 @@ aaudio_OpenDevice(_THIS, const char *devname)
ctx.AAudioStreamBuilder_setFormat(ctx.builder, format); ctx.AAudioStreamBuilder_setFormat(ctx.builder, format);
} }
ctx.AAudioStreamBuilder_setErrorCallback( ctx.builder, aaudio_errorCallback, private ); ctx.AAudioStreamBuilder_setErrorCallback(ctx.builder, aaudio_errorCallback, private);
LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u", LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u",
this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format), this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples); this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
res = ctx.AAudioStreamBuilder_openStream(ctx.builder, &private->stream); res = ctx.AAudioStreamBuilder_openStream(ctx.builder, &private->stream);
if (res != AAUDIO_OK) { if (res != AAUDIO_OK) {
@@ -138,15 +137,15 @@ aaudio_OpenDevice(_THIS, const char *devname)
} }
LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u", LOGI("AAudio Try to open %u hz %u bit chan %u %s samples %u",
this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format), this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples); this->spec.channels, (this->spec.format & 0x1000) ? "BE" : "LE", this->spec.samples);
SDL_CalculateAudioSpec(&this->spec); SDL_CalculateAudioSpec(&this->spec);
/* Allocate mixing buffer */ /* Allocate mixing buffer */
if (!iscapture) { if (!iscapture) {
private->mixlen = this->spec.size; private->mixlen = this->spec.size;
private->mixbuf = (Uint8 *) SDL_malloc(private->mixlen); private->mixbuf = (Uint8 *)SDL_malloc(private->mixlen);
if (private->mixbuf == NULL) { if (private->mixbuf == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -165,8 +164,7 @@ aaudio_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static void static void aaudio_CloseDevice(_THIS)
aaudio_CloseDevice(_THIS)
{ {
struct SDL_PrivateAudioData *private = this->hidden; struct SDL_PrivateAudioData *private = this->hidden;
aaudio_result_t res; aaudio_result_t res;
@@ -200,20 +198,18 @@ aaudio_CloseDevice(_THIS)
SDL_free(this->hidden); SDL_free(this->hidden);
} }
static Uint8 * static Uint8 *aaudio_GetDeviceBuf(_THIS)
aaudio_GetDeviceBuf(_THIS)
{ {
struct SDL_PrivateAudioData *private = this->hidden; struct SDL_PrivateAudioData *private = this->hidden;
return private->mixbuf; return private->mixbuf;
} }
static void static void aaudio_PlayDevice(_THIS)
aaudio_PlayDevice(_THIS)
{ {
struct SDL_PrivateAudioData *private = this->hidden; struct SDL_PrivateAudioData *private = this->hidden;
aaudio_result_t res; aaudio_result_t res;
int64_t timeoutNanoseconds = 1 * 1000 * 1000; /* 8 ms */ int64_t timeoutNanoseconds = 1 * 1000 * 1000; /* 8 ms */
res = ctx.AAudioStream_write(private->stream, private->mixbuf, private->mixlen / private->frame_size, timeoutNanoseconds); res = ctx.AAudioStream_write(private->stream, private->mixbuf, private->mixlen / private->frame_size, timeoutNanoseconds);
if (res < 0) { if (res < 0) {
LOGI("%s : %s", __func__, ctx.AAudio_convertResultToText(res)); LOGI("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
} else { } else {
@@ -233,13 +229,12 @@ aaudio_PlayDevice(_THIS)
#endif #endif
} }
static int static int aaudio_CaptureFromDevice(_THIS, void *buffer, int buflen)
aaudio_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
struct SDL_PrivateAudioData *private = this->hidden; struct SDL_PrivateAudioData *private = this->hidden;
aaudio_result_t res; aaudio_result_t res;
int64_t timeoutNanoseconds = 8 * 1000 * 1000; /* 8 ms */ int64_t timeoutNanoseconds = 8 * 1000 * 1000; /* 8 ms */
res = ctx.AAudioStream_read(private->stream, buffer, buflen / private->frame_size, timeoutNanoseconds); res = ctx.AAudioStream_read(private->stream, buffer, buflen / private->frame_size, timeoutNanoseconds);
if (res < 0) { if (res < 0) {
LOGI("%s : %s", __func__, ctx.AAudio_convertResultToText(res)); LOGI("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
return -1; return -1;
@@ -248,8 +243,7 @@ aaudio_CaptureFromDevice(_THIS, void *buffer, int buflen)
return res * private->frame_size; return res * private->frame_size;
} }
static void static void aaudio_Deinitialize(void)
aaudio_Deinitialize(void)
{ {
LOGI(__func__); LOGI(__func__);
if (ctx.handle) { if (ctx.handle) {
@@ -267,8 +261,7 @@ aaudio_Deinitialize(void)
LOGI("End AAUDIO %s", SDL_GetError()); LOGI("End AAUDIO %s", SDL_GetError());
} }
static SDL_bool static SDL_bool aaudio_Init(SDL_AudioDriverImpl *impl)
aaudio_Init(SDL_AudioDriverImpl *impl)
{ {
aaudio_result_t res; aaudio_result_t res;
LOGI(__func__); LOGI(__func__);
@@ -343,7 +336,7 @@ void aaudio_PauseDevices(void)
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (private->stream) { if (private->stream) {
aaudio_result_t res = ctx.AAudioStream_requestPause(private->stream); aaudio_result_t res = ctx.AAudioStream_requestPause(private->stream);
@@ -364,7 +357,7 @@ void aaudio_PauseDevices(void)
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (private->stream) { if (private->stream) {
/* Pause() isn't implemented for 'capture', use Stop() */ /* Pause() isn't implemented for 'capture', use Stop() */
@@ -392,7 +385,7 @@ void aaudio_ResumeDevices(void)
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&audioDevice->paused, 0); SDL_AtomicSet(&audioDevice->paused, 0);
@@ -410,7 +403,7 @@ void aaudio_ResumeDevices(void)
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&captureDevice->paused, 0); SDL_AtomicSet(&captureDevice->paused, 0);
@@ -433,24 +426,24 @@ void aaudio_ResumeDevices(void)
None of the standard state queries indicate any problem in my testing. And the error callback doesn't actually get called. None of the standard state queries indicate any problem in my testing. And the error callback doesn't actually get called.
But, AAudioStream_getTimestamp() does return AAUDIO_ERROR_INVALID_STATE But, AAudioStream_getTimestamp() does return AAUDIO_ERROR_INVALID_STATE
*/ */
SDL_bool aaudio_DetectBrokenPlayState( void ) SDL_bool aaudio_DetectBrokenPlayState(void)
{ {
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
int64_t framePosition, timeNanoseconds; int64_t framePosition, timeNanoseconds;
aaudio_result_t res; aaudio_result_t res;
if (audioDevice == NULL || !audioDevice->hidden ) { if (audioDevice == NULL || !audioDevice->hidden) {
return SDL_FALSE; return SDL_FALSE;
} }
private = audioDevice->hidden; private = audioDevice->hidden;
res = ctx.AAudioStream_getTimestamp( private->stream, CLOCK_MONOTONIC, &framePosition, &timeNanoseconds ); res = ctx.AAudioStream_getTimestamp(private->stream, CLOCK_MONOTONIC, &framePosition, &timeNanoseconds);
if ( res == AAUDIO_ERROR_INVALID_STATE ) { if (res == AAUDIO_ERROR_INVALID_STATE) {
aaudio_stream_state_t currentState = ctx.AAudioStream_getState( private->stream ); aaudio_stream_state_t currentState = ctx.AAudioStream_getState(private->stream);
/* AAudioStream_getTimestamp() will also return AAUDIO_ERROR_INVALID_STATE while the stream is still initially starting. But we only care if it silently went invalid while playing. */ /* AAudioStream_getTimestamp() will also return AAUDIO_ERROR_INVALID_STATE while the stream is still initially starting. But we only care if it silently went invalid while playing. */
if ( currentState == AAUDIO_STREAM_STATE_STARTED ) { if (currentState == AAUDIO_STREAM_STATE_STARTED) {
LOGI( "SDL aaudio_DetectBrokenPlayState: detected invalid audio device state: AAudioStream_getTimestamp result=%d, framePosition=%lld, timeNanoseconds=%lld, getState=%d", (int)res, (long long)framePosition, (long long)timeNanoseconds, (int)currentState ); LOGI("SDL aaudio_DetectBrokenPlayState: detected invalid audio device state: AAudioStream_getTimestamp result=%d, framePosition=%lld, timeNanoseconds=%lld, getState=%d", (int)res, (long long)framePosition, (long long)timeNanoseconds, (int)currentState);
return SDL_TRUE; return SDL_TRUE;
} }
} }

View File

@@ -28,7 +28,7 @@
#include <aaudio/AAudio.h> #include <aaudio/AAudio.h>
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {
@@ -42,12 +42,11 @@ struct SDL_PrivateAudioData
/* Resume device if it was paused automatically */ /* Resume device if it was paused automatically */
int resume; int resume;
}; };
void aaudio_ResumeDevices(void); void aaudio_ResumeDevices(void);
void aaudio_PauseDevices(void); void aaudio_PauseDevices(void);
SDL_bool aaudio_DetectBrokenPlayState(void); SDL_bool aaudio_DetectBrokenPlayState(void);
#endif /* _SDL_aaudio_h */ #endif /* _SDL_aaudio_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -19,62 +19,61 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#define SDL_PROC_UNUSED(ret,func,params) #define SDL_PROC_UNUSED(ret, func, params)
SDL_PROC(const char *, AAudio_convertResultToText, (aaudio_result_t returnCode)) SDL_PROC(const char *, AAudio_convertResultToText, (aaudio_result_t returnCode))
SDL_PROC(const char *, AAudio_convertStreamStateToText, (aaudio_stream_state_t state)) SDL_PROC(const char *, AAudio_convertStreamStateToText, (aaudio_stream_state_t state))
SDL_PROC(aaudio_result_t, AAudio_createStreamBuilder, (AAudioStreamBuilder** builder)) SDL_PROC(aaudio_result_t, AAudio_createStreamBuilder, (AAudioStreamBuilder * *builder))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDeviceId, (AAudioStreamBuilder* builder, int32_t deviceId)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDeviceId, (AAudioStreamBuilder * builder, int32_t deviceId))
SDL_PROC(void, AAudioStreamBuilder_setSampleRate, (AAudioStreamBuilder* builder, int32_t sampleRate)) SDL_PROC(void, AAudioStreamBuilder_setSampleRate, (AAudioStreamBuilder * builder, int32_t sampleRate))
SDL_PROC(void, AAudioStreamBuilder_setChannelCount, (AAudioStreamBuilder* builder, int32_t channelCount)) SDL_PROC(void, AAudioStreamBuilder_setChannelCount, (AAudioStreamBuilder * builder, int32_t channelCount))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSamplesPerFrame, (AAudioStreamBuilder* builder, int32_t samplesPerFrame)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSamplesPerFrame, (AAudioStreamBuilder * builder, int32_t samplesPerFrame))
SDL_PROC(void, AAudioStreamBuilder_setFormat, (AAudioStreamBuilder* builder, aaudio_format_t format)) SDL_PROC(void, AAudioStreamBuilder_setFormat, (AAudioStreamBuilder * builder, aaudio_format_t format))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSharingMode, (AAudioStreamBuilder* builder, aaudio_sharing_mode_t sharingMode)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSharingMode, (AAudioStreamBuilder * builder, aaudio_sharing_mode_t sharingMode))
SDL_PROC(void, AAudioStreamBuilder_setDirection, (AAudioStreamBuilder* builder, aaudio_direction_t direction)) SDL_PROC(void, AAudioStreamBuilder_setDirection, (AAudioStreamBuilder * builder, aaudio_direction_t direction))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setBufferCapacityInFrames, (AAudioStreamBuilder* builder, int32_t numFrames)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setBufferCapacityInFrames, (AAudioStreamBuilder * builder, int32_t numFrames))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setPerformanceMode, (AAudioStreamBuilder* builder, aaudio_performance_mode_t mode)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setPerformanceMode, (AAudioStreamBuilder * builder, aaudio_performance_mode_t mode))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setUsage, (AAudioStreamBuilder* builder, aaudio_usage_t usage)) /* API 28 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setUsage, (AAudioStreamBuilder * builder, aaudio_usage_t usage)) /* API 28 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setContentType, (AAudioStreamBuilder* builder, aaudio_content_type_t contentType)) /* API 28 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setContentType, (AAudioStreamBuilder * builder, aaudio_content_type_t contentType)) /* API 28 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setInputPreset, (AAudioStreamBuilder* builder, aaudio_input_preset_t inputPreset)) /* API 28 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setInputPreset, (AAudioStreamBuilder * builder, aaudio_input_preset_t inputPreset)) /* API 28 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setAllowedCapturePolicy, (AAudioStreamBuilder* builder, aaudio_allowed_capture_policy_t capturePolicy)) /* API 29 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setAllowedCapturePolicy, (AAudioStreamBuilder * builder, aaudio_allowed_capture_policy_t capturePolicy)) /* API 29 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSessionId, (AAudioStreamBuilder* builder, aaudio_session_id_t sessionId)) /* API 28 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setSessionId, (AAudioStreamBuilder * builder, aaudio_session_id_t sessionId)) /* API 28 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setPrivacySensitive, (AAudioStreamBuilder* builder, bool privacySensitive)) /* API 30 */ SDL_PROC_UNUSED(void, AAudioStreamBuilder_setPrivacySensitive, (AAudioStreamBuilder * builder, bool privacySensitive)) /* API 30 */
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDataCallback, (AAudioStreamBuilder* builder, AAudioStream_dataCallback callback, void *userData)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setDataCallback, (AAudioStreamBuilder * builder, AAudioStream_dataCallback callback, void *userData))
SDL_PROC_UNUSED(void, AAudioStreamBuilder_setFramesPerDataCallback, (AAudioStreamBuilder* builder, int32_t numFrames)) SDL_PROC_UNUSED(void, AAudioStreamBuilder_setFramesPerDataCallback, (AAudioStreamBuilder * builder, int32_t numFrames))
SDL_PROC(void, AAudioStreamBuilder_setErrorCallback, (AAudioStreamBuilder* builder, AAudioStream_errorCallback callback, void *userData)) SDL_PROC(void, AAudioStreamBuilder_setErrorCallback, (AAudioStreamBuilder * builder, AAudioStream_errorCallback callback, void *userData))
SDL_PROC(aaudio_result_t , AAudioStreamBuilder_openStream, (AAudioStreamBuilder* builder, AAudioStream** stream)) SDL_PROC(aaudio_result_t, AAudioStreamBuilder_openStream, (AAudioStreamBuilder * builder, AAudioStream **stream))
SDL_PROC(aaudio_result_t , AAudioStreamBuilder_delete, (AAudioStreamBuilder* builder)) SDL_PROC(aaudio_result_t, AAudioStreamBuilder_delete, (AAudioStreamBuilder * builder))
SDL_PROC_UNUSED(aaudio_result_t , AAudioStream_release, (AAudioStream* stream)) /* API 30 */ SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_release, (AAudioStream * stream)) /* API 30 */
SDL_PROC(aaudio_result_t , AAudioStream_close, (AAudioStream* stream)) SDL_PROC(aaudio_result_t, AAudioStream_close, (AAudioStream * stream))
SDL_PROC(aaudio_result_t , AAudioStream_requestStart, (AAudioStream* stream)) SDL_PROC(aaudio_result_t, AAudioStream_requestStart, (AAudioStream * stream))
SDL_PROC(aaudio_result_t , AAudioStream_requestPause, (AAudioStream* stream)) SDL_PROC(aaudio_result_t, AAudioStream_requestPause, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_result_t , AAudioStream_requestFlush, (AAudioStream* stream)) SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_requestFlush, (AAudioStream * stream))
SDL_PROC(aaudio_result_t , AAudioStream_requestStop, (AAudioStream* stream)) SDL_PROC(aaudio_result_t, AAudioStream_requestStop, (AAudioStream * stream))
SDL_PROC(aaudio_stream_state_t, AAudioStream_getState, (AAudioStream* stream)) SDL_PROC(aaudio_stream_state_t, AAudioStream_getState, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_waitForStateChange, (AAudioStream* stream, aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, int64_t timeoutNanoseconds)) SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_waitForStateChange, (AAudioStream * stream, aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, int64_t timeoutNanoseconds))
SDL_PROC(aaudio_result_t, AAudioStream_read, (AAudioStream* stream, void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)) SDL_PROC(aaudio_result_t, AAudioStream_read, (AAudioStream * stream, void *buffer, int32_t numFrames, int64_t timeoutNanoseconds))
SDL_PROC(aaudio_result_t, AAudioStream_write, (AAudioStream* stream, const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)) SDL_PROC(aaudio_result_t, AAudioStream_write, (AAudioStream * stream, const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds))
SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_setBufferSizeInFrames, (AAudioStream* stream, int32_t numFrames)) SDL_PROC_UNUSED(aaudio_result_t, AAudioStream_setBufferSizeInFrames, (AAudioStream * stream, int32_t numFrames))
SDL_PROC_UNUSED(int32_t, AAudioStream_getBufferSizeInFrames, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getBufferSizeInFrames, (AAudioStream * stream))
SDL_PROC_UNUSED(int32_t, AAudioStream_getFramesPerBurst, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getFramesPerBurst, (AAudioStream * stream))
SDL_PROC_UNUSED(int32_t, AAudioStream_getBufferCapacityInFrames, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getBufferCapacityInFrames, (AAudioStream * stream))
SDL_PROC_UNUSED(int32_t, AAudioStream_getFramesPerDataCallback, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getFramesPerDataCallback, (AAudioStream * stream))
SDL_PROC(int32_t, AAudioStream_getXRunCount, (AAudioStream* stream)) SDL_PROC(int32_t, AAudioStream_getXRunCount, (AAudioStream * stream))
SDL_PROC(int32_t, AAudioStream_getSampleRate, (AAudioStream* stream)) SDL_PROC(int32_t, AAudioStream_getSampleRate, (AAudioStream * stream))
SDL_PROC(int32_t, AAudioStream_getChannelCount, (AAudioStream* stream)) SDL_PROC(int32_t, AAudioStream_getChannelCount, (AAudioStream * stream))
SDL_PROC_UNUSED(int32_t, AAudioStream_getSamplesPerFrame, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getSamplesPerFrame, (AAudioStream * stream))
SDL_PROC_UNUSED(int32_t, AAudioStream_getDeviceId, (AAudioStream* stream)) SDL_PROC_UNUSED(int32_t, AAudioStream_getDeviceId, (AAudioStream * stream))
SDL_PROC(aaudio_format_t, AAudioStream_getFormat, (AAudioStream* stream)) SDL_PROC(aaudio_format_t, AAudioStream_getFormat, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_sharing_mode_t, AAudioStream_getSharingMode, (AAudioStream* stream)) SDL_PROC_UNUSED(aaudio_sharing_mode_t, AAudioStream_getSharingMode, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_performance_mode_t, AAudioStream_getPerformanceMode, (AAudioStream* stream)) SDL_PROC_UNUSED(aaudio_performance_mode_t, AAudioStream_getPerformanceMode, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_direction_t, AAudioStream_getDirection, (AAudioStream* stream)) SDL_PROC_UNUSED(aaudio_direction_t, AAudioStream_getDirection, (AAudioStream * stream))
SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesWritten, (AAudioStream* stream)) SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesWritten, (AAudioStream * stream))
SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesRead, (AAudioStream* stream)) SDL_PROC_UNUSED(int64_t, AAudioStream_getFramesRead, (AAudioStream * stream))
SDL_PROC_UNUSED(aaudio_session_id_t, AAudioStream_getSessionId, (AAudioStream* stream)) /* API 28 */ SDL_PROC_UNUSED(aaudio_session_id_t, AAudioStream_getSessionId, (AAudioStream * stream)) /* API 28 */
SDL_PROC(aaudio_result_t, AAudioStream_getTimestamp, (AAudioStream* stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds)) SDL_PROC(aaudio_result_t, AAudioStream_getTimestamp, (AAudioStream * stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds))
SDL_PROC_UNUSED(aaudio_usage_t, AAudioStream_getUsage, (AAudioStream* stream)) /* API 28 */ SDL_PROC_UNUSED(aaudio_usage_t, AAudioStream_getUsage, (AAudioStream * stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_content_type_t, AAudioStream_getContentType, (AAudioStream* stream)) /* API 28 */ SDL_PROC_UNUSED(aaudio_content_type_t, AAudioStream_getContentType, (AAudioStream * stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_input_preset_t, AAudioStream_getInputPreset, (AAudioStream* stream)) /* API 28 */ SDL_PROC_UNUSED(aaudio_input_preset_t, AAudioStream_getInputPreset, (AAudioStream * stream)) /* API 28 */
SDL_PROC_UNUSED(aaudio_allowed_capture_policy_t, AAudioStream_getAllowedCapturePolicy, ( AAudioStream* stream)) /* API 29 */ SDL_PROC_UNUSED(aaudio_allowed_capture_policy_t, AAudioStream_getAllowedCapturePolicy, (AAudioStream * stream)) /* API 29 */
SDL_PROC_UNUSED(bool, AAudioStream_isPrivacySensitive, (AAudioStream* stream)) /* API 30 */ SDL_PROC_UNUSED(bool, AAudioStream_isPrivacySensitive, (AAudioStream * stream)) /* API 30 */

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -31,11 +31,10 @@
#include <android/log.h> #include <android/log.h>
static SDL_AudioDevice* audioDevice = NULL; static SDL_AudioDevice *audioDevice = NULL;
static SDL_AudioDevice* captureDevice = NULL; static SDL_AudioDevice *captureDevice = NULL;
static int static int ANDROIDAUDIO_OpenDevice(_THIS, const char *devname)
ANDROIDAUDIO_OpenDevice(_THIS, const char *devname)
{ {
SDL_AudioFormat test_format; SDL_AudioFormat test_format;
SDL_bool iscapture = this->iscapture; SDL_bool iscapture = this->iscapture;
@@ -49,7 +48,7 @@ ANDROIDAUDIO_OpenDevice(_THIS, const char *devname)
audioDevice = this; audioDevice = this;
} }
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden)); this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, (sizeof *this->hidden));
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -77,32 +76,27 @@ ANDROIDAUDIO_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static void static void ANDROIDAUDIO_PlayDevice(_THIS)
ANDROIDAUDIO_PlayDevice(_THIS)
{ {
Android_JNI_WriteAudioBuffer(); Android_JNI_WriteAudioBuffer();
} }
static Uint8 * static Uint8 *ANDROIDAUDIO_GetDeviceBuf(_THIS)
ANDROIDAUDIO_GetDeviceBuf(_THIS)
{ {
return Android_JNI_GetAudioBuffer(); return Android_JNI_GetAudioBuffer();
} }
static int static int ANDROIDAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
ANDROIDAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
return Android_JNI_CaptureAudioBuffer(buffer, buflen); return Android_JNI_CaptureAudioBuffer(buffer, buflen);
} }
static void static void ANDROIDAUDIO_FlushCapture(_THIS)
ANDROIDAUDIO_FlushCapture(_THIS)
{ {
Android_JNI_FlushCapturedAudio(); Android_JNI_FlushCapturedAudio();
} }
static void static void ANDROIDAUDIO_CloseDevice(_THIS)
ANDROIDAUDIO_CloseDevice(_THIS)
{ {
/* At this point SDL_CloseAudioDevice via close_audio_device took care of terminating the audio thread /* At this point SDL_CloseAudioDevice via close_audio_device took care of terminating the audio thread
so it's safe to terminate the Java side buffer and AudioTrack so it's safe to terminate the Java side buffer and AudioTrack
@@ -118,8 +112,7 @@ ANDROIDAUDIO_CloseDevice(_THIS)
SDL_free(this->hidden); SDL_free(this->hidden);
} }
static SDL_bool static SDL_bool ANDROIDAUDIO_Init(SDL_AudioDriverImpl *impl)
ANDROIDAUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
/* Set the function pointers */ /* Set the function pointers */
impl->OpenDevice = ANDROIDAUDIO_OpenDevice; impl->OpenDevice = ANDROIDAUDIO_OpenDevice;
@@ -134,7 +127,7 @@ ANDROIDAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->OnlyHasDefaultOutputDevice = SDL_TRUE; impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
impl->OnlyHasDefaultCaptureDevice = SDL_TRUE; impl->OnlyHasDefaultCaptureDevice = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap ANDROIDAUDIO_bootstrap = { AudioBootStrap ANDROIDAUDIO_bootstrap = {
@@ -147,7 +140,7 @@ void ANDROIDAUDIO_PauseDevices(void)
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (SDL_AtomicGet(&audioDevice->paused)) { if (SDL_AtomicGet(&audioDevice->paused)) {
/* The device is already paused, leave it alone */ /* The device is already paused, leave it alone */
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
@@ -159,7 +152,7 @@ void ANDROIDAUDIO_PauseDevices(void)
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (SDL_AtomicGet(&captureDevice->paused)) { if (SDL_AtomicGet(&captureDevice->paused)) {
/* The device is already paused, leave it alone */ /* The device is already paused, leave it alone */
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
@@ -177,7 +170,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
/* TODO: Handle multiple devices? */ /* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private; struct SDL_PrivateAudioData *private;
if (audioDevice != NULL && audioDevice->hidden != NULL) { if (audioDevice != NULL && audioDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) audioDevice->hidden; private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&audioDevice->paused, 0); SDL_AtomicSet(&audioDevice->paused, 0);
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
@@ -186,7 +179,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
} }
if (captureDevice != NULL && captureDevice->hidden != NULL) { if (captureDevice != NULL && captureDevice->hidden != NULL) {
private = (struct SDL_PrivateAudioData *) captureDevice->hidden; private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (private->resume) { if (private->resume) {
SDL_AtomicSet(&captureDevice->paused, 0); SDL_AtomicSet(&captureDevice->paused, 0);
private->resume = SDL_FALSE; private->resume = SDL_FALSE;
@@ -195,7 +188,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
} }
} }
#else #else
void ANDROIDAUDIO_ResumeDevices(void) {} void ANDROIDAUDIO_ResumeDevices(void) {}
void ANDROIDAUDIO_PauseDevices(void) {} void ANDROIDAUDIO_PauseDevices(void) {}
@@ -203,4 +196,3 @@ void ANDROIDAUDIO_PauseDevices(void) {}
#endif /* SDL_AUDIO_DRIVER_ANDROID */ #endif /* SDL_AUDIO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -48,7 +48,7 @@
#endif #endif
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -41,21 +41,20 @@ static SDL_bool SupportsIMMDevice = SDL_FALSE;
#endif /* HAVE_MMDEVICEAPI_H */ #endif /* HAVE_MMDEVICEAPI_H */
/* DirectX function pointers for audio */ /* DirectX function pointers for audio */
static void* DSoundDLL = NULL; static void *DSoundDLL = NULL;
typedef HRESULT (WINAPI *fnDirectSoundCreate8)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN); typedef HRESULT(WINAPI *fnDirectSoundCreate8)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
typedef HRESULT (WINAPI *fnDirectSoundEnumerateW)(LPDSENUMCALLBACKW, LPVOID); typedef HRESULT(WINAPI *fnDirectSoundEnumerateW)(LPDSENUMCALLBACKW, LPVOID);
typedef HRESULT (WINAPI *fnDirectSoundCaptureCreate8)(LPCGUID,LPDIRECTSOUNDCAPTURE8 *,LPUNKNOWN); typedef HRESULT(WINAPI *fnDirectSoundCaptureCreate8)(LPCGUID, LPDIRECTSOUNDCAPTURE8 *, LPUNKNOWN);
typedef HRESULT (WINAPI *fnDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW,LPVOID); typedef HRESULT(WINAPI *fnDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW, LPVOID);
static fnDirectSoundCreate8 pDirectSoundCreate8 = NULL; static fnDirectSoundCreate8 pDirectSoundCreate8 = NULL;
static fnDirectSoundEnumerateW pDirectSoundEnumerateW = NULL; static fnDirectSoundEnumerateW pDirectSoundEnumerateW = NULL;
static fnDirectSoundCaptureCreate8 pDirectSoundCaptureCreate8 = NULL; static fnDirectSoundCaptureCreate8 pDirectSoundCaptureCreate8 = NULL;
static fnDirectSoundCaptureEnumerateW pDirectSoundCaptureEnumerateW = NULL; static fnDirectSoundCaptureEnumerateW pDirectSoundCaptureEnumerateW = NULL;
static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } }; static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
static const GUID SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = { 0x00000003, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } }; static const GUID SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = { 0x00000003, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
static void static void DSOUND_Unload(void)
DSOUND_Unload(void)
{ {
pDirectSoundCreate8 = NULL; pDirectSoundCreate8 = NULL;
pDirectSoundEnumerateW = NULL; pDirectSoundEnumerateW = NULL;
@@ -68,9 +67,7 @@ DSOUND_Unload(void)
} }
} }
static int DSOUND_Load(void)
static int
DSOUND_Load(void)
{ {
int loaded = 0; int loaded = 0;
@@ -80,17 +77,19 @@ DSOUND_Load(void)
if (DSoundDLL == NULL) { if (DSoundDLL == NULL) {
SDL_SetError("DirectSound: failed to load DSOUND.DLL"); SDL_SetError("DirectSound: failed to load DSOUND.DLL");
} else { } else {
/* Now make sure we have DirectX 8 or better... */ /* Now make sure we have DirectX 8 or better... */
#define DSOUNDLOAD(f) { \ #define DSOUNDLOAD(f) \
p##f = (fn##f) SDL_LoadFunction(DSoundDLL, #f); \ { \
if (!p##f) loaded = 0; \ p##f = (fn##f)SDL_LoadFunction(DSoundDLL, #f); \
} if (!p##f) \
loaded = 1; /* will reset if necessary. */ loaded = 0; \
}
loaded = 1; /* will reset if necessary. */
DSOUNDLOAD(DirectSoundCreate8); DSOUNDLOAD(DirectSoundCreate8);
DSOUNDLOAD(DirectSoundEnumerateW); DSOUNDLOAD(DirectSoundEnumerateW);
DSOUNDLOAD(DirectSoundCaptureCreate8); DSOUNDLOAD(DirectSoundCaptureCreate8);
DSOUNDLOAD(DirectSoundCaptureEnumerateW); DSOUNDLOAD(DirectSoundCaptureEnumerateW);
#undef DSOUNDLOAD #undef DSOUNDLOAD
if (!loaded) { if (!loaded) {
SDL_SetError("DirectSound: System doesn't appear to have DX8."); SDL_SetError("DirectSound: System doesn't appear to have DX8.");
@@ -104,8 +103,7 @@ DSOUND_Load(void)
return loaded; return loaded;
} }
static int static int SetDSerror(const char *function, int code)
SetDSerror(const char *function, int code)
{ {
const char *error; const char *error;
@@ -151,14 +149,12 @@ SetDSerror(const char *function, int code)
return SDL_SetError("%s: %s (0x%x)", function, error, code); return SDL_SetError("%s: %s (0x%x)", function, error, code);
} }
static void static void DSOUND_FreeDeviceHandle(void *handle)
DSOUND_FreeDeviceHandle(void *handle)
{ {
SDL_free(handle); SDL_free(handle);
} }
static int static int DSOUND_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
DSOUND_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
{ {
#if HAVE_MMDEVICEAPI_H #if HAVE_MMDEVICEAPI_H
if (SupportsIMMDevice) { if (SupportsIMMDevice) {
@@ -168,29 +164,27 @@ DSOUND_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
return SDL_Unsupported(); return SDL_Unsupported();
} }
static BOOL CALLBACK static BOOL CALLBACK FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID data)
FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID data)
{ {
const int iscapture = (int) ((size_t) data); const int iscapture = (int)((size_t)data);
if (guid != NULL) { /* skip default device */ if (guid != NULL) { /* skip default device */
char *str = WIN_LookupAudioDeviceName(desc, guid); char *str = WIN_LookupAudioDeviceName(desc, guid);
if (str != NULL) { if (str != NULL) {
LPGUID cpyguid = (LPGUID) SDL_malloc(sizeof (GUID)); LPGUID cpyguid = (LPGUID)SDL_malloc(sizeof(GUID));
SDL_memcpy(cpyguid, guid, sizeof (GUID)); SDL_memcpy(cpyguid, guid, sizeof(GUID));
/* Note that spec is NULL, because we are required to connect to the /* Note that spec is NULL, because we are required to connect to the
* device before getting the channel mask and output format, making * device before getting the channel mask and output format, making
* this information inaccessible at enumeration time * this information inaccessible at enumeration time
*/ */
SDL_AddAudioDevice(iscapture, str, NULL, cpyguid); SDL_AddAudioDevice(iscapture, str, NULL, cpyguid);
SDL_free(str); /* addfn() makes a copy of this string. */ SDL_free(str); /* addfn() makes a copy of this string. */
} }
} }
return TRUE; /* keep enumerating. */ return TRUE; /* keep enumerating. */
} }
static void static void DSOUND_DetectDevices(void)
DSOUND_DetectDevices(void)
{ {
#if HAVE_MMDEVICEAPI_H #if HAVE_MMDEVICEAPI_H
if (SupportsIMMDevice) { if (SupportsIMMDevice) {
@@ -204,9 +198,7 @@ DSOUND_DetectDevices(void)
#endif /* HAVE_MMDEVICEAPI_H*/ #endif /* HAVE_MMDEVICEAPI_H*/
} }
static void DSOUND_WaitDevice(_THIS)
static void
DSOUND_WaitDevice(_THIS)
{ {
DWORD status = 0; DWORD status = 0;
DWORD cursor = 0; DWORD cursor = 0;
@@ -263,8 +255,7 @@ DSOUND_WaitDevice(_THIS)
} }
} }
static void static void DSOUND_PlayDevice(_THIS)
DSOUND_PlayDevice(_THIS)
{ {
/* Unlock the buffer, allowing it to play */ /* Unlock the buffer, allowing it to play */
if (this->hidden->locked_buf) { if (this->hidden->locked_buf) {
@@ -274,8 +265,7 @@ DSOUND_PlayDevice(_THIS)
} }
} }
static Uint8 * static Uint8 *DSOUND_GetDeviceBuf(_THIS)
DSOUND_GetDeviceBuf(_THIS)
{ {
DWORD cursor = 0; DWORD cursor = 0;
DWORD junk = 0; DWORD junk = 0;
@@ -316,14 +306,13 @@ DSOUND_GetDeviceBuf(_THIS)
/* Lock the audio buffer */ /* Lock the audio buffer */
result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
this->spec.size, this->spec.size,
(LPVOID *) & this->hidden->locked_buf, (LPVOID *)&this->hidden->locked_buf,
&rawlen, NULL, &junk, 0); &rawlen, NULL, &junk, 0);
if (result == DSERR_BUFFERLOST) { if (result == DSERR_BUFFERLOST) {
IDirectSoundBuffer_Restore(this->hidden->mixbuf); IDirectSoundBuffer_Restore(this->hidden->mixbuf);
result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
this->spec.size, this->spec.size,
(LPVOID *) & this-> (LPVOID *)&this->hidden->locked_buf, &rawlen, NULL,
hidden->locked_buf, &rawlen, NULL,
&junk, 0); &junk, 0);
} }
if (result != DS_OK) { if (result != DS_OK) {
@@ -333,8 +322,7 @@ DSOUND_GetDeviceBuf(_THIS)
return this->hidden->locked_buf; return this->hidden->locked_buf;
} }
static int static int DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
struct SDL_PrivateAudioData *h = this->hidden; struct SDL_PrivateAudioData *h = this->hidden;
DWORD junk, cursor, ptr1len, ptr2len; DWORD junk, cursor, ptr1len, ptr2len;
@@ -343,7 +331,7 @@ DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
SDL_assert(buflen == this->spec.size); SDL_assert(buflen == this->spec.size);
while (SDL_TRUE) { while (SDL_TRUE) {
if (SDL_AtomicGet(&this->shutdown)) { /* in case the buffer froze... */ if (SDL_AtomicGet(&this->shutdown)) { /* in case the buffer froze... */
SDL_memset(buffer, this->spec.silence, buflen); SDL_memset(buffer, this->spec.silence, buflen);
return buflen; return buflen;
} }
@@ -352,7 +340,7 @@ DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
return -1; return -1;
} }
if ((cursor / this->spec.size) == h->lastchunk) { if ((cursor / this->spec.size) == h->lastchunk) {
SDL_Delay(1); /* FIXME: find out how much time is left and sleep that long */ SDL_Delay(1); /* FIXME: find out how much time is left and sleep that long */
} else { } else {
break; break;
} }
@@ -377,8 +365,7 @@ DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
return ptr1len; return ptr1len;
} }
static void static void DSOUND_FlushCapture(_THIS)
DSOUND_FlushCapture(_THIS)
{ {
struct SDL_PrivateAudioData *h = this->hidden; struct SDL_PrivateAudioData *h = this->hidden;
DWORD junk, cursor; DWORD junk, cursor;
@@ -387,8 +374,7 @@ DSOUND_FlushCapture(_THIS)
} }
} }
static void static void DSOUND_CloseDevice(_THIS)
DSOUND_CloseDevice(_THIS)
{ {
if (this->hidden->mixbuf != NULL) { if (this->hidden->mixbuf != NULL) {
IDirectSoundBuffer_Stop(this->hidden->mixbuf); IDirectSoundBuffer_Stop(this->hidden->mixbuf);
@@ -411,8 +397,7 @@ DSOUND_CloseDevice(_THIS)
number of audio chunks available in the created buffer. This is for number of audio chunks available in the created buffer. This is for
playback devices, not capture. playback devices, not capture.
*/ */
static int static int CreateSecondary(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
CreateSecondary(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
{ {
LPDIRECTSOUND sndObj = this->hidden->sound; LPDIRECTSOUND sndObj = this->hidden->sound;
LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf; LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf;
@@ -436,14 +421,14 @@ CreateSecondary(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
/* Silence the initial audio buffer */ /* Silence the initial audio buffer */
result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes, result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
(LPVOID *) & pvAudioPtr1, &dwAudioBytes1, (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
(LPVOID *) & pvAudioPtr2, &dwAudioBytes2, (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
DSBLOCK_ENTIREBUFFER); DSBLOCK_ENTIREBUFFER);
if (result == DS_OK) { if (result == DS_OK) {
SDL_memset(pvAudioPtr1, this->spec.silence, dwAudioBytes1); SDL_memset(pvAudioPtr1, this->spec.silence, dwAudioBytes1);
IDirectSoundBuffer_Unlock(*sndbuf, IDirectSoundBuffer_Unlock(*sndbuf,
(LPVOID) pvAudioPtr1, dwAudioBytes1, (LPVOID)pvAudioPtr1, dwAudioBytes1,
(LPVOID) pvAudioPtr2, dwAudioBytes2); (LPVOID)pvAudioPtr2, dwAudioBytes2);
} }
/* We're ready to go */ /* We're ready to go */
@@ -454,8 +439,7 @@ CreateSecondary(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
number of audio chunks available in the created buffer. This is for number of audio chunks available in the created buffer. This is for
capture devices, not playback. capture devices, not playback.
*/ */
static int static int CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
{ {
LPDIRECTSOUNDCAPTURE capture = this->hidden->capture; LPDIRECTSOUNDCAPTURE capture = this->hidden->capture;
LPDIRECTSOUNDCAPTUREBUFFER *capturebuf = &this->hidden->capturebuf; LPDIRECTSOUNDCAPTUREBUFFER *capturebuf = &this->hidden->capturebuf;
@@ -463,7 +447,7 @@ CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
HRESULT result; HRESULT result;
SDL_zero(format); SDL_zero(format);
format.dwSize = sizeof (format); format.dwSize = sizeof(format);
format.dwFlags = DSCBCAPS_WAVEMAPPED; format.dwFlags = DSCBCAPS_WAVEMAPPED;
format.dwBufferBytes = bufsize; format.dwBufferBytes = bufsize;
format.lpwfxFormat = wfmt; format.lpwfxFormat = wfmt;
@@ -494,15 +478,14 @@ CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
return 0; return 0;
} }
static int static int DSOUND_OpenDevice(_THIS, const char *devname)
DSOUND_OpenDevice(_THIS, const char *devname)
{ {
const DWORD numchunks = 8; const DWORD numchunks = 8;
HRESULT result; HRESULT result;
SDL_bool tried_format = SDL_FALSE; SDL_bool tried_format = SDL_FALSE;
SDL_bool iscapture = this->iscapture; SDL_bool iscapture = this->iscapture;
SDL_AudioFormat test_format; SDL_AudioFormat test_format;
LPGUID guid = (LPGUID) this->handle; LPGUID guid = (LPGUID)this->handle;
DWORD bufsize; DWORD bufsize;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
@@ -548,8 +531,8 @@ DSOUND_OpenDevice(_THIS, const char *devname)
bufsize = numchunks * this->spec.size; bufsize = numchunks * this->spec.size;
if ((bufsize < DSBSIZE_MIN) || (bufsize > DSBSIZE_MAX)) { if ((bufsize < DSBSIZE_MIN) || (bufsize > DSBSIZE_MAX)) {
SDL_SetError("Sound buffer size must be between %d and %d", SDL_SetError("Sound buffer size must be between %d and %d",
(int) ((DSBSIZE_MIN < numchunks) ? 1 : DSBSIZE_MIN / numchunks), (int)((DSBSIZE_MIN < numchunks) ? 1 : DSBSIZE_MIN / numchunks),
(int) (DSBSIZE_MAX / numchunks)); (int)(DSBSIZE_MAX / numchunks));
} else { } else {
int rc; int rc;
WAVEFORMATEXTENSIBLE wfmt; WAVEFORMATEXTENSIBLE wfmt;
@@ -565,8 +548,7 @@ DSOUND_OpenDevice(_THIS, const char *devname)
} }
wfmt.Samples.wValidBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format); wfmt.Samples.wValidBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
switch (this->spec.channels) switch (this->spec.channels) {
{
case 3: /* 3.0 (or 2.1) */ case 3: /* 3.0 (or 2.1) */
wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER; wfmt.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER;
break; break;
@@ -601,7 +583,7 @@ DSOUND_OpenDevice(_THIS, const char *devname)
wfmt.Format.nBlockAlign = wfmt.Format.nChannels * (wfmt.Format.wBitsPerSample / 8); wfmt.Format.nBlockAlign = wfmt.Format.nChannels * (wfmt.Format.wBitsPerSample / 8);
wfmt.Format.nAvgBytesPerSec = wfmt.Format.nSamplesPerSec * wfmt.Format.nBlockAlign; wfmt.Format.nAvgBytesPerSec = wfmt.Format.nSamplesPerSec * wfmt.Format.nBlockAlign;
rc = iscapture ? CreateCaptureBuffer(this, bufsize, (WAVEFORMATEX*) &wfmt) : CreateSecondary(this, bufsize, (WAVEFORMATEX*) &wfmt); rc = iscapture ? CreateCaptureBuffer(this, bufsize, (WAVEFORMATEX *)&wfmt) : CreateSecondary(this, bufsize, (WAVEFORMATEX *)&wfmt);
if (rc == 0) { if (rc == 0) {
this->hidden->num_buffers = numchunks; this->hidden->num_buffers = numchunks;
break; break;
@@ -616,19 +598,17 @@ DSOUND_OpenDevice(_THIS, const char *devname)
if (!test_format) { if (!test_format) {
if (tried_format) { if (tried_format) {
return -1; /* CreateSecondary() should have called SDL_SetError(). */ return -1; /* CreateSecondary() should have called SDL_SetError(). */
} }
return SDL_SetError("%s: Unsupported audio format", "directsound"); return SDL_SetError("%s: Unsupported audio format", "directsound");
} }
/* Playback buffers will auto-start playing in DSOUND_WaitDevice() */ /* Playback buffers will auto-start playing in DSOUND_WaitDevice() */
return 0; /* good to go. */ return 0; /* good to go. */
} }
static void DSOUND_Deinitialize(void)
static void
DSOUND_Deinitialize(void)
{ {
#if HAVE_MMDEVICEAPI_H #if HAVE_MMDEVICEAPI_H
if (SupportsIMMDevice) { if (SupportsIMMDevice) {
@@ -639,9 +619,7 @@ DSOUND_Deinitialize(void)
DSOUND_Unload(); DSOUND_Unload();
} }
static SDL_bool DSOUND_Init(SDL_AudioDriverImpl *impl)
static SDL_bool
DSOUND_Init(SDL_AudioDriverImpl * impl)
{ {
if (!DSOUND_Load()) { if (!DSOUND_Load()) {
return SDL_FALSE; return SDL_FALSE;
@@ -667,7 +645,7 @@ DSOUND_Init(SDL_AudioDriverImpl * impl)
impl->HasCaptureSupport = SDL_TRUE; impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE; impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap DSOUND_bootstrap = { AudioBootStrap DSOUND_bootstrap = {

View File

@@ -28,7 +28,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
/* The DirectSound objects */ /* The DirectSound objects */
struct SDL_PrivateAudioData struct SDL_PrivateAudioData

View File

@@ -33,21 +33,19 @@
/* !!! FIXME: these should be SDL hints, not environment variables. */ /* !!! FIXME: these should be SDL hints, not environment variables. */
/* environment variables and defaults. */ /* environment variables and defaults. */
#define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE" #define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE"
#define DISKDEFAULT_OUTFILE "sdlaudio.raw" #define DISKDEFAULT_OUTFILE "sdlaudio.raw"
#define DISKENVR_INFILE "SDL_DISKAUDIOFILEIN" #define DISKENVR_INFILE "SDL_DISKAUDIOFILEIN"
#define DISKDEFAULT_INFILE "sdlaudio-in.raw" #define DISKDEFAULT_INFILE "sdlaudio-in.raw"
#define DISKENVR_IODELAY "SDL_DISKAUDIODELAY" #define DISKENVR_IODELAY "SDL_DISKAUDIODELAY"
/* This function waits until it is possible to write a full sound buffer */ /* This function waits until it is possible to write a full sound buffer */
static void static void DISKAUDIO_WaitDevice(_THIS)
DISKAUDIO_WaitDevice(_THIS)
{ {
SDL_Delay(_this->hidden->io_delay); SDL_Delay(_this->hidden->io_delay);
} }
static void static void DISKAUDIO_PlayDevice(_THIS)
DISKAUDIO_PlayDevice(_THIS)
{ {
const size_t written = SDL_RWwrite(_this->hidden->io, const size_t written = SDL_RWwrite(_this->hidden->io,
_this->hidden->mixbuf, _this->hidden->mixbuf,
@@ -62,14 +60,12 @@ DISKAUDIO_PlayDevice(_THIS)
#endif #endif
} }
static Uint8 * static Uint8 *DISKAUDIO_GetDeviceBuf(_THIS)
DISKAUDIO_GetDeviceBuf(_THIS)
{ {
return _this->hidden->mixbuf; return _this->hidden->mixbuf;
} }
static int static int DISKAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
DISKAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
struct SDL_PrivateAudioData *h = _this->hidden; struct SDL_PrivateAudioData *h = _this->hidden;
const int origbuflen = buflen; const int origbuflen = buflen;
@@ -78,9 +74,9 @@ DISKAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
if (h->io) { if (h->io) {
const size_t br = SDL_RWread(h->io, buffer, 1, buflen); const size_t br = SDL_RWread(h->io, buffer, 1, buflen);
buflen -= (int) br; buflen -= (int)br;
buffer = ((Uint8 *) buffer) + br; buffer = ((Uint8 *)buffer) + br;
if (buflen > 0) { /* EOF (or error, but whatever). */ if (buflen > 0) { /* EOF (or error, but whatever). */
SDL_RWclose(h->io); SDL_RWclose(h->io);
h->io = NULL; h->io = NULL;
} }
@@ -92,15 +88,12 @@ DISKAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
return origbuflen; return origbuflen;
} }
static void static void DISKAUDIO_FlushCapture(_THIS)
DISKAUDIO_FlushCapture(_THIS)
{ {
/* no op...we don't advance the file pointer or anything. */ /* no op...we don't advance the file pointer or anything. */
} }
static void DISKAUDIO_CloseDevice(_THIS)
static void
DISKAUDIO_CloseDevice(_THIS)
{ {
if (_this->hidden->io != NULL) { if (_this->hidden->io != NULL) {
SDL_RWclose(_this->hidden->io); SDL_RWclose(_this->hidden->io);
@@ -109,9 +102,7 @@ DISKAUDIO_CloseDevice(_THIS)
SDL_free(_this->hidden); SDL_free(_this->hidden);
} }
static const char *get_filename(const SDL_bool iscapture, const char *devname)
static const char *
get_filename(const SDL_bool iscapture, const char *devname)
{ {
if (devname == NULL) { if (devname == NULL) {
devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE); devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE);
@@ -122,8 +113,7 @@ get_filename(const SDL_bool iscapture, const char *devname)
return devname; return devname;
} }
static int static int DISKAUDIO_OpenDevice(_THIS, const char *devname)
DISKAUDIO_OpenDevice(_THIS, const char *devname)
{ {
void *handle = _this->handle; void *handle = _this->handle;
/* handle != NULL means "user specified the placeholder name on the fake detected device list" */ /* handle != NULL means "user specified the placeholder name on the fake detected device list" */
@@ -152,7 +142,7 @@ DISKAUDIO_OpenDevice(_THIS, const char *devname)
/* Allocate mixing buffer */ /* Allocate mixing buffer */
if (!iscapture) { if (!iscapture) {
_this->hidden->mixbuf = (Uint8 *) SDL_malloc(_this->spec.size); _this->hidden->mixbuf = (Uint8 *)SDL_malloc(_this->spec.size);
if (_this->hidden->mixbuf == NULL) { if (_this->hidden->mixbuf == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -160,24 +150,22 @@ DISKAUDIO_OpenDevice(_THIS, const char *devname)
} }
SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO, SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO,
"You are using the SDL disk i/o audio driver!\n"); "You are using the SDL disk i/o audio driver!\n");
SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO, SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO,
" %s file [%s].\n", iscapture ? "Reading from" : "Writing to", " %s file [%s].\n", iscapture ? "Reading from" : "Writing to",
fname); fname);
/* We're ready to rock and roll. :-) */ /* We're ready to rock and roll. :-) */
return 0; return 0;
} }
static void static void DISKAUDIO_DetectDevices(void)
DISKAUDIO_DetectDevices(void)
{ {
SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, NULL, (void *) 0x1); SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, NULL, (void *)0x1);
SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, NULL, (void *) 0x2); SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, NULL, (void *)0x2);
} }
static SDL_bool static SDL_bool DISKAUDIO_Init(SDL_AudioDriverImpl *impl)
DISKAUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
/* Set the function pointers */ /* Set the function pointers */
impl->OpenDevice = DISKAUDIO_OpenDevice; impl->OpenDevice = DISKAUDIO_OpenDevice;
@@ -194,7 +182,7 @@ DISKAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->HasCaptureSupport = SDL_TRUE; impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE; impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap DISKAUDIO_bootstrap = { AudioBootStrap DISKAUDIO_bootstrap = {

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *_this #define _THIS SDL_AudioDevice *_this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -24,8 +24,8 @@
/* Allow access to a raw mixing buffer */ /* Allow access to a raw mixing buffer */
#include <stdio.h> /* For perror() */ #include <stdio.h> /* For perror() */
#include <string.h> /* For strerror() */ #include <string.h> /* For strerror() */
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@@ -40,16 +40,12 @@
#include "../SDL_audiodev_c.h" #include "../SDL_audiodev_c.h"
#include "SDL_dspaudio.h" #include "SDL_dspaudio.h"
static void DSP_DetectDevices(void)
static void
DSP_DetectDevices(void)
{ {
SDL_EnumUnixAudioDevices(0, NULL); SDL_EnumUnixAudioDevices(0, NULL);
} }
static void DSP_CloseDevice(_THIS)
static void
DSP_CloseDevice(_THIS)
{ {
if (this->hidden->audio_fd >= 0) { if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd); close(this->hidden->audio_fd);
@@ -58,9 +54,7 @@ DSP_CloseDevice(_THIS)
SDL_free(this->hidden); SDL_free(this->hidden);
} }
static int DSP_OpenDevice(_THIS, const char *devname)
static int
DSP_OpenDevice(_THIS, const char *devname)
{ {
SDL_bool iscapture = this->iscapture; SDL_bool iscapture = this->iscapture;
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT); const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
@@ -203,11 +197,12 @@ DSP_OpenDevice(_THIS, const char *devname)
SDL_CalculateAudioSpec(&this->spec); SDL_CalculateAudioSpec(&this->spec);
/* Determine the power of two of the fragment size */ /* Determine the power of two of the fragment size */
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec); for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec)
;
if ((0x01U << frag_spec) != this->spec.size) { if ((0x01U << frag_spec) != this->spec.size) {
return SDL_SetError("Fragment size must be a power of two"); return SDL_SetError("Fragment size must be a power of two");
} }
frag_spec |= 0x00020000; /* two fragments, for low latency */ frag_spec |= 0x00020000; /* two fragments, for low latency */
/* Set the audio buffering parameters */ /* Set the audio buffering parameters */
#ifdef DEBUG_AUDIO #ifdef DEBUG_AUDIO
@@ -231,7 +226,7 @@ DSP_OpenDevice(_THIS, const char *devname)
/* Allocate mixing buffer */ /* Allocate mixing buffer */
if (!iscapture) { if (!iscapture) {
this->hidden->mixlen = this->spec.size; this->hidden->mixlen = this->spec.size;
this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen); this->hidden->mixbuf = (Uint8 *)SDL_malloc(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) { if (this->hidden->mixbuf == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -242,9 +237,7 @@ DSP_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static void DSP_PlayDevice(_THIS)
static void
DSP_PlayDevice(_THIS)
{ {
struct SDL_PrivateAudioData *h = this->hidden; struct SDL_PrivateAudioData *h = this->hidden;
if (write(h->audio_fd, h->mixbuf, h->mixlen) == -1) { if (write(h->audio_fd, h->mixbuf, h->mixlen) == -1) {
@@ -256,27 +249,24 @@ DSP_PlayDevice(_THIS)
#endif #endif
} }
static Uint8 * static Uint8 *DSP_GetDeviceBuf(_THIS)
DSP_GetDeviceBuf(_THIS)
{ {
return this->hidden->mixbuf; return this->hidden->mixbuf;
} }
static int static int DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
return (int)read(this->hidden->audio_fd, buffer, buflen); return (int)read(this->hidden->audio_fd, buffer, buflen);
} }
static void static void DSP_FlushCapture(_THIS)
DSP_FlushCapture(_THIS)
{ {
struct SDL_PrivateAudioData *h = this->hidden; struct SDL_PrivateAudioData *h = this->hidden;
audio_buf_info info; audio_buf_info info;
if (ioctl(h->audio_fd, SNDCTL_DSP_GETISPACE, &info) == 0) { if (ioctl(h->audio_fd, SNDCTL_DSP_GETISPACE, &info) == 0) {
while (info.bytes > 0) { while (info.bytes > 0) {
char buf[512]; char buf[512];
const size_t len = SDL_min(sizeof (buf), info.bytes); const size_t len = SDL_min(sizeof(buf), info.bytes);
const ssize_t br = read(h->audio_fd, buf, len); const ssize_t br = read(h->audio_fd, buf, len);
if (br <= 0) { if (br <= 0) {
break; break;
@@ -287,22 +277,20 @@ DSP_FlushCapture(_THIS)
} }
static SDL_bool InitTimeDevicesExist = SDL_FALSE; static SDL_bool InitTimeDevicesExist = SDL_FALSE;
static int static int look_for_devices_test(int fd)
look_for_devices_test(int fd)
{ {
InitTimeDevicesExist = SDL_TRUE; /* note that _something_ exists. */ InitTimeDevicesExist = SDL_TRUE; /* note that _something_ exists. */
/* Don't add to the device list, we're just seeing if any devices exist. */ /* Don't add to the device list, we're just seeing if any devices exist. */
return 0; return 0;
} }
static SDL_bool static SDL_bool DSP_Init(SDL_AudioDriverImpl *impl)
DSP_Init(SDL_AudioDriverImpl * impl)
{ {
InitTimeDevicesExist = SDL_FALSE; InitTimeDevicesExist = SDL_FALSE;
SDL_EnumUnixAudioDevices(0, look_for_devices_test); SDL_EnumUnixAudioDevices(0, look_for_devices_test);
if (!InitTimeDevicesExist) { if (!InitTimeDevicesExist) {
SDL_SetError("dsp: No such audio device"); SDL_SetError("dsp: No such audio device");
return SDL_FALSE; /* maybe try a different backend. */ return SDL_FALSE; /* maybe try a different backend. */
} }
/* Set the function pointers */ /* Set the function pointers */
@@ -317,10 +305,9 @@ DSP_Init(SDL_AudioDriverImpl * impl)
impl->AllowsArbitraryDeviceNames = SDL_TRUE; impl->AllowsArbitraryDeviceNames = SDL_TRUE;
impl->HasCaptureSupport = SDL_TRUE; impl->HasCaptureSupport = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap DSP_bootstrap = { AudioBootStrap DSP_bootstrap = {
"dsp", "OSS /dev/dsp standard audio", DSP_Init, SDL_FALSE "dsp", "OSS /dev/dsp standard audio", DSP_Init, SDL_FALSE
}; };

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {
@@ -37,7 +37,7 @@ struct SDL_PrivateAudioData
Uint8 *mixbuf; Uint8 *mixbuf;
int mixlen; int mixlen;
}; };
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */ #define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#endif /* SDL_dspaudio_h_ */ #endif /* SDL_dspaudio_h_ */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@@ -25,15 +25,14 @@
#include "../SDL_audio_c.h" #include "../SDL_audio_c.h"
#include "SDL_dummyaudio.h" #include "SDL_dummyaudio.h"
static int static int DUMMYAUDIO_OpenDevice(_THIS, const char *devname)
DUMMYAUDIO_OpenDevice(_THIS, const char *devname)
{ {
_this->hidden = (void *) 0x1; /* just something non-NULL */ _this->hidden = (void *)0x1; /* just something non-NULL */
return 0; /* always succeeds. */
return 0; /* always succeeds. */
} }
static int static int DUMMYAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
DUMMYAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
/* Delay to make this sort of simulate real audio input. */ /* Delay to make this sort of simulate real audio input. */
SDL_Delay((_this->spec.samples * 1000) / _this->spec.freq); SDL_Delay((_this->spec.samples * 1000) / _this->spec.freq);
@@ -43,8 +42,7 @@ DUMMYAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
return buflen; return buflen;
} }
static SDL_bool static SDL_bool DUMMYAUDIO_Init(SDL_AudioDriverImpl *impl)
DUMMYAUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
/* Set the function pointers */ /* Set the function pointers */
impl->OpenDevice = DUMMYAUDIO_OpenDevice; impl->OpenDevice = DUMMYAUDIO_OpenDevice;
@@ -54,7 +52,7 @@ DUMMYAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->OnlyHasDefaultCaptureDevice = SDL_TRUE; impl->OnlyHasDefaultCaptureDevice = SDL_TRUE;
impl->HasCaptureSupport = SDL_TRUE; impl->HasCaptureSupport = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap DUMMYAUDIO_bootstrap = { AudioBootStrap DUMMYAUDIO_bootstrap = {

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *_this #define _THIS SDL_AudioDevice *_this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -32,10 +32,10 @@
!!! FIXME: true always once pthread support becomes widespread. Revisit this code !!! FIXME: true always once pthread support becomes widespread. Revisit this code
!!! FIXME: at some point and see what needs to be done for that! */ !!! FIXME: at some point and see what needs to be done for that! */
static void static void FeedAudioDevice(_THIS, const void *buf, const int buflen)
FeedAudioDevice(_THIS, const void *buf, const int buflen)
{ {
const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels; const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({ MAIN_THREAD_EM_ASM({
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
var numChannels = SDL3.audio.currentOutputBuffer['numberOfChannels']; var numChannels = SDL3.audio.currentOutputBuffer['numberOfChannels'];
@@ -50,10 +50,10 @@ FeedAudioDevice(_THIS, const void *buf, const int buflen)
} }
} }
}, buf, buflen / framelen); }, buf, buflen / framelen);
/* *INDENT-ON* */ /* clang-format on */
} }
static void static void HandleAudioProcess(_THIS)
HandleAudioProcess(_THIS)
{ {
SDL_AudioCallback callback = this->callbackspec.callback; SDL_AudioCallback callback = this->callbackspec.callback;
const int stream_len = this->callbackspec.size; const int stream_len = this->callbackspec.size;
@@ -69,12 +69,12 @@ HandleAudioProcess(_THIS)
return; return;
} }
if (this->stream == NULL) { /* no conversion necessary. */ if (this->stream == NULL) { /* no conversion necessary. */
SDL_assert(this->spec.size == stream_len); SDL_assert(this->spec.size == stream_len);
callback(this->callbackspec.userdata, this->work_buffer, stream_len); callback(this->callbackspec.userdata, this->work_buffer, stream_len);
} else { /* streaming/converting */ } else { /* streaming/converting */
int got; int got;
while (SDL_AudioStreamAvailable(this->stream) < ((int) this->spec.size)) { while (SDL_AudioStreamAvailable(this->stream) < ((int)this->spec.size)) {
callback(this->callbackspec.userdata, this->work_buffer, stream_len); callback(this->callbackspec.userdata, this->work_buffer, stream_len);
if (SDL_AudioStreamPut(this->stream, this->work_buffer, stream_len) == -1) { if (SDL_AudioStreamPut(this->stream, this->work_buffer, stream_len) == -1) {
SDL_AudioStreamClear(this->stream); SDL_AudioStreamClear(this->stream);
@@ -93,8 +93,7 @@ HandleAudioProcess(_THIS)
FeedAudioDevice(this, this->work_buffer, this->spec.size); FeedAudioDevice(this, this->work_buffer, this->spec.size);
} }
static void static void HandleCaptureProcess(_THIS)
HandleCaptureProcess(_THIS)
{ {
SDL_AudioCallback callback = this->callbackspec.callback; SDL_AudioCallback callback = this->callbackspec.callback;
const int stream_len = this->callbackspec.size; const int stream_len = this->callbackspec.size;
@@ -105,6 +104,7 @@ HandleCaptureProcess(_THIS)
return; return;
} }
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({ MAIN_THREAD_EM_ASM({
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
var numChannels = SDL3.capture.currentCaptureBuffer.numberOfChannels; var numChannels = SDL3.capture.currentCaptureBuffer.numberOfChannels;
@@ -125,13 +125,14 @@ HandleCaptureProcess(_THIS)
} }
} }
}, this->work_buffer, (this->spec.size / sizeof (float)) / this->spec.channels); }, this->work_buffer, (this->spec.size / sizeof (float)) / this->spec.channels);
/* *INDENT-ON* */ /* clang-format on */
/* okay, we've got an interleaved float32 array in C now. */ /* okay, we've got an interleaved float32 array in C now. */
if (this->stream == NULL) { /* no conversion necessary. */ if (this->stream == NULL) { /* no conversion necessary. */
SDL_assert(this->spec.size == stream_len); SDL_assert(this->spec.size == stream_len);
callback(this->callbackspec.userdata, this->work_buffer, stream_len); callback(this->callbackspec.userdata, this->work_buffer, stream_len);
} else { /* streaming/converting */ } else { /* streaming/converting */
if (SDL_AudioStreamPut(this->stream, this->work_buffer, this->spec.size) == -1) { if (SDL_AudioStreamPut(this->stream, this->work_buffer, this->spec.size) == -1) {
SDL_AtomicSet(&this->enabled, 0); SDL_AtomicSet(&this->enabled, 0);
} }
@@ -142,15 +143,14 @@ HandleCaptureProcess(_THIS)
if (got != stream_len) { if (got != stream_len) {
SDL_memset(this->work_buffer, this->callbackspec.silence, stream_len); SDL_memset(this->work_buffer, this->callbackspec.silence, stream_len);
} }
callback(this->callbackspec.userdata, this->work_buffer, stream_len); /* Send it to the app. */ callback(this->callbackspec.userdata, this->work_buffer, stream_len); /* Send it to the app. */
} }
} }
} }
static void EMSCRIPTENAUDIO_CloseDevice(_THIS)
static void
EMSCRIPTENAUDIO_CloseDevice(_THIS)
{ {
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({ MAIN_THREAD_EM_ASM({
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
if ($0) { if ($0) {
@@ -189,14 +189,14 @@ EMSCRIPTENAUDIO_CloseDevice(_THIS)
SDL3.audioContext = undefined; SDL3.audioContext = undefined;
} }
}, this->iscapture); }, this->iscapture);
/* *INDENT-ON* */ /* clang-format on */
#if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL3 namespace? --ryan. */ #if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL3 namespace? --ryan. */
SDL_free(this->hidden); SDL_free(this->hidden);
#endif #endif
} }
static int static int EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
{ {
SDL_AudioFormat test_format; SDL_AudioFormat test_format;
SDL_bool iscapture = this->iscapture; SDL_bool iscapture = this->iscapture;
@@ -204,6 +204,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
/* based on parts of library_sdl.js */ /* based on parts of library_sdl.js */
/* *INDENT-OFF* */ /* clang-format off */
/* create context */ /* create context */
result = MAIN_THREAD_EM_ASM_INT({ result = MAIN_THREAD_EM_ASM_INT({
if (typeof(Module['SDL3']) === 'undefined') { if (typeof(Module['SDL3']) === 'undefined') {
@@ -228,6 +229,8 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
} }
return SDL3.audioContext === undefined ? -1 : 0; return SDL3.audioContext === undefined ? -1 : 0;
}, iscapture); }, iscapture);
/* *INDENT-ON* */ /* clang-format on */
if (result < 0) { if (result < 0) {
return SDL_SetError("Web Audio API is not available!"); return SDL_SetError("Web Audio API is not available!");
} }
@@ -249,7 +252,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
this->spec.format = test_format; this->spec.format = test_format;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
#if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL3 namespace? --ryan. */ #if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL3 namespace? --ryan. */
this->hidden = (struct SDL_PrivateAudioData *) this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden)); SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) { if (this->hidden == NULL) {
@@ -261,12 +264,13 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
/* limit to native freq */ /* limit to native freq */
this->spec.freq = EM_ASM_INT_V({ this->spec.freq = EM_ASM_INT_V({
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
return SDL3.audioContext.sampleRate; return SDL3.audioContext.sampleRate;
}); });
SDL_CalculateAudioSpec(&this->spec); SDL_CalculateAudioSpec(&this->spec);
/* *INDENT-OFF* */ /* clang-format off */
if (iscapture) { if (iscapture) {
/* The idea is to take the capture media stream, hook it up to an /* The idea is to take the capture media stream, hook it up to an
audio graph where we can pass it through a ScriptProcessorNode audio graph where we can pass it through a ScriptProcessorNode
@@ -338,17 +342,16 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
SDL3.audio.scriptProcessorNode['connect'](SDL3.audioContext['destination']); SDL3.audio.scriptProcessorNode['connect'](SDL3.audioContext['destination']);
}, this->spec.channels, this->spec.samples, HandleAudioProcess, this); }, this->spec.channels, this->spec.samples, HandleAudioProcess, this);
} }
/* *INDENT-ON* */ /* clang-format on */
return 0; return 0;
} }
static void static void EMSCRIPTENAUDIO_LockOrUnlockDeviceWithNoMixerLock(SDL_AudioDevice *device)
EMSCRIPTENAUDIO_LockOrUnlockDeviceWithNoMixerLock(SDL_AudioDevice * device)
{ {
} }
static SDL_bool static SDL_bool EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl *impl)
EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
SDL_bool available, capture_available; SDL_bool available, capture_available;
@@ -362,6 +365,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->LockDevice = impl->UnlockDevice = EMSCRIPTENAUDIO_LockOrUnlockDeviceWithNoMixerLock; impl->LockDevice = impl->UnlockDevice = EMSCRIPTENAUDIO_LockOrUnlockDeviceWithNoMixerLock;
impl->ProvidesOwnCallbackThread = SDL_TRUE; impl->ProvidesOwnCallbackThread = SDL_TRUE;
/* *INDENT-OFF* */ /* clang-format off */
/* check availability */ /* check availability */
available = MAIN_THREAD_EM_ASM_INT({ available = MAIN_THREAD_EM_ASM_INT({
if (typeof(AudioContext) !== 'undefined') { if (typeof(AudioContext) !== 'undefined') {
@@ -371,11 +375,13 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
} }
return false; return false;
}); });
/* *INDENT-ON* */ /* clang-format on */
if (!available) { if (!available) {
SDL_SetError("No audio context available"); SDL_SetError("No audio context available");
} }
/* *INDENT-OFF* */ /* clang-format off */
capture_available = available && MAIN_THREAD_EM_ASM_INT({ capture_available = available && MAIN_THREAD_EM_ASM_INT({
if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) { if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
return true; return true;
@@ -384,6 +390,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
} }
return false; return false;
}); });
/* *INDENT-ON* */ /* clang-format on */
impl->HasCaptureSupport = capture_available ? SDL_TRUE : SDL_FALSE; impl->HasCaptureSupport = capture_available ? SDL_TRUE : SDL_FALSE;
impl->OnlyHasDefaultCaptureDevice = capture_available ? SDL_TRUE : SDL_FALSE; impl->OnlyHasDefaultCaptureDevice = capture_available ? SDL_TRUE : SDL_FALSE;

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this #define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -41,8 +41,7 @@ extern "C"
/* !!! FIXME: have the callback call the higher level to avoid code dupe. */ /* !!! FIXME: have the callback call the higher level to avoid code dupe. */
/* The Haiku callback for handling the audio buffer */ /* The Haiku callback for handling the audio buffer */
static void static void FillSound(void *device, void *stream, size_t len,
FillSound(void *device, void *stream, size_t len,
const media_raw_audio_format & format) const media_raw_audio_format & format)
{ {
SDL_AudioDevice *audio = (SDL_AudioDevice *) device; SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
@@ -84,8 +83,7 @@ FillSound(void *device, void *stream, size_t len,
SDL_UnlockMutex(audio->mixer_lock); SDL_UnlockMutex(audio->mixer_lock);
} }
static void static void HAIKUAUDIO_CloseDevice(_THIS)
HAIKUAUDIO_CloseDevice(_THIS)
{ {
if (_this->hidden->audio_obj) { if (_this->hidden->audio_obj) {
_this->hidden->audio_obj->Stop(); _this->hidden->audio_obj->Stop();
@@ -99,8 +97,7 @@ static const int sig_list[] = {
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
}; };
static inline void static inline void MaskSignals(sigset_t * omask)
MaskSignals(sigset_t * omask)
{ {
sigset_t mask; sigset_t mask;
int i; int i;
@@ -112,15 +109,13 @@ MaskSignals(sigset_t * omask)
sigprocmask(SIG_BLOCK, &mask, omask); sigprocmask(SIG_BLOCK, &mask, omask);
} }
static inline void static inline void UnmaskSignals(sigset_t * omask)
UnmaskSignals(sigset_t * omask)
{ {
sigprocmask(SIG_SETMASK, omask, NULL); sigprocmask(SIG_SETMASK, omask, NULL);
} }
static int static int HAIKUAUDIO_OpenDevice(_THIS, const char *devname)
HAIKUAUDIO_OpenDevice(_THIS, const char *devname)
{ {
media_raw_audio_format format; media_raw_audio_format format;
SDL_AudioFormat test_format; SDL_AudioFormat test_format;
@@ -207,14 +202,12 @@ HAIKUAUDIO_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static void static void HAIKUAUDIO_Deinitialize(void)
HAIKUAUDIO_Deinitialize(void)
{ {
SDL_QuitBeApp(); SDL_QuitBeApp();
} }
static SDL_bool static SDL_bool HAIKUAUDIO_Init(SDL_AudioDriverImpl * impl)
HAIKUAUDIO_Init(SDL_AudioDriverImpl * impl)
{ {
/* Initialize the Be Application, if it's not already started */ /* Initialize the Be Application, if it's not already started */
if (SDL_InitBeApp() < 0) { if (SDL_InitBeApp() < 0) {

View File

@@ -26,7 +26,7 @@
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
/* Hidden "this" pointer for the audio functions */ /* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *_this #define _THIS SDL_AudioDevice *_this
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {

View File

@@ -26,36 +26,33 @@
#include "SDL_jackaudio.h" #include "SDL_jackaudio.h"
#include "../../thread/SDL_systhread.h" #include "../../thread/SDL_systhread.h"
static jack_client_t *(*JACK_jack_client_open)(const char *, jack_options_t, jack_status_t *, ...);
static jack_client_t * (*JACK_jack_client_open) (const char *, jack_options_t, jack_status_t *, ...); static int (*JACK_jack_client_close)(jack_client_t *);
static int (*JACK_jack_client_close) (jack_client_t *); static void (*JACK_jack_on_shutdown)(jack_client_t *, JackShutdownCallback, void *);
static void (*JACK_jack_on_shutdown) (jack_client_t *, JackShutdownCallback, void *); static int (*JACK_jack_activate)(jack_client_t *);
static int (*JACK_jack_activate) (jack_client_t *); static int (*JACK_jack_deactivate)(jack_client_t *);
static int (*JACK_jack_deactivate) (jack_client_t *); static void *(*JACK_jack_port_get_buffer)(jack_port_t *, jack_nframes_t);
static void * (*JACK_jack_port_get_buffer) (jack_port_t *, jack_nframes_t); static int (*JACK_jack_port_unregister)(jack_client_t *, jack_port_t *);
static int (*JACK_jack_port_unregister) (jack_client_t *, jack_port_t *); static void (*JACK_jack_free)(void *);
static void (*JACK_jack_free) (void *); static const char **(*JACK_jack_get_ports)(jack_client_t *, const char *, const char *, unsigned long);
static const char ** (*JACK_jack_get_ports) (jack_client_t *, const char *, const char *, unsigned long); static jack_nframes_t (*JACK_jack_get_sample_rate)(jack_client_t *);
static jack_nframes_t (*JACK_jack_get_sample_rate) (jack_client_t *); static jack_nframes_t (*JACK_jack_get_buffer_size)(jack_client_t *);
static jack_nframes_t (*JACK_jack_get_buffer_size) (jack_client_t *); static jack_port_t *(*JACK_jack_port_register)(jack_client_t *, const char *, const char *, unsigned long, unsigned long);
static jack_port_t * (*JACK_jack_port_register) (jack_client_t *, const char *, const char *, unsigned long, unsigned long); static jack_port_t *(*JACK_jack_port_by_name)(jack_client_t *, const char *);
static jack_port_t * (*JACK_jack_port_by_name) (jack_client_t *, const char *); static const char *(*JACK_jack_port_name)(const jack_port_t *);
static const char * (*JACK_jack_port_name) (const jack_port_t *); static const char *(*JACK_jack_port_type)(const jack_port_t *);
static const char * (*JACK_jack_port_type) (const jack_port_t *); static int (*JACK_jack_connect)(jack_client_t *, const char *, const char *);
static int (*JACK_jack_connect) (jack_client_t *, const char *, const char *); static int (*JACK_jack_set_process_callback)(jack_client_t *, JackProcessCallback, void *);
static int (*JACK_jack_set_process_callback) (jack_client_t *, JackProcessCallback, void *);
static int load_jack_syms(void); static int load_jack_syms(void);
#ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC #ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC
static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC; static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC;
static void *jack_handle = NULL; static void *jack_handle = NULL;
/* !!! FIXME: this is copy/pasted in several places now */ /* !!! FIXME: this is copy/pasted in several places now */
static int static int load_jack_sym(const char *fn, void **addr)
load_jack_sym(const char *fn, void **addr)
{ {
*addr = SDL_LoadFunction(jack_handle, fn); *addr = SDL_LoadFunction(jack_handle, fn);
if (*addr == NULL) { if (*addr == NULL) {
@@ -67,11 +64,11 @@ load_jack_sym(const char *fn, void **addr)
} }
/* cast funcs to char* first, to please GCC's strict aliasing rules. */ /* cast funcs to char* first, to please GCC's strict aliasing rules. */
#define SDL_JACK_SYM(x) \ #define SDL_JACK_SYM(x) \
if (!load_jack_sym(#x, (void **) (char *) &JACK_##x)) return -1 if (!load_jack_sym(#x, (void **)(char *)&JACK_##x)) \
return -1
static void static void UnloadJackLibrary(void)
UnloadJackLibrary(void)
{ {
if (jack_handle != NULL) { if (jack_handle != NULL) {
SDL_UnloadObject(jack_handle); SDL_UnloadObject(jack_handle);
@@ -79,8 +76,7 @@ UnloadJackLibrary(void)
} }
} }
static int static int LoadJackLibrary(void)
LoadJackLibrary(void)
{ {
int retval = 0; int retval = 0;
if (jack_handle == NULL) { if (jack_handle == NULL) {
@@ -102,13 +98,11 @@ LoadJackLibrary(void)
#define SDL_JACK_SYM(x) JACK_##x = x #define SDL_JACK_SYM(x) JACK_##x = x
static void static void UnloadJackLibrary(void)
UnloadJackLibrary(void)
{ {
} }
static int static int LoadJackLibrary(void)
LoadJackLibrary(void)
{ {
load_jack_syms(); load_jack_syms();
return 0; return 0;
@@ -116,9 +110,7 @@ LoadJackLibrary(void)
#endif /* SDL_AUDIO_DRIVER_JACK_DYNAMIC */ #endif /* SDL_AUDIO_DRIVER_JACK_DYNAMIC */
static int load_jack_syms(void)
static int
load_jack_syms(void)
{ {
SDL_JACK_SYM(jack_client_open); SDL_JACK_SYM(jack_client_open);
SDL_JACK_SYM(jack_client_close); SDL_JACK_SYM(jack_client_close);
@@ -140,23 +132,20 @@ load_jack_syms(void)
return 0; return 0;
} }
static void jackShutdownCallback(void *arg) /* JACK went away; device is lost. */
static void
jackShutdownCallback(void *arg) /* JACK went away; device is lost. */
{ {
SDL_AudioDevice *this = (SDL_AudioDevice *) arg; SDL_AudioDevice *this = (SDL_AudioDevice *)arg;
SDL_OpenedAudioDeviceDisconnected(this); SDL_OpenedAudioDeviceDisconnected(this);
SDL_SemPost(this->hidden->iosem); /* unblock the SDL thread. */ SDL_SemPost(this->hidden->iosem); /* unblock the SDL thread. */
} }
// !!! FIXME: implement and register these! // !!! FIXME: implement and register these!
//typedef int(* JackSampleRateCallback)(jack_nframes_t nframes, void *arg) // typedef int(* JackSampleRateCallback)(jack_nframes_t nframes, void *arg)
//typedef int(* JackBufferSizeCallback)(jack_nframes_t nframes, void *arg) // typedef int(* JackBufferSizeCallback)(jack_nframes_t nframes, void *arg)
static int static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
{ {
SDL_AudioDevice *this = (SDL_AudioDevice *) arg; SDL_AudioDevice *this = (SDL_AudioDevice *)arg;
jack_port_t **ports = this->hidden->sdlports; jack_port_t **ports = this->hidden->sdlports;
const int total_channels = this->spec.channels; const int total_channels = this->spec.channels;
const int total_frames = this->spec.samples; const int total_frames = this->spec.samples;
@@ -168,9 +157,9 @@ jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
} }
for (channelsi = 0; channelsi < total_channels; channelsi++) { for (channelsi = 0; channelsi < total_channels; channelsi++) {
float *dst = (float *) JACK_jack_port_get_buffer(ports[channelsi], nframes); float *dst = (float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
if (dst) { if (dst) {
const float *src = ((float *) this->hidden->iobuffer) + channelsi; const float *src = ((float *)this->hidden->iobuffer) + channelsi;
int framesi; int framesi;
for (framesi = 0; framesi < total_frames; framesi++) { for (framesi = 0; framesi < total_frames; framesi++) {
*(dst++) = *src; *(dst++) = *src;
@@ -179,14 +168,12 @@ jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
} }
} }
SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; refill the buffer. */ SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; refill the buffer. */
return 0; /* success */ return 0;
} }
/* This function waits until it is possible to write a full sound buffer */ /* This function waits until it is possible to write a full sound buffer */
static void static void JACK_WaitDevice(_THIS)
JACK_WaitDevice(_THIS)
{ {
if (SDL_AtomicGet(&this->enabled)) { if (SDL_AtomicGet(&this->enabled)) {
if (SDL_SemWait(this->hidden->iosem) == -1) { if (SDL_SemWait(this->hidden->iosem) == -1) {
@@ -195,27 +182,24 @@ JACK_WaitDevice(_THIS)
} }
} }
static Uint8 * static Uint8 *JACK_GetDeviceBuf(_THIS)
JACK_GetDeviceBuf(_THIS)
{ {
return (Uint8 *) this->hidden->iobuffer; return (Uint8 *)this->hidden->iobuffer;
} }
static int jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
static int
jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
{ {
SDL_AudioDevice *this = (SDL_AudioDevice *) arg; SDL_AudioDevice *this = (SDL_AudioDevice *)arg;
if (SDL_AtomicGet(&this->enabled)) { if (SDL_AtomicGet(&this->enabled)) {
jack_port_t **ports = this->hidden->sdlports; jack_port_t **ports = this->hidden->sdlports;
const int total_channels = this->spec.channels; const int total_channels = this->spec.channels;
const int total_frames = this->spec.samples; const int total_frames = this->spec.samples;
int channelsi; int channelsi;
for (channelsi = 0; channelsi < total_channels; channelsi++) { for (channelsi = 0; channelsi < total_channels; channelsi++) {
const float *src = (const float *) JACK_jack_port_get_buffer(ports[channelsi], nframes); const float *src = (const float *)JACK_jack_port_get_buffer(ports[channelsi], nframes);
if (src) { if (src) {
float *dst = ((float *) this->hidden->iobuffer) + channelsi; float *dst = ((float *)this->hidden->iobuffer) + channelsi;
int framesi; int framesi;
for (framesi = 0; framesi < total_frames; framesi++) { for (framesi = 0; framesi < total_frames; framesi++) {
*dst = *(src++); *dst = *(src++);
@@ -225,14 +209,13 @@ jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
} }
} }
SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; new buffer is ready! */ SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; new buffer is ready! */
return 0; /* success */ return 0;
} }
static int static int JACK_CaptureFromDevice(_THIS, void *buffer, int buflen)
JACK_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
SDL_assert(buflen == this->spec.size); /* we always fill a full buffer. */ SDL_assert(buflen == this->spec.size); /* we always fill a full buffer. */
/* Wait for JACK to fill the iobuffer */ /* Wait for JACK to fill the iobuffer */
if (SDL_SemWait(this->hidden->iosem) == -1) { if (SDL_SemWait(this->hidden->iosem) == -1) {
@@ -243,15 +226,12 @@ JACK_CaptureFromDevice(_THIS, void *buffer, int buflen)
return buflen; return buflen;
} }
static void static void JACK_FlushCapture(_THIS)
JACK_FlushCapture(_THIS)
{ {
SDL_SemWait(this->hidden->iosem); SDL_SemWait(this->hidden->iosem);
} }
static void JACK_CloseDevice(_THIS)
static void
JACK_CloseDevice(_THIS)
{ {
if (this->hidden->client) { if (this->hidden->client) {
JACK_jack_deactivate(this->hidden->client); JACK_jack_deactivate(this->hidden->client);
@@ -276,8 +256,7 @@ JACK_CloseDevice(_THIS)
SDL_free(this->hidden); SDL_free(this->hidden);
} }
static int static int JACK_OpenDevice(_THIS, const char *devname)
JACK_OpenDevice(_THIS, const char *devname)
{ {
/* Note that JACK uses "output" for capture devices (they output audio /* Note that JACK uses "output" for capture devices (they output audio
data to us) and "input" for playback (we input audio data to them). data to us) and "input" for playback (we input audio data to them).
@@ -297,7 +276,7 @@ JACK_OpenDevice(_THIS, const char *devname)
int i; int i;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof (*this->hidden)); this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*this->hidden));
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -325,7 +304,7 @@ JACK_OpenDevice(_THIS, const char *devname)
const char *type = JACK_jack_port_type(dport); const char *type = JACK_jack_port_type(dport);
const int len = SDL_strlen(type); const int len = SDL_strlen(type);
/* See if type ends with "audio" */ /* See if type ends with "audio" */
if (len >= 5 && !SDL_memcmp(type+len-5, "audio", 5)) { if (len >= 5 && !SDL_memcmp(type + len - 5, "audio", 5)) {
audio_ports[channels++] = i; audio_ports[channels++] = i;
} }
} }
@@ -333,7 +312,6 @@ JACK_OpenDevice(_THIS, const char *devname)
return SDL_SetError("No physical JACK ports available"); return SDL_SetError("No physical JACK ports available");
} }
/* !!! FIXME: docs say about buffer size: "This size may change, clients that depend on it must register a bufsize_callback so they will be notified if it does." */ /* !!! FIXME: docs say about buffer size: "This size may change, clients that depend on it must register a bufsize_callback so they will be notified if it does." */
/* Jack pretty much demands what it wants. */ /* Jack pretty much demands what it wants. */
@@ -346,23 +324,23 @@ JACK_OpenDevice(_THIS, const char *devname)
this->hidden->iosem = SDL_CreateSemaphore(0); this->hidden->iosem = SDL_CreateSemaphore(0);
if (!this->hidden->iosem) { if (!this->hidden->iosem) {
return -1; /* error was set by SDL_CreateSemaphore */ return -1; /* error was set by SDL_CreateSemaphore */
} }
this->hidden->iobuffer = (float *) SDL_calloc(1, this->spec.size); this->hidden->iobuffer = (float *)SDL_calloc(1, this->spec.size);
if (!this->hidden->iobuffer) { if (!this->hidden->iobuffer) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
/* Build SDL's ports, which we will connect to the device ports. */ /* Build SDL's ports, which we will connect to the device ports. */
this->hidden->sdlports = (jack_port_t **) SDL_calloc(channels, sizeof (jack_port_t *)); this->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *));
if (this->hidden->sdlports == NULL) { if (this->hidden->sdlports == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
for (i = 0; i < channels; i++) { for (i = 0; i < channels; i++) {
char portname[32]; char portname[32];
SDL_snprintf(portname, sizeof (portname), "sdl_jack_%s_%d", sdlportstr, i); SDL_snprintf(portname, sizeof(portname), "sdl_jack_%s_%d", sdlportstr, i);
this->hidden->sdlports[i] = JACK_jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, sdlportflags, 0); this->hidden->sdlports[i] = JACK_jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, sdlportflags, 0);
if (this->hidden->sdlports[i] == NULL) { if (this->hidden->sdlports[i] == NULL) {
return SDL_SetError("jack_port_register failed"); return SDL_SetError("jack_port_register failed");
@@ -397,14 +375,12 @@ JACK_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static void static void JACK_Deinitialize(void)
JACK_Deinitialize(void)
{ {
UnloadJackLibrary(); UnloadJackLibrary();
} }
static SDL_bool static SDL_bool JACK_Init(SDL_AudioDriverImpl *impl)
JACK_Init(SDL_AudioDriverImpl * impl)
{ {
if (LoadJackLibrary() < 0) { if (LoadJackLibrary() < 0) {
return SDL_FALSE; return SDL_FALSE;
@@ -431,7 +407,7 @@ JACK_Init(SDL_AudioDriverImpl * impl)
impl->OnlyHasDefaultCaptureDevice = SDL_TRUE; impl->OnlyHasDefaultCaptureDevice = SDL_TRUE;
impl->HasCaptureSupport = SDL_TRUE; impl->HasCaptureSupport = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */ return SDL_TRUE; /* this audio target is available. */
} }
AudioBootStrap JACK_bootstrap = { AudioBootStrap JACK_bootstrap = {

View File

@@ -22,7 +22,6 @@
#ifdef SDL_AUDIO_DRIVER_N3DS #ifdef SDL_AUDIO_DRIVER_N3DS
/* N3DS Audio driver */ /* N3DS Audio driver */
#include "../SDL_sysaudio.h" #include "../SDL_sysaudio.h"
@@ -36,32 +35,27 @@ static SDL_AudioDevice *audio_device;
static void FreePrivateData(_THIS); static void FreePrivateData(_THIS);
static int FindAudioFormat(_THIS); static int FindAudioFormat(_THIS);
static SDL_INLINE void static SDL_INLINE void contextLock(_THIS)
contextLock(_THIS)
{ {
LightLock_Lock(&this->hidden->lock); LightLock_Lock(&this->hidden->lock);
} }
static SDL_INLINE void static SDL_INLINE void contextUnlock(_THIS)
contextUnlock(_THIS)
{ {
LightLock_Unlock(&this->hidden->lock); LightLock_Unlock(&this->hidden->lock);
} }
static void static void N3DSAUD_LockAudio(_THIS)
N3DSAUD_LockAudio(_THIS)
{ {
contextLock(this); contextLock(this);
} }
static void static void N3DSAUD_UnlockAudio(_THIS)
N3DSAUD_UnlockAudio(_THIS)
{ {
contextUnlock(this); contextUnlock(this);
} }
static void static void N3DSAUD_DspHook(DSP_HookType hook)
N3DSAUD_DspHook(DSP_HookType hook)
{ {
if (hook == DSPHOOK_ONCANCEL) { if (hook == DSPHOOK_ONCANCEL) {
contextLock(audio_device); contextLock(audio_device);
@@ -72,12 +66,11 @@ N3DSAUD_DspHook(DSP_HookType hook)
} }
} }
static void static void AudioFrameFinished(void *device)
AudioFrameFinished(void *device)
{ {
bool shouldBroadcast = false; bool shouldBroadcast = false;
unsigned i; unsigned i;
SDL_AudioDevice *this = (SDL_AudioDevice *) device; SDL_AudioDevice *this = (SDL_AudioDevice *)device;
contextLock(this); contextLock(this);
@@ -95,13 +88,12 @@ AudioFrameFinished(void *device)
contextUnlock(this); contextUnlock(this);
} }
static int static int N3DSAUDIO_OpenDevice(_THIS, const char *devname)
N3DSAUDIO_OpenDevice(_THIS, const char *devname)
{ {
Result ndsp_init_res; Result ndsp_init_res;
Uint8 *data_vaddr; Uint8 *data_vaddr;
float mix[12]; float mix[12];
this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof *this->hidden); this->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof *this->hidden);
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@@ -140,14 +132,14 @@ N3DSAUDIO_OpenDevice(_THIS, const char *devname)
} }
this->hidden->mixlen = this->spec.size; this->hidden->mixlen = this->spec.size;
this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->spec.size); this->hidden->mixbuf = (Uint8 *)SDL_malloc(this->spec.size);
if (this->hidden->mixbuf == NULL) { if (this->hidden->mixbuf == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
data_vaddr = (Uint8 *) linearAlloc(this->hidden->mixlen * NUM_BUFFERS); data_vaddr = (Uint8 *)linearAlloc(this->hidden->mixlen * NUM_BUFFERS);
if (data_vaddr == NULL) { if (data_vaddr == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
@@ -186,8 +178,7 @@ N3DSAUDIO_OpenDevice(_THIS, const char *devname)
return 0; return 0;
} }
static int static int N3DSAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
N3DSAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
{ {
/* Delay to make this sort of simulate real audio input. */ /* Delay to make this sort of simulate real audio input. */
SDL_Delay((this->spec.samples * 1000) / this->spec.freq); SDL_Delay((this->spec.samples * 1000) / this->spec.freq);
@@ -197,8 +188,7 @@ N3DSAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
return buflen; return buflen;
} }
static void static void N3DSAUDIO_PlayDevice(_THIS)
N3DSAUDIO_PlayDevice(_THIS)
{ {
size_t nextbuf; size_t nextbuf;
size_t sampleLen; size_t sampleLen;
@@ -217,15 +207,14 @@ N3DSAUDIO_PlayDevice(_THIS)
contextUnlock(this); contextUnlock(this);
memcpy((void *) this->hidden->waveBuf[nextbuf].data_vaddr, memcpy((void *)this->hidden->waveBuf[nextbuf].data_vaddr,
this->hidden->mixbuf, sampleLen); this->hidden->mixbuf, sampleLen);
DSP_FlushDataCache(this->hidden->waveBuf[nextbuf].data_vaddr, sampleLen); DSP_FlushDataCache(this->hidden->waveBuf[nextbuf].data_vaddr, sampleLen);
ndspChnWaveBufAdd(0, &this->hidden->waveBuf[nextbuf]); ndspChnWaveBufAdd(0, &this->hidden->waveBuf[nextbuf]);
} }
static void static void N3DSAUDIO_WaitDevice(_THIS)
N3DSAUDIO_WaitDevice(_THIS)
{ {
contextLock(this); contextLock(this);
while (!this->hidden->isCancelled && while (!this->hidden->isCancelled &&
@@ -235,14 +224,12 @@ N3DSAUDIO_WaitDevice(_THIS)
contextUnlock(this); contextUnlock(this);
} }
static Uint8 * static Uint8 *N3DSAUDIO_GetDeviceBuf(_THIS)
N3DSAUDIO_GetDeviceBuf(_THIS)
{ {
return this->hidden->mixbuf; return this->hidden->mixbuf;
} }
static void static void N3DSAUDIO_CloseDevice(_THIS)
N3DSAUDIO_CloseDevice(_THIS)
{ {
contextLock(this); contextLock(this);
@@ -262,8 +249,7 @@ N3DSAUDIO_CloseDevice(_THIS)
FreePrivateData(this); FreePrivateData(this);
} }
static void static void N3DSAUDIO_ThreadInit(_THIS)
N3DSAUDIO_ThreadInit(_THIS)
{ {
s32 current_priority; s32 current_priority;
svcGetThreadPriority(&current_priority, CUR_THREAD_HANDLE); svcGetThreadPriority(&current_priority, CUR_THREAD_HANDLE);
@@ -273,8 +259,7 @@ N3DSAUDIO_ThreadInit(_THIS)
svcSetThreadPriority(CUR_THREAD_HANDLE, current_priority); svcSetThreadPriority(CUR_THREAD_HANDLE, current_priority);
} }
static SDL_bool static SDL_bool N3DSAUDIO_Init(SDL_AudioDriverImpl *impl)
N3DSAUDIO_Init(SDL_AudioDriverImpl *impl)
{ {
/* Set the function pointers */ /* Set the function pointers */
impl->OpenDevice = N3DSAUDIO_OpenDevice; impl->OpenDevice = N3DSAUDIO_OpenDevice;
@@ -304,15 +289,14 @@ AudioBootStrap N3DSAUDIO_bootstrap = {
/** /**
* Cleans up all allocated memory, safe to call with null pointers * Cleans up all allocated memory, safe to call with null pointers
*/ */
static void static void FreePrivateData(_THIS)
FreePrivateData(_THIS)
{ {
if (!this->hidden) { if (!this->hidden) {
return; return;
} }
if (this->hidden->waveBuf[0].data_vaddr) { if (this->hidden->waveBuf[0].data_vaddr) {
linearFree((void *) this->hidden->waveBuf[0].data_vaddr); linearFree((void *)this->hidden->waveBuf[0].data_vaddr);
} }
if (this->hidden->mixbuf) { if (this->hidden->mixbuf) {
@@ -324,8 +308,7 @@ FreePrivateData(_THIS)
this->hidden = NULL; this->hidden = NULL;
} }
static int static int FindAudioFormat(_THIS)
FindAudioFormat(_THIS)
{ {
SDL_bool found_valid_format = SDL_FALSE; SDL_bool found_valid_format = SDL_FALSE;
Uint16 test_format = SDL_FirstAudioFormat(this->spec.format); Uint16 test_format = SDL_FirstAudioFormat(this->spec.format);

Some files were not shown because too many files have changed in this diff Show More