mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 15:47:31 +08:00
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:
+6
-5
@@ -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
|
||||||
|
|||||||
Executable
+32
@@ -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!"
|
||||||
@@ -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);
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
+23
-29
@@ -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,7 +67,6 @@ 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
|
||||||
@@ -83,18 +79,18 @@ static void SDL_AddAssertionToReport(SDL_assert_data *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,8 +139,7 @@ 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;
|
||||||
@@ -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);
|
||||||
@@ -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)
|
||||||
@@ -363,7 +358,8 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
|
|||||||
} 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,8 +367,7 @@ 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;
|
||||||
@@ -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;
|
||||||
|
|||||||
+14
-22
@@ -39,8 +39,7 @@ struct SDL_DataQueue
|
|||||||
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;
|
||||||
@@ -135,8 +131,7 @@ SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -285,7 +278,7 @@ SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
|||||||
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
|
||||||
@@ -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: */
|
||||||
|
|
||||||
|
|||||||
@@ -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: */
|
||||||
|
|
||||||
|
|||||||
+4
-10
@@ -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) {
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-6
@@ -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;
|
||||||
|
|||||||
+11
-13
@@ -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);
|
||||||
|
|||||||
+22
-18
@@ -41,8 +41,13 @@
|
|||||||
#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,44 +73,43 @@
|
|||||||
#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
|
||||||
|
|||||||
+5
-9
@@ -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;
|
||||||
|
|
||||||
@@ -61,8 +59,7 @@ SDL_ListPop(SDL_ListNode **head, void **ent)
|
|||||||
*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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
+28
-47
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
#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
|
||||||
|
|
||||||
@@ -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,8 +357,7 @@ 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__)
|
||||||
@@ -438,7 +421,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
|
|||||||
#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"));
|
||||||
@@ -446,7 +429,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} 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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
+27
-33
@@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
#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
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,9 +162,9 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
|
|||||||
#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));
|
||||||
@@ -238,7 +235,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int 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();
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-14
@@ -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
|
||||||
@@ -99,30 +100,38 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
|||||||
|
|
||||||
#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__)
|
||||||
|
|||||||
+109
-180
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -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: */
|
||||||
|
|
||||||
|
|||||||
+228
-206
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
#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));
|
||||||
|
|||||||
+405
-345
File diff suppressed because it is too large
Load Diff
+38
-50
@@ -78,13 +78,11 @@ 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
|
|
||||||
SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|
||||||
Uint32 len, int volume)
|
Uint32 len, int volume)
|
||||||
{
|
{
|
||||||
if (volume == 0) {
|
if (volume == 0) {
|
||||||
@@ -104,8 +102,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
++dst;
|
++dst;
|
||||||
++src;
|
++src;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AUDIO_S8:
|
case AUDIO_S8:
|
||||||
{
|
{
|
||||||
@@ -115,8 +112,8 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
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);
|
||||||
@@ -130,8 +127,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
++dst8;
|
++dst8;
|
||||||
++src8;
|
++src8;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AUDIO_S16LSB:
|
case AUDIO_S16LSB:
|
||||||
{
|
{
|
||||||
@@ -155,8 +151,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
*(Sint16 *)dst = SDL_SwapLE16(dst_sample);
|
*(Sint16 *)dst = SDL_SwapLE16(dst_sample);
|
||||||
dst += 2;
|
dst += 2;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AUDIO_S16MSB:
|
case AUDIO_S16MSB:
|
||||||
{
|
{
|
||||||
@@ -180,8 +175,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
*(Sint16 *)dst = SDL_SwapBE16(dst_sample);
|
*(Sint16 *)dst = SDL_SwapBE16(dst_sample);
|
||||||
dst += 2;
|
dst += 2;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AUDIO_U16LSB:
|
case AUDIO_U16LSB:
|
||||||
{
|
{
|
||||||
@@ -206,8 +200,7 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
*(Uint16 *)dst = SDL_SwapLE16(dst_sample);
|
*(Uint16 *)dst = SDL_SwapLE16(dst_sample);
|
||||||
dst += 2;
|
dst += 2;
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case AUDIO_U16MSB:
|
case AUDIO_U16MSB:
|
||||||
{
|
{
|
||||||
@@ -232,13 +225,12 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
*(Uint16 *)dst = SDL_SwapBE16(dst_sample);
|
*(Uint16 *)dst = SDL_SwapBE16(dst_sample);
|
||||||
dst += 2;
|
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;
|
||||||
@@ -246,25 +238,24 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
|
|
||||||
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;
|
||||||
@@ -272,27 +263,26 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
|
|
||||||
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? */
|
||||||
@@ -305,23 +295,22 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
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? */
|
||||||
@@ -334,16 +323,15 @@ SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
|
|||||||
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");
|
||||||
|
|||||||
+16
-19
@@ -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,7 +171,7 @@ 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;
|
||||||
|
|
||||||
|
|||||||
+63
-84
@@ -41,8 +41,7 @@
|
|||||||
* Returns 0 on success, or -1 if the multiplication overflows, in which case f1
|
* Returns 0 on success, or -1 if the multiplication overflows, in which case f1
|
||||||
* does not get modified.
|
* does not get modified.
|
||||||
*/
|
*/
|
||||||
static int
|
static int SafeMult(size_t *f1, size_t f2)
|
||||||
SafeMult(size_t *f1, size_t f2)
|
|
||||||
{
|
{
|
||||||
if (*f1 > 0 && SIZE_MAX / *f1 <= f2) {
|
if (*f1 > 0 && SIZE_MAX / *f1 <= f2) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -64,21 +63,24 @@ typedef struct ADPCM_DecoderState
|
|||||||
void *cstate; /* Decoding state for each channel. */
|
void *cstate; /* Decoding state for each channel. */
|
||||||
|
|
||||||
/* ADPCM data. */
|
/* ADPCM data. */
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
Uint8 *data;
|
Uint8 *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
} input;
|
} input;
|
||||||
|
|
||||||
/* Current ADPCM block in the ADPCM data above. */
|
/* Current ADPCM block in the ADPCM data above. */
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
Uint8 *data;
|
Uint8 *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
} block;
|
} block;
|
||||||
|
|
||||||
/* Decoded 16-bit PCM data. */
|
/* Decoded 16-bit PCM data. */
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
Sint16 *data;
|
Sint16 *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
@@ -100,8 +102,7 @@ typedef struct MS_ADPCM_ChannelState
|
|||||||
} MS_ADPCM_ChannelState;
|
} MS_ADPCM_ChannelState;
|
||||||
|
|
||||||
#ifdef SDL_WAVE_DEBUG_LOG_FORMAT
|
#ifdef SDL_WAVE_DEBUG_LOG_FORMAT
|
||||||
static void
|
static void WaveDebugLogFormat(WaveFile *file)
|
||||||
WaveDebugLogFormat(WaveFile *file)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
const char *fmtstr = "WAVE file: %s, %u Hz, %s, %u bits, %u %s/s";
|
const char *fmtstr = "WAVE file: %s, %u Hz, %s, %u bits, %u %s/s";
|
||||||
@@ -135,9 +136,14 @@ WaveDebugLogFormat(WaveFile *file)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SDL_WAVE_DEBUG_CHANNELCFG(STR, CODE) case CODE: wavechannel = STR; break;
|
#define SDL_WAVE_DEBUG_CHANNELCFG(STR, CODE) \
|
||||||
#define SDL_WAVE_DEBUG_CHANNELSTR(STR, CODE) if (format->channelmask & CODE) { \
|
case CODE: \
|
||||||
SDL_strlcat(channelstr, channelstr[0] ? "-" STR : STR, sizeof(channelstr));}
|
wavechannel = STR; \
|
||||||
|
break;
|
||||||
|
#define SDL_WAVE_DEBUG_CHANNELSTR(STR, CODE) \
|
||||||
|
if (format->channelmask & CODE) { \
|
||||||
|
SDL_strlcat(channelstr, channelstr[0] ? "-" STR : STR, sizeof(channelstr)); \
|
||||||
|
}
|
||||||
|
|
||||||
if (format->formattag == EXTENSIBLE_CODE && format->channelmask > 0) {
|
if (format->formattag == EXTENSIBLE_CODE && format->channelmask > 0) {
|
||||||
switch (format->channelmask) {
|
switch (format->channelmask) {
|
||||||
@@ -224,8 +230,7 @@ WaveDebugLogFormat(WaveFile *file)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SDL_WAVE_DEBUG_DUMP_FORMAT
|
#ifdef SDL_WAVE_DEBUG_DUMP_FORMAT
|
||||||
static void
|
static void WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, Uint32 datalen)
|
||||||
WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, Uint32 datalen)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
const char *fmtstr1 = "WAVE chunk dump:\n"
|
const char *fmtstr1 = "WAVE chunk dump:\n"
|
||||||
@@ -315,8 +320,7 @@ WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, Uint32 datale
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Sint64
|
static Sint64 WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes)
|
||||||
WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes)
|
|
||||||
{
|
{
|
||||||
if (file->fact.status == 2) {
|
if (file->fact.status == 2) {
|
||||||
if (file->facthint == FactStrict && sampleframes < file->fact.samplelength) {
|
if (file->facthint == FactStrict && sampleframes < file->fact.samplelength) {
|
||||||
@@ -329,8 +333,7 @@ WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes)
|
|||||||
return sampleframes;
|
return sampleframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
||||||
MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
const size_t blockheadersize = (size_t)file->format.channels * 7;
|
const size_t blockheadersize = (size_t)file->format.channels * 7;
|
||||||
@@ -369,8 +372,7 @@ MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int MS_ADPCM_Init(WaveFile *file, size_t datalength)
|
||||||
MS_ADPCM_Init(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
WaveChunk *chunk = &file->chunk;
|
WaveChunk *chunk = &file->chunk;
|
||||||
@@ -378,7 +380,7 @@ MS_ADPCM_Init(WaveFile *file, size_t datalength)
|
|||||||
const size_t blockdatasize = (size_t)format->blockalign - blockheadersize;
|
const size_t blockdatasize = (size_t)format->blockalign - blockheadersize;
|
||||||
const size_t blockframebitsize = (size_t)format->bitspersample * format->channels;
|
const size_t blockframebitsize = (size_t)format->bitspersample * format->channels;
|
||||||
const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
|
const size_t blockdatasamples = (blockdatasize * 8) / blockframebitsize;
|
||||||
const Sint16 presetcoeffs[14] = {256, 0, 512, -256, 0, 0, 192, 64, 240, 0, 460, -208, 392, -232};
|
const Sint16 presetcoeffs[14] = { 256, 0, 512, -256, 0, 0, 192, 64, 240, 0, 460, -208, 392, -232 };
|
||||||
size_t i, coeffcount;
|
size_t i, coeffcount;
|
||||||
MS_ADPCM_CoeffData *coeffdata;
|
MS_ADPCM_CoeffData *coeffdata;
|
||||||
|
|
||||||
@@ -488,8 +490,7 @@ MS_ADPCM_Init(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sint16
|
static Sint16 MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sample1, Sint32 sample2, Uint8 nybble)
|
||||||
MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sample1, Sint32 sample2, Uint8 nybble)
|
|
||||||
{
|
{
|
||||||
const Sint32 max_audioval = 32767;
|
const Sint32 max_audioval = 32767;
|
||||||
const Sint32 min_audioval = -32768;
|
const Sint32 min_audioval = -32768;
|
||||||
@@ -525,8 +526,7 @@ MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sample1, Sint32 sam
|
|||||||
return (Sint16)new_sample;
|
return (Sint16)new_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
||||||
MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
|
||||||
{
|
{
|
||||||
Uint8 coeffindex;
|
Uint8 coeffindex;
|
||||||
const Uint32 channels = state->channels;
|
const Uint32 channels = state->channels;
|
||||||
@@ -586,8 +586,7 @@ MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
|||||||
* will always contain full sample frames (same sample count for each channel).
|
* will always contain full sample frames (same sample count for each channel).
|
||||||
* Incomplete sample frames are discarded.
|
* Incomplete sample frames are discarded.
|
||||||
*/
|
*/
|
||||||
static int
|
static int MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
||||||
MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
|
||||||
{
|
{
|
||||||
Uint16 nybble = 0;
|
Uint16 nybble = 0;
|
||||||
Sint16 sample1, sample2;
|
Sint16 sample1, sample2;
|
||||||
@@ -634,8 +633,7 @@ MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
size_t bytesleft, outputsize;
|
size_t bytesleft, outputsize;
|
||||||
@@ -734,8 +732,7 @@ MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
||||||
IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
const size_t blockheadersize = (size_t)format->channels * 4;
|
const size_t blockheadersize = (size_t)format->channels * 4;
|
||||||
@@ -788,8 +785,7 @@ IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int IMA_ADPCM_Init(WaveFile *file, size_t datalength)
|
||||||
IMA_ADPCM_Init(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
WaveChunk *chunk = &file->chunk;
|
WaveChunk *chunk = &file->chunk;
|
||||||
@@ -854,8 +850,7 @@ IMA_ADPCM_Init(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sint16
|
static Sint16 IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
|
||||||
IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
|
|
||||||
{
|
{
|
||||||
const Sint32 max_audioval = 32767;
|
const Sint32 max_audioval = 32767;
|
||||||
const Sint32 min_audioval = -32768;
|
const Sint32 min_audioval = -32768;
|
||||||
@@ -924,12 +919,11 @@ IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble)
|
|||||||
return (Sint16)sample;
|
return (Sint16)sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
||||||
IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
|
||||||
{
|
{
|
||||||
Sint16 step;
|
Sint16 step;
|
||||||
Uint32 c;
|
Uint32 c;
|
||||||
Uint8 *cstate = (Uint8 *) state->cstate;
|
Uint8 *cstate = (Uint8 *)state->cstate;
|
||||||
|
|
||||||
for (c = 0; c < state->channels; c++) {
|
for (c = 0; c < state->channels; c++) {
|
||||||
size_t o = state->block.pos + c * 4;
|
size_t o = state->block.pos + c * 4;
|
||||||
@@ -947,7 +941,7 @@ IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
|||||||
|
|
||||||
/* Reserved byte in block header, should be 0. */
|
/* Reserved byte in block header, should be 0. */
|
||||||
if (state->block.data[o + 3] != 0) {
|
if (state->block.data[o + 3] != 0) {
|
||||||
/* Uh oh, corrupt data? Buggy code? */ ;
|
/* Uh oh, corrupt data? Buggy code? */;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -964,8 +958,7 @@ IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
|
|||||||
* contains full sample frames (same sample count for each channel).
|
* contains full sample frames (same sample count for each channel).
|
||||||
* Incomplete sample frames are discarded.
|
* Incomplete sample frames are discarded.
|
||||||
*/
|
*/
|
||||||
static int
|
static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
||||||
IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
@@ -1034,8 +1027,7 @@ IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
size_t bytesleft, outputsize;
|
size_t bytesleft, outputsize;
|
||||||
@@ -1138,8 +1130,7 @@ IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LAW_Init(WaveFile *file, size_t datalength)
|
||||||
LAW_Init(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
|
|
||||||
@@ -1167,8 +1158,7 @@ LAW_Init(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
#ifdef SDL_WAVE_LAW_LUT
|
#ifdef SDL_WAVE_LAW_LUT
|
||||||
const Sint16 alaw_lut[256] = {
|
const Sint16 alaw_lut[256] = {
|
||||||
@@ -1310,8 +1300,7 @@ LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PCM_Init(WaveFile *file, size_t datalength)
|
||||||
PCM_Init(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
|
|
||||||
@@ -1354,8 +1343,7 @@ PCM_Init(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
WaveChunk *chunk = &file->chunk;
|
WaveChunk *chunk = &file->chunk;
|
||||||
@@ -1406,8 +1394,7 @@ PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
WaveChunk *chunk = &file->chunk;
|
WaveChunk *chunk = &file->chunk;
|
||||||
@@ -1449,8 +1436,7 @@ PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WaveRiffSizeHint
|
static WaveRiffSizeHint WaveGetRiffSizeHint()
|
||||||
WaveGetRiffSizeHint()
|
|
||||||
{
|
{
|
||||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_RIFF_CHUNK_SIZE);
|
const char *hint = SDL_GetHint(SDL_HINT_WAVE_RIFF_CHUNK_SIZE);
|
||||||
|
|
||||||
@@ -1469,8 +1455,7 @@ WaveGetRiffSizeHint()
|
|||||||
return RiffSizeNoHint;
|
return RiffSizeNoHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WaveTruncationHint
|
static WaveTruncationHint WaveGetTruncationHint()
|
||||||
WaveGetTruncationHint()
|
|
||||||
{
|
{
|
||||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_TRUNCATION);
|
const char *hint = SDL_GetHint(SDL_HINT_WAVE_TRUNCATION);
|
||||||
|
|
||||||
@@ -1489,8 +1474,7 @@ WaveGetTruncationHint()
|
|||||||
return TruncNoHint;
|
return TruncNoHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WaveFactChunkHint
|
static WaveFactChunkHint WaveGetFactChunkHint()
|
||||||
WaveGetFactChunkHint()
|
|
||||||
{
|
{
|
||||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_FACT_CHUNK);
|
const char *hint = SDL_GetHint(SDL_HINT_WAVE_FACT_CHUNK);
|
||||||
|
|
||||||
@@ -1509,8 +1493,7 @@ WaveGetFactChunkHint()
|
|||||||
return FactNoHint;
|
return FactNoHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void WaveFreeChunkData(WaveChunk *chunk)
|
||||||
WaveFreeChunkData(WaveChunk *chunk)
|
|
||||||
{
|
{
|
||||||
if (chunk->data != NULL) {
|
if (chunk->data != NULL) {
|
||||||
SDL_free(chunk->data);
|
SDL_free(chunk->data);
|
||||||
@@ -1519,8 +1502,7 @@ WaveFreeChunkData(WaveChunk *chunk)
|
|||||||
chunk->size = 0;
|
chunk->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveNextChunk(SDL_RWops *src, WaveChunk *chunk)
|
||||||
WaveNextChunk(SDL_RWops *src, WaveChunk *chunk)
|
|
||||||
{
|
{
|
||||||
Uint32 chunkheader[2];
|
Uint32 chunkheader[2];
|
||||||
Sint64 nextposition = chunk->position + chunk->length;
|
Sint64 nextposition = chunk->position + chunk->length;
|
||||||
@@ -1552,8 +1534,7 @@ WaveNextChunk(SDL_RWops *src, WaveChunk *chunk)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t length)
|
||||||
WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t length)
|
|
||||||
{
|
{
|
||||||
WaveFreeChunkData(chunk);
|
WaveFreeChunkData(chunk);
|
||||||
|
|
||||||
@@ -1562,7 +1543,7 @@ WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
chunk->data = (Uint8 *) SDL_malloc(length);
|
chunk->data = (Uint8 *)SDL_malloc(length);
|
||||||
if (chunk->data == NULL) {
|
if (chunk->data == NULL) {
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
@@ -1581,30 +1562,32 @@ WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t length)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveReadChunkData(SDL_RWops *src, WaveChunk *chunk)
|
||||||
WaveReadChunkData(SDL_RWops *src, WaveChunk *chunk)
|
|
||||||
{
|
{
|
||||||
return WaveReadPartialChunkData(src, chunk, chunk->length);
|
return WaveReadPartialChunkData(src, chunk, chunk->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct WaveExtensibleGUID {
|
typedef struct WaveExtensibleGUID
|
||||||
|
{
|
||||||
Uint16 encoding;
|
Uint16 encoding;
|
||||||
Uint8 guid[16];
|
Uint8 guid[16];
|
||||||
} WaveExtensibleGUID;
|
} WaveExtensibleGUID;
|
||||||
|
|
||||||
/* Some of the GUIDs that are used by WAVEFORMATEXTENSIBLE. */
|
/* Some of the GUIDs that are used by WAVEFORMATEXTENSIBLE. */
|
||||||
#define WAVE_FORMATTAG_GUID(tag) {(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113}
|
#define WAVE_FORMATTAG_GUID(tag) \
|
||||||
|
{ \
|
||||||
|
(tag) & 0xff, (tag) >> 8, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 \
|
||||||
|
}
|
||||||
static WaveExtensibleGUID extensible_guids[] = {
|
static WaveExtensibleGUID extensible_guids[] = {
|
||||||
{PCM_CODE, WAVE_FORMATTAG_GUID(PCM_CODE)},
|
{ PCM_CODE, WAVE_FORMATTAG_GUID(PCM_CODE) },
|
||||||
{MS_ADPCM_CODE, WAVE_FORMATTAG_GUID(MS_ADPCM_CODE)},
|
{ MS_ADPCM_CODE, WAVE_FORMATTAG_GUID(MS_ADPCM_CODE) },
|
||||||
{IEEE_FLOAT_CODE, WAVE_FORMATTAG_GUID(IEEE_FLOAT_CODE)},
|
{ IEEE_FLOAT_CODE, WAVE_FORMATTAG_GUID(IEEE_FLOAT_CODE) },
|
||||||
{ALAW_CODE, WAVE_FORMATTAG_GUID(ALAW_CODE)},
|
{ ALAW_CODE, WAVE_FORMATTAG_GUID(ALAW_CODE) },
|
||||||
{MULAW_CODE, WAVE_FORMATTAG_GUID(MULAW_CODE)},
|
{ MULAW_CODE, WAVE_FORMATTAG_GUID(MULAW_CODE) },
|
||||||
{IMA_ADPCM_CODE, WAVE_FORMATTAG_GUID(IMA_ADPCM_CODE)}
|
{ IMA_ADPCM_CODE, WAVE_FORMATTAG_GUID(IMA_ADPCM_CODE) }
|
||||||
};
|
};
|
||||||
|
|
||||||
static Uint16
|
static Uint16 WaveGetFormatGUIDEncoding(WaveFormat *format)
|
||||||
WaveGetFormatGUIDEncoding(WaveFormat *format)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < SDL_arraysize(extensible_guids); i++) {
|
for (i = 0; i < SDL_arraysize(extensible_guids); i++) {
|
||||||
@@ -1615,8 +1598,7 @@ WaveGetFormatGUIDEncoding(WaveFormat *format)
|
|||||||
return UNKNOWN_CODE;
|
return UNKNOWN_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveReadFormat(WaveFile *file)
|
||||||
WaveReadFormat(WaveFile *file)
|
|
||||||
{
|
{
|
||||||
WaveChunk *chunk = &file->chunk;
|
WaveChunk *chunk = &file->chunk;
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
@@ -1677,8 +1659,7 @@ WaveReadFormat(WaveFile *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveCheckFormat(WaveFile *file, size_t datalength)
|
||||||
WaveCheckFormat(WaveFile *file, size_t datalength)
|
|
||||||
{
|
{
|
||||||
WaveFormat *format = &file->format;
|
WaveFormat *format = &file->format;
|
||||||
|
|
||||||
@@ -1785,8 +1766,7 @@ WaveCheckFormat(WaveFile *file, size_t datalength)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
|
||||||
WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
|
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
Uint32 chunkcount = 0;
|
Uint32 chunkcount = 0;
|
||||||
@@ -2148,8 +2128,7 @@ SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_b
|
|||||||
/* Since the WAV memory is allocated in the shared library, it must also
|
/* Since the WAV memory is allocated in the shared library, it must also
|
||||||
be freed here. (Necessary under Win32, VC++)
|
be freed here. (Necessary under Win32, VC++)
|
||||||
*/
|
*/
|
||||||
void
|
void SDL_FreeWAV(Uint8 *audio_buf)
|
||||||
SDL_FreeWAV(Uint8 *audio_buf)
|
|
||||||
{
|
{
|
||||||
SDL_free(audio_buf);
|
SDL_free(audio_buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ typedef struct WaveFormat
|
|||||||
} 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,
|
||||||
|
|||||||
@@ -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,10 +48,10 @@ 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);
|
||||||
@@ -60,16 +60,15 @@ static int aaudio_LoadFunctions(AAUDIO_Data *data)
|
|||||||
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,7 +113,7 @@ 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),
|
||||||
@@ -146,7 +145,7 @@ aaudio_OpenDevice(_THIS, const char *devname)
|
|||||||
/* 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,15 +198,13 @@ 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;
|
||||||
@@ -233,8 +229,7 @@ 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;
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ 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: */
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
|
||||||
|
|||||||
+111
-141
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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: */
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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 = 0; \
|
||||||
}
|
}
|
||||||
loaded = 1; /* will reset if necessary. */
|
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,15 +164,14 @@ 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
|
||||||
@@ -189,8 +184,7 @@ FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID data)
|
|||||||
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;
|
||||||
@@ -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;
|
||||||
@@ -626,9 +608,7 @@ DSOUND_OpenDevice(_THIS, const char *devname)
|
|||||||
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;
|
||||||
|
|||||||
@@ -40,14 +40,12 @@
|
|||||||
#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,8 +74,8 @@ 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();
|
||||||
}
|
}
|
||||||
@@ -169,15 +159,13 @@ DISKAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
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;
|
||||||
|
|||||||
@@ -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,7 +197,8 @@ 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");
|
||||||
}
|
}
|
||||||
@@ -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,16 +277,14 @@ 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);
|
||||||
@@ -320,7 +308,6 @@ DSP_Init(SDL_AudioDriverImpl * impl)
|
|||||||
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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -74,7 +74,7 @@ HandleAudioProcess(_THIS)
|
|||||||
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,6 +125,7 @@ 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. */
|
||||||
|
|
||||||
@@ -147,10 +148,9 @@ HandleCaptureProcess(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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!");
|
||||||
}
|
}
|
||||||
@@ -267,6 +270,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -68,10 +65,10 @@ 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;
|
||||||
@@ -180,13 +169,11 @@ 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,17 +182,14 @@ 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;
|
||||||
@@ -213,9 +197,9 @@ jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
|
|||||||
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++);
|
||||||
@@ -226,11 +210,10 @@ 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. */
|
||||||
|
|
||||||
@@ -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. */
|
||||||
@@ -349,20 +327,20 @@ JACK_OpenDevice(_THIS, const char *devname)
|
|||||||
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;
|
||||||
|
|||||||
@@ -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(¤t_priority, CUR_THREAD_HANDLE);
|
svcGetThreadPriority(¤t_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);
|
||||||
|
|||||||
@@ -43,15 +43,12 @@
|
|||||||
|
|
||||||
/* #define DEBUG_AUDIO */
|
/* #define DEBUG_AUDIO */
|
||||||
|
|
||||||
static void
|
static void NETBSDAUDIO_DetectDevices(void)
|
||||||
NETBSDAUDIO_DetectDevices(void)
|
|
||||||
{
|
{
|
||||||
SDL_EnumUnixAudioDevices(0, NULL);
|
SDL_EnumUnixAudioDevices(0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NETBSDAUDIO_Status(_THIS)
|
||||||
static void
|
|
||||||
NETBSDAUDIO_Status(_THIS)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
/* *INDENT-OFF* */ /* clang-format off */
|
/* *INDENT-OFF* */ /* clang-format off */
|
||||||
@@ -117,12 +114,11 @@ NETBSDAUDIO_Status(_THIS)
|
|||||||
this->spec.format,
|
this->spec.format,
|
||||||
this->spec.size);
|
this->spec.size);
|
||||||
/* *INDENT-ON* */ /* clang-format on */
|
/* *INDENT-ON* */ /* clang-format on */
|
||||||
|
|
||||||
#endif /* DEBUG_AUDIO */
|
#endif /* DEBUG_AUDIO */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NETBSDAUDIO_PlayDevice(_THIS)
|
||||||
static void
|
|
||||||
NETBSDAUDIO_PlayDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = this->hidden;
|
struct SDL_PrivateAudioData *h = this->hidden;
|
||||||
int written;
|
int written;
|
||||||
@@ -141,17 +137,14 @@ NETBSDAUDIO_PlayDevice(_THIS)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *
|
static Uint8 *NETBSDAUDIO_GetDeviceBuf(_THIS)
|
||||||
NETBSDAUDIO_GetDeviceBuf(_THIS)
|
|
||||||
{
|
{
|
||||||
return this->hidden->mixbuf;
|
return this->hidden->mixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
|
||||||
static int
|
|
||||||
NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
|
|
||||||
{
|
{
|
||||||
Uint8 *buffer = (Uint8 *) _buffer;
|
Uint8 *buffer = (Uint8 *)_buffer;
|
||||||
int br;
|
int br;
|
||||||
|
|
||||||
br = read(this->hidden->audio_fd, buffer, buflen);
|
br = read(this->hidden->audio_fd, buffer, buflen);
|
||||||
@@ -167,8 +160,7 @@ NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void NETBSDAUDIO_FlushCapture(_THIS)
|
||||||
NETBSDAUDIO_FlushCapture(_THIS)
|
|
||||||
{
|
{
|
||||||
audio_info_t info;
|
audio_info_t info;
|
||||||
size_t remain;
|
size_t remain;
|
||||||
@@ -178,9 +170,9 @@ NETBSDAUDIO_FlushCapture(_THIS)
|
|||||||
return; /* oh well. */
|
return; /* oh well. */
|
||||||
}
|
}
|
||||||
|
|
||||||
remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
|
remain = (size_t)(info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
|
||||||
while (remain > 0) {
|
while (remain > 0) {
|
||||||
const size_t len = SDL_min(sizeof (buf), remain);
|
const size_t len = SDL_min(sizeof(buf), remain);
|
||||||
const int br = read(this->hidden->audio_fd, buf, len);
|
const int br = read(this->hidden->audio_fd, buf, len);
|
||||||
if (br <= 0) {
|
if (br <= 0) {
|
||||||
return; /* oh well. */
|
return; /* oh well. */
|
||||||
@@ -189,8 +181,7 @@ NETBSDAUDIO_FlushCapture(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void NETBSDAUDIO_CloseDevice(_THIS)
|
||||||
NETBSDAUDIO_CloseDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
if (this->hidden->audio_fd >= 0) {
|
if (this->hidden->audio_fd >= 0) {
|
||||||
close(this->hidden->audio_fd);
|
close(this->hidden->audio_fd);
|
||||||
@@ -199,8 +190,7 @@ NETBSDAUDIO_CloseDevice(_THIS)
|
|||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int NETBSDAUDIO_OpenDevice(_THIS, const char *devname)
|
||||||
NETBSDAUDIO_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
SDL_bool iscapture = this->iscapture;
|
SDL_bool iscapture = this->iscapture;
|
||||||
SDL_AudioFormat test_format;
|
SDL_AudioFormat test_format;
|
||||||
@@ -239,8 +229,7 @@ NETBSDAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
* Use the device's native sample rate so the kernel doesn't have to
|
* Use the device's native sample rate so the kernel doesn't have to
|
||||||
* resample.
|
* resample.
|
||||||
*/
|
*/
|
||||||
this->spec.freq = iscapture ?
|
this->spec.freq = iscapture ? hwinfo.record.sample_rate : hwinfo.play.sample_rate;
|
||||||
hwinfo.record.sample_rate : hwinfo.play.sample_rate;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -305,7 +294,7 @@ NETBSDAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
if (!iscapture) {
|
if (!iscapture) {
|
||||||
/* Allocate mixing buffer */
|
/* Allocate mixing buffer */
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -318,8 +307,7 @@ NETBSDAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool NETBSDAUDIO_Init(SDL_AudioDriverImpl *impl)
|
||||||
NETBSDAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->DetectDevices = NETBSDAUDIO_DetectDevices;
|
impl->DetectDevices = NETBSDAUDIO_DetectDevices;
|
||||||
@@ -336,7 +324,6 @@ NETBSDAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|||||||
return SDL_TRUE; /* this audio target is available. */
|
return SDL_TRUE; /* this audio target is available. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AudioBootStrap NETBSDAUDIO_bootstrap = {
|
AudioBootStrap NETBSDAUDIO_bootstrap = {
|
||||||
"netbsd", "NetBSD audio", NETBSDAUDIO_Init, SDL_FALSE
|
"netbsd", "NetBSD audio", NETBSDAUDIO_Init, SDL_FALSE
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,8 +38,8 @@
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define LOG_TAG "SDL_openslES"
|
#define LOG_TAG "SDL_openslES"
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||||
//#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
|
//#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
|
||||||
#define LOGV(...)
|
#define LOGV(...)
|
||||||
#else
|
#else
|
||||||
@@ -127,8 +127,7 @@ static void openslES_DestroyEngine(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int openslES_CreateEngine(void)
|
||||||
openslES_CreateEngine(void)
|
|
||||||
{
|
{
|
||||||
const SLInterfaceID ids[1] = { SL_IID_VOLUME };
|
const SLInterfaceID ids[1] = { SL_IID_VOLUME };
|
||||||
const SLboolean req[1] = { SL_BOOLEAN_FALSE };
|
const SLboolean req[1] = { SL_BOOLEAN_FALSE };
|
||||||
@@ -182,17 +181,15 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* this callback handler is called every time a buffer finishes recording */
|
/* this callback handler is called every time a buffer finishes recording */
|
||||||
static void
|
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||||
bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context;
|
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *)context;
|
||||||
|
|
||||||
LOGV("SLES: Recording Callback");
|
LOGV("SLES: Recording Callback");
|
||||||
SDL_SemPost(audiodata->playsem);
|
SDL_SemPost(audiodata->playsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void openslES_DestroyPCMRecorder(_THIS)
|
||||||
openslES_DestroyPCMRecorder(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLresult result;
|
SLresult result;
|
||||||
@@ -223,8 +220,7 @@ openslES_DestroyPCMRecorder(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int openslES_CreatePCMRecorder(_THIS)
|
||||||
openslES_CreatePCMRecorder(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLDataFormat_PCM format_pcm;
|
SLDataFormat_PCM format_pcm;
|
||||||
@@ -322,7 +318,7 @@ openslES_CreatePCMRecorder(_THIS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the sound buffers */
|
/* Create the sound buffers */
|
||||||
audiodata->mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * this->spec.size);
|
||||||
if (audiodata->mixbuff == NULL) {
|
if (audiodata->mixbuff == NULL) {
|
||||||
LOGE("mixbuffer allocate - out of memory");
|
LOGE("mixbuffer allocate - out of memory");
|
||||||
goto failed;
|
goto failed;
|
||||||
@@ -362,17 +358,15 @@ failed:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* this callback handler is called every time a buffer finishes playing */
|
/* this callback handler is called every time a buffer finishes playing */
|
||||||
static void
|
static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||||
bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) context;
|
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *)context;
|
||||||
|
|
||||||
LOGV("SLES: Playback Callback");
|
LOGV("SLES: Playback Callback");
|
||||||
SDL_SemPost(audiodata->playsem);
|
SDL_SemPost(audiodata->playsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void openslES_DestroyPCMPlayer(_THIS)
|
||||||
openslES_DestroyPCMPlayer(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLresult result;
|
SLresult result;
|
||||||
@@ -404,8 +398,7 @@ openslES_DestroyPCMPlayer(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int openslES_CreatePCMPlayer(_THIS)
|
||||||
openslES_CreatePCMPlayer(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq;
|
SLDataLocator_AndroidSimpleBufferQueue loc_bufq;
|
||||||
@@ -433,7 +426,7 @@ openslES_CreatePCMPlayer(_THIS)
|
|||||||
|
|
||||||
if (!test_format) {
|
if (!test_format) {
|
||||||
/* Didn't find a compatible format : */
|
/* Didn't find a compatible format : */
|
||||||
LOGI( "No compatible audio format, using signed 16-bit audio" );
|
LOGI("No compatible audio format, using signed 16-bit audio");
|
||||||
test_format = AUDIO_S16SYS;
|
test_format = AUDIO_S16SYS;
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
@@ -465,8 +458,7 @@ openslES_CreatePCMPlayer(_THIS)
|
|||||||
format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
|
format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this->spec.channels)
|
switch (this->spec.channels) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT;
|
format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT;
|
||||||
break;
|
break;
|
||||||
@@ -511,7 +503,7 @@ openslES_CreatePCMPlayer(_THIS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
audioSrc.pLocator = &loc_bufq;
|
audioSrc.pLocator = &loc_bufq;
|
||||||
audioSrc.pFormat = SDL_AUDIO_ISFLOAT(this->spec.format) ? (void*)&format_pcm_ex : (void*)&format_pcm;
|
audioSrc.pFormat = SDL_AUDIO_ISFLOAT(this->spec.format) ? (void *)&format_pcm_ex : (void *)&format_pcm;
|
||||||
|
|
||||||
/* configure audio sink */
|
/* configure audio sink */
|
||||||
loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
|
loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
|
||||||
@@ -572,7 +564,7 @@ openslES_CreatePCMPlayer(_THIS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the sound buffers */
|
/* Create the sound buffers */
|
||||||
audiodata->mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * this->spec.size);
|
||||||
if (audiodata->mixbuff == NULL) {
|
if (audiodata->mixbuff == NULL) {
|
||||||
LOGE("mixbuffer allocate - out of memory");
|
LOGE("mixbuffer allocate - out of memory");
|
||||||
goto failed;
|
goto failed;
|
||||||
@@ -595,10 +587,9 @@ failed:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int openslES_OpenDevice(_THIS, const char *devname)
|
||||||
openslES_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -624,12 +615,10 @@ openslES_OpenDevice(_THIS, const char *devname)
|
|||||||
} else {
|
} else {
|
||||||
return SDL_SetError("Open device failed!");
|
return SDL_SetError("Open device failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void openslES_WaitDevice(_THIS)
|
||||||
openslES_WaitDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
|
|
||||||
@@ -639,8 +628,7 @@ openslES_WaitDevice(_THIS)
|
|||||||
SDL_SemWait(audiodata->playsem);
|
SDL_SemWait(audiodata->playsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void openslES_PlayDevice(_THIS)
|
||||||
openslES_PlayDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLresult result;
|
SLresult result;
|
||||||
@@ -674,8 +662,7 @@ openslES_PlayDevice(_THIS)
|
|||||||
/* */
|
/* */
|
||||||
/* okay.. */
|
/* okay.. */
|
||||||
|
|
||||||
static Uint8 *
|
static Uint8 *openslES_GetDeviceBuf(_THIS)
|
||||||
openslES_GetDeviceBuf(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
|
|
||||||
@@ -683,8 +670,7 @@ openslES_GetDeviceBuf(_THIS)
|
|||||||
return audiodata->pmixbuff[audiodata->next_buffer];
|
return audiodata->pmixbuff[audiodata->next_buffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int openslES_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
||||||
openslES_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
struct SDL_PrivateAudioData *audiodata = this->hidden;
|
||||||
SLresult result;
|
SLresult result;
|
||||||
@@ -711,8 +697,7 @@ openslES_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|||||||
return this->spec.size;
|
return this->spec.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void openslES_CloseDevice(_THIS)
|
||||||
openslES_CloseDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
/* struct SDL_PrivateAudioData *audiodata = this->hidden; */
|
/* struct SDL_PrivateAudioData *audiodata = this->hidden; */
|
||||||
|
|
||||||
@@ -727,8 +712,7 @@ openslES_CloseDevice(_THIS)
|
|||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool openslES_Init(SDL_AudioDriverImpl *impl)
|
||||||
openslES_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
LOGI("openslES_Init() called");
|
LOGI("openslES_Init() called");
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,7 @@ static int pipewire_version_patch;
|
|||||||
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
|
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
|
||||||
static void *pipewire_handle = NULL;
|
static void *pipewire_handle = NULL;
|
||||||
|
|
||||||
static int
|
static int pipewire_dlsym(const char *fn, void **addr)
|
||||||
pipewire_dlsym(const char *fn, void **addr)
|
|
||||||
{
|
{
|
||||||
*addr = SDL_LoadFunction(pipewire_handle, fn);
|
*addr = SDL_LoadFunction(pipewire_handle, fn);
|
||||||
if (*addr == NULL) {
|
if (*addr == NULL) {
|
||||||
@@ -140,8 +139,7 @@ pipewire_dlsym(const char *fn, void **addr)
|
|||||||
return -1; \
|
return -1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int load_pipewire_library()
|
||||||
load_pipewire_library()
|
|
||||||
{
|
{
|
||||||
if ((pipewire_handle = SDL_LoadObject(pipewire_library))) {
|
if ((pipewire_handle = SDL_LoadObject(pipewire_library))) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -150,8 +148,7 @@ load_pipewire_library()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void unload_pipewire_library()
|
||||||
unload_pipewire_library()
|
|
||||||
{
|
{
|
||||||
if (pipewire_handle) {
|
if (pipewire_handle) {
|
||||||
SDL_UnloadObject(pipewire_handle);
|
SDL_UnloadObject(pipewire_handle);
|
||||||
@@ -163,21 +160,18 @@ unload_pipewire_library()
|
|||||||
|
|
||||||
#define SDL_PIPEWIRE_SYM(x) PIPEWIRE_##x = x
|
#define SDL_PIPEWIRE_SYM(x) PIPEWIRE_##x = x
|
||||||
|
|
||||||
static int
|
static int load_pipewire_library()
|
||||||
load_pipewire_library()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void unload_pipewire_library()
|
||||||
unload_pipewire_library()
|
|
||||||
{ /* Nothing to do */
|
{ /* Nothing to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC */
|
#endif /* SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC */
|
||||||
|
|
||||||
static int
|
static int load_pipewire_syms()
|
||||||
load_pipewire_syms()
|
|
||||||
{
|
{
|
||||||
SDL_PIPEWIRE_SYM(pw_get_library_version);
|
SDL_PIPEWIRE_SYM(pw_get_library_version);
|
||||||
SDL_PIPEWIRE_SYM(pw_init);
|
SDL_PIPEWIRE_SYM(pw_init);
|
||||||
@@ -219,8 +213,7 @@ pipewire_version_at_least(int major, int minor, int patch)
|
|||||||
(pipewire_version_major > major || pipewire_version_minor > minor || pipewire_version_patch >= patch);
|
(pipewire_version_major > major || pipewire_version_minor > minor || pipewire_version_patch >= patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int init_pipewire_library()
|
||||||
init_pipewire_library()
|
|
||||||
{
|
{
|
||||||
if (!load_pipewire_library()) {
|
if (!load_pipewire_library()) {
|
||||||
if (!load_pipewire_syms()) {
|
if (!load_pipewire_syms()) {
|
||||||
@@ -242,8 +235,7 @@ init_pipewire_library()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void deinit_pipewire_library()
|
||||||
deinit_pipewire_library()
|
|
||||||
{
|
{
|
||||||
PIPEWIRE_pw_deinit();
|
PIPEWIRE_pw_deinit();
|
||||||
unload_pipewire_library();
|
unload_pipewire_library();
|
||||||
@@ -304,8 +296,7 @@ static char *pipewire_default_sink_id = NULL;
|
|||||||
static char *pipewire_default_source_id = NULL;
|
static char *pipewire_default_source_id = NULL;
|
||||||
|
|
||||||
/* The active node list */
|
/* The active node list */
|
||||||
static SDL_bool
|
static SDL_bool io_list_check_add(struct io_node *node)
|
||||||
io_list_check_add(struct io_node *node)
|
|
||||||
{
|
{
|
||||||
struct io_node *n;
|
struct io_node *n;
|
||||||
SDL_bool ret = SDL_TRUE;
|
SDL_bool ret = SDL_TRUE;
|
||||||
@@ -330,8 +321,7 @@ dup_found:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void io_list_remove(Uint32 id)
|
||||||
io_list_remove(Uint32 id)
|
|
||||||
{
|
{
|
||||||
struct io_node *n, *temp;
|
struct io_node *n, *temp;
|
||||||
|
|
||||||
@@ -351,8 +341,7 @@ io_list_remove(Uint32 id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void io_list_sort()
|
||||||
io_list_sort()
|
|
||||||
{
|
{
|
||||||
struct io_node *default_sink = NULL, *default_source = NULL;
|
struct io_node *default_sink = NULL, *default_source = NULL;
|
||||||
struct io_node *n, *temp;
|
struct io_node *n, *temp;
|
||||||
@@ -377,8 +366,7 @@ io_list_sort()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void io_list_clear()
|
||||||
io_list_clear()
|
|
||||||
{
|
{
|
||||||
struct io_node *n, *temp;
|
struct io_node *n, *temp;
|
||||||
|
|
||||||
@@ -388,7 +376,7 @@ io_list_clear()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_node*
|
static struct io_node *
|
||||||
io_list_get_by_id(Uint32 id)
|
io_list_get_by_id(Uint32 id)
|
||||||
{
|
{
|
||||||
struct io_node *n, *temp;
|
struct io_node *n, *temp;
|
||||||
@@ -400,7 +388,7 @@ io_list_get_by_id(Uint32 id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_node*
|
static struct io_node *
|
||||||
io_list_get_by_path(char *path)
|
io_list_get_by_path(char *path)
|
||||||
{
|
{
|
||||||
struct io_node *n, *temp;
|
struct io_node *n, *temp;
|
||||||
@@ -412,8 +400,7 @@ io_list_get_by_path(char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void node_object_destroy(struct node_object *node)
|
||||||
node_object_destroy(struct node_object *node)
|
|
||||||
{
|
{
|
||||||
SDL_assert(node);
|
SDL_assert(node);
|
||||||
|
|
||||||
@@ -425,15 +412,13 @@ node_object_destroy(struct node_object *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The pending node list */
|
/* The pending node list */
|
||||||
static void
|
static void pending_list_add(struct node_object *node)
|
||||||
pending_list_add(struct node_object *node)
|
|
||||||
{
|
{
|
||||||
SDL_assert(node);
|
SDL_assert(node);
|
||||||
spa_list_append(&hotplug_pending_list, &node->link);
|
spa_list_append(&hotplug_pending_list, &node->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void pending_list_remove(Uint32 id)
|
||||||
pending_list_remove(Uint32 id)
|
|
||||||
{
|
{
|
||||||
struct node_object *node, *temp;
|
struct node_object *node, *temp;
|
||||||
|
|
||||||
@@ -444,8 +429,7 @@ pending_list_remove(Uint32 id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void pending_list_clear()
|
||||||
pending_list_clear()
|
|
||||||
{
|
{
|
||||||
struct node_object *node, *temp;
|
struct node_object *node, *temp;
|
||||||
|
|
||||||
@@ -454,8 +438,7 @@ pending_list_clear()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *node_object_new(Uint32 id, const char *type, Uint32 version, const void *funcs, const struct pw_core_events *core_events)
|
||||||
node_object_new(Uint32 id, const char *type, Uint32 version, const void *funcs, const struct pw_core_events *core_events)
|
|
||||||
{
|
{
|
||||||
struct pw_proxy *proxy;
|
struct pw_proxy *proxy;
|
||||||
struct node_object *node;
|
struct node_object *node;
|
||||||
@@ -484,8 +467,7 @@ node_object_new(Uint32 id, const char *type, Uint32 version, const void *funcs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Core sync points */
|
/* Core sync points */
|
||||||
static void
|
static void core_events_hotplug_init_callback(void *object, uint32_t id, int seq)
|
||||||
core_events_hotplug_init_callback(void *object, uint32_t id, int seq)
|
|
||||||
{
|
{
|
||||||
if (id == PW_ID_CORE && seq == hotplug_init_seq_val) {
|
if (id == PW_ID_CORE && seq == hotplug_init_seq_val) {
|
||||||
/* This core listener is no longer needed. */
|
/* This core listener is no longer needed. */
|
||||||
@@ -497,8 +479,7 @@ core_events_hotplug_init_callback(void *object, uint32_t id, int seq)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void core_events_interface_callback(void *object, uint32_t id, int seq)
|
||||||
core_events_interface_callback(void *object, uint32_t id, int seq)
|
|
||||||
{
|
{
|
||||||
struct node_object *node = object;
|
struct node_object *node = object;
|
||||||
struct io_node *io = node->userdata;
|
struct io_node *io = node->userdata;
|
||||||
@@ -516,8 +497,7 @@ core_events_interface_callback(void *object, uint32_t id, int seq)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void core_events_metadata_callback(void *object, uint32_t id, int seq)
|
||||||
core_events_metadata_callback(void *object, uint32_t id, int seq)
|
|
||||||
{
|
{
|
||||||
struct node_object *node = object;
|
struct node_object *node = object;
|
||||||
|
|
||||||
@@ -530,8 +510,7 @@ static const struct pw_core_events hotplug_init_core_events = { PW_VERSION_CORE_
|
|||||||
static const struct pw_core_events interface_core_events = { PW_VERSION_CORE_EVENTS, .done = core_events_interface_callback };
|
static const struct pw_core_events interface_core_events = { PW_VERSION_CORE_EVENTS, .done = core_events_interface_callback };
|
||||||
static const struct pw_core_events metadata_core_events = { PW_VERSION_CORE_EVENTS, .done = core_events_metadata_callback };
|
static const struct pw_core_events metadata_core_events = { PW_VERSION_CORE_EVENTS, .done = core_events_metadata_callback };
|
||||||
|
|
||||||
static void
|
static void hotplug_core_sync(struct node_object *node)
|
||||||
hotplug_core_sync(struct node_object *node)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Node sync events *must* come before the hotplug init sync events or the initial
|
* Node sync events *must* come before the hotplug init sync events or the initial
|
||||||
@@ -547,8 +526,7 @@ hotplug_core_sync(struct node_object *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Helpers for retrieving values from params */
|
/* Helpers for retrieving values from params */
|
||||||
static SDL_bool
|
static SDL_bool get_range_param(const struct spa_pod *param, Uint32 key, int *def, int *min, int *max)
|
||||||
get_range_param(const struct spa_pod *param, Uint32 key, int *def, int *min, int *max)
|
|
||||||
{
|
{
|
||||||
const struct spa_pod_prop *prop;
|
const struct spa_pod_prop *prop;
|
||||||
struct spa_pod *value;
|
struct spa_pod *value;
|
||||||
@@ -581,8 +559,7 @@ get_range_param(const struct spa_pod *param, Uint32 key, int *def, int *min, int
|
|||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool get_int_param(const struct spa_pod *param, Uint32 key, int *val)
|
||||||
get_int_param(const struct spa_pod *param, Uint32 key, int *val)
|
|
||||||
{
|
{
|
||||||
const struct spa_pod_prop *prop;
|
const struct spa_pod_prop *prop;
|
||||||
Sint32 v;
|
Sint32 v;
|
||||||
@@ -601,8 +578,7 @@ get_int_param(const struct spa_pod *param, Uint32 key, int *val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Interface node callbacks */
|
/* Interface node callbacks */
|
||||||
static void
|
static void node_event_info(void *object, const struct pw_node_info *info)
|
||||||
node_event_info(void *object, const struct pw_node_info *info)
|
|
||||||
{
|
{
|
||||||
struct node_object *node = object;
|
struct node_object *node = object;
|
||||||
struct io_node *io = node->userdata;
|
struct io_node *io = node->userdata;
|
||||||
@@ -624,8 +600,7 @@ node_event_info(void *object, const struct pw_node_info *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void node_event_param(void *object, int seq, uint32_t id, uint32_t index, uint32_t next, const struct spa_pod *param)
|
||||||
node_event_param(void *object, int seq, uint32_t id, uint32_t index, uint32_t next, const struct spa_pod *param)
|
|
||||||
{
|
{
|
||||||
struct node_object *node = object;
|
struct node_object *node = object;
|
||||||
struct io_node *io = node->userdata;
|
struct io_node *io = node->userdata;
|
||||||
@@ -650,8 +625,7 @@ node_event_param(void *object, int seq, uint32_t id, uint32_t index, uint32_t ne
|
|||||||
static const struct pw_node_events interface_node_events = { PW_VERSION_NODE_EVENTS, .info = node_event_info,
|
static const struct pw_node_events interface_node_events = { PW_VERSION_NODE_EVENTS, .info = node_event_info,
|
||||||
.param = node_event_param };
|
.param = node_event_param };
|
||||||
|
|
||||||
static char*
|
static char *get_name_from_json(const char *json)
|
||||||
get_name_from_json(const char *json)
|
|
||||||
{
|
{
|
||||||
struct spa_json parser[2];
|
struct spa_json parser[2];
|
||||||
char key[7]; /* "name" */
|
char key[7]; /* "name" */
|
||||||
@@ -673,8 +647,7 @@ get_name_from_json(const char *json)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Metadata node callback */
|
/* Metadata node callback */
|
||||||
static int
|
static int metadata_property(void *object, Uint32 subject, const char *key, const char *type, const char *value)
|
||||||
metadata_property(void *object, Uint32 subject, const char *key, const char *type, const char *value)
|
|
||||||
{
|
{
|
||||||
struct node_object *node = object;
|
struct node_object *node = object;
|
||||||
|
|
||||||
@@ -700,8 +673,7 @@ metadata_property(void *object, Uint32 subject, const char *key, const char *typ
|
|||||||
static const struct pw_metadata_events metadata_node_events = { PW_VERSION_METADATA_EVENTS, .property = metadata_property };
|
static const struct pw_metadata_events metadata_node_events = { PW_VERSION_METADATA_EVENTS, .property = metadata_property };
|
||||||
|
|
||||||
/* Global registry callbacks */
|
/* Global registry callbacks */
|
||||||
static void
|
static void registry_event_global_callback(void *object, uint32_t id, uint32_t permissions, const char *type, uint32_t version,
|
||||||
registry_event_global_callback(void *object, uint32_t id, uint32_t permissions, const char *type, uint32_t version,
|
|
||||||
const struct spa_dict *props)
|
const struct spa_dict *props)
|
||||||
{
|
{
|
||||||
struct node_object *node;
|
struct node_object *node;
|
||||||
@@ -772,8 +744,7 @@ registry_event_global_callback(void *object, uint32_t id, uint32_t permissions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void registry_event_remove_callback(void *object, uint32_t id)
|
||||||
registry_event_remove_callback(void *object, uint32_t id)
|
|
||||||
{
|
{
|
||||||
io_list_remove(id);
|
io_list_remove(id);
|
||||||
pending_list_remove(id);
|
pending_list_remove(id);
|
||||||
@@ -783,8 +754,7 @@ static const struct pw_registry_events registry_events = { PW_VERSION_REGISTRY_E
|
|||||||
.global_remove = registry_event_remove_callback };
|
.global_remove = registry_event_remove_callback };
|
||||||
|
|
||||||
/* The hotplug thread */
|
/* The hotplug thread */
|
||||||
static int
|
static int hotplug_loop_init()
|
||||||
hotplug_loop_init()
|
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@@ -827,8 +797,7 @@ hotplug_loop_init()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void hotplug_loop_destroy()
|
||||||
hotplug_loop_destroy()
|
|
||||||
{
|
{
|
||||||
if (hotplug_loop) {
|
if (hotplug_loop) {
|
||||||
PIPEWIRE_pw_thread_loop_stop(hotplug_loop);
|
PIPEWIRE_pw_thread_loop_stop(hotplug_loop);
|
||||||
@@ -870,8 +839,7 @@ hotplug_loop_destroy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PIPEWIRE_DetectDevices()
|
||||||
PIPEWIRE_DetectDevices()
|
|
||||||
{
|
{
|
||||||
struct io_node *io;
|
struct io_node *io;
|
||||||
|
|
||||||
@@ -913,8 +881,7 @@ static const enum spa_audio_channel PIPEWIRE_channel_map_8[] = { SPA_AUDIO_CHANN
|
|||||||
|
|
||||||
#define COPY_CHANNEL_MAP(c) SDL_memcpy(info->position, PIPEWIRE_channel_map_##c, sizeof(PIPEWIRE_channel_map_##c))
|
#define COPY_CHANNEL_MAP(c) SDL_memcpy(info->position, PIPEWIRE_channel_map_##c, sizeof(PIPEWIRE_channel_map_##c))
|
||||||
|
|
||||||
static void
|
static void initialize_spa_info(const SDL_AudioSpec *spec, struct spa_audio_info_raw *info)
|
||||||
initialize_spa_info(const SDL_AudioSpec *spec, struct spa_audio_info_raw *info)
|
|
||||||
{
|
{
|
||||||
info->channels = spec->channels;
|
info->channels = spec->channels;
|
||||||
info->rate = spec->freq;
|
info->rate = spec->freq;
|
||||||
@@ -981,8 +948,7 @@ initialize_spa_info(const SDL_AudioSpec *spec, struct spa_audio_info_raw *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void output_callback(void *data)
|
||||||
output_callback(void *data)
|
|
||||||
{
|
{
|
||||||
struct pw_buffer *pw_buf;
|
struct pw_buffer *pw_buf;
|
||||||
struct spa_buffer *spa_buf;
|
struct spa_buffer *spa_buf;
|
||||||
@@ -1047,8 +1013,7 @@ output_callback(void *data)
|
|||||||
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void input_callback(void *data)
|
||||||
input_callback(void *data)
|
|
||||||
{
|
{
|
||||||
struct pw_buffer *pw_buf;
|
struct pw_buffer *pw_buf;
|
||||||
struct spa_buffer *spa_buf;
|
struct spa_buffer *spa_buf;
|
||||||
@@ -1103,8 +1068,7 @@ input_callback(void *data)
|
|||||||
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void stream_add_buffer_callback(void *data, struct pw_buffer *buffer)
|
||||||
stream_add_buffer_callback(void *data, struct pw_buffer *buffer)
|
|
||||||
{
|
{
|
||||||
_THIS = data;
|
_THIS = data;
|
||||||
|
|
||||||
@@ -1134,8 +1098,7 @@ stream_add_buffer_callback(void *data, struct pw_buffer *buffer)
|
|||||||
PIPEWIRE_pw_thread_loop_signal(this->hidden->loop, false);
|
PIPEWIRE_pw_thread_loop_signal(this->hidden->loop, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void stream_state_changed_callback(void *data, enum pw_stream_state old, enum pw_stream_state state, const char *error)
|
||||||
stream_state_changed_callback(void *data, enum pw_stream_state old, enum pw_stream_state state, const char *error)
|
|
||||||
{
|
{
|
||||||
_THIS = data;
|
_THIS = data;
|
||||||
|
|
||||||
@@ -1157,8 +1120,7 @@ static const struct pw_stream_events stream_input_events = { PW_VERSION_STREAM_
|
|||||||
.add_buffer = stream_add_buffer_callback,
|
.add_buffer = stream_add_buffer_callback,
|
||||||
.process = input_callback };
|
.process = input_callback };
|
||||||
|
|
||||||
static int
|
static int PIPEWIRE_OpenDevice(_THIS, const char *devname)
|
||||||
PIPEWIRE_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* NOTE: The PW_STREAM_FLAG_RT_PROCESS flag can be set to call the stream
|
* NOTE: The PW_STREAM_FLAG_RT_PROCESS flag can be set to call the stream
|
||||||
@@ -1341,8 +1303,7 @@ static void PIPEWIRE_CloseDevice(_THIS)
|
|||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PIPEWIRE_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
|
||||||
PIPEWIRE_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
|
|
||||||
{
|
{
|
||||||
struct io_node *node;
|
struct io_node *node;
|
||||||
char *target;
|
char *target;
|
||||||
@@ -1380,8 +1341,7 @@ failed:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PIPEWIRE_Deinitialize()
|
||||||
PIPEWIRE_Deinitialize()
|
|
||||||
{
|
{
|
||||||
if (pipewire_initialized) {
|
if (pipewire_initialized) {
|
||||||
hotplug_loop_destroy();
|
hotplug_loop_destroy();
|
||||||
@@ -1390,8 +1350,7 @@ PIPEWIRE_Deinitialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool PIPEWIRE_Init(SDL_AudioDriverImpl *impl)
|
||||||
PIPEWIRE_Init(SDL_AudioDriverImpl *impl)
|
|
||||||
{
|
{
|
||||||
if (!pipewire_initialized) {
|
if (!pipewire_initialized) {
|
||||||
if (init_pipewire_library() < 0) {
|
if (init_pipewire_library() < 0) {
|
||||||
|
|||||||
@@ -33,8 +33,7 @@
|
|||||||
/* The tag name used by PS2 audio */
|
/* The tag name used by PS2 audio */
|
||||||
#define PS2AUDIO_DRIVER_NAME "ps2"
|
#define PS2AUDIO_DRIVER_NAME "ps2"
|
||||||
|
|
||||||
static int
|
static int PS2AUDIO_OpenDevice(_THIS, const char *devname)
|
||||||
PS2AUDIO_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
int i, mixlen;
|
int i, mixlen;
|
||||||
struct audsrv_fmt_t format;
|
struct audsrv_fmt_t format;
|
||||||
@@ -46,7 +45,6 @@ PS2AUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
}
|
}
|
||||||
SDL_zerop(this->hidden);
|
SDL_zerop(this->hidden);
|
||||||
|
|
||||||
|
|
||||||
/* These are the native supported audio PS2 configs */
|
/* These are the native supported audio PS2 configs */
|
||||||
switch (this->spec.freq) {
|
switch (this->spec.freq) {
|
||||||
case 11025:
|
case 11025:
|
||||||
@@ -89,7 +87,7 @@ PS2AUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
be a multiple of 64 bytes. Our sample count is already a multiple of
|
be a multiple of 64 bytes. Our sample count is already a multiple of
|
||||||
64, so spec->size should be a multiple of 64 as well. */
|
64, so spec->size should be a multiple of 64 as well. */
|
||||||
mixlen = this->spec.size * NUM_BUFFERS;
|
mixlen = this->spec.size * NUM_BUFFERS;
|
||||||
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
|
this->hidden->rawbuf = (Uint8 *)memalign(64, mixlen);
|
||||||
if (this->hidden->rawbuf == NULL) {
|
if (this->hidden->rawbuf == NULL) {
|
||||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||||
}
|
}
|
||||||
@@ -152,7 +150,7 @@ static void PS2AUDIO_Deinitialize(void)
|
|||||||
deinit_audio_driver();
|
deinit_audio_driver();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl * impl)
|
static SDL_bool PS2AUDIO_Init(SDL_AudioDriverImpl *impl)
|
||||||
{
|
{
|
||||||
if (init_audio_driver() < 0) {
|
if (init_audio_driver() < 0) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
|||||||
@@ -38,8 +38,7 @@
|
|||||||
/* The tag name used by PSP audio */
|
/* The tag name used by PSP audio */
|
||||||
#define PSPAUDIO_DRIVER_NAME "psp"
|
#define PSPAUDIO_DRIVER_NAME "psp"
|
||||||
|
|
||||||
static int
|
static int PSPAUDIO_OpenDevice(_THIS, const char *devname)
|
||||||
PSPAUDIO_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
int format, mixlen, i;
|
int format, mixlen, i;
|
||||||
|
|
||||||
@@ -86,7 +85,7 @@ PSPAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
be a multiple of 64 bytes. Our sample count is already a multiple of
|
be a multiple of 64 bytes. Our sample count is already a multiple of
|
||||||
64, so spec->size should be a multiple of 64 as well. */
|
64, so spec->size should be a multiple of 64 as well. */
|
||||||
mixlen = this->spec.size * NUM_BUFFERS;
|
mixlen = this->spec.size * NUM_BUFFERS;
|
||||||
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
|
this->hidden->rawbuf = (Uint8 *)memalign(64, mixlen);
|
||||||
if (this->hidden->rawbuf == NULL) {
|
if (this->hidden->rawbuf == NULL) {
|
||||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||||
}
|
}
|
||||||
@@ -155,8 +154,7 @@ static void PSPAUDIO_ThreadInit(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool PSPAUDIO_Init(SDL_AudioDriverImpl *impl)
|
||||||
PSPAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->OpenDevice = PSPAUDIO_OpenDevice;
|
impl->OpenDevice = PSPAUDIO_OpenDevice;
|
||||||
|
|||||||
@@ -29,7 +29,8 @@
|
|||||||
|
|
||||||
#define NUM_BUFFERS 2
|
#define NUM_BUFFERS 2
|
||||||
|
|
||||||
struct SDL_PrivateAudioData {
|
struct SDL_PrivateAudioData
|
||||||
|
{
|
||||||
/* The hardware output channel. */
|
/* The hardware output channel. */
|
||||||
int channel;
|
int channel;
|
||||||
/* The raw allocated mixing buffer. */
|
/* The raw allocated mixing buffer. */
|
||||||
|
|||||||
@@ -45,81 +45,79 @@
|
|||||||
/* should we include monitors in the device list? Set at SDL_Init time */
|
/* should we include monitors in the device list? Set at SDL_Init time */
|
||||||
static SDL_bool include_monitors = SDL_FALSE;
|
static SDL_bool include_monitors = SDL_FALSE;
|
||||||
|
|
||||||
|
|
||||||
#if (PA_API_VERSION < 12)
|
#if (PA_API_VERSION < 12)
|
||||||
/** Return non-zero if the passed state is one of the connected states */
|
/** Return non-zero if the passed state is one of the connected states */
|
||||||
static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
|
static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x)
|
||||||
|
{
|
||||||
return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY;
|
return x == PA_CONTEXT_CONNECTING || x == PA_CONTEXT_AUTHORIZING || x == PA_CONTEXT_SETTING_NAME || x == PA_CONTEXT_READY;
|
||||||
}
|
}
|
||||||
/** Return non-zero if the passed state is one of the connected states */
|
/** Return non-zero if the passed state is one of the connected states */
|
||||||
static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
|
static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x)
|
||||||
|
{
|
||||||
return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
|
return x == PA_STREAM_CREATING || x == PA_STREAM_READY;
|
||||||
}
|
}
|
||||||
#endif /* pulseaudio <= 0.9.10 */
|
#endif /* pulseaudio <= 0.9.10 */
|
||||||
|
|
||||||
|
static const char *(*PULSEAUDIO_pa_get_library_version)(void);
|
||||||
static const char *(*PULSEAUDIO_pa_get_library_version) (void);
|
static pa_channel_map *(*PULSEAUDIO_pa_channel_map_init_auto)(
|
||||||
static pa_channel_map *(*PULSEAUDIO_pa_channel_map_init_auto) (
|
|
||||||
pa_channel_map *, unsigned, pa_channel_map_def_t);
|
pa_channel_map *, unsigned, pa_channel_map_def_t);
|
||||||
static const char * (*PULSEAUDIO_pa_strerror) (int);
|
static const char *(*PULSEAUDIO_pa_strerror)(int);
|
||||||
static pa_mainloop * (*PULSEAUDIO_pa_mainloop_new) (void);
|
static pa_mainloop *(*PULSEAUDIO_pa_mainloop_new)(void);
|
||||||
static pa_mainloop_api * (*PULSEAUDIO_pa_mainloop_get_api) (pa_mainloop *);
|
static pa_mainloop_api *(*PULSEAUDIO_pa_mainloop_get_api)(pa_mainloop *);
|
||||||
static int (*PULSEAUDIO_pa_mainloop_iterate) (pa_mainloop *, int, int *);
|
static int (*PULSEAUDIO_pa_mainloop_iterate)(pa_mainloop *, int, int *);
|
||||||
static int (*PULSEAUDIO_pa_mainloop_run) (pa_mainloop *, int *);
|
static int (*PULSEAUDIO_pa_mainloop_run)(pa_mainloop *, int *);
|
||||||
static void (*PULSEAUDIO_pa_mainloop_quit) (pa_mainloop *, int);
|
static void (*PULSEAUDIO_pa_mainloop_quit)(pa_mainloop *, int);
|
||||||
static void (*PULSEAUDIO_pa_mainloop_free) (pa_mainloop *);
|
static void (*PULSEAUDIO_pa_mainloop_free)(pa_mainloop *);
|
||||||
|
|
||||||
static pa_operation_state_t (*PULSEAUDIO_pa_operation_get_state) (
|
static pa_operation_state_t (*PULSEAUDIO_pa_operation_get_state)(
|
||||||
const pa_operation *);
|
const pa_operation *);
|
||||||
static void (*PULSEAUDIO_pa_operation_cancel) (pa_operation *);
|
static void (*PULSEAUDIO_pa_operation_cancel)(pa_operation *);
|
||||||
static void (*PULSEAUDIO_pa_operation_unref) (pa_operation *);
|
static void (*PULSEAUDIO_pa_operation_unref)(pa_operation *);
|
||||||
|
|
||||||
static pa_context * (*PULSEAUDIO_pa_context_new) (pa_mainloop_api *,
|
static pa_context *(*PULSEAUDIO_pa_context_new)(pa_mainloop_api *,
|
||||||
const char *);
|
const char *);
|
||||||
static int (*PULSEAUDIO_pa_context_connect) (pa_context *, const char *,
|
static int (*PULSEAUDIO_pa_context_connect)(pa_context *, const char *,
|
||||||
pa_context_flags_t, const pa_spawn_api *);
|
pa_context_flags_t, const pa_spawn_api *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_list) (pa_context *, pa_sink_info_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_get_sink_info_list)(pa_context *, pa_sink_info_cb_t, void *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_list) (pa_context *, pa_source_info_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_get_source_info_list)(pa_context *, pa_source_info_cb_t, void *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_by_index) (pa_context *, uint32_t, pa_sink_info_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_get_sink_info_by_index)(pa_context *, uint32_t, pa_sink_info_cb_t, void *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_by_index) (pa_context *, uint32_t, pa_source_info_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_get_source_info_by_index)(pa_context *, uint32_t, pa_source_info_cb_t, void *);
|
||||||
static pa_context_state_t (*PULSEAUDIO_pa_context_get_state) (const pa_context *);
|
static pa_context_state_t (*PULSEAUDIO_pa_context_get_state)(const pa_context *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_subscribe) (pa_context *, pa_subscription_mask_t, pa_context_success_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_subscribe)(pa_context *, pa_subscription_mask_t, pa_context_success_cb_t, void *);
|
||||||
static void (*PULSEAUDIO_pa_context_set_subscribe_callback) (pa_context *, pa_context_subscribe_cb_t, void *);
|
static void (*PULSEAUDIO_pa_context_set_subscribe_callback)(pa_context *, pa_context_subscribe_cb_t, void *);
|
||||||
static void (*PULSEAUDIO_pa_context_disconnect) (pa_context *);
|
static void (*PULSEAUDIO_pa_context_disconnect)(pa_context *);
|
||||||
static void (*PULSEAUDIO_pa_context_unref) (pa_context *);
|
static void (*PULSEAUDIO_pa_context_unref)(pa_context *);
|
||||||
|
|
||||||
static pa_stream * (*PULSEAUDIO_pa_stream_new) (pa_context *, const char *,
|
static pa_stream *(*PULSEAUDIO_pa_stream_new)(pa_context *, const char *,
|
||||||
const pa_sample_spec *, const pa_channel_map *);
|
const pa_sample_spec *, const pa_channel_map *);
|
||||||
static int (*PULSEAUDIO_pa_stream_connect_playback) (pa_stream *, const char *,
|
static int (*PULSEAUDIO_pa_stream_connect_playback)(pa_stream *, const char *,
|
||||||
const pa_buffer_attr *, pa_stream_flags_t, const pa_cvolume *, pa_stream *);
|
const pa_buffer_attr *, pa_stream_flags_t, const pa_cvolume *, pa_stream *);
|
||||||
static int (*PULSEAUDIO_pa_stream_connect_record) (pa_stream *, const char *,
|
static int (*PULSEAUDIO_pa_stream_connect_record)(pa_stream *, const char *,
|
||||||
const pa_buffer_attr *, pa_stream_flags_t);
|
const pa_buffer_attr *, pa_stream_flags_t);
|
||||||
static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state) (const pa_stream *);
|
static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state)(const pa_stream *);
|
||||||
static size_t (*PULSEAUDIO_pa_stream_writable_size) (const pa_stream *);
|
static size_t (*PULSEAUDIO_pa_stream_writable_size)(const pa_stream *);
|
||||||
static size_t (*PULSEAUDIO_pa_stream_readable_size) (const pa_stream *);
|
static size_t (*PULSEAUDIO_pa_stream_readable_size)(const pa_stream *);
|
||||||
static int (*PULSEAUDIO_pa_stream_write) (pa_stream *, const void *, size_t,
|
static int (*PULSEAUDIO_pa_stream_write)(pa_stream *, const void *, size_t,
|
||||||
pa_free_cb_t, int64_t, pa_seek_mode_t);
|
pa_free_cb_t, int64_t, pa_seek_mode_t);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_stream_drain) (pa_stream *,
|
static pa_operation *(*PULSEAUDIO_pa_stream_drain)(pa_stream *,
|
||||||
pa_stream_success_cb_t, void *);
|
pa_stream_success_cb_t, void *);
|
||||||
static int (*PULSEAUDIO_pa_stream_peek) (pa_stream *, const void **, size_t *);
|
static int (*PULSEAUDIO_pa_stream_peek)(pa_stream *, const void **, size_t *);
|
||||||
static int (*PULSEAUDIO_pa_stream_drop) (pa_stream *);
|
static int (*PULSEAUDIO_pa_stream_drop)(pa_stream *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_stream_flush) (pa_stream *,
|
static pa_operation *(*PULSEAUDIO_pa_stream_flush)(pa_stream *,
|
||||||
pa_stream_success_cb_t, void *);
|
pa_stream_success_cb_t, void *);
|
||||||
static int (*PULSEAUDIO_pa_stream_disconnect) (pa_stream *);
|
static int (*PULSEAUDIO_pa_stream_disconnect)(pa_stream *);
|
||||||
static void (*PULSEAUDIO_pa_stream_unref) (pa_stream *);
|
static void (*PULSEAUDIO_pa_stream_unref)(pa_stream *);
|
||||||
static void (*PULSEAUDIO_pa_stream_set_write_callback)(pa_stream *, pa_stream_request_cb_t, void *);
|
static void (*PULSEAUDIO_pa_stream_set_write_callback)(pa_stream *, pa_stream_request_cb_t, void *);
|
||||||
static pa_operation * (*PULSEAUDIO_pa_context_get_server_info)(pa_context *, pa_server_info_cb_t, void *);
|
static pa_operation *(*PULSEAUDIO_pa_context_get_server_info)(pa_context *, pa_server_info_cb_t, void *);
|
||||||
|
|
||||||
static int load_pulseaudio_syms(void);
|
static int load_pulseaudio_syms(void);
|
||||||
|
|
||||||
|
|
||||||
#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
|
#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
|
||||||
|
|
||||||
static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
|
static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
|
||||||
static void *pulseaudio_handle = NULL;
|
static void *pulseaudio_handle = NULL;
|
||||||
|
|
||||||
static int
|
static int load_pulseaudio_sym(const char *fn, void **addr)
|
||||||
load_pulseaudio_sym(const char *fn, void **addr)
|
|
||||||
{
|
{
|
||||||
*addr = SDL_LoadFunction(pulseaudio_handle, fn);
|
*addr = SDL_LoadFunction(pulseaudio_handle, fn);
|
||||||
if (*addr == NULL) {
|
if (*addr == NULL) {
|
||||||
@@ -132,10 +130,10 @@ load_pulseaudio_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_PULSEAUDIO_SYM(x) \
|
#define SDL_PULSEAUDIO_SYM(x) \
|
||||||
if (!load_pulseaudio_sym(#x, (void **) (char *) &PULSEAUDIO_##x)) return -1
|
if (!load_pulseaudio_sym(#x, (void **)(char *)&PULSEAUDIO_##x)) \
|
||||||
|
return -1
|
||||||
|
|
||||||
static void
|
static void UnloadPulseAudioLibrary(void)
|
||||||
UnloadPulseAudioLibrary(void)
|
|
||||||
{
|
{
|
||||||
if (pulseaudio_handle != NULL) {
|
if (pulseaudio_handle != NULL) {
|
||||||
SDL_UnloadObject(pulseaudio_handle);
|
SDL_UnloadObject(pulseaudio_handle);
|
||||||
@@ -143,8 +141,7 @@ UnloadPulseAudioLibrary(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LoadPulseAudioLibrary(void)
|
||||||
LoadPulseAudioLibrary(void)
|
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
if (pulseaudio_handle == NULL) {
|
if (pulseaudio_handle == NULL) {
|
||||||
@@ -166,13 +163,11 @@ LoadPulseAudioLibrary(void)
|
|||||||
|
|
||||||
#define SDL_PULSEAUDIO_SYM(x) PULSEAUDIO_##x = x
|
#define SDL_PULSEAUDIO_SYM(x) PULSEAUDIO_##x = x
|
||||||
|
|
||||||
static void
|
static void UnloadPulseAudioLibrary(void)
|
||||||
UnloadPulseAudioLibrary(void)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LoadPulseAudioLibrary(void)
|
||||||
LoadPulseAudioLibrary(void)
|
|
||||||
{
|
{
|
||||||
load_pulseaudio_syms();
|
load_pulseaudio_syms();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -180,9 +175,7 @@ LoadPulseAudioLibrary(void)
|
|||||||
|
|
||||||
#endif /* SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */
|
#endif /* SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */
|
||||||
|
|
||||||
|
static int load_pulseaudio_syms(void)
|
||||||
static int
|
|
||||||
load_pulseaudio_syms(void)
|
|
||||||
{
|
{
|
||||||
SDL_PULSEAUDIO_SYM(pa_get_library_version);
|
SDL_PULSEAUDIO_SYM(pa_get_library_version);
|
||||||
SDL_PULSEAUDIO_SYM(pa_mainloop_new);
|
SDL_PULSEAUDIO_SYM(pa_mainloop_new);
|
||||||
@@ -225,15 +218,13 @@ load_pulseaudio_syms(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_INLINE int
|
static SDL_INLINE int squashVersion(const int major, const int minor, const int patch)
|
||||||
squashVersion(const int major, const int minor, const int patch)
|
|
||||||
{
|
{
|
||||||
return ((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF);
|
return ((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Workaround for older pulse: pa_context_new() must have non-NULL appname */
|
/* Workaround for older pulse: pa_context_new() must have non-NULL appname */
|
||||||
static const char *
|
static const char *getAppName(void)
|
||||||
getAppName(void)
|
|
||||||
{
|
{
|
||||||
const char *retval = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
|
const char *retval = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
|
||||||
if (retval && *retval) {
|
if (retval && *retval) {
|
||||||
@@ -257,8 +248,7 @@ getAppName(void)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
|
||||||
WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
|
|
||||||
{
|
{
|
||||||
/* This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about. */
|
/* This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about. */
|
||||||
if (mainloop && o) {
|
if (mainloop && o) {
|
||||||
@@ -270,8 +260,7 @@ WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void DisconnectFromPulseServer(pa_mainloop *mainloop, pa_context *context)
|
||||||
DisconnectFromPulseServer(pa_mainloop *mainloop, pa_context *context)
|
|
||||||
{
|
{
|
||||||
if (context) {
|
if (context) {
|
||||||
PULSEAUDIO_pa_context_disconnect(context);
|
PULSEAUDIO_pa_context_disconnect(context);
|
||||||
@@ -282,8 +271,7 @@ DisconnectFromPulseServer(pa_mainloop *mainloop, pa_context *context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
|
||||||
ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
|
|
||||||
{
|
{
|
||||||
pa_mainloop *mainloop = NULL;
|
pa_mainloop *mainloop = NULL;
|
||||||
pa_context *context = NULL;
|
pa_context *context = NULL;
|
||||||
@@ -334,8 +322,7 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
|
|||||||
return 0; /* connected and ready! */
|
return 0; /* connected and ready! */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int ConnectToPulseServer(pa_mainloop **_mainloop, pa_context **_context)
|
||||||
ConnectToPulseServer(pa_mainloop **_mainloop, pa_context **_context)
|
|
||||||
{
|
{
|
||||||
const int retval = ConnectToPulseServer_Internal(_mainloop, _context);
|
const int retval = ConnectToPulseServer_Internal(_mainloop, _context);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
@@ -344,23 +331,20 @@ ConnectToPulseServer(pa_mainloop **_mainloop, pa_context **_context)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 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 PULSEAUDIO_WaitDevice(_THIS)
|
||||||
PULSEAUDIO_WaitDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
/* this is a no-op; we wait in PULSEAUDIO_PlayDevice now. */
|
/* this is a no-op; we wait in PULSEAUDIO_PlayDevice now. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteCallback(pa_stream *p, size_t nbytes, void *userdata)
|
static void WriteCallback(pa_stream *p, size_t nbytes, void *userdata)
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = (struct SDL_PrivateAudioData *) userdata;
|
struct SDL_PrivateAudioData *h = (struct SDL_PrivateAudioData *)userdata;
|
||||||
/*printf("PULSEAUDIO WRITE CALLBACK! nbytes=%u\n", (unsigned int) nbytes);*/
|
/*printf("PULSEAUDIO WRITE CALLBACK! nbytes=%u\n", (unsigned int) nbytes);*/
|
||||||
h->bytes_requested += nbytes;
|
h->bytes_requested += nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PULSEAUDIO_PlayDevice(_THIS)
|
||||||
PULSEAUDIO_PlayDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = this->hidden;
|
struct SDL_PrivateAudioData *h = this->hidden;
|
||||||
int available = h->mixlen;
|
int available = h->mixlen;
|
||||||
@@ -395,15 +379,12 @@ PULSEAUDIO_PlayDevice(_THIS)
|
|||||||
/*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/
|
/*printf("PULSEAUDIO PLAYDEVICE END! written=%d\n", written);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *
|
static Uint8 *PULSEAUDIO_GetDeviceBuf(_THIS)
|
||||||
PULSEAUDIO_GetDeviceBuf(_THIS)
|
|
||||||
{
|
{
|
||||||
return this->hidden->mixbuf;
|
return this->hidden->mixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int PULSEAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
||||||
static int
|
|
||||||
PULSEAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = this->hidden;
|
struct SDL_PrivateAudioData *h = this->hidden;
|
||||||
const void *data = NULL;
|
const void *data = NULL;
|
||||||
@@ -437,12 +418,13 @@ PULSEAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|||||||
/* a new fragment is available! */
|
/* a new fragment is available! */
|
||||||
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
|
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
|
||||||
SDL_assert(nbytes > 0);
|
SDL_assert(nbytes > 0);
|
||||||
if (data == NULL) { /* NULL==buffer had a hole. Ignore that. */
|
/* If data == NULL, then the buffer had a hole, ignore that */
|
||||||
|
if (data == NULL) {
|
||||||
PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */
|
PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */
|
||||||
} else {
|
} else {
|
||||||
/* store this fragment's data, start feeding it to SDL. */
|
/* store this fragment's data, start feeding it to SDL. */
|
||||||
/*printf("PULSEAUDIO: captured %d new bytes\n", (int) nbytes);*/
|
/*printf("PULSEAUDIO: captured %d new bytes\n", (int) nbytes);*/
|
||||||
h->capturebuf = (const Uint8 *) data;
|
h->capturebuf = (const Uint8 *)data;
|
||||||
h->capturelen = nbytes;
|
h->capturelen = nbytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,8 +432,7 @@ PULSEAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|||||||
return -1; /* not enabled? */
|
return -1; /* not enabled? */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PULSEAUDIO_FlushCapture(_THIS)
|
||||||
PULSEAUDIO_FlushCapture(_THIS)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = this->hidden;
|
struct SDL_PrivateAudioData *h = this->hidden;
|
||||||
const void *data = NULL;
|
const void *data = NULL;
|
||||||
@@ -481,8 +462,7 @@ PULSEAUDIO_FlushCapture(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PULSEAUDIO_CloseDevice(_THIS)
|
||||||
PULSEAUDIO_CloseDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
if (this->hidden->stream) {
|
if (this->hidden->stream) {
|
||||||
if (this->hidden->capturebuf != NULL) {
|
if (this->hidden->capturebuf != NULL) {
|
||||||
@@ -498,28 +478,25 @@ PULSEAUDIO_CloseDevice(_THIS)
|
|||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SinkDeviceNameCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
||||||
SinkDeviceNameCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
|
||||||
{
|
{
|
||||||
if (i) {
|
if (i) {
|
||||||
char **devname = (char **) data;
|
char **devname = (char **)data;
|
||||||
*devname = SDL_strdup(i->name);
|
*devname = SDL_strdup(i->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SourceDeviceNameCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
|
||||||
SourceDeviceNameCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
|
|
||||||
{
|
{
|
||||||
if (i) {
|
if (i) {
|
||||||
char **devname = (char **) data;
|
char **devname = (char **)data;
|
||||||
*devname = SDL_strdup(i->name);
|
*devname = SDL_strdup(i->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *handle)
|
||||||
FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *handle)
|
|
||||||
{
|
{
|
||||||
const uint32_t idx = ((uint32_t) ((intptr_t) handle)) - 1;
|
const uint32_t idx = ((uint32_t)((intptr_t)handle)) - 1;
|
||||||
|
|
||||||
if (handle == NULL) { /* NULL == default device. */
|
if (handle == NULL) { /* NULL == default device. */
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
@@ -538,8 +515,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *h
|
|||||||
return h->device_name != NULL;
|
return h->device_name != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PULSEAUDIO_OpenDevice(_THIS, const char *devname)
|
||||||
PULSEAUDIO_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
struct SDL_PrivateAudioData *h = NULL;
|
struct SDL_PrivateAudioData *h = NULL;
|
||||||
SDL_AudioFormat test_format;
|
SDL_AudioFormat test_format;
|
||||||
@@ -604,7 +580,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
/* Allocate mixing buffer */
|
/* Allocate mixing buffer */
|
||||||
if (!iscapture) {
|
if (!iscapture) {
|
||||||
h->mixlen = this->spec.size;
|
h->mixlen = this->spec.size;
|
||||||
h->mixbuf = (Uint8 *) SDL_malloc(h->mixlen);
|
h->mixbuf = (Uint8 *)SDL_malloc(h->mixlen);
|
||||||
if (h->mixbuf == NULL) {
|
if (h->mixbuf == NULL) {
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
@@ -692,8 +668,7 @@ static char *default_source_name = NULL;
|
|||||||
|
|
||||||
/* device handles are device index + 1, cast to void*, so we never pass a NULL. */
|
/* device handles are device index + 1, cast to void*, so we never pass a NULL. */
|
||||||
|
|
||||||
static SDL_AudioFormat
|
static SDL_AudioFormat PulseFormatToSDLFormat(pa_sample_format_t format)
|
||||||
PulseFormatToSDLFormat(pa_sample_format_t format)
|
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case PA_SAMPLE_U8:
|
case PA_SAMPLE_U8:
|
||||||
@@ -716,11 +691,10 @@ PulseFormatToSDLFormat(pa_sample_format_t format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is called when PulseAudio adds an output ("sink") device. */
|
/* This is called when PulseAudio adds an output ("sink") device. */
|
||||||
static void
|
static void SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
||||||
SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
|
||||||
{
|
{
|
||||||
SDL_AudioSpec spec;
|
SDL_AudioSpec spec;
|
||||||
SDL_bool add = (SDL_bool) ((intptr_t) data);
|
SDL_bool add = (SDL_bool)((intptr_t)data);
|
||||||
if (i) {
|
if (i) {
|
||||||
spec.freq = i->sample_spec.rate;
|
spec.freq = i->sample_spec.rate;
|
||||||
spec.channels = i->sample_spec.channels;
|
spec.channels = i->sample_spec.channels;
|
||||||
@@ -732,7 +706,7 @@ SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
|||||||
spec.userdata = NULL;
|
spec.userdata = NULL;
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
SDL_AddAudioDevice(SDL_FALSE, i->description, &spec, (void *) ((intptr_t) i->index+1));
|
SDL_AddAudioDevice(SDL_FALSE, i->description, &spec, (void *)((intptr_t)i->index + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (default_sink_path != NULL && SDL_strcmp(i->name, default_sink_path) == 0) {
|
if (default_sink_path != NULL && SDL_strcmp(i->name, default_sink_path) == 0) {
|
||||||
@@ -745,11 +719,10 @@ SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is called when PulseAudio adds a capture ("source") device. */
|
/* This is called when PulseAudio adds a capture ("source") device. */
|
||||||
static void
|
static void SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
|
||||||
SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
|
|
||||||
{
|
{
|
||||||
SDL_AudioSpec spec;
|
SDL_AudioSpec spec;
|
||||||
SDL_bool add = (SDL_bool) ((intptr_t) data);
|
SDL_bool add = (SDL_bool)((intptr_t)data);
|
||||||
if (i) {
|
if (i) {
|
||||||
/* Maybe skip "monitor" sources. These are just output from other sinks. */
|
/* Maybe skip "monitor" sources. These are just output from other sinks. */
|
||||||
if (include_monitors || (i->monitor_of_sink == PA_INVALID_INDEX)) {
|
if (include_monitors || (i->monitor_of_sink == PA_INVALID_INDEX)) {
|
||||||
@@ -763,7 +736,7 @@ SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_last, void *da
|
|||||||
spec.userdata = NULL;
|
spec.userdata = NULL;
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
SDL_AddAudioDevice(SDL_TRUE, i->description, &spec, (void *) ((intptr_t) i->index+1));
|
SDL_AddAudioDevice(SDL_TRUE, i->description, &spec, (void *)((intptr_t)i->index + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (default_source_path != NULL && SDL_strcmp(i->name, default_source_path) == 0) {
|
if (default_source_path != NULL && SDL_strcmp(i->name, default_source_path) == 0) {
|
||||||
@@ -776,8 +749,7 @@ SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_last, void *da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void ServerInfoCallback(pa_context *c, const pa_server_info *i, void *data)
|
||||||
ServerInfoCallback(pa_context *c, const pa_server_info *i, void *data)
|
|
||||||
{
|
{
|
||||||
if (default_sink_path != NULL) {
|
if (default_sink_path != NULL) {
|
||||||
SDL_free(default_sink_path);
|
SDL_free(default_sink_path);
|
||||||
@@ -790,8 +762,7 @@ ServerInfoCallback(pa_context *c, const pa_server_info *i, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is called when PulseAudio has a device connected/removed/changed. */
|
/* This is called when PulseAudio has a device connected/removed/changed. */
|
||||||
static void
|
static void HotplugCallback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *data)
|
||||||
HotplugCallback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *data)
|
|
||||||
{
|
{
|
||||||
const SDL_bool added = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW);
|
const SDL_bool added = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW);
|
||||||
const SDL_bool removed = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE);
|
const SDL_bool removed = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE);
|
||||||
@@ -806,22 +777,21 @@ HotplugCallback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, voi
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL);
|
PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL);
|
||||||
}
|
}
|
||||||
PULSEAUDIO_pa_context_get_sink_info_by_index(hotplug_context, idx, SinkInfoCallback, (void*) ((intptr_t) added));
|
PULSEAUDIO_pa_context_get_sink_info_by_index(hotplug_context, idx, SinkInfoCallback, (void *)((intptr_t)added));
|
||||||
} else if ((added || changed) && source) {
|
} else if ((added || changed) && source) {
|
||||||
if (changed) {
|
if (changed) {
|
||||||
PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL);
|
PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL);
|
||||||
}
|
}
|
||||||
PULSEAUDIO_pa_context_get_source_info_by_index(hotplug_context, idx, SourceInfoCallback, (void*) ((intptr_t) added));
|
PULSEAUDIO_pa_context_get_source_info_by_index(hotplug_context, idx, SourceInfoCallback, (void *)((intptr_t)added));
|
||||||
} else if (removed && (sink || source)) {
|
} else if (removed && (sink || source)) {
|
||||||
/* removes we can handle just with the device index. */
|
/* removes we can handle just with the device index. */
|
||||||
SDL_RemoveAudioDevice(source != 0, (void *) ((intptr_t) idx+1));
|
SDL_RemoveAudioDevice(source != 0, (void *)((intptr_t)idx + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this runs as a thread while the Pulse target is initialized to catch hotplug events. */
|
/* this runs as a thread while the Pulse target is initialized to catch hotplug events. */
|
||||||
static int SDLCALL
|
static int SDLCALL HotplugThread(void *data)
|
||||||
HotplugThread(void *data)
|
|
||||||
{
|
{
|
||||||
pa_operation *o;
|
pa_operation *o;
|
||||||
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
|
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
|
||||||
@@ -832,19 +802,17 @@ HotplugThread(void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PULSEAUDIO_DetectDevices()
|
||||||
PULSEAUDIO_DetectDevices()
|
|
||||||
{
|
{
|
||||||
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL));
|
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_server_info(hotplug_context, ServerInfoCallback, NULL));
|
||||||
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_sink_info_list(hotplug_context, SinkInfoCallback, (void*) ((intptr_t) SDL_TRUE)));
|
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_sink_info_list(hotplug_context, SinkInfoCallback, (void *)((intptr_t)SDL_TRUE)));
|
||||||
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_source_info_list(hotplug_context, SourceInfoCallback, (void*) ((intptr_t) SDL_TRUE)));
|
WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_source_info_list(hotplug_context, SourceInfoCallback, (void *)((intptr_t)SDL_TRUE)));
|
||||||
|
|
||||||
/* ok, we have a sane list, let's set up hotplug notifications now... */
|
/* ok, we have a sane list, let's set up hotplug notifications now... */
|
||||||
hotplug_thread = SDL_CreateThreadInternal(HotplugThread, "PulseHotplug", 256 * 1024, NULL);
|
hotplug_thread = SDL_CreateThreadInternal(HotplugThread, "PulseHotplug", 256 * 1024, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int PULSEAUDIO_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
|
||||||
PULSEAUDIO_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int numdevices;
|
int numdevices;
|
||||||
@@ -875,8 +843,7 @@ PULSEAUDIO_GetDefaultAudioInfo(char **name, SDL_AudioSpec *spec, int iscapture)
|
|||||||
return SDL_SetError("Could not find default PulseAudio device");
|
return SDL_SetError("Could not find default PulseAudio device");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void PULSEAUDIO_Deinitialize(void)
|
||||||
PULSEAUDIO_Deinitialize(void)
|
|
||||||
{
|
{
|
||||||
if (hotplug_thread) {
|
if (hotplug_thread) {
|
||||||
PULSEAUDIO_pa_mainloop_quit(hotplug_mainloop, 0);
|
PULSEAUDIO_pa_mainloop_quit(hotplug_mainloop, 0);
|
||||||
@@ -908,8 +875,7 @@ PULSEAUDIO_Deinitialize(void)
|
|||||||
UnloadPulseAudioLibrary();
|
UnloadPulseAudioLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool PULSEAUDIO_Init(SDL_AudioDriverImpl *impl)
|
||||||
PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
if (LoadPulseAudioLibrary() < 0) {
|
if (LoadPulseAudioLibrary() < 0) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
#define SIO_DEVANY "default"
|
#define SIO_DEVANY "default"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct sio_hdl * (*SNDIO_sio_open)(const char *, unsigned int, int);
|
static struct sio_hdl *(*SNDIO_sio_open)(const char *, unsigned int, int);
|
||||||
static void (*SNDIO_sio_close)(struct sio_hdl *);
|
static void (*SNDIO_sio_close)(struct sio_hdl *);
|
||||||
static int (*SNDIO_sio_setpar)(struct sio_hdl *, struct sio_par *);
|
static int (*SNDIO_sio_setpar)(struct sio_hdl *, struct sio_par *);
|
||||||
static int (*SNDIO_sio_getpar)(struct sio_hdl *, struct sio_par *);
|
static int (*SNDIO_sio_getpar)(struct sio_hdl *, struct sio_par *);
|
||||||
@@ -68,8 +68,7 @@ static void (*SNDIO_sio_initpar)(struct sio_par *);
|
|||||||
static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
|
static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
|
||||||
static void *sndio_handle = NULL;
|
static void *sndio_handle = NULL;
|
||||||
|
|
||||||
static int
|
static int load_sndio_sym(const char *fn, void **addr)
|
||||||
load_sndio_sym(const char *fn, void **addr)
|
|
||||||
{
|
{
|
||||||
*addr = SDL_LoadFunction(sndio_handle, fn);
|
*addr = SDL_LoadFunction(sndio_handle, fn);
|
||||||
if (*addr == NULL) {
|
if (*addr == NULL) {
|
||||||
@@ -82,13 +81,13 @@ load_sndio_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_SNDIO_SYM(x) \
|
#define SDL_SNDIO_SYM(x) \
|
||||||
if (!load_sndio_sym(#x, (void **) (char *) &SNDIO_##x)) return -1
|
if (!load_sndio_sym(#x, (void **)(char *)&SNDIO_##x)) \
|
||||||
|
return -1
|
||||||
#else
|
#else
|
||||||
#define SDL_SNDIO_SYM(x) SNDIO_##x = x
|
#define SDL_SNDIO_SYM(x) SNDIO_##x = x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int load_sndio_syms(void)
|
||||||
load_sndio_syms(void)
|
|
||||||
{
|
{
|
||||||
SDL_SNDIO_SYM(sio_open);
|
SDL_SNDIO_SYM(sio_open);
|
||||||
SDL_SNDIO_SYM(sio_close);
|
SDL_SNDIO_SYM(sio_close);
|
||||||
@@ -110,8 +109,7 @@ load_sndio_syms(void)
|
|||||||
|
|
||||||
#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
|
#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
|
||||||
|
|
||||||
static void
|
static void UnloadSNDIOLibrary(void)
|
||||||
UnloadSNDIOLibrary(void)
|
|
||||||
{
|
{
|
||||||
if (sndio_handle != NULL) {
|
if (sndio_handle != NULL) {
|
||||||
SDL_UnloadObject(sndio_handle);
|
SDL_UnloadObject(sndio_handle);
|
||||||
@@ -119,8 +117,7 @@ UnloadSNDIOLibrary(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LoadSNDIOLibrary(void)
|
||||||
LoadSNDIOLibrary(void)
|
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
if (sndio_handle == NULL) {
|
if (sndio_handle == NULL) {
|
||||||
@@ -140,13 +137,11 @@ LoadSNDIOLibrary(void)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static void
|
static void UnloadSNDIOLibrary(void)
|
||||||
UnloadSNDIOLibrary(void)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int LoadSNDIOLibrary(void)
|
||||||
LoadSNDIOLibrary(void)
|
|
||||||
{
|
{
|
||||||
load_sndio_syms();
|
load_sndio_syms();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -154,24 +149,19 @@ LoadSNDIOLibrary(void)
|
|||||||
|
|
||||||
#endif /* SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
|
#endif /* SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
|
||||||
|
|
||||||
|
static void SNDIO_WaitDevice(_THIS)
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
SNDIO_WaitDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
/* no-op; SNDIO_sio_write() blocks if necessary. */
|
/* no-op; SNDIO_sio_write() blocks if necessary. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SNDIO_PlayDevice(_THIS)
|
||||||
SNDIO_PlayDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
const int written = SNDIO_sio_write(this->hidden->dev,
|
const int written = SNDIO_sio_write(this->hidden->dev,
|
||||||
this->hidden->mixbuf,
|
this->hidden->mixbuf,
|
||||||
this->hidden->mixlen);
|
this->hidden->mixlen);
|
||||||
|
|
||||||
/* If we couldn't write, assume fatal error for now */
|
/* If we couldn't write, assume fatal error for now */
|
||||||
if ( written == 0 ) {
|
if (written == 0) {
|
||||||
SDL_OpenedAudioDeviceDisconnected(this);
|
SDL_OpenedAudioDeviceDisconnected(this);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
@@ -179,8 +169,7 @@ SNDIO_PlayDevice(_THIS)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
||||||
SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|
||||||
{
|
{
|
||||||
size_t r;
|
size_t r;
|
||||||
int revents;
|
int revents;
|
||||||
@@ -189,8 +178,7 @@ SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|||||||
/* Emulate a blocking read */
|
/* Emulate a blocking read */
|
||||||
r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
|
r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
|
||||||
while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
|
while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
|
||||||
if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0
|
if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0 || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
|
||||||
|| poll(this->hidden->pfd, nfds, INFTIM) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
|
revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
|
||||||
@@ -201,11 +189,10 @@ SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (int) r;
|
return (int)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SNDIO_FlushCapture(_THIS)
|
||||||
SNDIO_FlushCapture(_THIS)
|
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
@@ -214,19 +201,17 @@ SNDIO_FlushCapture(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *
|
static Uint8 *SNDIO_GetDeviceBuf(_THIS)
|
||||||
SNDIO_GetDeviceBuf(_THIS)
|
|
||||||
{
|
{
|
||||||
return this->hidden->mixbuf;
|
return this->hidden->mixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SNDIO_CloseDevice(_THIS)
|
||||||
SNDIO_CloseDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
if ( this->hidden->pfd != NULL ) {
|
if (this->hidden->pfd != NULL) {
|
||||||
SDL_free(this->hidden->pfd);
|
SDL_free(this->hidden->pfd);
|
||||||
}
|
}
|
||||||
if ( this->hidden->dev != NULL ) {
|
if (this->hidden->dev != NULL) {
|
||||||
SNDIO_sio_stop(this->hidden->dev);
|
SNDIO_sio_stop(this->hidden->dev);
|
||||||
SNDIO_sio_close(this->hidden->dev);
|
SNDIO_sio_close(this->hidden->dev);
|
||||||
}
|
}
|
||||||
@@ -234,8 +219,7 @@ SNDIO_CloseDevice(_THIS)
|
|||||||
SDL_free(this->hidden);
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int SNDIO_OpenDevice(_THIS, const char *devname)
|
||||||
SNDIO_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
SDL_AudioFormat test_format;
|
SDL_AudioFormat test_format;
|
||||||
struct sio_par par;
|
struct sio_par par;
|
||||||
@@ -325,7 +309,7 @@ SNDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
|
|
||||||
/* Allocate mixing buffer */
|
/* Allocate mixing buffer */
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -339,21 +323,18 @@ SNDIO_OpenDevice(_THIS, const char *devname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SNDIO_Deinitialize(void)
|
||||||
SNDIO_Deinitialize(void)
|
|
||||||
{
|
{
|
||||||
UnloadSNDIOLibrary();
|
UnloadSNDIOLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void SNDIO_DetectDevices(void)
|
||||||
SNDIO_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 SNDIO_Init(SDL_AudioDriverImpl *impl)
|
||||||
SNDIO_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
if (LoadSNDIOLibrary() < 0) {
|
if (LoadSNDIOLibrary() < 0) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
|||||||
@@ -39,8 +39,7 @@
|
|||||||
#define SCE_AUDIO_SAMPLE_ALIGN(s) (((s) + 63) & ~63)
|
#define SCE_AUDIO_SAMPLE_ALIGN(s) (((s) + 63) & ~63)
|
||||||
#define SCE_AUDIO_MAX_VOLUME 0x8000
|
#define SCE_AUDIO_MAX_VOLUME 0x8000
|
||||||
|
|
||||||
static int
|
static int VITAAUD_OpenCaptureDevice(_THIS)
|
||||||
VITAAUD_OpenCaptureDevice(_THIS)
|
|
||||||
{
|
{
|
||||||
this->spec.freq = 16000;
|
this->spec.freq = 16000;
|
||||||
this->spec.samples = 512;
|
this->spec.samples = 512;
|
||||||
@@ -48,7 +47,7 @@ VITAAUD_OpenCaptureDevice(_THIS)
|
|||||||
|
|
||||||
SDL_CalculateAudioSpec(&this->spec);
|
SDL_CalculateAudioSpec(&this->spec);
|
||||||
|
|
||||||
this->hidden->port = sceAudioInOpenPort(SCE_AUDIO_IN_PORT_TYPE_VOICE , 512, 16000, SCE_AUDIO_IN_PARAM_FORMAT_S16_MONO);
|
this->hidden->port = sceAudioInOpenPort(SCE_AUDIO_IN_PORT_TYPE_VOICE, 512, 16000, SCE_AUDIO_IN_PARAM_FORMAT_S16_MONO);
|
||||||
|
|
||||||
if (this->hidden->port < 0) {
|
if (this->hidden->port < 0) {
|
||||||
return SDL_SetError("Couldn't open audio in port: %x", this->hidden->port);
|
return SDL_SetError("Couldn't open audio in port: %x", this->hidden->port);
|
||||||
@@ -57,11 +56,10 @@ VITAAUD_OpenCaptureDevice(_THIS)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int VITAAUD_OpenDevice(_THIS, const char *devname)
|
||||||
VITAAUD_OpenDevice(_THIS, const char *devname)
|
|
||||||
{
|
{
|
||||||
int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN;
|
int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN;
|
||||||
int vols[2] = {SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME};
|
int vols[2] = { SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME };
|
||||||
SDL_AudioFormat test_format;
|
SDL_AudioFormat test_format;
|
||||||
|
|
||||||
this->hidden = (struct SDL_PrivateAudioData *)
|
this->hidden = (struct SDL_PrivateAudioData *)
|
||||||
@@ -96,7 +94,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
|
|||||||
be a multiple of 64 bytes. Our sample count is already a multiple of
|
be a multiple of 64 bytes. Our sample count is already a multiple of
|
||||||
64, so spec->size should be a multiple of 64 as well. */
|
64, so spec->size should be a multiple of 64 as well. */
|
||||||
mixlen = this->spec.size * NUM_BUFFERS;
|
mixlen = this->spec.size * NUM_BUFFERS;
|
||||||
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
|
this->hidden->rawbuf = (Uint8 *)memalign(64, mixlen);
|
||||||
if (this->hidden->rawbuf == NULL) {
|
if (this->hidden->rawbuf == NULL) {
|
||||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||||
}
|
}
|
||||||
@@ -119,7 +117,7 @@ VITAAUD_OpenDevice(_THIS, const char *devname)
|
|||||||
return SDL_SetError("Couldn't open audio out port: %x", this->hidden->port);
|
return SDL_SetError("Couldn't open audio out port: %x", this->hidden->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
sceAudioOutSetVolume(this->hidden->port, SCE_AUDIO_VOLUME_FLAG_L_CH|SCE_AUDIO_VOLUME_FLAG_R_CH, vols);
|
sceAudioOutSetVolume(this->hidden->port, SCE_AUDIO_VOLUME_FLAG_L_CH | SCE_AUDIO_VOLUME_FLAG_R_CH, vols);
|
||||||
|
|
||||||
SDL_memset(this->hidden->rawbuf, 0, mixlen);
|
SDL_memset(this->hidden->rawbuf, 0, mixlen);
|
||||||
for (i = 0; i < NUM_BUFFERS; i++) {
|
for (i = 0; i < NUM_BUFFERS; i++) {
|
||||||
@@ -191,8 +189,7 @@ static void VITAAUD_ThreadInit(_THIS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool VITAAUD_Init(SDL_AudioDriverImpl *impl)
|
||||||
VITAAUD_Init(SDL_AudioDriverImpl * impl)
|
|
||||||
{
|
{
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->OpenDevice = VITAAUD_OpenDevice;
|
impl->OpenDevice = VITAAUD_OpenDevice;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user