SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.

This commit is contained in:
Sam Lantinga 2006-07-10 21:04:37 +00:00
parent 8f3655506a
commit 6bc598ea61
686 changed files with 117556 additions and 98661 deletions

1
.indent.pro vendored Normal file
View File

@ -0,0 +1 @@
-i4 -nut -nsc -br -ce -cdw -npcs

Binary file not shown.

View File

@ -55,6 +55,7 @@ SRCS = \
src/video/dummy/SDL_nullevents.c \
src/video/dummy/SDL_nullmouse.c \
src/video/dummy/SDL_nullvideo.c \
src/video/glsdl/SDL_glsdl.c \
src/video/SDL_blit.c \
src/video/SDL_blit_0.c \
src/video/SDL_blit_1.c \

View File

@ -167,6 +167,29 @@ dist $(distfile):
rpm: $(distfile)
rpmbuild -ta $?
# Run indent on the source to standardize coding style
indent:
@echo "Running indent... modified files:"
@cd $(srcdir) && \
find . \( \
-name '*.h' -o \
-name '*.c' -o \
-name '*.cc' \) \
-print | \
while read file; do \
indent "$$file" -o "$$file.indent"; \
if cmp "$$file" "$$file.indent" >/dev/null; then \
rm -f "$$file.indent"; \
else \
echo "$$file"; \
mv -f "$$file.indent" "$$file"; \
fi; \
done
# Run indent and then commit modified files
commit: indent
svn commit
# Create a SVN snapshot that people can run update on
snapshot:
svn co svn://libsdl.org/trunk/SDL

View File

@ -3,7 +3,7 @@
SDL on OS/2
===========
Last updated on May. 17, 2006.
Last updated on May. 1, 2006.
1. How to compile?
@ -13,6 +13,8 @@ To compile this, you'll need the followings installed:
- The OS/2 Developer's Toolkit
- The OpenWatcom compiler
(http://www.openwatcom.org)
- The FSLib library
(ftp://ftp.netlabs.org/pub/SDL)
First of all, you have to unzip the Watcom-OS2.zip file. This will result in a
file called "makefile" and a file called "setvars.cmd" in this folder (and some
@ -30,7 +32,7 @@ is full of printf()'s, so if something goes wrong, its output can help a lot
for debugging.
Then run "wmake".
This should create the SDL12.DLL and the corresponding SDL12.LIB file here.
This should create the SDL.DLL and the corresponding SDL.LIB file here.
To test applications, it's a good idea to use the 'debug' build of SDL, and
redirect the standard output and standard error output to files, to see what
@ -46,8 +48,8 @@ wmake
2. How to compile the testapps?
-------------------------------
Once you have SDL12.DLL compiled, navigate into the 'test' folder, copy in
there the newly built SDL12.DLL, and copy in there FSLib.DLL.
Once you have SDL.DLL compiled, navigate into the 'test' folder, copy in there
the newly built SDL.DLL, and copy in there FSLib.DLL.
Then run "wmake" in there to compile some of the testapps.
@ -189,10 +191,6 @@ please, be our guest and contact us!
10. Changelog of the OS/2 port
------------------------------
Version 1.2.10 - 2006-05-17 - Doodle
- Small modifications for v1.2.10 release
- Changed DLL name to include version info (currently SDL12.dll)
Version 1.2 - 2006-05-01 - Doodle
- Modified makefile system to have only one makefile
- Included FSLib headers, DLL and LIB file
@ -218,7 +216,7 @@ Version 1.2.7 - 2005-12-22 - Doodle
SET SDL_USE_PROPORTIONAL_WINDOW=1
dosbox.exe
)
or, if you have the HOME environment variable set, then SDL12.DLL will
or, if you have the HOME environment variable set, then SDL.DLL will
create a file in that directory called .sdl.proportionals, and you can
put there the name of executable files that will be automatically made
proportional.

3
TODO
View File

@ -2,6 +2,9 @@
Wish list for the 1.3 development branch:
http://bugzilla.libsdl.org/
* Add a way to register custom events
* Add internal support for adding video modes and refresh rates
* Support querying and setting refresh rate with video modes
* Add mousewheel events (new unified event architecture?)
* DirectInput joystick support needs to be implemented
* Be able to enumerate and select available audio and video drivers

1
UNDER_CONSTRUCTION.txt Normal file
View File

@ -0,0 +1 @@
WARNING: This code is under construction, may not build, and is unstable!

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,11 @@
This is a list of API changes in SDL's version history.
Version 1.0:
1.3.0:
Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
1.2.10:
If SDL_OpenAudio() is passed zero for the desired format
@ -416,8 +420,6 @@ Version 1.0:
1.0.0:
New public release
Version 0.11:
0.11.5:
A new function SDL_GetVideoSurface() has been added, and returns
a pointer to the current display surface.
@ -436,8 +438,6 @@ Version 0.11:
installing fatal signal handlers on operating systems that support
them.
Version 0.9:
0.9.15:
SDL_CreateColorCursor() has been removed. Color cursors should
be implemented as sprites, blitted by the application when the

View File

@ -15,10 +15,10 @@ dnl Set various version strings - taken gratefully from the GTk sources
# set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
#
SDL_MAJOR_VERSION=1
SDL_MINOR_VERSION=2
SDL_MICRO_VERSION=11
SDL_MINOR_VERSION=3
SDL_MICRO_VERSION=0
SDL_INTERFACE_AGE=0
SDL_BINARY_AGE=11
SDL_BINARY_AGE=0
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION
AC_SUBST(SDL_MAJOR_VERSION)
@ -1533,6 +1533,20 @@ CheckMacGL()
fi
}
dnl Find glSDL
CheckglSDL()
{
AC_ARG_ENABLE(video-glsdl,
[ --enable-video-glsdl use glSDL video driver [default=yes]],
, enable_video_glsdl=yes)
AC_MSG_CHECKING(for glSDL support)
AC_MSG_RESULT($video_opengl)
if test x$video_opengl = xyes -a x$enable_video_glsdl = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_GLSDL)
SOURCES="$SOURCES $srcdir/src/video/glsdl/*.c"
fi
}
dnl Check for Mesa offscreen rendering
CheckAtariOSMesa()
{
@ -1847,13 +1861,6 @@ AC_HELP_STRING([--enable-stdio-redirect], [Redirect STDIO to files on Win32 [[de
if test x$enable_stdio_redirect != xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -DNO_STDIO_REDIRECT"
fi
if test x$enable_video = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_WINDIB)
SOURCES="$SOURCES $srcdir/src/video/wincommon/*.c"
SOURCES="$SOURCES $srcdir/src/video/windib/*.c"
have_video=yes
fi
}
dnl Find the DirectX includes and libraries
@ -1863,18 +1870,9 @@ CheckDIRECTX()
AC_HELP_STRING([--enable-directx], [use DirectX for Win32 audio/video [[default=yes]]]),
, enable_directx=yes)
if test x$enable_directx = xyes; then
have_directx=no
AC_CHECK_HEADER(ddraw.h, have_ddraw=yes)
AC_CHECK_HEADER(d3d9.h, have_d3d=yes)
AC_CHECK_HEADER(dsound.h, have_dsound=yes)
AC_CHECK_HEADER(dinput.h, use_dinput=yes)
if test x$have_ddraw = xyes -a x$have_dsound = xyes -a x$use_dinput = xyes; then
have_directx=yes
fi
if test x$enable_video = xyes -a x$have_directx = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_DDRAW)
SOURCES="$SOURCES $srcdir/src/video/windx5/*.c"
have_video=yes
fi
fi
}
@ -2155,6 +2153,7 @@ case "$host" in
CheckQtopia
CheckPicoGUI
CheckOpenGLX11
CheckglSDL
CheckInputEvents
CheckTslib
CheckUSBHID
@ -2253,6 +2252,7 @@ case "$host" in
CheckPHOTON
CheckX11
CheckOpenGLX11
CheckglSDL
CheckPTHREAD
# Set up files for the audio library
if test x$enable_audio = xyes; then
@ -2290,13 +2290,32 @@ case "$host" in
CheckDummyAudio
CheckWIN32
CheckWIN32GL
CheckglSDL
CheckDIRECTX
CheckNASM
# Set up files for the video library
if test x$enable_video = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_WIN32)
SOURCES="$SOURCES $srcdir/src/video/win32/*.c"
have_video=yes
AC_ARG_ENABLE(render-gdi,
AC_HELP_STRING([--enable-render-gdi], [enable the GDI render driver [[default=yes]]]),
, enable_render_gdi=yes)
if test x$enable_render_gdi = xyes; then
AC_DEFINE(SDL_VIDEO_RENDER_GDI)
fi
AC_ARG_ENABLE(render-d3d,
AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[default=yes]]]),
, enable_render_d3d=yes)
if test x$enable_render_d3d = xyes -a x$have_d3d = xyes; then
AC_DEFINE(SDL_VIDEO_RENDER_D3D)
fi
fi
# Set up files for the audio library
if test x$enable_audio = xyes; then
AC_DEFINE(SDL_AUDIO_DRIVER_WAVEOUT)
SOURCES="$SOURCES $srcdir/src/audio/windib/*.c"
if test x$have_directx = xyes; then
if test x$have_dsound = xyes; then
AC_DEFINE(SDL_AUDIO_DRIVER_DSOUND)
SOURCES="$SOURCES $srcdir/src/audio/windx5/*.c"
fi
@ -2304,8 +2323,13 @@ case "$host" in
fi
# Set up files for the joystick library
if test x$enable_joystick = xyes; then
AC_DEFINE(SDL_JOYSTICK_WINMM)
SOURCES="$SOURCES $srcdir/src/joystick/win32/*.c"
if test x$have_dinput = xyes; then
AC_DEFINE(SDL_JOYSTICK_DINPUT)
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_dxjoystick.c"
else
AC_DEFINE(SDL_JOYSTICK_WINMM)
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_mmjoystick.c"
fi
have_joystick=yes
fi
# Set up files for the cdrom library
@ -2336,10 +2360,7 @@ case "$host" in
have_loadso=yes
fi
# Set up the system libraries we need
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm"
if test x$have_directx = xyes; then
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldxguid"
fi
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lmsimg32 -lwinmm"
# The Win32 platform requires special setup
SDLMAIN_SOURCES="$srcdir/src/main/win32/*.c"
SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
@ -2354,6 +2375,7 @@ case "$host" in
CheckNASM
CheckBWINDOW
CheckBeGL
CheckglSDL
# Set up files for the audio library
if test x$enable_audio = xyes; then
AC_DEFINE(SDL_AUDIO_DRIVER_BAUDIO)
@ -2435,6 +2457,7 @@ case "$host" in
CheckX11
CheckMacGL
CheckOpenGLX11
CheckglSDL
CheckPTHREAD
CheckAltivec
@ -2496,6 +2519,7 @@ case "$host" in
CheckAtariAudio
CheckAtariLdg
CheckAtariOSMesa
CheckglSDL
CheckPTH
# Set up files for the audio library
if test x$enable_threads = xyes -a x$enable_pth = xyes; then

View File

@ -14,64 +14,6 @@ The latest stable release may be found on the
<H2> <A HREF="docs/index.html">API Documentation</A> </H2>
<H2> SDL 1.2.11 Release Notes </H2>
<P>
SDL 1.2.11 is a minor bug fix release.
</P>
<H3> Unix Notes </H3>
<BLOCKQUOTE>
<P>
Dynamic X11 loading is only enabled with gcc 4 supporting -fvisibility=hidden. This fixes crashes related to symbol collisions, and allows building on Solaris and IRIX.
</P>
<P>
Fixed building SDL with Xinerama disabled.
</P>
<P>
Fixed DRI OpenGL library loading, using RTLD_GLOBAL in dlopen().
</P>
<P>
Added pkgconfig configuration support.
</P>
</BLOCKQUOTE>
<H3> Windows Notes </H3>
<BLOCKQUOTE>
<P>
Setting SDL_GL_SWAP_CONTROL now works with Windows OpenGL.
</P>
<P>
The Win32 window positioning code works properly for windows with menus.
</P>
<P>
DirectSound audio quality has been improved on certain sound cards.
</P>
<P>
Fixed 5.1 audio channel ordering on Windows and Mac OS X.
</P>
<P>
Plugged a couple of minor memory leaks in the windib video driver.
</P>
<P>
Fixed type collision with stdint.h when building with gcc on Win32.
</P>
<P>
Fixed building with the Digital Mars Compiler on Win32.
</P>
</BLOCKQUOTE>
<H3> Mac OS X Notes </H3>
<BLOCKQUOTE>
<P>
The Quartz video driver supports 32x32 cursors on Mac OS X 10.3 and above.
</P>
</BLOCKQUOTE>
<IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
<H2> SDL 1.2.10 Release Notes </H2>
<P>
SDL 1.2.10 is a major release, featuring a revamp of the build system and many API improvements and bug fixes.

View File

@ -20,7 +20,56 @@
slouken@libsdl.org
*/
/* Main include header for the SDL library */
/**
* \file SDL.h
*
* Main include header for the SDL library
*/
/**
* \mainpage Simple DirectMedia Layer (SDL)
http://www.libsdl.org/
* \section intro_sec Introduction
This is the Simple DirectMedia Layer, a general API that provides low
level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
and 2D framebuffer across multiple platforms.
The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64,
RISC OS, SymbianOS, and OS/2, but these are not officially supported.
SDL is written in C, but works with C++ natively, and has bindings to
several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
Pike, Pliant, Python, Ruby, and Smalltalk.
This library is distributed under GNU LGPL version 2, which can be
found in the file "COPYING". This license allows you to use SDL
freely in commercial programs as long as you link with the dynamic
library.
The best way to learn how to use SDL is to check out the header files in
the "include" subdirectory and the programs in the "test" subdirectory.
The header files and test programs are well commented and always up to date.
More documentation is available in HTML format in "docs/index.html", and
a documentation wiki is available online at:
http://www.libsdl.org/cgi/docwiki.cgi
The test programs in the "test" subdirectory are in the public domain.
Frequently asked questions are answered online:
http://www.libsdl.org/faq.php
If you need help with the library, or just want to discuss SDL related
issues, you can join the developers mailing list:
http://www.libsdl.org/mailing-list.php
Enjoy!
Sam Lantinga (slouken@libsdl.org)
*/
#ifndef _SDL_H
#define _SDL_H
@ -40,11 +89,14 @@
#include "SDL_timer.h"
#include "SDL_video.h"
#include "SDL_version.h"
#include "SDL_compat.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* As of version 0.5, SDL is loaded dynamically into the application */
@ -57,8 +109,8 @@ extern "C" {
#define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_CDROM 0x00000100
#define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
#define SDL_INIT_EVENTTHREAD 0x01000000 /* Not supported on all OS's */
#define SDL_INIT_EVERYTHING 0x0000FFFF
/* This function loads the SDL dynamically linked library and initializes
@ -87,8 +139,12 @@ extern DECLSPEC void SDLCALL SDL_Quit(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_H */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,58 +0,0 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/* Include file for SDL application focus event handling */
#ifndef _SDL_active_h
#define _SDL_active_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* The available application states */
#define SDL_APPMOUSEFOCUS 0x01 /* The app has mouse coverage */
#define SDL_APPINPUTFOCUS 0x02 /* The app has input focus */
#define SDL_APPACTIVE 0x04 /* The application is active */
/* Function prototypes */
/*
* This function returns the current state of the application, which is a
* bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and
* SDL_APPACTIVE. If SDL_APPACTIVE is set, then the user is able to
* see your application, otherwise it has been iconified or disabled.
*/
extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_active_h */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Access to the raw audio mixing buffer for the SDL library */
/**
* \file SDL_audio.h
*
* Access to the raw audio mixing buffer for the SDL library
*/
#ifndef _SDL_audio_h
#define _SDL_audio_h
@ -35,35 +39,38 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* The calculated values in this structure are calculated by SDL_OpenAudio() */
typedef struct SDL_AudioSpec {
int freq; /* DSP frequency -- samples per second */
Uint16 format; /* Audio data format */
Uint8 channels; /* Number of channels: 1 mono, 2 stereo */
Uint8 silence; /* Audio buffer silence value (calculated) */
Uint16 samples; /* Audio buffer size in samples (power of 2) */
Uint16 padding; /* Necessary for some compile environments */
Uint32 size; /* Audio buffer size in bytes (calculated) */
/* This function is called when the audio device needs more data.
'stream' is a pointer to the audio data buffer
'len' is the length of that buffer in bytes.
Once the callback returns, the buffer will no longer be valid.
Stereo samples are stored in a LRLRLR ordering.
*/
void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);
void *userdata;
typedef struct SDL_AudioSpec
{
int freq; /* DSP frequency -- samples per second */
Uint16 format; /* Audio data format */
Uint8 channels; /* Number of channels: 1 mono, 2 stereo */
Uint8 silence; /* Audio buffer silence value (calculated) */
Uint16 samples; /* Audio buffer size in samples (power of 2) */
Uint16 padding; /* Necessary for some compile environments */
Uint32 size; /* Audio buffer size in bytes (calculated) */
/* This function is called when the audio device needs more data.
'stream' is a pointer to the audio data buffer
'len' is the length of that buffer in bytes.
Once the callback returns, the buffer will no longer be valid.
Stereo samples are stored in a LRLRLR ordering.
*/
void (SDLCALL * callback) (void *userdata, Uint8 * stream, int len);
void *userdata;
} SDL_AudioSpec;
/* Audio format flags (defaults to LSB byte order) */
#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */
#define AUDIO_S8 0x8008 /* Signed 8-bit samples */
#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */
#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */
#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */
#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */
#define AUDIO_U8 0x0008 /* Unsigned 8-bit samples */
#define AUDIO_S8 0x8008 /* Signed 8-bit samples */
#define AUDIO_U16LSB 0x0010 /* Unsigned 16-bit samples */
#define AUDIO_S16LSB 0x8010 /* Signed 16-bit samples */
#define AUDIO_U16MSB 0x1010 /* As above, but big-endian byte order */
#define AUDIO_S16MSB 0x9010 /* As above, but big-endian byte order */
#define AUDIO_U16 AUDIO_U16LSB
#define AUDIO_S16 AUDIO_S16LSB
@ -78,23 +85,30 @@ typedef struct SDL_AudioSpec {
/* A structure to hold a set of audio conversion filters and buffers */
typedef struct SDL_AudioCVT {
int needed; /* Set to 1 if conversion possible */
Uint16 src_format; /* Source audio format */
Uint16 dst_format; /* Target audio format */
double rate_incr; /* Rate conversion increment */
Uint8 *buf; /* Buffer to hold entire audio data */
int len; /* Length of original audio buffer */
int len_cvt; /* Length of converted audio buffer */
int len_mult; /* buffer must be len*len_mult big */
double len_ratio; /* Given len, final size is len*len_ratio */
void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
int filter_index; /* Current audio conversion function */
typedef struct SDL_AudioCVT
{
int needed; /* Set to 1 if conversion possible */
Uint16 src_format; /* Source audio format */
Uint16 dst_format; /* Target audio format */
double rate_incr; /* Rate conversion increment */
Uint8 *buf; /* Buffer to hold entire audio data */
int len; /* Length of original audio buffer */
int len_cvt; /* Length of converted audio buffer */
int len_mult; /* buffer must be len*len_mult big */
double len_ratio; /* Given len, final size is len*len_ratio */
void (SDLCALL * filters[10]) (struct SDL_AudioCVT * cvt, Uint16 format);
int filter_index; /* Current audio conversion function */
} SDL_AudioCVT;
/* Function prototypes */
/* These functions return the list of built in video drivers, in the
* order that they are normally initialized by default.
*/
extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
/* These functions are used internally, and should not be used unless you
* have a specific need to specify the audio driver you want to use.
* You should normally use SDL_Init() or SDL_InitSubSystem().
@ -102,11 +116,10 @@ typedef struct SDL_AudioCVT {
extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
/* This function fills the given character buffer with the name of the
* current audio driver, and returns a pointer to it if the audio driver has
* been initialized. It returns NULL if no driver has been initialized.
/* This function returns the name of the current audio driver, or NULL
* if no driver has been initialized.
*/
extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
/*
* This function opens the audio device with the desired parameters, and
@ -149,15 +162,17 @@ extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
* may modify the requested size of the audio buffer, you should allocate
* any local mixing buffers after you open the audio device.
*/
extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained);
extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
SDL_AudioSpec * obtained);
/*
* Get the current audio state:
*/
typedef enum {
SDL_AUDIO_STOPPED = 0,
SDL_AUDIO_PLAYING,
SDL_AUDIO_PAUSED
typedef enum
{
SDL_AUDIO_STOPPED = 0,
SDL_AUDIO_PLAYING,
SDL_AUDIO_PAUSED
} SDL_audiostatus;
extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void);
@ -187,7 +202,11 @@ extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
* wave file cannot be opened, uses an unknown data format, or is
* corrupt. Currently raw and MS-ADPCM WAVE files are supported.
*/
extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
int freesrc,
SDL_AudioSpec * spec,
Uint8 ** audio_buf,
Uint32 * audio_len);
/* Compatibility convenience function -- loads a WAV from a file */
#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
@ -196,7 +215,7 @@ extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int frees
/*
* This function frees data previously allocated with SDL_LoadWAV_RW()
*/
extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 *audio_buf);
extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
/*
* This function takes a source format and rate and a destination format
@ -205,9 +224,13 @@ extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 *audio_buf);
* to the other.
* This function returns 0, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
Uint16 src_format, Uint8 src_channels, int src_rate,
Uint16 dst_format, Uint8 dst_channels, int dst_rate);
extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
Uint16 src_format,
Uint8 src_channels,
int src_rate,
Uint16 dst_format,
Uint8 dst_channels,
int dst_rate);
/* Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(),
* created an audio buffer cvt->buf, and filled it with cvt->len bytes of
@ -217,7 +240,7 @@ extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
* cvt->buf should be allocated after the cvt structure is initialized by
* SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long.
*/
extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt);
extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
/*
* This takes two audio buffers of the playing audio format and mixes
@ -227,7 +250,8 @@ extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt);
* This is provided for convenience -- you can mix your own audio data.
*/
#define SDL_MIX_MAXVOLUME 128
extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, Uint32 len, int volume);
extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
Uint32 len, int volume);
/*
* The lock manipulated by these functions protects the callback function.
@ -246,8 +270,12 @@ extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_audio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* This is the CD-audio control API for Simple DirectMedia Layer */
/**
* \file SDL_cdrom.h
*
* This is the CD-audio control API for Simple DirectMedia Layer
*/
#ifndef _SDL_cdrom_h
#define _SDL_cdrom_h
@ -31,7 +35,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* In order to use these functions, SDL_Init() must have been called
@ -47,35 +53,38 @@ extern "C" {
#define SDL_DATA_TRACK 0x04
/* The possible states which a CD-ROM drive can be in. */
typedef enum {
CD_TRAYEMPTY,
CD_STOPPED,
CD_PLAYING,
CD_PAUSED,
CD_ERROR = -1
typedef enum
{
CD_TRAYEMPTY,
CD_STOPPED,
CD_PLAYING,
CD_PAUSED,
CD_ERROR = -1
} CDstatus;
/* Given a status, returns true if there's a disk in the drive */
#define CD_INDRIVE(status) ((int)(status) > 0)
typedef struct SDL_CDtrack {
Uint8 id; /* Track number */
Uint8 type; /* Data or audio track */
Uint16 unused;
Uint32 length; /* Length, in frames, of this track */
Uint32 offset; /* Offset, in frames, from start of disk */
typedef struct SDL_CDtrack
{
Uint8 id; /* Track number */
Uint8 type; /* Data or audio track */
Uint16 unused;
Uint32 length; /* Length, in frames, of this track */
Uint32 offset; /* Offset, in frames, from start of disk */
} SDL_CDtrack;
/* This structure is only current as of the last call to SDL_CDStatus() */
typedef struct SDL_CD {
int id; /* Private drive identifier */
CDstatus status; /* Current drive status */
typedef struct SDL_CD
{
int id; /* Private drive identifier */
CDstatus status; /* Current drive status */
/* The rest of this structure is only valid if there's a CD in drive */
int numtracks; /* Number of tracks on disk */
int cur_track; /* Current track position */
int cur_frame; /* Current frame offset within current track */
SDL_CDtrack track[SDL_MAX_TRACKS+1];
/* The rest of this structure is only valid if there's a CD in drive */
int numtracks; /* Number of tracks on disk */
int cur_track; /* Current track position */
int cur_frame; /* Current frame offset within current track */
SDL_CDtrack track[SDL_MAX_TRACKS + 1];
} SDL_CD;
/* Conversion functions from frames to Minute/Second/Frames and vice versa */
@ -103,7 +112,7 @@ extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
"E:"
"/dev/disk/ide/1/master"
*/
extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
extern DECLSPEC const char *SDLCALL SDL_CDName(int drive);
/* Opens a CD-ROM drive for access. It returns a drive handle on success,
or NULL if the drive was invalid or busy. This newly opened CD-ROM
@ -111,13 +120,13 @@ extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
CD-ROM handle.
Drives are numbered starting with 0. Drive 0 is the system default CD-ROM.
*/
extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive);
extern DECLSPEC SDL_CD *SDLCALL SDL_CDOpen(int drive);
/* This function returns the current status of the given drive.
If the drive has a CD in it, the table of contents of the CD and current
play position of the CD will be stored in the SDL_CD structure.
*/
extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD * cdrom);
/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play
@ -138,34 +147,40 @@ extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
This function returns 0, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
int start_track, int start_frame, int ntracks, int nframes);
extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD * cdrom,
int start_track,
int start_frame, int ntracks,
int nframes);
/* Play the given CD starting at 'start' frame for 'length' frames.
It returns 0, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length);
extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD * cdrom, int start, int length);
/* Pause play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom);
extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD * cdrom);
/* Resume play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom);
extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD * cdrom);
/* Stop play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom);
extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD * cdrom);
/* Eject CD-ROM -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom);
extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD * cdrom);
/* Closes the handle for the CD-ROM drive */
extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom);
extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD * cdrom);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_video_h */
/* vi: set ts=4 sw=4 expandtab: */

186
include/SDL_compat.h Normal file
View File

@ -0,0 +1,186 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/* This file contains functions for backwards compatibility with SDL 1.2 */
#ifndef _SDL_compat_h
#define _SDL_compat_h
#include "SDL_video.h"
#include "SDL_version.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
#define SDL_SWSURFACE 0x00000000
#define SDL_ANYFORMAT 0x00100000
#define SDL_HWPALETTE 0x00200000
#define SDL_DOUBLEBUF 0x00400000
#define SDL_FULLSCREEN 0x00800000
#define SDL_RESIZABLE 0x01000000
#define SDL_NOFRAME 0x02000000
#define SDL_OPENGL 0x04000000
#define SDL_ASYNCBLIT 0x08000000 /* Not used */
#define SDL_HWACCEL 0x08000000 /* Not used */
#define SDL_APPMOUSEFOCUS 0x01
#define SDL_APPINPUTFOCUS 0x02
#define SDL_APPACTIVE 0x04
#define SDL_LOGPAL 0x01
#define SDL_PHYSPAL 0x02
#define SDL_ACTIVEEVENT SDL_EVENT_RESERVED1
#define SDL_VIDEORESIZE SDL_EVENT_RESERVED2
#define SDL_VIDEOEXPOSE SDL_EVENT_RESERVED3
#define SDL_ACTIVEEVENTMASK SDL_EVENTMASK(SDL_ACTIVEEVENT)
#define SDL_VIDEORESIZEMASK SDL_EVENTMASK(SDL_VIDEORESIZE)
#define SDL_VIDEOEXPOSEMASK SDL_EVENTMASK(SDL_VIDEOEXPOSE)
#define SDL_BUTTON_WHEELUP 4
#define SDL_BUTTON_WHEELDOWN 5
typedef struct SDL_VideoInfo
{
Uint32 hw_available:1;
Uint32 wm_available:1;
Uint32 UnusedBits1:6;
Uint32 UnusedBits2:1;
Uint32 blit_hw:1;
Uint32 blit_hw_CC:1;
Uint32 blit_hw_A:1;
Uint32 blit_sw:1;
Uint32 blit_sw_CC:1;
Uint32 blit_sw_A:1;
Uint32 blit_fill:1;
Uint32 UnusedBits3:16;
Uint32 video_mem;
SDL_PixelFormat *vfmt;
} SDL_VideoInfo;
/* The most common video overlay formats.
For an explanation of these pixel formats, see:
http://www.webartz.com/fourcc/indexyuv.htm
For information on the relationship between color spaces, see:
http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
*/
#define SDL_YV12_OVERLAY 0x32315659 /* Planar mode: Y + V + U (3 planes) */
#define SDL_IYUV_OVERLAY 0x56555949 /* Planar mode: Y + U + V (3 planes) */
#define SDL_YUY2_OVERLAY 0x32595559 /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
#define SDL_UYVY_OVERLAY 0x59565955 /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
#define SDL_YVYU_OVERLAY 0x55595659 /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
/* The YUV hardware video overlay */
typedef struct SDL_Overlay
{
Uint32 format; /* Read-only */
int w, h; /* Read-only */
int planes; /* Read-only */
Uint16 *pitches; /* Read-only */
Uint8 **pixels; /* Read-write */
/* Hardware-specific surface info */
struct private_yuvhwfuncs *hwfuncs;
struct private_yuvhwdata *hwdata;
/* Special flags */
Uint32 hw_overlay:1; /* Flag: This overlay hardware accelerated? */
Uint32 UnusedBits:31;
} SDL_Overlay;
typedef enum
{
SDL_GRAB_QUERY = -1,
SDL_GRAB_OFF = 0,
SDL_GRAB_ON = 1
} SDL_GrabMode;
struct SDL_SysWMinfo;
#define SDL_SetModuleHandle(x)
#define SDL_AllocSurface SDL_CreateRGBSurface
extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version(void);
extern DECLSPEC char *SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
extern DECLSPEC char *SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo(void);
extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp,
Uint32 flags);
extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes(SDL_PixelFormat * format,
Uint32 flags);
extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode(int width, int height,
int bpp, Uint32 flags);
extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface(void);
extern DECLSPEC void SDLCALL SDL_UpdateRects(SDL_Surface * screen,
int numrects, SDL_Rect * rects);
extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen, Sint32 x,
Sint32 y, Uint32 w, Uint32 h);
extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
surface);
extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title,
const char *icon);
extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon);
extern DECLSPEC void SDLCALL SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask);
extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void);
extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface);
extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags,
const SDL_Color * colors,
int firstcolor, int ncolors);
extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface,
const SDL_Color * colors,
int firstcolor, int ncolors);
extern DECLSPEC int SDLCALL SDL_GetWMInfo(struct SDL_SysWMinfo *info);
extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
extern DECLSPEC SDL_Overlay *SDLCALL SDL_CreateYUVOverlay(int width,
int height,
Uint32 format,
SDL_Surface *
display);
extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
SDL_Rect * dstrect);
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_compat_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -198,6 +198,7 @@
#undef SDL_JOYSTICK_AMIGA
#undef SDL_JOYSTICK_BEOS
#undef SDL_JOYSTICK_DC
#undef SDL_JOYSTICK_DINPUT
#undef SDL_JOYSTICK_DUMMY
#undef SDL_JOYSTICK_IOKIT
#undef SDL_JOYSTICK_LINUX
@ -252,7 +253,6 @@
#undef SDL_VIDEO_DRIVER_BWINDOW
#undef SDL_VIDEO_DRIVER_CYBERGRAPHICS
#undef SDL_VIDEO_DRIVER_DC
#undef SDL_VIDEO_DRIVER_DDRAW
#undef SDL_VIDEO_DRIVER_DGA
#undef SDL_VIDEO_DRIVER_DIRECTFB
#undef SDL_VIDEO_DRIVER_DRAWSPROCKET
@ -262,6 +262,7 @@
#undef SDL_VIDEO_DRIVER_GAPI
#undef SDL_VIDEO_DRIVER_GEM
#undef SDL_VIDEO_DRIVER_GGI
#undef SDL_VIDEO_DRIVER_GLSDL
#undef SDL_VIDEO_DRIVER_IPOD
#undef SDL_VIDEO_DRIVER_NANOX
#undef SDL_VIDEO_DRIVER_OS2FS
@ -274,7 +275,7 @@
#undef SDL_VIDEO_DRIVER_SVGALIB
#undef SDL_VIDEO_DRIVER_TOOLBOX
#undef SDL_VIDEO_DRIVER_VGL
#undef SDL_VIDEO_DRIVER_WINDIB
#undef SDL_VIDEO_DRIVER_WIN32
#undef SDL_VIDEO_DRIVER_WSCONS
#undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
@ -290,6 +291,10 @@
#undef SDL_VIDEO_DRIVER_X11_XV
#undef SDL_VIDEO_DRIVER_XBIOS
#undef SDL_VIDEO_RENDER_D3D
#undef SDL_VIDEO_RENDER_GDI
#undef SDL_VIDEO_RENDER_OGL
/* Enable OpenGL support */
#undef SDL_VIDEO_OPENGL
#undef SDL_VIDEO_OPENGL_GLX

View File

@ -73,6 +73,7 @@
/* Enable various video drivers */
#define SDL_VIDEO_DRIVER_CYBERGRAPHICS 1
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_GLSDL 1
/* Enable OpenGL support */
#define SDL_VIDEO_OPENGL 1

View File

@ -102,5 +102,6 @@ typedef unsigned long uintptr_t;
/* Enable various video drivers */
#define SDL_VIDEO_DRIVER_DC 1
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_GLSDL 1
#endif /* _SDL_config_dreamcast_h */

View File

@ -29,15 +29,15 @@
#include <MacTypes.h>
typedef SInt8 int8_t;
typedef UInt8 uint8_t;
typedef SInt16 int16_t;
typedef UInt16 uint16_t;
typedef SInt32 int32_t;
typedef UInt32 uint32_t;
typedef SInt64 int64_t;
typedef UInt64 uint64_t;
typedef unsigned long uintptr_t;
typedef SInt8 int8_t;
typedef UInt8 uint8_t;
typedef SInt16 int16_t;
typedef UInt16 uint16_t;
typedef SInt32 int32_t;
typedef UInt32 uint32_t;
typedef SInt64 int64_t;
typedef UInt64 uint64_t;
typedef unsigned long uintptr_t;
#define SDL_HAS_64BIT_TYPE 1
@ -104,6 +104,7 @@ typedef unsigned long uintptr_t;
/* Enable various video drivers */
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_DRAWSPROCKET 1
#define SDL_VIDEO_DRIVER_GLSDL 1
#define SDL_VIDEO_DRIVER_TOOLBOX 1
/* Enable OpenGL support */

View File

@ -27,16 +27,16 @@
/* This is a set of defines to configure the SDL features */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef unsigned int size_t;
typedef unsigned long uintptr_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef unsigned int size_t;
typedef unsigned long uintptr_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#define SDL_HAS_64BIT_TYPE 1

View File

@ -30,23 +30,23 @@
#ifdef __GNUC__
#define HAVE_STDINT_H 1
#elif defined(_MSC_VER)
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
typedef unsigned int uintptr_t;
#endif
#define _UINTPTR_T_DEFINED
#endif
#else /* !__GNUC__ && !_MSC_VER */
#else /* !__GNUC__ && !_MSC_VER */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
@ -150,19 +150,17 @@ typedef unsigned int uintptr_t;
#endif
/* Enable various video drivers */
#ifdef _WIN32_WCE
#define SDL_VIDEO_DRIVER_GAPI 1
#endif
#ifndef _WIN32_WCE
#define SDL_VIDEO_DRIVER_DDRAW 1
#endif
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_WINDIB 1
#define SDL_VIDEO_DRIVER_WIN32 1
#define SDL_VIDEO_RENDER_D3D 1
#define SDL_VIDEO_RENDER_GDI 1
/* Enable OpenGL support */
#ifndef _WIN32_WCE
#define SDL_VIDEO_OPENGL 1
#define SDL_VIDEO_OPENGL_WGL 1
#define SDL_VIDEO_RENDER_OGL 1
#endif
/* Enable assembly routines (Win64 doesn't have inline asm) */

View File

@ -19,4 +19,3 @@
Sam Lantinga
slouken@libsdl.org
*/

View File

@ -20,8 +20,11 @@
slouken@libsdl.org
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* CPU feature detection for SDL */
/**
* \file SDL_cpuinfo.h
*
* CPU feature detection for SDL
*/
#ifndef _SDL_cpuinfo_h
#define _SDL_cpuinfo_h
@ -31,7 +34,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* This function returns true if the CPU has the RDTSC instruction
@ -68,8 +73,12 @@ extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_cpuinfo_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Functions for reading and writing endian-specific values */
/**
* \file SDL_endian.h
*
* Functions for reading and writing endian-specific values
*/
#ifndef _SDL_endian_h
#define _SDL_endian_h
@ -31,7 +35,7 @@
#define SDL_LIL_ENDIAN 1234
#define SDL_BIG_ENDIAN 4321
#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
#if defined(__hppa__) || \
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
(defined(__MIPS__) && defined(__MISPEB__)) || \
@ -47,7 +51,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Use inline functions for compilers that support them, and static
@ -57,104 +63,124 @@ extern "C" {
*/
#if defined(__GNUC__) && defined(__i386__) && \
!(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
static __inline__ Uint16 SDL_Swap16(Uint16 x)
static __inline__ Uint16
SDL_Swap16(Uint16 x)
{
__asm__("xchgb %b0,%h0" : "=q" (x) : "0" (x));
return x;
__asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
return x;
}
#elif defined(__GNUC__) && defined(__x86_64__)
static __inline__ Uint16 SDL_Swap16(Uint16 x)
static __inline__ Uint16
SDL_Swap16(Uint16 x)
{
__asm__("xchgb %b0,%h0" : "=Q" (x) : "0" (x));
return x;
__asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
return x;
}
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
static __inline__ Uint16 SDL_Swap16(Uint16 x)
static __inline__ Uint16
SDL_Swap16(Uint16 x)
{
Uint16 result;
Uint16 result;
__asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x));
return result;
__asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
return result;
}
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
static __inline__ Uint16 SDL_Swap16(Uint16 x)
static __inline__ Uint16
SDL_Swap16(Uint16 x)
{
__asm__("rorw #8,%0" : "=d" (x) : "0" (x) : "cc");
return x;
__asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
return x;
}
#else
static __inline__ Uint16 SDL_Swap16(Uint16 x) {
return((x<<8)|(x>>8));
static __inline__ Uint16
SDL_Swap16(Uint16 x)
{
return ((x << 8) | (x >> 8));
}
#endif
#if defined(__GNUC__) && defined(__i386__)
static __inline__ Uint32 SDL_Swap32(Uint32 x)
static __inline__ Uint32
SDL_Swap32(Uint32 x)
{
__asm__("bswap %0" : "=r" (x) : "0" (x));
return x;
__asm__("bswap %0": "=r"(x):"0"(x));
return x;
}
#elif defined(__GNUC__) && defined(__x86_64__)
static __inline__ Uint32 SDL_Swap32(Uint32 x)
static __inline__ Uint32
SDL_Swap32(Uint32 x)
{
__asm__("bswapl %0" : "=r" (x) : "0" (x));
return x;
__asm__("bswapl %0": "=r"(x):"0"(x));
return x;
}
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
static __inline__ Uint32 SDL_Swap32(Uint32 x)
static __inline__ Uint32
SDL_Swap32(Uint32 x)
{
Uint32 result;
Uint32 result;
__asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
__asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x));
__asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x));
return result;
__asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
__asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
__asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
return result;
}
#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__))
static __inline__ Uint32 SDL_Swap32(Uint32 x)
static __inline__ Uint32
SDL_Swap32(Uint32 x)
{
__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) : "0" (x) : "cc");
return x;
__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
return x;
}
#else
static __inline__ Uint32 SDL_Swap32(Uint32 x) {
return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24));
static __inline__ Uint32
SDL_Swap32(Uint32 x)
{
return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) |
(x >> 24));
}
#endif
#ifdef SDL_HAS_64BIT_TYPE
#if defined(__GNUC__) && defined(__i386__)
static __inline__ Uint64 SDL_Swap64(Uint64 x)
static __inline__ Uint64
SDL_Swap64(Uint64 x)
{
union {
struct { Uint32 a,b; } s;
Uint64 u;
} v;
v.u = x;
__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
: "=r" (v.s.a), "=r" (v.s.b)
: "0" (v.s.a), "1" (v.s.b));
return v.u;
union
{
struct
{
Uint32 a, b;
} s;
Uint64 u;
} v;
v.u = x;
__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
"1"(v.s.
b));
return v.u;
}
#elif defined(__GNUC__) && defined(__x86_64__)
static __inline__ Uint64 SDL_Swap64(Uint64 x)
static __inline__ Uint64
SDL_Swap64(Uint64 x)
{
__asm__("bswapq %0" : "=r" (x) : "0" (x));
return x;
__asm__("bswapq %0": "=r"(x):"0"(x));
return x;
}
#else
static __inline__ Uint64 SDL_Swap64(Uint64 x)
static __inline__ Uint64
SDL_Swap64(Uint64 x)
{
Uint32 hi, lo;
Uint32 hi, lo;
/* Separate into high and low 32-bit values and swap them */
lo = (Uint32)(x&0xFFFFFFFF);
x >>= 32;
hi = (Uint32)(x&0xFFFFFFFF);
x = SDL_Swap32(lo);
x <<= 32;
x |= SDL_Swap32(hi);
return(x);
/* Separate into high and low 32-bit values and swap them */
lo = (Uint32) (x & 0xFFFFFFFF);
x >>= 32;
hi = (Uint32) (x & 0xFFFFFFFF);
x = SDL_Swap32(lo);
x <<= 32;
x |= SDL_Swap32(hi);
return (x);
}
#endif
#else
@ -185,8 +211,12 @@ static __inline__ Uint64 SDL_Swap64(Uint64 x)
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_endian_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,10 @@
slouken@libsdl.org
*/
/* Simple error message routines for SDL */
/**
* \file SDL_error.h
* Simple error message routines for SDL
*/
#ifndef _SDL_error_h
#define _SDL_error_h
@ -30,32 +33,39 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Public functions */
extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...);
extern DECLSPEC char * SDLCALL SDL_GetError(void);
extern DECLSPEC char *SDLCALL SDL_GetError(void);
extern DECLSPEC void SDLCALL SDL_ClearError(void);
/* Private error message function - used internally */
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
typedef enum {
SDL_ENOMEM,
SDL_EFREAD,
SDL_EFWRITE,
SDL_EFSEEK,
SDL_UNSUPPORTED,
SDL_LASTERROR
typedef enum
{
SDL_ENOMEM,
SDL_EFREAD,
SDL_EFWRITE,
SDL_EFSEEK,
SDL_UNSUPPORTED,
SDL_LASTERROR
} SDL_errorcode;
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_error_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,14 +20,18 @@
slouken@libsdl.org
*/
/* Include file for SDL event handling */
/**
* \file SDL_events.h
*
* Include file for SDL event handling
*/
#ifndef _SDL_events_h
#define _SDL_events_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_active.h"
#include "SDL_video.h"
#include "SDL_keyboard.h"
#include "SDL_mouse.h"
#include "SDL_joystick.h"
@ -36,202 +40,304 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* General keyboard/mouse state definitions */
#define SDL_RELEASED 0
#define SDL_PRESSED 1
/* Event enumerations */
typedef enum {
SDL_NOEVENT = 0, /* Unused (do not remove) */
SDL_ACTIVEEVENT, /* Application loses/gains visibility */
SDL_KEYDOWN, /* Keys pressed */
SDL_KEYUP, /* Keys released */
SDL_MOUSEMOTION, /* Mouse moved */
SDL_MOUSEBUTTONDOWN, /* Mouse button pressed */
SDL_MOUSEBUTTONUP, /* Mouse button released */
SDL_JOYAXISMOTION, /* Joystick axis motion */
SDL_JOYBALLMOTION, /* Joystick trackball motion */
SDL_JOYHATMOTION, /* Joystick hat position change */
SDL_JOYBUTTONDOWN, /* Joystick button pressed */
SDL_JOYBUTTONUP, /* Joystick button released */
SDL_QUIT, /* User-requested quit */
SDL_SYSWMEVENT, /* System specific event */
SDL_EVENT_RESERVEDA, /* Reserved for future use.. */
SDL_EVENT_RESERVEDB, /* Reserved for future use.. */
SDL_VIDEORESIZE, /* User resized video mode */
SDL_VIDEOEXPOSE, /* Screen needs to be redrawn */
SDL_EVENT_RESERVED2, /* Reserved for future use.. */
SDL_EVENT_RESERVED3, /* Reserved for future use.. */
SDL_EVENT_RESERVED4, /* Reserved for future use.. */
SDL_EVENT_RESERVED5, /* Reserved for future use.. */
SDL_EVENT_RESERVED6, /* Reserved for future use.. */
SDL_EVENT_RESERVED7, /* Reserved for future use.. */
/* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
SDL_USEREVENT = 24,
/* This last event is only for bounding internal arrays
It is the number of bits in the event mask datatype -- Uint32
*/
SDL_NUMEVENTS = 32
/**
* \enum SDL_EventType
*
* \brief The types of events that can be delivered
*/
typedef enum
{
SDL_NOEVENT = 0, /**< Unused (do not remove) */
SDL_WINDOWEVENT, /**< Window state change */
SDL_KEYDOWN, /**< Keys pressed */
SDL_KEYUP, /**< Keys released */
SDL_TEXTINPUT, /**< Keyboard text input */
SDL_MOUSEMOTION, /**< Mouse moved */
SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
SDL_MOUSEBUTTONUP, /**< Mouse button released */
SDL_MOUSEWHEEL, /**< Mouse wheel motion */
SDL_JOYAXISMOTION, /**< Joystick axis motion */
SDL_JOYBALLMOTION, /**< Joystick trackball motion */
SDL_JOYHATMOTION, /**< Joystick hat position change */
SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
SDL_JOYBUTTONUP, /**< Joystick button released */
SDL_QUIT, /**< User-requested quit */
SDL_SYSWMEVENT, /**< System specific event */
SDL_EVENT_RESERVED1, /**< Reserved for future use... */
SDL_EVENT_RESERVED2, /**< Reserved for future use... */
SDL_EVENT_RESERVED3, /**< Reserved for future use... */
/* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
SDL_USEREVENT = 24,
/* This last event is only for bounding internal arrays
It is the number of bits in the event mask datatype -- Uint32
*/
SDL_NUMEVENTS = 32
} SDL_EventType;
/* Predefined event masks */
/**
* \enum SDL_EventMask
*
* \brief Predefined event masks
*/
#define SDL_EVENTMASK(X) (1<<(X))
typedef enum {
SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT),
SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN),
SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP),
SDL_KEYEVENTMASK = SDL_EVENTMASK(SDL_KEYDOWN)|
SDL_EVENTMASK(SDL_KEYUP),
SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION),
SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION)|
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION),
SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION),
SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION),
SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION)|
SDL_EVENTMASK(SDL_JOYBALLMOTION)|
SDL_EVENTMASK(SDL_JOYHATMOTION)|
SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE),
SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE),
SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT)
} SDL_EventMask ;
typedef enum
{
SDL_WINDOWEVENTMASK = SDL_EVENTMASK(SDL_WINDOWEVENT),
SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN),
SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP),
SDL_KEYEVENTMASK = SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP),
SDL_TEXTINPUTMASK = SDL_EVENTMASK(SDL_TEXTINPUT),
SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION),
SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_MOUSEWHEELMASK = SDL_EVENTMASK(SDL_MOUSEWHEEL),
SDL_MOUSEEVENTMASK = SDL_EVENTMASK(SDL_MOUSEMOTION) |
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN) | SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_JOYAXISMOTIONMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION),
SDL_JOYBALLMOTIONMASK = SDL_EVENTMASK(SDL_JOYBALLMOTION),
SDL_JOYHATMOTIONMASK = SDL_EVENTMASK(SDL_JOYHATMOTION),
SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_JOYEVENTMASK = SDL_EVENTMASK(SDL_JOYAXISMOTION) |
SDL_EVENTMASK(SDL_JOYBALLMOTION) |
SDL_EVENTMASK(SDL_JOYHATMOTION) |
SDL_EVENTMASK(SDL_JOYBUTTONDOWN) | SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT)
} SDL_EventMask;
#define SDL_ALLEVENTS 0xFFFFFFFF
/* Application visibility event structure */
typedef struct SDL_ActiveEvent {
Uint8 type; /* SDL_ACTIVEEVENT */
Uint8 gain; /* Whether given states were gained or lost (1/0) */
Uint8 state; /* A mask of the focus states */
} SDL_ActiveEvent;
/**
* \struct SDL_WindowEvent
*
* \brief Window state change event data
*/
typedef struct SDL_WindowEvent
{
Uint8 type; /**< SDL_WINDOWEVENT */
Uint8 event; /**< SDL_WindowEventID */
int data1; /**< event dependent data */
int data2; /**< event dependent data */
SDL_WindowID windowID; /**< The associated window */
} SDL_WindowEvent;
/* Keyboard event structure */
typedef struct SDL_KeyboardEvent {
Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */
Uint8 which; /* The keyboard device index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
SDL_keysym keysym;
/**
* \struct SDL_KeyboardEvent
*
* \brief Keyboard button event structure
*/
typedef struct SDL_KeyboardEvent
{
Uint8 type; /**< SDL_KEYDOWN or SDL_KEYUP */
Uint8 which; /**< The keyboard device index */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
SDL_keysym keysym; /**< The key that was pressed or released */
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
} SDL_KeyboardEvent;
/* Mouse motion event structure */
typedef struct SDL_MouseMotionEvent {
Uint8 type; /* SDL_MOUSEMOTION */
Uint8 which; /* The mouse device index */
Uint8 state; /* The current button state */
Uint16 x, y; /* The X/Y coordinates of the mouse */
Sint16 xrel; /* The relative motion in the X direction */
Sint16 yrel; /* The relative motion in the Y direction */
/**
* \struct SDL_TextInputEvent
*
* \brief Keyboard text input event structure
*/
typedef struct SDL_TextInputEvent
{
Uint8 type; /**< SDL_TEXTINPUT */
Uint8 which; /**< The keyboard device index */
char text[32]; /**< The input text */
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
} SDL_TextInputEvent;
/**
* \struct SDL_MouseMotionEvent
*
* \brief Mouse motion event structure
*/
typedef struct SDL_MouseMotionEvent
{
Uint8 type; /**< SDL_MOUSEMOTION */
Uint8 which; /**< The mouse device index */
Uint8 state; /**< The current button state */
int x; /**< X coordinate, relative to window */
int y; /**< Y coordinate, relative to window */
int xrel; /**< The relative motion in the X direction */
int yrel; /**< The relative motion in the Y direction */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
} SDL_MouseMotionEvent;
/* Mouse button event structure */
typedef struct SDL_MouseButtonEvent {
Uint8 type; /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
Uint8 which; /* The mouse device index */
Uint8 button; /* The mouse button index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
Uint16 x, y; /* The X/Y coordinates of the mouse at press time */
/**
* \struct SDL_MouseButtonEvent
*
* \brief Mouse button event structure
*/
typedef struct SDL_MouseButtonEvent
{
Uint8 type; /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
Uint8 which; /**< The mouse device index */
Uint8 button; /**< The mouse button index */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
int x; /**< X coordinate, relative to window */
int y; /**< Y coordinate, relative to window */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
} SDL_MouseButtonEvent;
/* Joystick axis motion event structure */
typedef struct SDL_JoyAxisEvent {
Uint8 type; /* SDL_JOYAXISMOTION */
Uint8 which; /* The joystick device index */
Uint8 axis; /* The joystick axis index */
Sint16 value; /* The axis value (range: -32768 to 32767) */
/**
* \struct SDL_MouseWheelEvent
*
* \brief Mouse wheel event structure
*/
typedef struct SDL_MouseWheelEvent
{
Uint8 type; /**< SDL_MOUSEWHEEL */
Uint8 which; /**< The mouse device index */
int motion; /**< The direction and distance scrolled */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
} SDL_MouseWheelEvent;
/**
* \struct SDL_JoyAxisEvent
*
* \brief Joystick axis motion event structure
*/
typedef struct SDL_JoyAxisEvent
{
Uint8 type; /**< SDL_JOYAXISMOTION */
Uint8 which; /**< The joystick device index */
Uint8 axis; /**< The joystick axis index */
int value; /**< The axis value (range: -32768 to 32767) */
} SDL_JoyAxisEvent;
/* Joystick trackball motion event structure */
typedef struct SDL_JoyBallEvent {
Uint8 type; /* SDL_JOYBALLMOTION */
Uint8 which; /* The joystick device index */
Uint8 ball; /* The joystick trackball index */
Sint16 xrel; /* The relative motion in the X direction */
Sint16 yrel; /* The relative motion in the Y direction */
/**
* \struct SDL_JoyBallEvent
*
* \brief Joystick trackball motion event structure
*/
typedef struct SDL_JoyBallEvent
{
Uint8 type; /**< SDL_JOYBALLMOTION */
Uint8 which; /**< The joystick device index */
Uint8 ball; /**< The joystick trackball index */
int xrel; /**< The relative motion in the X direction */
int yrel; /**< The relative motion in the Y direction */
} SDL_JoyBallEvent;
/* Joystick hat position change event structure */
typedef struct SDL_JoyHatEvent {
Uint8 type; /* SDL_JOYHATMOTION */
Uint8 which; /* The joystick device index */
Uint8 hat; /* The joystick hat index */
Uint8 value; /* The hat position value:
SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
Note that zero means the POV is centered.
*/
/**
* \struct SDL_JoyHatEvent
*
* \brief Joystick hat position change event structure
*/
typedef struct SDL_JoyHatEvent
{
Uint8 type; /**< SDL_JOYHATMOTION */
Uint8 which; /**< The joystick device index */
Uint8 hat; /**< The joystick hat index */
Uint8 value; /**< The hat position value:
SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
Note that zero means the POV is centered.
*/
} SDL_JoyHatEvent;
/* Joystick button event structure */
typedef struct SDL_JoyButtonEvent {
Uint8 type; /* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
Uint8 which; /* The joystick device index */
Uint8 button; /* The joystick button index */
Uint8 state; /* SDL_PRESSED or SDL_RELEASED */
/**
* \struct SDL_JoyButtonEvent
*
* \brief Joystick button event structure
*/
typedef struct SDL_JoyButtonEvent
{
Uint8 type; /**< SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
Uint8 which; /**< The joystick device index */
Uint8 button; /**< The joystick button index */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
} SDL_JoyButtonEvent;
/* The "window resized" event
When you get this event, you are responsible for setting a new video
mode with the new width and height.
/**
* \struct SDL_QuitEvent
*
* \brief The "quit requested" event
*/
typedef struct SDL_ResizeEvent {
Uint8 type; /* SDL_VIDEORESIZE */
int w; /* New width */
int h; /* New height */
} SDL_ResizeEvent;
/* The "screen redraw" event */
typedef struct SDL_ExposeEvent {
Uint8 type; /* SDL_VIDEOEXPOSE */
} SDL_ExposeEvent;
/* The "quit requested" event */
typedef struct SDL_QuitEvent {
Uint8 type; /* SDL_QUIT */
typedef struct SDL_QuitEvent
{
Uint8 type; /**< SDL_QUIT */
} SDL_QuitEvent;
/* A user-defined event type */
typedef struct SDL_UserEvent {
Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */
int code; /* User defined event code */
void *data1; /* User defined data pointer */
void *data2; /* User defined data pointer */
/**
* \struct SDL_UserEvent
*
* \brief A user-defined event type
*/
typedef struct SDL_UserEvent
{
Uint8 type; /**< SDL_USEREVENT through SDL_NUMEVENTS-1 */
int code; /**< User defined event code */
void *data1; /**< User defined data pointer */
void *data2; /**< User defined data pointer */
} SDL_UserEvent;
/* If you want to use this event, you should include SDL_syswm.h */
/**
* \struct SDL_SysWMEvent
*
* \brief A video driver dependent system event
*
* \note If you want to use this event, you should include SDL_syswm.h
*/
struct SDL_SysWMmsg;
typedef struct SDL_SysWMmsg SDL_SysWMmsg;
typedef struct SDL_SysWMEvent {
Uint8 type;
SDL_SysWMmsg *msg;
typedef struct SDL_SysWMEvent
{
Uint8 type; /**< SDL_SYSWMEVENT */
SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
} SDL_SysWMEvent;
/* General event structure */
typedef union SDL_Event {
Uint8 type;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_ExposeEvent expose;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
/* Typedefs for backwards compatibility */
typedef struct SDL_ActiveEvent
{
Uint8 type;
Uint8 gain;
Uint8 state;
} SDL_ActiveEvent;
typedef struct SDL_ResizeEvent
{
Uint8 type;
int w;
int h;
} SDL_ResizeEvent;
/**
* \union SDL_Event
*
* \brief General event structure
*/
typedef union SDL_Event
{
Uint8 type; /**< Event type, shared with all events */
SDL_WindowEvent window; /**< Window event data */
SDL_KeyboardEvent key; /**< Keyboard event data */
SDL_TextInputEvent text; /**< Text input event data */
SDL_MouseMotionEvent motion; /**< Mouse motion event data */
SDL_MouseButtonEvent button; /**< Mouse button event data */
SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
SDL_JoyBallEvent jball; /**< Joystick ball event data */
SDL_JoyHatEvent jhat; /**< Joystick hat event data */
SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
SDL_QuitEvent quit; /**< Quit request event data */
SDL_UserEvent user; /**< Custom event data */
SDL_SysWMEvent syswm; /**< System dependent window event data */
/* Temporarily here for backwards compatibility */
SDL_ActiveEvent active;
SDL_ResizeEvent resize;
} SDL_Event;
@ -255,32 +361,38 @@ extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
This function returns the number of events actually stored, or -1
if there was an error. This function is thread-safe.
*/
typedef enum {
SDL_ADDEVENT,
SDL_PEEKEVENT,
SDL_GETEVENT
typedef enum
{
SDL_ADDEVENT,
SDL_PEEKEVENT,
SDL_GETEVENT
} SDL_eventaction;
/* */
extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents,
SDL_eventaction action, Uint32 mask);
extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
SDL_eventaction action,
Uint32 mask);
/* Checks to see if certain event types are in the event queue.
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 mask);
/* Polls for currently pending events, and returns 1 if there are any pending
events, or 0 if there are none available. If 'event' is not NULL, the next
event is removed from the queue and stored in that area.
*/
extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event);
extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
/* Waits indefinitely for the next available event, returning 1, or 0 if there
was an error while waiting for events. If 'event' is not NULL, the next
event is removed from the queue and stored in that area.
*/
extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event *event);
extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
/* Add an event to the event queue.
This function returns 0 on success, or -1 if the event queue was full
or there was some other error.
This function returns 1 on success, 0 if the event was filtered,
or -1 if the event queue was full or there was some other error.
*/
extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
/*
This function sets up a filter to process all events before they
@ -288,7 +400,7 @@ extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
The filter is protypted as:
*/
typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event);
typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
/*
If the filter returns 1, then the event will be added to the internal queue.
If it returns 0, then the event will be dropped from the queue, but the
@ -305,13 +417,22 @@ typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event);
If the quit event is generated by an interrupt signal, it will bypass the
internal queue and be delivered to the application at the next event poll.
*/
extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter);
extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
void *userdata);
/*
Return the current event filter - can be used to "chain" filters.
If there is no event filter set, this function returns NULL.
If there is no event filter set, this function returns SDL_FALSE.
*/
extern DECLSPEC SDL_EventFilter SDLCALL SDL_GetEventFilter(void);
extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
void **userdata);
/*
Run the filter function on the current event queue, removing any
events for which the filter returns 0.
*/
extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
void *userdata);
/*
This function allows you to set the state of processing certain events.
@ -330,8 +451,12 @@ extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint8 type, int state);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_events_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Include file for SDL joystick event handling */
/**
* \file SDL_joystick.h
*
* Include file for SDL joystick event handling
*/
#ifndef _SDL_joystick_h
#define _SDL_joystick_h
@ -31,7 +35,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* In order to use these functions, SDL_Init() must have been called
@ -55,7 +61,7 @@ extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
* This can be called before any joysticks are opened.
* If no name can be found, this function returns NULL.
*/
extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index);
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
/*
* Open a joystick for use - the index passed as an argument refers to
@ -64,7 +70,7 @@ extern DECLSPEC const char * SDLCALL SDL_JoystickName(int device_index);
*
* This function returns a joystick identifier, or NULL if an error occurred.
*/
extern DECLSPEC SDL_Joystick * SDLCALL SDL_JoystickOpen(int device_index);
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
/*
* Returns 1 if the joystick has been opened, or 0 if it has not.
@ -74,29 +80,29 @@ extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
/*
* Get the device index of an opened joystick.
*/
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick *joystick);
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
/*
* Get the number of general axis controls on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
/*
* Get the number of trackballs on a joystick
* Joystick trackballs have only relative motion events associated
* with them and their state cannot be polled.
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
/*
* Get the number of POV hats on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
/*
* Get the number of buttons on a joystick
*/
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
/*
* Update the current state of the open joysticks.
@ -119,7 +125,8 @@ extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
* The state is a value ranging from -32768 to 32767.
* The axis indices start at index 0.
*/
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis);
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
int axis);
/*
* Get the current state of a POV hat on a joystick
@ -137,31 +144,38 @@ extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, int a
/*
* The hat indices start at index 0.
*/
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, int hat);
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
int hat);
/*
* Get the ball axis change since the last poll
* This returns 0, or -1 if you passed it invalid parameters.
* The ball indices start at index 0.
*/
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
int ball, int *dx, int *dy);
/*
* Get the current state of a button on a joystick
* The button indices start at index 0.
*/
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, int button);
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
int button);
/*
* Close a joystick previously opened with SDL_JoystickOpen()
*/
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_joystick_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Include file for SDL keyboard event handling */
/**
* \file SDL_keyboard.h
*
* Include file for SDL keyboard event handling
*/
#ifndef _SDL_keyboard_h
#define _SDL_keyboard_h
@ -32,90 +36,133 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Keysym structure
- The scancode is hardware dependent, and should not be used by general
applications. If no hardware scancode is available, it will be 0.
- The 'unicode' translated character is only available when character
translation is enabled by the SDL_EnableUNICODE() API. If non-zero,
this is a UNICODE character corresponding to the keypress. If the
high 9 bits of the character are 0, then this maps to the equivalent
ASCII character:
char ch;
if ( (keysym.unicode & 0xFF80) == 0 ) {
ch = keysym.unicode & 0x7F;
} else {
An international character..
}
/**
* \struct SDL_keysym
*
* \brief The SDL keysym structure, used in key events.
*/
typedef struct SDL_keysym {
Uint8 scancode; /* hardware specific scancode */
SDLKey sym; /* SDL virtual keysym */
SDLMod mod; /* current key modifiers */
Uint16 unicode; /* translated character */
typedef struct SDL_keysym
{
Uint8 scancode; /**< keyboard specific scancode */
Uint8 padding[3]; /**< alignment padding */
Uint16 sym; /**< SDL virtual keysym */
Uint16 mod; /**< current key modifiers */
Uint32 unicode; /**< OBSOLETE, use SDL_TextInputEvent instead */
} SDL_keysym;
/* This is the mask which refers to all hotkey bindings */
#define SDL_ALL_HOTKEYS 0xFFFFFFFF
/* Function prototypes */
/*
* Enable/Disable UNICODE translation of keyboard input.
* This translation has some overhead, so translation defaults off.
* If 'enable' is 1, translation is enabled.
* If 'enable' is 0, translation is disabled.
* If 'enable' is -1, the translation state is not changed.
* It returns the previous state of keyboard translation.
/**
* \fn int SDL_GetNumKeyboards(void)
*
* \brief Get the number of keyboard input devices available.
*
* \sa SDL_SelectKeyboard()
*/
extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
/**
* \fn int SDL_SelectKeyboard(int index)
*
* \brief Set the index of the currently selected keyboard.
*
* \return The index of the previously selected keyboard.
*
* \note You can query the currently selected keyboard by passing an index of -1.
*
* \sa SDL_GetNumKeyboards()
*/
extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
/**
* \fn int SDL_EnableUNICODE(int enable)
*
* \brief Enable/Disable UNICODE translation of keyboard input.
*
* \param enable 1 to enable translation, 0 to disable translation, -1 to query translation
*
* \return The previous state of keyboard translation
*
* \note This translation has some overhead, so translation defaults off.
*/
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
/*
* Enable/Disable keyboard repeat. Keyboard repeat defaults to off.
* 'delay' is the initial delay in ms between the time when a key is
* pressed, and keyboard repeat begins.
* 'interval' is the time in ms between keyboard repeat events.
/**
* \fn int SDL_EnableKeyRepeat(int delay, int interval)
*
* \brief Enable keyboard repeat for the selected keyboard.
*
* \param delay The initial delay in milliseconds between the time when a
* key is pressed and keyboard repeat begins. Setting a delay
* of 0 will disable keyboard repeat.
* \param interval The time in milliseconds between keyboard repeat events.
*
* \return 0 on success, or -1 if there was an error.
*
* \note Keyboard repeat defaults to off.
*/
#define SDL_DEFAULT_REPEAT_DELAY 500
#define SDL_DEFAULT_REPEAT_INTERVAL 30
/*
* If 'delay' is set to 0, keyboard repeat is disabled.
/**/
extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
/**
* \fn void SDL_GetKeyRepeat(int *delay, int *interval)
*
* \brief Get the current keyboard repeat setting for the selected keyboard.
*/
extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
/*
* Get a snapshot of the current state of the keyboard.
* Returns an array of keystates, indexed by the SDLK_* syms.
* Used:
/**
* \fn Uint8 *SDL_GetKeyState(int *numkeys)
*
* \brief Get a snapshot of the current state of the selected keyboard.
*
* \return An array of keystates, indexed by the SDLK_* syms.
*
* Example:
* Uint8 *keystate = SDL_GetKeyState(NULL);
* if ( keystate[SDLK_RETURN] ) ... <RETURN> is pressed.
*/
extern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys);
extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys);
/*
* Get the current key modifier state
/**
* \fn SDLMod SDL_GetModState(void)
*
* \brief Get the current key modifier state for the selected keyboard.
*/
extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
/*
* Set the current key modifier state
* This does not change the keyboard state, only the key modifier flags.
/**
* \fn void SDL_SetModState(SDLMod modstate)
*
* \brief Set the current key modifier state for the selected keyboard.
*
* \note This does not change the keyboard state, only the key modifier flags.
*/
extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
/*
* Get the name of an SDL virtual keysym
/**
* \fn const char *SDL_GetKeyName(SDLKey key)
*
* \brief Get the name of an SDL virtual keysym
*/
extern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key);
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_keyboard_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,287 +20,203 @@
slouken@libsdl.org
*/
/**
* \file SDL_keysym.h
*/
#ifndef _SDL_keysym_h
#define _SDL_keysym_h
/* What we really want is a mapping of every raw key on the keyboard.
To support international keyboards, we use the range 0xA1 - 0xFF
as international virtual keycodes. We'll follow in the footsteps of X11...
The names of the keys
/**
* \enum SDLKey
*
* \brief The SDL virtual key representation
*
* The SDLKey represents the unmodified character printed on the key
* for the current keyboard layout. The first 255 characters are used
* unchanged from Latin-1, e.g. a key with 'a' on it will have the value "a".
* The rest of the keys are named below, and fall into the range above 255.
*/
typedef enum {
/* The keyboard syms have been cleverly chosen to map to ASCII */
SDLK_UNKNOWN = 0,
SDLK_FIRST = 0,
SDLK_BACKSPACE = 8,
SDLK_TAB = 9,
SDLK_CLEAR = 12,
SDLK_RETURN = 13,
SDLK_PAUSE = 19,
SDLK_ESCAPE = 27,
SDLK_SPACE = 32,
SDLK_EXCLAIM = 33,
SDLK_QUOTEDBL = 34,
SDLK_HASH = 35,
SDLK_DOLLAR = 36,
SDLK_AMPERSAND = 38,
SDLK_QUOTE = 39,
SDLK_LEFTPAREN = 40,
SDLK_RIGHTPAREN = 41,
SDLK_ASTERISK = 42,
SDLK_PLUS = 43,
SDLK_COMMA = 44,
SDLK_MINUS = 45,
SDLK_PERIOD = 46,
SDLK_SLASH = 47,
SDLK_0 = 48,
SDLK_1 = 49,
SDLK_2 = 50,
SDLK_3 = 51,
SDLK_4 = 52,
SDLK_5 = 53,
SDLK_6 = 54,
SDLK_7 = 55,
SDLK_8 = 56,
SDLK_9 = 57,
SDLK_COLON = 58,
SDLK_SEMICOLON = 59,
SDLK_LESS = 60,
SDLK_EQUALS = 61,
SDLK_GREATER = 62,
SDLK_QUESTION = 63,
SDLK_AT = 64,
/*
Skip uppercase letters
*/
SDLK_LEFTBRACKET = 91,
SDLK_BACKSLASH = 92,
SDLK_RIGHTBRACKET = 93,
SDLK_CARET = 94,
SDLK_UNDERSCORE = 95,
SDLK_BACKQUOTE = 96,
SDLK_a = 97,
SDLK_b = 98,
SDLK_c = 99,
SDLK_d = 100,
SDLK_e = 101,
SDLK_f = 102,
SDLK_g = 103,
SDLK_h = 104,
SDLK_i = 105,
SDLK_j = 106,
SDLK_k = 107,
SDLK_l = 108,
SDLK_m = 109,
SDLK_n = 110,
SDLK_o = 111,
SDLK_p = 112,
SDLK_q = 113,
SDLK_r = 114,
SDLK_s = 115,
SDLK_t = 116,
SDLK_u = 117,
SDLK_v = 118,
SDLK_w = 119,
SDLK_x = 120,
SDLK_y = 121,
SDLK_z = 122,
SDLK_DELETE = 127,
/* End of ASCII mapped keysyms */
typedef enum
{
/* The keyboard syms have been cleverly chosen to map to ASCII */
SDLK_UNKNOWN = 0,
SDLK_FIRST = 0,
SDLK_BACKSPACE = 8,
SDLK_TAB = 9,
SDLK_CLEAR = 12,
SDLK_RETURN = 13,
SDLK_PAUSE = 19,
SDLK_ESCAPE = 27,
SDLK_SPACE = 32,
SDLK_EXCLAIM = 33,
SDLK_QUOTEDBL = 34,
SDLK_HASH = 35,
SDLK_DOLLAR = 36,
SDLK_AMPERSAND = 38,
SDLK_QUOTE = 39,
SDLK_LEFTPAREN = 40,
SDLK_RIGHTPAREN = 41,
SDLK_ASTERISK = 42,
SDLK_PLUS = 43,
SDLK_COMMA = 44,
SDLK_MINUS = 45,
SDLK_PERIOD = 46,
SDLK_SLASH = 47,
SDLK_0 = 48,
SDLK_1 = 49,
SDLK_2 = 50,
SDLK_3 = 51,
SDLK_4 = 52,
SDLK_5 = 53,
SDLK_6 = 54,
SDLK_7 = 55,
SDLK_8 = 56,
SDLK_9 = 57,
SDLK_COLON = 58,
SDLK_SEMICOLON = 59,
SDLK_LESS = 60,
SDLK_EQUALS = 61,
SDLK_GREATER = 62,
SDLK_QUESTION = 63,
SDLK_AT = 64,
/*
Skip uppercase letters
*/
SDLK_LEFTBRACKET = 91,
SDLK_BACKSLASH = 92,
SDLK_RIGHTBRACKET = 93,
SDLK_CARET = 94,
SDLK_UNDERSCORE = 95,
SDLK_BACKQUOTE = 96,
SDLK_a = 97,
SDLK_b = 98,
SDLK_c = 99,
SDLK_d = 100,
SDLK_e = 101,
SDLK_f = 102,
SDLK_g = 103,
SDLK_h = 104,
SDLK_i = 105,
SDLK_j = 106,
SDLK_k = 107,
SDLK_l = 108,
SDLK_m = 109,
SDLK_n = 110,
SDLK_o = 111,
SDLK_p = 112,
SDLK_q = 113,
SDLK_r = 114,
SDLK_s = 115,
SDLK_t = 116,
SDLK_u = 117,
SDLK_v = 118,
SDLK_w = 119,
SDLK_x = 120,
SDLK_y = 121,
SDLK_z = 122,
SDLK_DELETE = 127,
/* End of ASCII mapped keysyms */
/* International keyboard syms */
SDLK_WORLD_0 = 160, /* 0xA0 */
SDLK_WORLD_1 = 161,
SDLK_WORLD_2 = 162,
SDLK_WORLD_3 = 163,
SDLK_WORLD_4 = 164,
SDLK_WORLD_5 = 165,
SDLK_WORLD_6 = 166,
SDLK_WORLD_7 = 167,
SDLK_WORLD_8 = 168,
SDLK_WORLD_9 = 169,
SDLK_WORLD_10 = 170,
SDLK_WORLD_11 = 171,
SDLK_WORLD_12 = 172,
SDLK_WORLD_13 = 173,
SDLK_WORLD_14 = 174,
SDLK_WORLD_15 = 175,
SDLK_WORLD_16 = 176,
SDLK_WORLD_17 = 177,
SDLK_WORLD_18 = 178,
SDLK_WORLD_19 = 179,
SDLK_WORLD_20 = 180,
SDLK_WORLD_21 = 181,
SDLK_WORLD_22 = 182,
SDLK_WORLD_23 = 183,
SDLK_WORLD_24 = 184,
SDLK_WORLD_25 = 185,
SDLK_WORLD_26 = 186,
SDLK_WORLD_27 = 187,
SDLK_WORLD_28 = 188,
SDLK_WORLD_29 = 189,
SDLK_WORLD_30 = 190,
SDLK_WORLD_31 = 191,
SDLK_WORLD_32 = 192,
SDLK_WORLD_33 = 193,
SDLK_WORLD_34 = 194,
SDLK_WORLD_35 = 195,
SDLK_WORLD_36 = 196,
SDLK_WORLD_37 = 197,
SDLK_WORLD_38 = 198,
SDLK_WORLD_39 = 199,
SDLK_WORLD_40 = 200,
SDLK_WORLD_41 = 201,
SDLK_WORLD_42 = 202,
SDLK_WORLD_43 = 203,
SDLK_WORLD_44 = 204,
SDLK_WORLD_45 = 205,
SDLK_WORLD_46 = 206,
SDLK_WORLD_47 = 207,
SDLK_WORLD_48 = 208,
SDLK_WORLD_49 = 209,
SDLK_WORLD_50 = 210,
SDLK_WORLD_51 = 211,
SDLK_WORLD_52 = 212,
SDLK_WORLD_53 = 213,
SDLK_WORLD_54 = 214,
SDLK_WORLD_55 = 215,
SDLK_WORLD_56 = 216,
SDLK_WORLD_57 = 217,
SDLK_WORLD_58 = 218,
SDLK_WORLD_59 = 219,
SDLK_WORLD_60 = 220,
SDLK_WORLD_61 = 221,
SDLK_WORLD_62 = 222,
SDLK_WORLD_63 = 223,
SDLK_WORLD_64 = 224,
SDLK_WORLD_65 = 225,
SDLK_WORLD_66 = 226,
SDLK_WORLD_67 = 227,
SDLK_WORLD_68 = 228,
SDLK_WORLD_69 = 229,
SDLK_WORLD_70 = 230,
SDLK_WORLD_71 = 231,
SDLK_WORLD_72 = 232,
SDLK_WORLD_73 = 233,
SDLK_WORLD_74 = 234,
SDLK_WORLD_75 = 235,
SDLK_WORLD_76 = 236,
SDLK_WORLD_77 = 237,
SDLK_WORLD_78 = 238,
SDLK_WORLD_79 = 239,
SDLK_WORLD_80 = 240,
SDLK_WORLD_81 = 241,
SDLK_WORLD_82 = 242,
SDLK_WORLD_83 = 243,
SDLK_WORLD_84 = 244,
SDLK_WORLD_85 = 245,
SDLK_WORLD_86 = 246,
SDLK_WORLD_87 = 247,
SDLK_WORLD_88 = 248,
SDLK_WORLD_89 = 249,
SDLK_WORLD_90 = 250,
SDLK_WORLD_91 = 251,
SDLK_WORLD_92 = 252,
SDLK_WORLD_93 = 253,
SDLK_WORLD_94 = 254,
SDLK_WORLD_95 = 255, /* 0xFF */
/* Numeric keypad */
SDLK_KP0 = 256,
SDLK_KP1 = 257,
SDLK_KP2 = 258,
SDLK_KP3 = 259,
SDLK_KP4 = 260,
SDLK_KP5 = 261,
SDLK_KP6 = 262,
SDLK_KP7 = 263,
SDLK_KP8 = 264,
SDLK_KP9 = 265,
SDLK_KP_PERIOD = 266,
SDLK_KP_DIVIDE = 267,
SDLK_KP_MULTIPLY = 268,
SDLK_KP_MINUS = 269,
SDLK_KP_PLUS = 270,
SDLK_KP_ENTER = 271,
SDLK_KP_EQUALS = 272,
/* Numeric keypad */
SDLK_KP0 = 256,
SDLK_KP1 = 257,
SDLK_KP2 = 258,
SDLK_KP3 = 259,
SDLK_KP4 = 260,
SDLK_KP5 = 261,
SDLK_KP6 = 262,
SDLK_KP7 = 263,
SDLK_KP8 = 264,
SDLK_KP9 = 265,
SDLK_KP_PERIOD = 266,
SDLK_KP_DIVIDE = 267,
SDLK_KP_MULTIPLY = 268,
SDLK_KP_MINUS = 269,
SDLK_KP_PLUS = 270,
SDLK_KP_ENTER = 271,
SDLK_KP_EQUALS = 272,
/* Arrows + Home/End pad */
SDLK_UP = 273,
SDLK_DOWN = 274,
SDLK_RIGHT = 275,
SDLK_LEFT = 276,
SDLK_INSERT = 277,
SDLK_HOME = 278,
SDLK_END = 279,
SDLK_PAGEUP = 280,
SDLK_PAGEDOWN = 281,
/* Arrows + Home/End pad */
SDLK_UP = 273,
SDLK_DOWN = 274,
SDLK_RIGHT = 275,
SDLK_LEFT = 276,
SDLK_INSERT = 277,
SDLK_HOME = 278,
SDLK_END = 279,
SDLK_PAGEUP = 280,
SDLK_PAGEDOWN = 281,
/* Function keys */
SDLK_F1 = 282,
SDLK_F2 = 283,
SDLK_F3 = 284,
SDLK_F4 = 285,
SDLK_F5 = 286,
SDLK_F6 = 287,
SDLK_F7 = 288,
SDLK_F8 = 289,
SDLK_F9 = 290,
SDLK_F10 = 291,
SDLK_F11 = 292,
SDLK_F12 = 293,
SDLK_F13 = 294,
SDLK_F14 = 295,
SDLK_F15 = 296,
/* Function keys */
SDLK_F1 = 282,
SDLK_F2 = 283,
SDLK_F3 = 284,
SDLK_F4 = 285,
SDLK_F5 = 286,
SDLK_F6 = 287,
SDLK_F7 = 288,
SDLK_F8 = 289,
SDLK_F9 = 290,
SDLK_F10 = 291,
SDLK_F11 = 292,
SDLK_F12 = 293,
SDLK_F13 = 294,
SDLK_F14 = 295,
SDLK_F15 = 296,
/* Key state modifier keys */
SDLK_NUMLOCK = 300,
SDLK_CAPSLOCK = 301,
SDLK_SCROLLOCK = 302,
SDLK_RSHIFT = 303,
SDLK_LSHIFT = 304,
SDLK_RCTRL = 305,
SDLK_LCTRL = 306,
SDLK_RALT = 307,
SDLK_LALT = 308,
SDLK_RMETA = 309,
SDLK_LMETA = 310,
SDLK_LSUPER = 311, /**< Left "Windows" key */
SDLK_RSUPER = 312, /**< Right "Windows" key */
SDLK_MODE = 313, /**< "Alt Gr" key */
SDLK_COMPOSE = 314, /**< Multi-key compose key */
/* Key state modifier keys */
SDLK_NUMLOCK = 300,
SDLK_CAPSLOCK = 301,
SDLK_SCROLLOCK = 302,
SDLK_RSHIFT = 303,
SDLK_LSHIFT = 304,
SDLK_RCTRL = 305,
SDLK_LCTRL = 306,
SDLK_RALT = 307,
SDLK_LALT = 308,
SDLK_RMETA = 309,
SDLK_LMETA = 310,
SDLK_LSUPER = 311, /* Left "Windows" key */
SDLK_RSUPER = 312, /* Right "Windows" key */
SDLK_MODE = 313, /* "Alt Gr" key */
SDLK_COMPOSE = 314, /* Multi-key compose key */
/* Miscellaneous function keys */
SDLK_HELP = 315,
SDLK_PRINT = 316,
SDLK_SYSREQ = 317,
SDLK_BREAK = 318,
SDLK_MENU = 319,
SDLK_POWER = 320, /**< Power Macintosh power key */
SDLK_EURO = 321, /**< Some european keyboards */
SDLK_UNDO = 322, /**< Atari keyboard has Undo */
/* Miscellaneous function keys */
SDLK_HELP = 315,
SDLK_PRINT = 316,
SDLK_SYSREQ = 317,
SDLK_BREAK = 318,
SDLK_MENU = 319,
SDLK_POWER = 320, /* Power Macintosh power key */
SDLK_EURO = 321, /* Some european keyboards */
SDLK_UNDO = 322, /* Atari keyboard has Undo */
/* Add any other keys here */
/* Add any other keys here */
SDLK_LAST
SDLK_LAST
} SDLKey;
/* Enumeration of valid key mods (possibly OR'd together) */
typedef enum {
KMOD_NONE = 0x0000,
KMOD_LSHIFT= 0x0001,
KMOD_RSHIFT= 0x0002,
KMOD_LCTRL = 0x0040,
KMOD_RCTRL = 0x0080,
KMOD_LALT = 0x0100,
KMOD_RALT = 0x0200,
KMOD_LMETA = 0x0400,
KMOD_RMETA = 0x0800,
KMOD_NUM = 0x1000,
KMOD_CAPS = 0x2000,
KMOD_MODE = 0x4000,
KMOD_RESERVED = 0x8000
/**
* \enum SDLMod
*
* \brief Enumeration of valid key mods (possibly OR'd together)
*/
typedef enum
{
KMOD_NONE = 0x0000,
KMOD_LSHIFT = 0x0001,
KMOD_RSHIFT = 0x0002,
KMOD_LCTRL = 0x0040,
KMOD_RCTRL = 0x0080,
KMOD_LALT = 0x0100,
KMOD_RALT = 0x0200,
KMOD_LMETA = 0x0400,
KMOD_RMETA = 0x0800,
KMOD_NUM = 0x1000,
KMOD_CAPS = 0x2000,
KMOD_MODE = 0x4000,
KMOD_RESERVED = 0x8000
} SDLMod;
#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL)

View File

@ -20,23 +20,24 @@
slouken@libsdl.org
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */
/* Some things to keep in mind:
- These functions only work on C function names. Other languages may
have name mangling and intrinsic language support that varies from
compiler to compiler.
- Make sure you declare your function pointers with the same calling
convention as the actual library function. Your code will crash
mysteriously if you do not do this.
- Avoid namespace collisions. If you load a symbol from the library,
it is not defined whether or not it goes into the global symbol
namespace for the application. If it does and it conflicts with
symbols in your code or other shared libraries, you will not get
the results you expect. :)
*/
/**
* \file SDL_loadso.h
*
* System dependent library loading routines
*
* Some things to keep in mind:
* - These functions only work on C function names. Other languages may
* have name mangling and intrinsic language support that varies from
* compiler to compiler.
* - Make sure you declare your function pointers with the same calling
* convention as the actual library function. Your code will crash
* mysteriously if you do not do this.
* - Avoid namespace collisions. If you load a symbol from the library,
* it is not defined whether or not it goes into the global symbol
* namespace for the application. If it does and it conflicts with
* symbols in your code or other shared libraries, you will not get
* the results you expect. :)
*/
#ifndef _SDL_loadso_h
#define _SDL_loadso_h
@ -47,28 +48,35 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* This function dynamically loads a shared object and returns a pointer
* to the object handle (or NULL if there was an error).
* The 'sofile' parameter is a system dependent name of the object file.
*/
extern DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile);
extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
/* Given an object handle, this function looks up the address of the
* named function in the shared object and returns it. This address
* is no longer valid after calling SDL_UnloadObject().
*/
extern DECLSPEC void * SDLCALL SDL_LoadFunction(void *handle, const char *name);
extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
const char *name);
/* Unload a shared object from memory */
extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_loadso_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -58,17 +58,20 @@ extern C_LINKAGE int SDL_main(int argc, char *argv[]);
#include "begin_code.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* This should be called from your WinMain() function, if any */
extern DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);
/* This can also be called, but is no longer necessary */
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst);
/* This can also be called, but is no longer necessary (SDL_Quit calls it) */
/* This can be called to set the application class at startup */
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
void *hInst);
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif
@ -78,7 +81,9 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
#include "begin_code.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Forward declaration so we don't need to include QuickDraw.h */
@ -88,7 +93,9 @@ struct QDGlobals;
extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd);
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif
@ -96,3 +103,5 @@ extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd);
#endif /* Need to redefine main()? */
#endif /* _SDL_main_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Include file for SDL mouse event handling */
/**
* \file SDL_mouse.h
*
* Include file for SDL mouse event handling
*/
#ifndef _SDL_mouse_h
#define _SDL_mouse_h
@ -32,43 +36,116 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
typedef struct WMcursor WMcursor; /* Implementation dependent */
typedef struct SDL_Cursor {
SDL_Rect area; /* The area of the mouse cursor */
Sint16 hot_x, hot_y; /* The "tip" of the cursor */
Uint8 *data; /* B/W cursor data */
Uint8 *mask; /* B/W cursor mask */
Uint8 *save[2]; /* Place to save cursor area */
WMcursor *wm_cursor; /* Window-manager cursor */
} SDL_Cursor;
typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */
/* Function prototypes */
/*
* Retrieve the current state of the mouse.
/**
* \fn int SDL_GetNumMice(void)
*
* \brief Get the number of mouse input devices available.
*
* \sa SDL_SelectMouse()
*/
extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
/**
* \fn int SDL_SelectMouse(int index)
*
* \brief Set the index of the currently selected mouse.
*
* \return The index of the previously selected mouse.
*
* \note You can query the currently selected mouse by passing an index of -1.
*
* \sa SDL_GetNumMice()
*/
extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
/**
* \fn SDL_WindowID SDL_GetMouseFocusWindow(void)
*
* \brief Get the window which currently has focus for the currently selected mouse.
*/
extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(void);
/**
* \fn int SDL_SetRelativeMouseMode(SDL_bool enabled)
*
* \brief Set relative mouse mode for the currently selected mouse.
*
* \param enabled Whether or not to enable relative mode
*
* \return 0 on success, or -1 if relative mode is not supported.
*
* While the mouse is in relative mode, the cursor is hidden, and the
* driver will try to report continuous motion in the current window.
* Only relative motion events will be delivered, the mouse position
* will not change.
*
* \note This function will flush any pending mouse motion.
*
* \sa SDL_GetRelativeMouseMode()
*/
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
/**
* \fn SDL_bool SDL_GetRelativeMouseMode()
*
* \brief Query whether relative mouse mode is enabled for the currently selected mouse.
*
* \sa SDL_SetRelativeMouseMode()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode();
/**
* \fn Uint8 SDL_GetMouseState(int *x, int *y)
*
* \brief Retrieve the current state of the currently selected mouse.
*
* The current button state is returned as a button bitmask, which can
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
* current mouse cursor position. You can pass NULL for either x or y.
* mouse cursor position relative to the focus window for the currently
* selected mouse. You can pass NULL for either x or y.
*/
extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
/*
* Retrieve the current state of the mouse.
/**
* \fn Uint8 SDL_GetRelativeMouseState(int *x, int *y)
*
* \brief Retrieve the state of the currently selected mouse.
*
* The current button state is returned as a button bitmask, which can
* be tested using the SDL_BUTTON(X) macros, and x and y are set to the
* mouse deltas since the last call to SDL_GetRelativeMouseState().
*/
extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
/*
* Set the position of the mouse cursor (generates a mouse motion event)
/**
* \fn void SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
*
* \brief Moves the currently selected mouse to the given position within the window.
*
* \param windowID The window to move the mouse into, or 0 for the current mouse focus
* \param x The x coordinate within the window
* \param y The y coordinate within the window
*
* \note This function generates a mouse motion event
*/
extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
int x, int y);
/*
* Create a cursor using the specified data and mask (in MSB format).
/**
* \fn SDL_Cursor *SDL_CreateCursor (const Uint8 * data, const Uint8 * mask, int w, int h, int hot_x, int hot_y)
*
* \brief Create a cursor for the currently selected mouse, using the
* specified bitmap data and mask (in MSB format).
*
* The cursor width must be a multiple of 8 bits.
*
* The cursor is created in black and white according to the following:
@ -78,34 +155,46 @@ extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
* 0 0 Transparent
* 1 0 Inverted color if possible, black if not.
*
* Cursors created with this function must be freed with SDL_FreeCursor().
* \sa SDL_FreeCursor()
*/
extern DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor
(Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
const Uint8 * mask,
int w, int h, int hot_x,
int hot_y);
/*
* Set the currently active cursor to the specified one.
* If the cursor is currently visible, the change will be immediately
* represented on the display.
/**
* \fn void SDL_SetCursor(SDL_Cursor * cursor)
*
* \brief Set the active cursor for the currently selected mouse.
*
* \note The cursor must have been created for the selected mouse.
*/
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor *cursor);
extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
/*
* Returns the currently active cursor.
/**
* \fn SDL_Cursor *SDL_GetCursor(void)
*
* \brief Return the active cursor for the currently selected mouse.
*/
extern DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void);
extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
/*
* Deallocates a cursor created with SDL_CreateCursor().
/**
* \fn void SDL_FreeCursor(SDL_Cursor * cursor)
*
* \brief Frees a cursor created with SDL_CreateCursor().
*
* \sa SDL_CreateCursor()
*/
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor *cursor);
extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
/*
* Toggle whether or not the cursor is shown on the screen.
* The cursor start off displayed, but can be turned off.
* SDL_ShowCursor() returns 1 if the cursor was being displayed
* before the call, or 0 if it was not. You can query the current
* state by passing a 'toggle' value of -1.
/**
* \fn int SDL_ShowCursor(int toggle)
*
* \brief Toggle whether or not the cursor is shown for the currently selected mouse.
*
* \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current state.
*
* \return 1 if the cursor is shown, or 0 if the cursor is hidden.
*/
extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
@ -113,15 +202,11 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
Button 1: Left mouse button
Button 2: Middle mouse button
Button 3: Right mouse button
Button 4: Mouse wheel up (may also be a real button)
Button 5: Mouse wheel down (may also be a real button)
*/
#define SDL_BUTTON(X) (1 << ((X)-1))
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
#define SDL_BUTTON_RIGHT 3
#define SDL_BUTTON_WHEELUP 4
#define SDL_BUTTON_WHEELDOWN 5
#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
@ -129,8 +214,12 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_mouse_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -23,10 +23,11 @@
#ifndef _SDL_mutex_h
#define _SDL_mutex_h
/* Functions to provide thread synchronization primitives
These are independent of the other SDL routines.
*/
/**
* \file SDL_mutex.h
*
* Functions to provide thread synchronization primitives
*/
#include "SDL_stdinc.h"
#include "SDL_error.h"
@ -34,7 +35,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Synchronization functions which can time out return this value
@ -55,21 +58,21 @@ struct SDL_mutex;
typedef struct SDL_mutex SDL_mutex;
/* Create a mutex, initialized unlocked */
extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void);
extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
/* Lock the mutex (Returns 0, or -1 on error) */
#define SDL_LockMutex(m) SDL_mutexP(m)
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex);
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
/* Unlock the mutex (Returns 0, or -1 on error)
It is an error to unlock a mutex that has not been locked by
the current thread, and doing so results in undefined behavior.
*/
#define SDL_UnlockMutex(m) SDL_mutexV(m)
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex);
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
/* Destroy a mutex */
extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex);
extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -81,21 +84,21 @@ struct SDL_semaphore;
typedef struct SDL_semaphore SDL_sem;
/* Create a semaphore, initialized with value, returns NULL on failure. */
extern DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
/* Destroy a semaphore */
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem);
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
/* This function suspends the calling thread until the semaphore pointed
* to by sem has a positive count. It then atomically decreases the semaphore
* count.
*/
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem);
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
/* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem);
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
/* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
@ -103,15 +106,15 @@ extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem);
On some platforms this function is implemented by looping with a delay
of 1 ms, and so should be avoided if possible.
*/
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms);
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
/* Atomically increases the semaphore's count (not blocking), returns 0,
or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem);
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
/* Returns the current count of the semaphore */
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem);
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -123,27 +126,27 @@ struct SDL_cond;
typedef struct SDL_cond SDL_cond;
/* Create a condition variable */
extern DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void);
extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
/* Destroy a condition variable */
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond);
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
/* Restart one of the threads that are waiting on the condition variable,
returns 0 or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond);
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
/* Restart all threads that are waiting on the condition variable,
returns 0 or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond);
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
/* Wait on the condition variable, unlocking the provided mutex.
The mutex must be locked before entering this function!
The mutex is re-locked once the condition variable is signaled.
Returns 0 when it is signaled, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mut);
/* Waits for at most 'ms' milliseconds, and returns 0 if the condition
variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
@ -151,12 +154,17 @@ extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
On some platforms this function is implemented by looping with a delay
of 1 ms, and so should be avoided if possible.
*/
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
SDL_mutex * mutex, Uint32 ms);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_mutex_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -27,33 +27,35 @@
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX /* Don't defined min() and max() */
#define NOMINMAX /* Don't defined min() and max() */
#endif
#include <windows.h>
#endif
#ifndef NO_SDL_GLEXT
#define __glext_h_ /* Don't let gl.h include glext.h */
#define __glext_h_ /* Don't let gl.h include glext.h */
#endif
#if defined(__MACOSX__)
#include <OpenGL/gl.h> /* Header File For The OpenGL Library */
#include <OpenGL/glu.h> /* Header File For The GLU Library */
#include <OpenGL/gl.h> /* Header File For The OpenGL Library */
#include <OpenGL/glu.h> /* Header File For The GLU Library */
#elif defined(__MACOS__)
#include <gl.h> /* Header File For The OpenGL Library */
#include <glu.h> /* Header File For The GLU Library */
#include <gl.h> /* Header File For The OpenGL Library */
#include <glu.h> /* Header File For The GLU Library */
#else
#include <GL/gl.h> /* Header File For The OpenGL Library */
#include <GL/glu.h> /* Header File For The GLU Library */
#include <GL/gl.h> /* Header File For The OpenGL Library */
#include <GL/glu.h> /* Header File For The GLU Library */
#endif
#ifndef NO_SDL_GLEXT
#undef __glext_h_
#endif
/* This file taken from "GLext.h" from the Jeff Molofee OpenGL tutorials.
It is included here because glext.h is not available on some systems.
/* This file is included because glext.h is not available on some systems.
If you don't want this version included, simply define "NO_SDL_GLEXT"
The latest version is available from:
http://oss.sgi.com/projects/ogl-sample/registry/
*/
#ifndef NO_SDL_GLEXT
#if !defined(__glext_h_) && !defined(GL_GLEXT_LEGACY)
#if !defined(NO_SDL_GLEXT) && !defined(GL_GLEXT_LEGACY)
/* *INDENT-OFF* */
#ifndef __glext_h_
#define __glext_h_
#ifdef __cplusplus
@ -6548,4 +6550,5 @@ typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid
#endif
#endif
/* *INDENT-ON* */
#endif /* NO_SDL_GLEXT */

348
include/SDL_pixels.h Normal file
View File

@ -0,0 +1,348 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
* \file SDL_pixels.h
*
* Header for the enumerated pixel format definitions
*/
#ifndef _SDL_pixels_h
#define _SDL_pixels_h
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
enum
{ /* Pixel type */
SDL_PixelType_Unknown,
SDL_PixelType_Index1,
SDL_PixelType_Index4,
SDL_PixelType_Index8,
SDL_PixelType_Packed8,
SDL_PixelType_Packed16,
SDL_PixelType_Packed32,
SDL_PixelType_ArrayU8,
SDL_PixelType_ArrayU16,
SDL_PixelType_ArrayU32,
SDL_PixelType_ArrayF16,
SDL_PixelType_ArrayF32,
};
enum
{ /* bitmap pixel order, high bit -> low bit */
SDL_BitmapOrder_None,
SDL_BitmapOrder_4321,
SDL_BitmapOrder_1234,
};
enum
{ /* packed component order, high bit -> low bit */
SDL_PackedOrder_None,
SDL_PackedOrder_XRGB,
SDL_PackedOrder_RGBX,
SDL_PackedOrder_ARGB,
SDL_PackedOrder_RGBA,
SDL_PackedOrder_XBGR,
SDL_PackedOrder_BGRX,
SDL_PackedOrder_ABGR,
SDL_PackedOrder_BGRA,
};
enum
{ /* array component order, low byte -> high byte */
SDL_ArrayOrder_None,
SDL_ArrayOrder_RGB,
SDL_ArrayOrder_RGBA,
SDL_ArrayOrder_ARGB,
SDL_ArrayOrder_BGR,
SDL_ArrayOrder_BGRA,
SDL_ArrayOrder_ABGR,
};
enum
{ /* Packed component layout */
SDL_PackedLayout_None,
SDL_PackedLayout_332,
SDL_PackedLayout_4444,
SDL_PackedLayout_1555,
SDL_PackedLayout_5551,
SDL_PackedLayout_565,
SDL_PackedLayout_8888,
SDL_PackedLayout_2101010,
SDL_PackedLayout_1010102,
};
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \
((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
((bits) << 8) | ((bytes) << 0))
#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
#define SDL_BYTESPERPIXEL(X) (((X) >> 0) & 0xFF)
#define SDL_ISPIXELFORMAT_INDEXED(format) \
((SDL_PIXELTYPE(format) == SDL_PixelType_Index1) || \
(SDL_PIXELTYPE(format) == SDL_PixelType_Index4) || \
(SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
#define SDL_ISPIXELFORMAT_FOURCC(format) \
((format) && !((format) & 0x80000000))
enum
{
SDL_PixelFormat_Unknown,
SDL_PixelFormat_Index1LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
1, 0),
SDL_PixelFormat_Index1MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
1, 0),
SDL_PixelFormat_Index4LSB =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
2, 0),
SDL_PixelFormat_Index4MSB =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
2, 0),
SDL_PixelFormat_Index8 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index8, 0, 0, 8, 1),
SDL_PixelFormat_RGB332 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
SDL_PackedLayout_332, 8, 1),
SDL_PixelFormat_RGB444 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
SDL_PackedLayout_4444, 12, 2),
SDL_PixelFormat_RGB555 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
SDL_PackedLayout_1555, 15, 2),
SDL_PixelFormat_ARGB4444 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
SDL_PackedLayout_4444, 16, 2),
SDL_PixelFormat_ARGB1555 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
SDL_PackedLayout_1555, 16, 2),
SDL_PixelFormat_RGB565 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
SDL_PackedLayout_565, 16, 2),
SDL_PixelFormat_RGB24 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
24, 3),
SDL_PixelFormat_BGR24 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
24, 3),
SDL_PixelFormat_RGB888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
SDL_PackedLayout_8888, 24, 4),
SDL_PixelFormat_BGR888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
SDL_PackedLayout_8888, 24, 4),
SDL_PixelFormat_ARGB8888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
SDL_PackedLayout_8888, 32, 4),
SDL_PixelFormat_RGBA8888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
SDL_PackedLayout_8888, 32, 4),
SDL_PixelFormat_ABGR8888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
SDL_PackedLayout_8888, 32, 4),
SDL_PixelFormat_BGRA8888 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
SDL_PackedLayout_8888, 32, 4),
SDL_PixelFormat_ARGB2101010 =
SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
SDL_PackedLayout_2101010, 32, 4),
SDL_PixelFormat_YV12 = /* Planar mode: Y + V + U (3 planes) */
SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
SDL_PixelFormat_IYUV = /* Planar mode: Y + U + V (3 planes) */
SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
SDL_PixelFormat_YUY2 = /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
SDL_PixelFormat_UYVY = /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
SDL_PixelFormat_YVYU = /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
};
typedef struct SDL_Color
{
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color;
#define SDL_Colour SDL_Color
typedef struct SDL_Palette SDL_Palette;
typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette);
typedef struct SDL_PaletteWatch
{
SDL_PaletteChangedFunc callback;
void *userdata;
struct SDL_PaletteWatch *next;
} SDL_PaletteWatch;
struct SDL_Palette
{
int ncolors;
SDL_Color *colors;
int refcount;
SDL_PaletteWatch *watch;
};
/* Everything in the pixel format structure is read-only */
typedef struct SDL_PixelFormat
{
SDL_Palette *palette;
Uint8 BitsPerPixel;
Uint8 BytesPerPixel;
Uint8 Rloss;
Uint8 Gloss;
Uint8 Bloss;
Uint8 Aloss;
Uint8 Rshift;
Uint8 Gshift;
Uint8 Bshift;
Uint8 Ashift;
Uint32 Rmask;
Uint32 Gmask;
Uint32 Bmask;
Uint32 Amask;
/* RGB color key information */
Uint32 colorkey;
/* Alpha value information (per-surface alpha) */
Uint8 alpha;
} SDL_PixelFormat;
/**
* \fn SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
*
* \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
*
* \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
*
* \sa SDL_MasksToPixelFormatEnum()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
int *bpp,
Uint32 * Rmask,
Uint32 * Gmask,
Uint32 * Bmask,
Uint32 * Amask);
/**
* \fn Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
*
* \brief Convert a bpp and RGBA masks to an enumerated pixel format.
*
* \return The pixel format, or SDL_PixelFormat_Unknown if the conversion wasn't possible.
*
* \sa SDL_PixelFormatEnumToMasks()
*/
extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
Uint32 Rmask,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask);
/**
* \fn SDL_Palette *SDL_AllocPalette(int ncolors)
*
* \brief Create a palette structure with the specified number of color entries.
*
* \return A new palette, or NULL if there wasn't enough memory
*
* \note The palette entries are initialized to white.
*
* \sa SDL_FreePalette()
*/
extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
/**
* \fn int SDL_AddPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
*
* \brief Add a callback function which is called when the palette changes.
*
* \sa SDL_DelPaletteWatch()
*/
extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
SDL_PaletteChangedFunc
callback, void *userdata);
/**
* \fn void SDL_DelPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
*
* \brief Remove a callback function previously added with SDL_AddPaletteWatch()
*
* \sa SDL_AddPaletteWatch()
*/
extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
SDL_PaletteChangedFunc
callback, void *userdata);
/**
* \fn int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Colors *colors, int firstcolor, int numcolors)
*
* \brief Set a range of colors in a palette.
*
* \param palette The palette to modify
* \param colors An array of colors to copy into the palette
* \param firstcolor The index of the first palette entry to modify
* \param ncolors The number of entries to modify
*
* \return 0 on success, or -1 if not all of the colors could be set
*/
extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
const SDL_Color * colors,
int firstcolor, int ncolors);
/**
* \fn void SDL_FreePalette(SDL_Palette *palette)
*
* \brief Free a palette created with SDL_AllocPalette()
*
* \sa SDL_AllocPalette()
*/
extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_pixels_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* Include file for SDL quit event handling */
/**
* \file SDL_quit.h
*
* Include file for SDL quit event handling
*/
#ifndef _SDL_quit_h
#define _SDL_quit_h

View File

@ -20,9 +20,12 @@
slouken@libsdl.org
*/
/* This file provides a general interface for SDL to read and write
data sources. It can easily be extended to files, memory, etc.
*/
/**
* \file SDL_rwops.h
*
* This file provides a general interface for SDL to read and write
* data sources. It can easily be extended to files, memory, etc.
*/
#ifndef _SDL_rwops_h
#define _SDL_rwops_h
@ -33,77 +36,89 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* This is the read/write operation structure -- very basic */
typedef struct SDL_RWops {
/* Seek to 'offset' relative to whence, one of stdio's whence values:
SEEK_SET, SEEK_CUR, SEEK_END
Returns the final offset in the data source.
*/
int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
typedef struct SDL_RWops
{
/* Seek to 'offset' relative to whence, one of stdio's whence values:
SEEK_SET, SEEK_CUR, SEEK_END
Returns the final offset in the data source.
*/
int (SDLCALL * seek) (struct SDL_RWops * context, int offset, int whence);
/* Read up to 'num' objects each of size 'objsize' from the data
source to the area pointed at by 'ptr'.
Returns the number of objects read, or -1 if the read failed.
*/
int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
/* Read up to 'num' objects each of size 'objsize' from the data
source to the area pointed at by 'ptr'.
Returns the number of objects read, or -1 if the read failed.
*/
int (SDLCALL * read) (struct SDL_RWops * context, void *ptr, int size,
int maxnum);
/* Write exactly 'num' objects each of size 'objsize' from the area
pointed at by 'ptr' to data source.
Returns 'num', or -1 if the write failed.
*/
int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
/* Write exactly 'num' objects each of size 'objsize' from the area
pointed at by 'ptr' to data source.
Returns 'num', or -1 if the write failed.
*/
int (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
int size, int num);
/* Close and free an allocated SDL_FSops structure */
int (SDLCALL *close)(struct SDL_RWops *context);
/* Close and free an allocated SDL_FSops structure */
int (SDLCALL * close) (struct SDL_RWops * context);
Uint32 type;
union {
Uint32 type;
union
{
#ifdef __WIN32__
struct {
int append;
void* h;
} win32io;
struct
{
int append;
void *h;
} win32io;
#endif
#ifdef HAVE_STDIO_H
struct {
int autoclose;
FILE *fp;
} stdio;
#ifdef HAVE_STDIO_H
struct
{
int autoclose;
FILE *fp;
} stdio;
#endif
struct {
Uint8 *base;
Uint8 *here;
Uint8 *stop;
} mem;
struct {
void *data1;
} unknown;
} hidden;
struct
{
Uint8 *base;
Uint8 *here;
Uint8 *stop;
} mem;
struct
{
void *data1;
} unknown;
} hidden;
} SDL_RWops;
/* Functions to create SDL_RWops structures from various data sources */
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode);
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
const char *mode);
#ifdef HAVE_STDIO_H
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, int autoclose);
#endif
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
int size);
extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
#define RW_SEEK_SET 0 /* Seek from the beginning of data */
#define RW_SEEK_CUR 1 /* Seek relative to current read point */
#define RW_SEEK_END 2 /* Seek relative to the end of data */
#define RW_SEEK_SET 0 /* Seek from the beginning of data */
#define RW_SEEK_CUR 1 /* Seek relative to current read point */
#define RW_SEEK_END 2 /* Seek relative to the end of data */
/* Macros to easily read and write from an SDL_RWops structure */
#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
@ -114,26 +129,30 @@ extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
/* Read an item of the specified endianness and return in native format */
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src);
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src);
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
/* Write an item of native format to the specified endianness */
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_rwops_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* This is a general header that includes C language support */
/**
* \file SDL_stdinc.h
*
* This is a general header that includes C language support
*/
#ifndef _SDL_stdinc_h
#define _SDL_stdinc_h
@ -77,33 +81,66 @@
#define SDL_TABLESIZE(table) SDL_arraysize(table)
/* Basic data types */
typedef enum SDL_bool {
SDL_FALSE = 0,
SDL_TRUE = 1
typedef enum SDL_bool
{
SDL_FALSE = 0,
SDL_TRUE = 1
} SDL_bool;
typedef int8_t Sint8;
typedef uint8_t Uint8;
typedef int16_t Sint16;
typedef uint16_t Uint16;
typedef int32_t Sint32;
typedef uint32_t Uint32;
/**
* \typedef Sint8
* \brief A signed 8-bit integer type.
*/
typedef int8_t Sint8;
/**
* \typedef Uint8
* \brief An unsigned 8-bit integer type.
*/
typedef uint8_t Uint8;
/**
* \typedef Sint16
* \brief A signed 16-bit integer type.
*/
typedef int16_t Sint16;
/**
* \typedef Uint16
* \brief An unsigned 16-bit integer type.
*/
typedef uint16_t Uint16;
/**
* \typedef Sint32
* \brief A signed 32-bit integer type.
*/
typedef int32_t Sint32;
/**
* \typedef Uint32
* \brief An unsigned 32-bit integer type.
*/
typedef uint32_t Uint32;
#ifdef SDL_HAS_64BIT_TYPE
typedef int64_t Sint64;
typedef uint64_t Uint64;
/**
* \typedef Sint64
* \brief A signed 64-bit integer type.
* \warning On platforms without any sort of 64-bit datatype, this is equivalent to Sint32!
*/
typedef int64_t Sint64;
/**
* \typedef Uint64
* \brief An unsigned 64-bit integer type.
* \warning On platforms without any sort of 64-bit datatype, this is equivalent to Uint32!
*/
typedef uint64_t Uint64;
#else
/* This is really just a hack to prevent the compiler from complaining */
typedef struct {
Uint32 hi;
Uint32 lo;
} Uint64, Sint64;
typdef Sint32 Sint64;
typdef Uint32 Uint32;
#endif
/* Make sure the types really have the right sizes */
#define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_dummy_ ## name[(x) * 2 - 1]
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
@ -112,6 +149,7 @@ SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
/* Check to make sure enums are the size of ints, for structure packing.
For both Watcom C/C++ and Borland C/C++ the compiler option that makes
@ -123,35 +161,39 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
#pragma enumsalwaysint on
#endif
typedef enum {
DUMMY_ENUM_VALUE
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
typedef enum
{
DUMMY_ENUM_VALUE
} SDL_DUMMY_ENUM;
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
#ifdef HAVE_MALLOC
#define SDL_malloc malloc
#else
extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
#endif
#ifdef HAVE_CALLOC
#define SDL_calloc calloc
#else
extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
#endif
#ifdef HAVE_REALLOC
#define SDL_realloc realloc
#else
extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
#endif
#ifdef HAVE_FREE
@ -173,11 +215,11 @@ extern DECLSPEC void SDLCALL SDL_free(void *mem);
# elif defined(__DMC__)
# include <stdlib.h>
# elif defined(__AIX__)
#pragma alloca
#pragma alloca
# elif defined(__MRC__)
void *alloca (unsigned);
void *alloca(unsigned);
# else
char *alloca ();
char *alloca();
# endif
#endif
#ifdef HAVE_ALLOCA
@ -191,7 +233,7 @@ extern DECLSPEC void SDLCALL SDL_free(void *mem);
#ifdef HAVE_GETENV
#define SDL_getenv getenv
#else
extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
#endif
#ifdef HAVE_PUTENV
@ -204,7 +246,8 @@ extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
#define SDL_qsort qsort
#else
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *));
int (*compare) (const void *,
const void *));
#endif
#ifdef HAVE_ABS
@ -231,8 +274,10 @@ extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
#ifdef HAVE_MEMSET
#define SDL_memset memset
#else
extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
#endif
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
#if defined(__GNUC__) && defined(i386)
#define SDL_memset4(dst, val, len) \
@ -288,7 +333,8 @@ do { \
#elif defined(HAVE_BCOPY)
#define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
#else
extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
size_t len);
#endif
#endif
@ -335,7 +381,8 @@ do { \
} while(0)
#endif
#ifndef SDL_revcpy
extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
extern DECLSPEC void *SDLCALL SDL_revcpy(void *dst, const void *src,
size_t len);
#endif
#ifdef HAVE_MEMMOVE
@ -356,7 +403,8 @@ do { \
#ifdef HAVE_MEMCMP
#define SDL_memcmp memcmp
#else
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
size_t len);
#endif
#ifdef HAVE_STRLEN
@ -368,37 +416,39 @@ extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
#ifdef HAVE_STRLCPY
#define SDL_strlcpy strlcpy
#else
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
size_t maxlen);
#endif
#ifdef HAVE_STRLCAT
#define SDL_strlcat strlcat
#else
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
size_t maxlen);
#endif
#ifdef HAVE_STRDUP
#define SDL_strdup strdup
#else
extern DECLSPEC char * SDLCALL SDL_strdup(const char *string);
extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
#endif
#ifdef HAVE__STRREV
#define SDL_strrev _strrev
#else
extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
#endif
#ifdef HAVE__STRUPR
#define SDL_strupr _strupr
#else
extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
#endif
#ifdef HAVE__STRLWR
#define SDL_strlwr _strlwr
#else
extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
#endif
#ifdef HAVE_STRCHR
@ -406,7 +456,7 @@ extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
#elif defined(HAVE_INDEX)
#define SDL_strchr index
#else
extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
#endif
#ifdef HAVE_STRRCHR
@ -414,13 +464,14 @@ extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
#elif defined(HAVE_RINDEX)
#define SDL_strrchr rindex
#else
extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
#endif
#ifdef HAVE_STRSTR
#define SDL_strstr strstr
#else
extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
const char *needle);
#endif
#ifdef HAVE_ITOA
@ -432,7 +483,7 @@ extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *need
#ifdef HAVE__LTOA
#define SDL_ltoa _ltoa
#else
extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
#endif
#ifdef HAVE__UITOA
@ -444,19 +495,22 @@ extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
#ifdef HAVE__ULTOA
#define SDL_ultoa _ultoa
#else
extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
int radix);
#endif
#ifdef HAVE_STRTOL
#define SDL_strtol strtol
#else
extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
int base);
#endif
#ifdef HAVE_STRTOUL
#define SDL_strtoul strtoul
#else
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base);
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
char **endp, int base);
#endif
#ifdef SDL_HAS_64BIT_TYPE
@ -464,25 +518,29 @@ extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **end
#ifdef HAVE__I64TOA
#define SDL_lltoa _i64toa
#else
extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
int radix);
#endif
#ifdef HAVE__UI64TOA
#define SDL_ulltoa _ui64toa
#else
extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
int radix);
#endif
#ifdef HAVE_STRTOLL
#define SDL_strtoll strtoll
#else
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
int base);
#endif
#ifdef HAVE_STRTOULL
#define SDL_strtoull strtoull
#else
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base);
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
int base);
#endif
#endif /* SDL_HAS_64BIT_TYPE */
@ -514,7 +572,8 @@ extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
#ifdef HAVE_STRNCMP
#define SDL_strncmp strncmp
#else
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
size_t maxlen);
#endif
#ifdef HAVE_STRCASECMP
@ -522,7 +581,8 @@ extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size
#elif defined(HAVE__STRICMP)
#define SDL_strcasecmp _stricmp
#else
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
const char *str2);
#endif
#ifdef HAVE_STRNCASECMP
@ -530,25 +590,29 @@ extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
#elif defined(HAVE__STRNICMP)
#define SDL_strncasecmp _strnicmp
#else
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
const char *str2, size_t maxlen);
#endif
#ifdef HAVE_SSCANF
#define SDL_sscanf sscanf
#else
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
...);
#endif
#ifdef HAVE_SNPRINTF
#define SDL_snprintf snprintf
#else
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
const char *fmt, ...);
#endif
#ifdef HAVE_VSNPRINTF
#define SDL_vsnprintf vsnprintf
#else
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
const char *fmt, va_list ap);
#endif
/* The SDL implementation of iconv() returns these error codes */
@ -561,17 +625,25 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char
#define SDL_iconv_t iconv_t
#define SDL_iconv_open iconv_open
#define SDL_iconv_close iconv_close
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf,
size_t * inbytesleft, char **outbuf,
size_t * outbytesleft);
#else
typedef struct _SDL_iconv_t *SDL_iconv_t;
extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode);
extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
const char *fromcode);
extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf,
size_t * inbytesleft, char **outbuf,
size_t * outbytesleft);
#endif
/* This function converts a string between encodings in one pass, returning a
string that must be freed with SDL_free() or NULL on error.
*/
extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft);
extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
const char *fromcode,
char *inbuf,
size_t inbytesleft);
#define SDL_iconv_utf8_ascii(S) SDL_iconv_string("ASCII", "UTF-8", S, SDL_strlen(S)+1)
#define SDL_iconv_utf8_latin1(S) SDL_iconv_string("LATIN1", "UTF-8", S, SDL_strlen(S)+1)
#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
@ -579,8 +651,12 @@ extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_stdinc_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,19 +20,26 @@
slouken@libsdl.org
*/
/* Include file for SDL custom system window manager hooks */
/**
* \file SDL_syswm.h
*
* Include file for SDL custom system window manager hooks
*/
#ifndef _SDL_syswm_h
#define _SDL_syswm_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_version.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* Your application has access to a special type of event 'SDL_SYSWMEVENT',
@ -42,7 +49,6 @@ extern "C" {
*/
#ifdef SDL_PROTOTYPES_ONLY
struct SDL_SysWMinfo;
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
#else
/* This is the structure for custom window manager events */
@ -61,150 +67,179 @@ typedef struct SDL_SysWMinfo SDL_SysWMinfo;
#endif
/* These are the various supported subsystems under UNIX */
typedef enum {
SDL_SYSWM_X11
typedef enum
{
SDL_SYSWM_X11
} SDL_SYSWM_TYPE;
/* The UNIX custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
SDL_SYSWM_TYPE subsystem;
union {
XEvent xevent;
} event;
struct SDL_SysWMmsg
{
SDL_version version;
SDL_SYSWM_TYPE subsystem;
union
{
XEvent xevent;
} event;
};
/* The UNIX custom window manager information structure.
When this structure is returned, it holds information about which
low level system it is using, and will be one of SDL_SYSWM_TYPE.
*/
typedef struct SDL_SysWMinfo {
SDL_version version;
SDL_SYSWM_TYPE subsystem;
union {
struct {
Display *display; /* The X11 display */
Window window; /* The X11 display window */
/* These locking functions should be called around
any X11 functions using the display variable.
They lock the event thread, so should not be
called around event functions or from event filters.
*/
void (*lock_func)(void);
void (*unlock_func)(void);
struct SDL_SysWMinfo
{
SDL_version version;
SDL_SYSWM_TYPE subsystem;
union
{
struct
{
Display *display; /* The X11 display */
Window window; /* The X11 display window */
/* These locking functions should be called around
any X11 functions using the display variable.
They lock the event thread, so should not be
called around event functions or from event filters.
*/
void (*lock_func) (void);
void (*unlock_func) (void);
/* Introduced in SDL 1.0.2 */
Window fswindow; /* The X11 fullscreen window */
Window wmwindow; /* The X11 managed input window */
} x11;
} info;
} SDL_SysWMinfo;
/* Introduced in SDL 1.0.2 */
Window fswindow; /* The X11 fullscreen window */
Window wmwindow; /* The X11 managed input window */
} x11;
} info;
};
#elif defined(SDL_VIDEO_DRIVER_NANOX)
#include <microwin/nano-X.h>
/* The generic custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
int data;
struct SDL_SysWMmsg
{
SDL_version version;
int data;
};
/* The windows custom window manager information structure */
typedef struct SDL_SysWMinfo {
SDL_version version ;
GR_WINDOW_ID window ; /* The display window */
} SDL_SysWMinfo;
struct SDL_SysWMinfo
{
SDL_version version;
GR_WINDOW_ID window; /* The display window */
};
#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
#elif defined(SDL_VIDEO_DRIVER_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* The windows custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
HWND hwnd; /* The window for the message */
UINT msg; /* The type of message */
WPARAM wParam; /* WORD message parameter */
LPARAM lParam; /* LONG message parameter */
struct SDL_SysWMmsg
{
SDL_version version;
HWND hwnd; /* The window for the message */
UINT msg; /* The type of message */
WPARAM wParam; /* WORD message parameter */
LPARAM lParam; /* LONG message parameter */
};
/* The windows custom window manager information structure */
typedef struct SDL_SysWMinfo {
SDL_version version;
HWND window; /* The Win32 display window */
HGLRC hglrc; /* The OpenGL context, if any */
} SDL_SysWMinfo;
struct SDL_SysWMinfo
{
SDL_version version;
HWND window; /* The Win32 display window */
HGLRC hglrc; /* The OpenGL context, if any */
};
#elif defined(SDL_VIDEO_DRIVER_RISCOS)
/* RISC OS custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
int eventCode; /* The window for the message */
int pollBlock[64];
struct SDL_SysWMmsg
{
SDL_version version;
int eventCode; /* The window for the message */
int pollBlock[64];
};
/* The RISC OS custom window manager information structure */
typedef struct SDL_SysWMinfo {
SDL_version version;
int wimpVersion; /* Wimp version running under */
int taskHandle; /* The RISC OS task handle */
int window; /* The RISC OS display window */
} SDL_SysWMinfo;
struct SDL_SysWMinfo
{
SDL_version version;
int wimpVersion; /* Wimp version running under */
int taskHandle; /* The RISC OS task handle */
int window; /* The RISC OS display window */
};
#elif defined(SDL_VIDEO_DRIVER_PHOTON)
#include <sys/neutrino.h>
#include <Ph.h>
/* The QNX custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
int data;
struct SDL_SysWMmsg
{
SDL_version version;
int data;
};
/* The QNX custom window manager information structure */
typedef struct SDL_SysWMinfo {
SDL_version version;
int data;
} SDL_SysWMinfo;
struct SDL_SysWMinfo
{
SDL_version version;
int data;
};
#else
/* The generic custom event structure */
struct SDL_SysWMmsg {
SDL_version version;
int data;
struct SDL_SysWMmsg
{
SDL_version version;
int data;
};
/* The generic custom window manager information structure */
typedef struct SDL_SysWMinfo {
SDL_version version;
int data;
} SDL_SysWMinfo;
struct SDL_SysWMinfo
{
SDL_version version;
int data;
};
#endif /* video driver type */
#endif /* SDL_PROTOTYPES_ONLY */
typedef struct SDL_SysWMinfo SDL_SysWMinfo;
/* Function prototypes */
/*
* This function gives you custom hooks into the window manager information.
* It fills the structure pointed to by 'info' with custom information and
* returns 1 if the function is implemented. If it's not implemented, or
* the version member of the 'info' structure is invalid, it returns 0.
/**
* \fn SDL_bool SDL_GetWindowWMInfo (SDL_WindowID windowID, SDL_SysWMinfo * info)
*
* \brief This function allows access to driver-dependent window information.
*
* \param windowID The window about which information is being requested
* \param info This structure must be initialized with the SDL version, and is then filled in with information about the given window.
*
* \return SDL_TRUE if the function is implemented and the version member of the 'info' struct is valid, SDL_FALSE otherwise.
*
* You typically use this function like this:
* \code
* SDL_SysWMInfo info;
* SDL_VERSION(&info.version);
* if ( SDL_GetWMInfo(&info) ) { ... }
* if ( SDL_GetWindowWMInfo(&info) ) { ... }
* \endcode
*/
extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info);
extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_WindowID windowID,
SDL_SysWMinfo * info);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_syswm_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -23,10 +23,11 @@
#ifndef _SDL_thread_h
#define _SDL_thread_h
/* Header for the SDL thread management routines
These are independent of the other SDL routines.
*/
/**
* \file SDL_thread.h
*
* Header for the SDL thread management routines
*/
#include "SDL_stdinc.h"
#include "SDL_error.h"
@ -37,7 +38,9 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* The SDL thread structure, defined in SDL_thread.c */
@ -61,25 +64,39 @@ typedef struct SDL_Thread SDL_Thread;
*/
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
#ifndef _WIN32_WCE
#include <process.h> /* This has _beginthread() and _endthread() defined! */
#include <process.h> /* This has _beginthread() and _endthread() defined! */
#endif
#ifdef __OS2__
typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg);
typedef void (*pfnSDL_CurrentEndThread)(void);
typedef int (*pfnSDL_CurrentBeginThread) (void (*func) (void *), void *,
unsigned, void *arg);
typedef void (*pfnSDL_CurrentEndThread) (void);
#elif __GNUC__
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *func)(void *), void *arg,
unsigned, unsigned *threadID);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned
(__stdcall *
func) (void *),
void *arg,
unsigned,
unsigned
*threadID);
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
#else
typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *func)(void *), void *arg,
unsigned, unsigned *threadID);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *
func) (void
*),
void *arg, unsigned,
unsigned *threadID);
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
#endif
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(int (*fn) (void *),
void *data,
pfnSDL_CurrentBeginThread
pfnBeginThread,
pfnSDL_CurrentEndThread
pfnEndThread);
#ifdef __OS2__
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
@ -89,7 +106,8 @@ extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *),
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
#endif
#else
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);
extern DECLSPEC SDL_Thread *SDLCALL
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data);
#endif
/* Get the 32-bit thread identifier for the current thread */
@ -98,22 +116,26 @@ extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
/* Get the 32-bit thread identifier for the specified thread,
equivalent to SDL_ThreadID() if the specified thread is NULL.
*/
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread *thread);
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread * thread);
/* Wait for a thread to finish.
The return code for the thread function is placed in the area
pointed to by 'status', if 'status' is not NULL.
*/
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status);
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
/* Forcefully kill a thread without worrying about its state */
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread *thread);
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread * thread);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_thread_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -23,7 +23,11 @@
#ifndef _SDL_timer_h
#define _SDL_timer_h
/* Header for the SDL time management routines */
/**
* \file SDL_timer.h
*
* Header for the SDL time management routines
*/
#include "SDL_stdinc.h"
#include "SDL_error.h"
@ -31,25 +35,27 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* This is the OS scheduler timeslice, in milliseconds */
#define SDL_TIMESLICE 10
/* This is the maximum resolution of the SDL timer on all platforms */
#define TIMER_RESOLUTION 10 /* Experimentally determined */
#define TIMER_RESOLUTION 10 /* Experimentally determined */
/* Get the number of milliseconds since the SDL library initialization.
* Note that this value wraps if the program runs for more than ~49 days.
*/
*/
extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
/* Wait a specified number of milliseconds before returning */
extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
/* Function prototype for the timer callback function */
typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval);
typedef Uint32(SDLCALL * SDL_TimerCallback) (Uint32 interval);
/* Set a callback to run after the specified number of milliseconds has
* elapsed. The callback function is passed the current timer interval
@ -79,7 +85,8 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval);
*
* This function returns 0 if successful, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback);
extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval,
SDL_TimerCallback callback);
/* New timer API, supports multiple timers
* Written by Stephane Peter <megastep@lokigames.com>
@ -91,7 +98,7 @@ extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback call
* passed in, the periodic alarm continues, otherwise a new alarm is
* scheduled. If the callback returns 0, the periodic alarm is cancelled.
*/
typedef Uint32 (SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param);
typedef Uint32(SDLCALL * SDL_NewTimerCallback) (Uint32 interval, void *param);
/* Definition of the timer ID type */
typedef struct _SDL_TimerID *SDL_TimerID;
@ -99,7 +106,9 @@ typedef struct _SDL_TimerID *SDL_TimerID;
/* Add a new timer to the pool of timers already running.
Returns a timer ID, or NULL when an error occurs.
*/
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param);
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
SDL_NewTimerCallback
callback, void *param);
/* Remove one of the multiple timers knowing its ID.
* Returns a boolean value indicating success.
@ -108,8 +117,12 @@ extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_timer_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -20,7 +20,11 @@
slouken@libsdl.org
*/
/* This header defines the current SDL version */
/**
* \file SDL_version.h
*
* This header defines the current SDL version
*/
#ifndef _SDL_version_h
#define _SDL_version_h
@ -30,29 +34,58 @@
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/**
* \struct SDL_version
* \brief Information the version of SDL in use.
*
* Represents the library's version as three levels: major revision
* (increments with massive changes, additions, and enhancements),
* minor revision (increments with backwards-compatible changes to the
* major revision), and patchlevel (increments with fixes to the minor
* revision).
*
* \sa SDL_VERSION
* \sa SDL_GetVersion
*/
typedef struct SDL_version
{
Uint8 major; /**< major version */
Uint8 minor; /**< minor version */
Uint8 patch; /**< update version */
} SDL_version;
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
#define SDL_MAJOR_VERSION 1
#define SDL_MINOR_VERSION 2
#define SDL_PATCHLEVEL 11
#define SDL_MINOR_VERSION 3
#define SDL_PATCHLEVEL 0
typedef struct SDL_version {
Uint8 major;
Uint8 minor;
Uint8 patch;
} SDL_version;
/* This macro can be used to fill a version structure with the compile-time
* version of the SDL library.
/**
* \def SDL_VERSION(x)
* \brief Macro to determine SDL version program was compiled against.
*
* This macro fills in a SDL_version structure with the version of the
* library you compiled against. This is determined by what header the
* compiler uses. Note that if you dynamically linked the library, you might
* have a slightly newer or older version at runtime. That version can be
* determined with SDL_GetVersion(), which, unlike SDL_VERSION,
* is not a macro.
*
* \param x A pointer to a SDL_version struct to initialize.
*
* \sa SDL_version
* \sa SDL_GetVersion
*/
#define SDL_VERSION(X) \
#define SDL_VERSION(x) \
{ \
(X)->major = SDL_MAJOR_VERSION; \
(X)->minor = SDL_MINOR_VERSION; \
(X)->patch = SDL_PATCHLEVEL; \
(x)->major = SDL_MAJOR_VERSION; \
(x)->minor = SDL_MINOR_VERSION; \
(x)->patch = SDL_PATCHLEVEL; \
}
/* This macro turns the version numbers into a numeric value:
@ -70,16 +103,42 @@ typedef struct SDL_version {
#define SDL_VERSION_ATLEAST(X, Y, Z) \
(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
/* This function gets the version of the dynamically linked SDL library.
it should NOT be used to fill a version structure, instead you should
use the SDL_Version() macro.
/**
* \fn void SDL_GetVersion(SDL_version *ver)
* \brief Get the version of SDL that is linked against your program.
*
* If you are using a shared library (DLL) version of SDL, then it is
* possible that it will be different than the version you compiled against.
*
* This is a real function; the macro SDL_VERSION tells you what version
* of SDL you compiled against:
*
* \code
* SDL_version compiled;
* SDL_version linked;
*
* SDL_VERSION(&compiled);
* SDL_GetVersion(&linked);
* printf("We compiled against SDL version %d.%d.%d ...\n",
* compiled.major, compiled.minor, compiled.patch);
* printf("But we linked against SDL version %d.%d.%d.\n",
* linked.major, linked.minor, linked.patch);
* \endcode
*
* This function may be called safely at any time, even before SDL_Init().
*
* \sa SDL_VERSION
*/
extern DECLSPEC const SDL_version * SDLCALL SDL_Linked_Version(void);
extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_version_h */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
# elif defined(__WIN32__)
# ifdef __BORLANDC__
# ifdef BUILD_SDL
# define DECLSPEC
# define DECLSPEC
# else
# define DECLSPEC __declspec(dllimport)
# endif
@ -84,7 +84,7 @@
#endif /* SDLCALL */
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
#ifdef __SYMBIAN32__
#ifdef __SYMBIAN32__
#undef DECLSPEC
#define DECLSPEC
#endif /* __SYMBIAN32__ */

View File

@ -38,4 +38,3 @@
#pragma pack(pop)
#endif
#endif /* Compiler needs structure packing set */

1229
include/doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'` ;;
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac

365
src/SDL.c
View File

@ -35,23 +35,19 @@
/* Initialization/Cleanup routines */
#if !SDL_JOYSTICK_DISABLED
extern int SDL_JoystickInit(void);
extern int SDL_JoystickInit(void);
extern void SDL_JoystickQuit(void);
#endif
#if !SDL_CDROM_DISABLED
extern int SDL_CDROMInit(void);
extern int SDL_CDROMInit(void);
extern void SDL_CDROMQuit(void);
#endif
#if !SDL_TIMERS_DISABLED
extern void SDL_StartTicks(void);
extern int SDL_TimerInit(void);
extern int SDL_TimerInit(void);
extern void SDL_TimerQuit(void);
#endif
/* The current SDL version */
static SDL_version version =
{ SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL };
/* The initialized subsystems */
static Uint32 SDL_initialized = 0;
static Uint32 ticks_started = 0;
@ -60,196 +56,205 @@ static Uint32 ticks_started = 0;
int surfaces_allocated = 0;
#endif
int SDL_InitSubSystem(Uint32 flags)
int
SDL_InitSubSystem(Uint32 flags)
{
#if !SDL_VIDEO_DISABLED
/* Initialize the video/event subsystem */
if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) {
if ( SDL_VideoInit(SDL_getenv("SDL_VIDEODRIVER"),
(flags&SDL_INIT_EVENTTHREAD)) < 0 ) {
return(-1);
}
SDL_initialized |= SDL_INIT_VIDEO;
}
/* Initialize the video/event subsystem */
if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) {
if (SDL_VideoInit(SDL_getenv("SDL_VIDEODRIVER"),
(flags & SDL_INIT_EVENTTHREAD)) < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_VIDEO;
}
#else
if ( flags & SDL_INIT_VIDEO ) {
SDL_SetError("SDL not built with video support");
return(-1);
}
if (flags & SDL_INIT_VIDEO) {
SDL_SetError("SDL not built with video support");
return (-1);
}
#endif
#if !SDL_AUDIO_DISABLED
/* Initialize the audio subsystem */
if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) {
if ( SDL_AudioInit(SDL_getenv("SDL_AUDIODRIVER")) < 0 ) {
return(-1);
}
SDL_initialized |= SDL_INIT_AUDIO;
}
/* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) {
if (SDL_AudioInit(SDL_getenv("SDL_AUDIODRIVER")) < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_AUDIO;
}
#else
if ( flags & SDL_INIT_AUDIO ) {
SDL_SetError("SDL not built with audio support");
return(-1);
}
if (flags & SDL_INIT_AUDIO) {
SDL_SetError("SDL not built with audio support");
return (-1);
}
#endif
#if !SDL_TIMERS_DISABLED
/* Initialize the timer subsystem */
if ( ! ticks_started ) {
SDL_StartTicks();
ticks_started = 1;
}
if ( (flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER) ) {
if ( SDL_TimerInit() < 0 ) {
return(-1);
}
SDL_initialized |= SDL_INIT_TIMER;
}
/* Initialize the timer subsystem */
if (!ticks_started) {
SDL_StartTicks();
ticks_started = 1;
}
if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_TIMER;
}
#else
if ( flags & SDL_INIT_TIMER ) {
SDL_SetError("SDL not built with timer support");
return(-1);
}
if (flags & SDL_INIT_TIMER) {
SDL_SetError("SDL not built with timer support");
return (-1);
}
#endif
#if !SDL_JOYSTICK_DISABLED
/* Initialize the joystick subsystem */
if ( (flags & SDL_INIT_JOYSTICK) &&
!(SDL_initialized & SDL_INIT_JOYSTICK) ) {
if ( SDL_JoystickInit() < 0 ) {
return(-1);
}
SDL_initialized |= SDL_INIT_JOYSTICK;
}
/* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_JOYSTICK;
}
#else
if ( flags & SDL_INIT_JOYSTICK ) {
SDL_SetError("SDL not built with joystick support");
return(-1);
}
if (flags & SDL_INIT_JOYSTICK) {
SDL_SetError("SDL not built with joystick support");
return (-1);
}
#endif
#if !SDL_CDROM_DISABLED
/* Initialize the CD-ROM subsystem */
if ( (flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM) ) {
if ( SDL_CDROMInit() < 0 ) {
return(-1);
}
SDL_initialized |= SDL_INIT_CDROM;
}
/* Initialize the CD-ROM subsystem */
if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
if (SDL_CDROMInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_CDROM;
}
#else
if ( flags & SDL_INIT_CDROM ) {
SDL_SetError("SDL not built with cdrom support");
return(-1);
}
if (flags & SDL_INIT_CDROM) {
SDL_SetError("SDL not built with cdrom support");
return (-1);
}
#endif
return(0);
return (0);
}
int SDL_Init(Uint32 flags)
int
SDL_Init(Uint32 flags)
{
#if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
if (!pth_init()) {
return -1;
}
if (!pth_init()) {
return -1;
}
#endif
/* Clear the error message */
SDL_ClearError();
/* Clear the error message */
SDL_ClearError();
/* Initialize the desired subsystems */
if ( SDL_InitSubSystem(flags) < 0 ) {
return(-1);
}
/* Initialize the desired subsystems */
if (SDL_InitSubSystem(flags) < 0) {
return (-1);
}
/* Everything is initialized */
if ( !(flags & SDL_INIT_NOPARACHUTE) ) {
SDL_InstallParachute();
}
return(0);
/* Everything is initialized */
if (!(flags & SDL_INIT_NOPARACHUTE)) {
SDL_InstallParachute();
}
return (0);
}
void SDL_QuitSubSystem(Uint32 flags)
void
SDL_QuitSubSystem(Uint32 flags)
{
/* Shut down requested initialized subsystems */
/* Shut down requested initialized subsystems */
#if !SDL_CDROM_DISABLED
if ( (flags & SDL_initialized & SDL_INIT_CDROM) ) {
SDL_CDROMQuit();
SDL_initialized &= ~SDL_INIT_CDROM;
}
if ((flags & SDL_initialized & SDL_INIT_CDROM)) {
SDL_CDROMQuit();
SDL_initialized &= ~SDL_INIT_CDROM;
}
#endif
#if !SDL_JOYSTICK_DISABLED
if ( (flags & SDL_initialized & SDL_INIT_JOYSTICK) ) {
SDL_JoystickQuit();
SDL_initialized &= ~SDL_INIT_JOYSTICK;
}
if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit();
SDL_initialized &= ~SDL_INIT_JOYSTICK;
}
#endif
#if !SDL_TIMERS_DISABLED
if ( (flags & SDL_initialized & SDL_INIT_TIMER) ) {
SDL_TimerQuit();
SDL_initialized &= ~SDL_INIT_TIMER;
}
if ((flags & SDL_initialized & SDL_INIT_TIMER)) {
SDL_TimerQuit();
SDL_initialized &= ~SDL_INIT_TIMER;
}
#endif
#if !SDL_AUDIO_DISABLED
if ( (flags & SDL_initialized & SDL_INIT_AUDIO) ) {
SDL_AudioQuit();
SDL_initialized &= ~SDL_INIT_AUDIO;
}
if ((flags & SDL_initialized & SDL_INIT_AUDIO)) {
SDL_AudioQuit();
SDL_initialized &= ~SDL_INIT_AUDIO;
}
#endif
#if !SDL_VIDEO_DISABLED
if ( (flags & SDL_initialized & SDL_INIT_VIDEO) ) {
SDL_VideoQuit();
SDL_initialized &= ~SDL_INIT_VIDEO;
}
if ((flags & SDL_initialized & SDL_INIT_VIDEO)) {
SDL_VideoQuit();
SDL_initialized &= ~SDL_INIT_VIDEO;
}
#endif
}
Uint32 SDL_WasInit(Uint32 flags)
Uint32
SDL_WasInit(Uint32 flags)
{
if ( ! flags ) {
flags = SDL_INIT_EVERYTHING;
}
return (SDL_initialized&flags);
if (!flags) {
flags = SDL_INIT_EVERYTHING;
}
return (SDL_initialized & flags);
}
void SDL_Quit(void)
void
SDL_Quit(void)
{
/* Quit all subsystems */
/* Quit all subsystems */
#ifdef DEBUG_BUILD
printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout);
printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n");
fflush(stdout);
#endif
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
#ifdef CHECK_LEAKS
#ifdef DEBUG_BUILD
printf("[SDL_Quit] : CHECK_LEAKS\n"); fflush(stdout);
printf("[SDL_Quit] : CHECK_LEAKS\n");
fflush(stdout);
#endif
/* Print the number of surfaces not freed */
if ( surfaces_allocated != 0 ) {
fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
surfaces_allocated);
}
/* Print the number of surfaces not freed */
if (surfaces_allocated != 0) {
fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n",
surfaces_allocated);
}
#endif
#ifdef DEBUG_BUILD
printf("[SDL_Quit] : SDL_UninstallParachute()\n"); fflush(stdout);
printf("[SDL_Quit] : SDL_UninstallParachute()\n");
fflush(stdout);
#endif
/* Uninstall any parachute signal handlers */
SDL_UninstallParachute();
/* Uninstall any parachute signal handlers */
SDL_UninstallParachute();
#if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
pth_kill();
pth_kill();
#endif
#ifdef DEBUG_BUILD
printf("[SDL_Quit] : Returning!\n"); fflush(stdout);
printf("[SDL_Quit] : Returning!\n");
fflush(stdout);
#endif
}
/* Return the library version number */
const SDL_version * SDL_Linked_Version(void)
/* Get the library version number */
void
SDL_GetVersion(SDL_version * ver)
{
return(&version);
SDL_VERSION(ver);
}
#if defined(__OS2__)
@ -261,65 +266,63 @@ const SDL_version * SDL_Linked_Version(void)
#include <os2.h>
/* Exception handler to prevent the Audio thread hanging, making a zombie process! */
ULONG _System SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec,
PEXCEPTIONREGISTRATIONRECORD pERegRec,
PCONTEXTRECORD pCtxRec,
PVOID p)
ULONG _System
SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec,
PEXCEPTIONREGISTRATIONRECORD pERegRec,
PCONTEXTRECORD pCtxRec, PVOID p)
{
if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND)
return XCPT_CONTINUE_SEARCH;
if (pERepRec->fHandlerFlags & EH_UNWINDING)
return XCPT_CONTINUE_SEARCH;
if (pERepRec->fHandlerFlags & EH_NESTED_CALL)
return XCPT_CONTINUE_SEARCH;
if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND)
return XCPT_CONTINUE_SEARCH;
if (pERepRec->fHandlerFlags & EH_UNWINDING)
return XCPT_CONTINUE_SEARCH;
if (pERepRec->fHandlerFlags & EH_NESTED_CALL)
return XCPT_CONTINUE_SEARCH;
/* Do cleanup at every fatal exception! */
if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) == XCPT_FATAL_EXCEPTION) &&
(pERepRec->ExceptionNum != XCPT_BREAKPOINT) &&
(pERepRec->ExceptionNum != XCPT_SINGLE_STEP)
)
{
if (SDL_initialized & SDL_INIT_AUDIO)
{
/* This removes the zombie audio thread in case of emergency. */
/* Do cleanup at every fatal exception! */
if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) ==
XCPT_FATAL_EXCEPTION) && (pERepRec->ExceptionNum != XCPT_BREAKPOINT)
&& (pERepRec->ExceptionNum != XCPT_SINGLE_STEP)) {
if (SDL_initialized & SDL_INIT_AUDIO) {
/* This removes the zombie audio thread in case of emergency. */
#ifdef DEBUG_BUILD
printf("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n");
printf
("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n");
#endif
SDL_CloseAudio();
SDL_CloseAudio();
}
}
}
return (XCPT_CONTINUE_SEARCH);
return (XCPT_CONTINUE_SEARCH);
}
EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand = {0, SDL_Main_ExceptionHandler};
EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand =
{ 0, SDL_Main_ExceptionHandler };
/* The main DLL entry for DLL Initialization and Uninitialization: */
unsigned _System LibMain(unsigned hmod, unsigned termination)
unsigned _System
LibMain(unsigned hmod, unsigned termination)
{
if (termination)
{
if (termination) {
#ifdef DEBUG_BUILD
/* printf("[SDL DLL Unintialization] : Removing exception handler\n"); */
#endif
DosUnsetExceptionHandler(&SDL_Main_xcpthand);
return 1;
} else
{
DosUnsetExceptionHandler(&SDL_Main_xcpthand);
return 1;
} else {
#ifdef DEBUG_BUILD
/* Make stdout and stderr unbuffered! */
setbuf(stdout, NULL);
setbuf(stderr, NULL);
/* Make stdout and stderr unbuffered! */
setbuf(stdout, NULL);
setbuf(stderr, NULL);
#endif
/* Fire up exception handler */
/* Fire up exception handler */
#ifdef DEBUG_BUILD
/* printf("[SDL DLL Initialization] : Setting exception handler\n"); */
#endif
/* Set exception handler */
DosSetExceptionHandler(&SDL_Main_xcpthand);
/* Set exception handler */
DosSetExceptionHandler(&SDL_Main_xcpthand);
return 1;
}
return 1;
}
}
#endif /* __WATCOMC__ */
@ -330,19 +333,21 @@ unsigned _System LibMain(unsigned hmod, unsigned termination)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL APIENTRY _DllMainCRTStartup( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
BOOL APIENTRY
_DllMainCRTStartup(HANDLE hModule,
DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif /* building DLL with Watcom C */
#endif /* OS/2 elif __WIN32__ */
/* vi: set ts=4 sw=4 expandtab: */

1415
src/SDL_compat.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -39,200 +39,217 @@ extern SDL_error *SDL_GetErrBuf(void);
/* Private functions */
static const char *SDL_LookupString(const char *key)
static const char *
SDL_LookupString(const char *key)
{
/* FIXME: Add code to lookup key in language string hash-table */
return key;
/* FIXME: Add code to lookup key in language string hash-table */
return key;
}
/* Public functions */
void SDL_SetError (const char *fmt, ...)
void
SDL_SetError(const char *fmt, ...)
{
va_list ap;
SDL_error *error;
va_list ap;
SDL_error *error;
/* Copy in the key, mark error as valid */
error = SDL_GetErrBuf();
error->error = 1;
SDL_strlcpy((char *)error->key, fmt, sizeof(error->key));
/* Copy in the key, mark error as valid */
error = SDL_GetErrBuf();
error->error = 1;
SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
va_start(ap, fmt);
error->argc = 0;
while ( *fmt ) {
if ( *fmt++ == '%' ) {
while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
++fmt;
}
switch (*fmt++) {
case 0: /* Malformed format string.. */
--fmt;
break;
case 'c':
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
error->args[error->argc++].value_i =
va_arg(ap, int);
break;
case 'f':
error->args[error->argc++].value_f =
va_arg(ap, double);
break;
case 'p':
error->args[error->argc++].value_ptr =
va_arg(ap, void *);
break;
case 's':
{
int i = error->argc;
const char *str = va_arg(ap, const char *);
if (str == NULL)
str = "(null)";
SDL_strlcpy((char *)error->args[i].buf, str, ERR_MAX_STRLEN);
error->argc++;
}
break;
default:
break;
}
if ( error->argc >= ERR_MAX_ARGS ) {
break;
}
}
}
va_end(ap);
va_start(ap, fmt);
error->argc = 0;
while (*fmt) {
if (*fmt++ == '%') {
while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
++fmt;
}
switch (*fmt++) {
case 0: /* Malformed format string.. */
--fmt;
break;
case 'c':
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
error->args[error->argc++].value_i = va_arg(ap, int);
break;
case 'f':
error->args[error->argc++].value_f = va_arg(ap, double);
break;
case 'p':
error->args[error->argc++].value_ptr = va_arg(ap, void *);
break;
case 's':
{
int i = error->argc;
const char *str = va_arg(ap, const char *);
if (str == NULL)
str = "(null)";
SDL_strlcpy((char *) error->args[i].buf, str,
ERR_MAX_STRLEN);
error->argc++;
}
break;
default:
break;
}
if (error->argc >= ERR_MAX_ARGS) {
break;
}
}
}
va_end(ap);
/* If we are in debug mode, print out an error message */
/* If we are in debug mode, print out an error message */
#ifdef DEBUG_ERROR
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
fprintf(stderr, "SDL_SetError: %s\n", SDL_GetError());
#endif
}
/* This function has a bit more overhead than most error functions
so that it supports internationalization and thread-safe errors.
*/
char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
char *
SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
{
SDL_error *error;
SDL_error *error;
/* Clear the error string */
*errstr = '\0'; --maxlen;
/* Clear the error string */
*errstr = '\0';
--maxlen;
/* Get the thread-safe error, and print it out */
error = SDL_GetErrBuf();
if ( error->error ) {
const char *fmt;
char *msg = errstr;
int len;
int argi;
/* Get the thread-safe error, and print it out */
error = SDL_GetErrBuf();
if (error->error) {
const char *fmt;
char *msg = errstr;
int len;
int argi;
fmt = SDL_LookupString(error->key);
argi = 0;
while ( *fmt && (maxlen > 0) ) {
if ( *fmt == '%' ) {
char tmp[32], *spot = tmp;
*spot++ = *fmt++;
while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) {
*spot++ = *fmt++;
}
*spot++ = *fmt++;
*spot++ = '\0';
switch (spot[-2]) {
case '%':
*msg++ = '%';
maxlen -= 1;
break;
case 'c':
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i);
msg += len;
maxlen -= len;
break;
case 'f':
len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f);
msg += len;
maxlen -= len;
break;
case 'p':
len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr);
msg += len;
maxlen -= len;
break;
case 's':
len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf));
msg += len;
maxlen -= len;
break;
}
} else {
*msg++ = *fmt++;
maxlen -= 1;
}
}
*msg = 0; /* NULL terminate the string */
}
return(errstr);
fmt = SDL_LookupString(error->key);
argi = 0;
while (*fmt && (maxlen > 0)) {
if (*fmt == '%') {
char tmp[32], *spot = tmp;
*spot++ = *fmt++;
while ((*fmt == '.' || (*fmt >= '0' && *fmt <= '9'))
&& spot < (tmp + SDL_arraysize(tmp) - 2)) {
*spot++ = *fmt++;
}
*spot++ = *fmt++;
*spot++ = '\0';
switch (spot[-2]) {
case '%':
*msg++ = '%';
maxlen -= 1;
break;
case 'c':
case 'i':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
len =
SDL_snprintf(msg, maxlen, tmp,
error->args[argi++].value_i);
msg += len;
maxlen -= len;
break;
case 'f':
len =
SDL_snprintf(msg, maxlen, tmp,
error->args[argi++].value_f);
msg += len;
maxlen -= len;
break;
case 'p':
len =
SDL_snprintf(msg, maxlen, tmp,
error->args[argi++].value_ptr);
msg += len;
maxlen -= len;
break;
case 's':
len =
SDL_snprintf(msg, maxlen, tmp,
SDL_LookupString(error->
args[argi++].buf));
msg += len;
maxlen -= len;
break;
}
} else {
*msg++ = *fmt++;
maxlen -= 1;
}
}
*msg = 0; /* NULL terminate the string */
}
return (errstr);
}
/* Available for backwards compatibility */
char *SDL_GetError (void)
char *
SDL_GetError(void)
{
static char errmsg[SDL_ERRBUFIZE];
static char errmsg[SDL_ERRBUFIZE];
return((char *)SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
return ((char *) SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
}
void SDL_ClearError(void)
void
SDL_ClearError(void)
{
SDL_error *error;
SDL_error *error;
error = SDL_GetErrBuf();
error->error = 0;
error = SDL_GetErrBuf();
error->error = 0;
}
/* Very common errors go here */
void SDL_Error(SDL_errorcode code)
void
SDL_Error(SDL_errorcode code)
{
switch (code) {
case SDL_ENOMEM:
SDL_SetError("Out of memory");
break;
case SDL_EFREAD:
SDL_SetError("Error reading from datastream");
break;
case SDL_EFWRITE:
SDL_SetError("Error writing to datastream");
break;
case SDL_EFSEEK:
SDL_SetError("Error seeking in datastream");
break;
default:
SDL_SetError("Unknown SDL error");
break;
}
switch (code) {
case SDL_ENOMEM:
SDL_SetError("Out of memory");
break;
case SDL_EFREAD:
SDL_SetError("Error reading from datastream");
break;
case SDL_EFWRITE:
SDL_SetError("Error writing to datastream");
break;
case SDL_EFSEEK:
SDL_SetError("Error seeking in datastream");
break;
default:
SDL_SetError("Unknown SDL error");
break;
}
}
#ifdef TEST_ERROR
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
char buffer[BUFSIZ+1];
char buffer[BUFSIZ + 1];
SDL_SetError("Hi there!");
printf("Error 1: %s\n", SDL_GetError());
SDL_ClearError();
SDL_memset(buffer, '1', BUFSIZ);
buffer[BUFSIZ] = 0;
SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
printf("Error 2: %s\n", SDL_GetError());
exit(0);
SDL_SetError("Hi there!");
printf("Error 1: %s\n", SDL_GetError());
SDL_ClearError();
SDL_memset(buffer, '1', BUFSIZ);
buffer[BUFSIZ] = 0;
SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
printf("Error 2: %s\n", SDL_GetError());
exit(0);
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,28 +31,31 @@
#define ERR_MAX_STRLEN 128
#define ERR_MAX_ARGS 5
typedef struct SDL_error {
/* This is a numeric value corresponding to the current error */
int error;
typedef struct SDL_error
{
/* This is a numeric value corresponding to the current error */
int error;
/* This is a key used to index into a language hashtable containing
internationalized versions of the SDL error messages. If the key
is not in the hashtable, or no hashtable is available, the key is
used directly as an error message format string.
*/
char key[ERR_MAX_STRLEN];
/* This is a key used to index into a language hashtable containing
internationalized versions of the SDL error messages. If the key
is not in the hashtable, or no hashtable is available, the key is
used directly as an error message format string.
*/
char key[ERR_MAX_STRLEN];
/* These are the arguments for the error functions */
int argc;
union {
void *value_ptr;
#if 0 /* What is a character anyway? (UNICODE issues) */
unsigned char value_c;
/* These are the arguments for the error functions */
int argc;
union
{
void *value_ptr;
#if 0 /* What is a character anyway? (UNICODE issues) */
unsigned char value_c;
#endif
int value_i;
double value_f;
char buf[ERR_MAX_STRLEN];
} args[ERR_MAX_ARGS];
int value_i;
double value_f;
char buf[ERR_MAX_STRLEN];
} args[ERR_MAX_ARGS];
} SDL_error;
#endif /* _SDL_error_c_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -35,85 +35,88 @@
the program crashes.
*/
static void SDL_Parachute(int sig)
static void
SDL_Parachute(int sig)
{
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
}
static int SDL_fatal_signals[] = {
SIGSEGV,
SIGSEGV,
#ifdef SIGBUS
SIGBUS,
SIGBUS,
#endif
#ifdef SIGFPE
SIGFPE,
SIGFPE,
#endif
#ifdef SIGQUIT
SIGQUIT,
SIGQUIT,
#endif
0
0
};
void SDL_InstallParachute(void)
void
SDL_InstallParachute(void)
{
/* Set a handler for any fatal signal not already handled */
int i;
/* Set a handler for any fatal signal not already handled */
int i;
#ifdef HAVE_SIGACTION
struct sigaction action;
struct sigaction action;
for ( i=0; SDL_fatal_signals[i]; ++i ) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if ( action.sa_handler == SIG_DFL ) {
action.sa_handler = SDL_Parachute;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
for (i = 0; SDL_fatal_signals[i]; ++i) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SDL_Parachute;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
#ifdef SIGALRM
/* Set SIGALRM to be ignored -- necessary on Solaris */
sigaction(SIGALRM, NULL, &action);
if ( action.sa_handler == SIG_DFL ) {
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, NULL);
}
/* Set SIGALRM to be ignored -- necessary on Solaris */
sigaction(SIGALRM, NULL, &action);
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, NULL);
}
#endif
#else
void (*ohandler)(int);
void (*ohandler) (int);
for ( i=0; SDL_fatal_signals[i]; ++i ) {
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
if ( ohandler != SIG_DFL ) {
signal(SDL_fatal_signals[i], ohandler);
}
}
for (i = 0; SDL_fatal_signals[i]; ++i) {
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
if (ohandler != SIG_DFL) {
signal(SDL_fatal_signals[i], ohandler);
}
}
#endif /* HAVE_SIGACTION */
return;
return;
}
void SDL_UninstallParachute(void)
void
SDL_UninstallParachute(void)
{
/* Remove a handler for any fatal signal handled */
int i;
/* Remove a handler for any fatal signal handled */
int i;
#ifdef HAVE_SIGACTION
struct sigaction action;
struct sigaction action;
for ( i=0; SDL_fatal_signals[i]; ++i ) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if ( action.sa_handler == SDL_Parachute ) {
action.sa_handler = SIG_DFL;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
for (i = 0; SDL_fatal_signals[i]; ++i) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if (action.sa_handler == SDL_Parachute) {
action.sa_handler = SIG_DFL;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
#else
void (*ohandler)(int);
void (*ohandler) (int);
for ( i=0; SDL_fatal_signals[i]; ++i ) {
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
if ( ohandler != SDL_Parachute ) {
signal(SDL_fatal_signals[i], ohandler);
}
}
for (i = 0; SDL_fatal_signals[i]; ++i) {
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
if (ohandler != SDL_Parachute) {
signal(SDL_fatal_signals[i], ohandler);
}
}
#endif /* HAVE_SIGACTION */
}
@ -121,14 +124,17 @@ void SDL_UninstallParachute(void)
/* No signals on this platform, nothing to do.. */
void SDL_InstallParachute(void)
void
SDL_InstallParachute(void)
{
return;
return;
}
void SDL_UninstallParachute(void)
void
SDL_UninstallParachute(void)
{
return;
return;
}
#endif /* HAVE_SIGNAL_H */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -25,4 +25,4 @@
extern void SDL_InstallParachute(void);
extern void SDL_UninstallParachute(void);
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,8 @@ extern Uint16 SDL_FirstAudioFormat(Uint16 format);
extern Uint16 SDL_NextAudioFormat(void);
/* Function to calculate the size and silence for a SDL_AudioSpec */
extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec);
extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
/* The actual mixing thread function */
extern int SDLCALL SDL_RunAudio(void *audiop);
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -47,53 +47,56 @@
#endif
int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
int
SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
{
const char *audiodev;
int audio_fd;
char audiopath[1024];
const char *audiodev;
int audio_fd;
char audiopath[1024];
/* Figure out what our audio device is */
if ( ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) &&
((audiodev=SDL_getenv("AUDIODEV")) == NULL) ) {
if ( classic ) {
audiodev = _PATH_DEV_AUDIO;
} else {
struct stat sb;
/* Figure out what our audio device is */
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
if (classic) {
audiodev = _PATH_DEV_AUDIO;
} else {
struct stat sb;
/* Added support for /dev/sound/\* in Linux 2.4 */
if ( ((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) &&
((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode)) ) {
audiodev = _PATH_DEV_DSP24;
} else {
audiodev = _PATH_DEV_DSP;
}
}
}
audio_fd = open(audiodev, flags, 0);
/* Added support for /dev/sound/\* in Linux 2.4 */
if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
&& ((stat(_PATH_DEV_DSP24, &sb) == 0)
&& S_ISCHR(sb.st_mode))) {
audiodev = _PATH_DEV_DSP24;
} else {
audiodev = _PATH_DEV_DSP;
}
}
}
audio_fd = open(audiodev, flags, 0);
/* If the first open fails, look for other devices */
if ( (audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath)-3)) ) {
int exists, instance;
struct stat sb;
/* If the first open fails, look for other devices */
if ((audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath) - 3))) {
int exists, instance;
struct stat sb;
instance = 1;
do { /* Don't use errno ENOENT - it may not be thread-safe */
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
"%s%d", audiodev, instance++);
exists = 0;
if ( stat(audiopath, &sb) == 0 ) {
exists = 1;
audio_fd = open(audiopath, flags, 0);
}
} while ( exists && (audio_fd < 0) );
audiodev = audiopath;
}
if ( path != NULL ) {
SDL_strlcpy(path, audiodev, maxlen);
path[maxlen-1] = '\0';
}
return(audio_fd);
instance = 1;
do { /* Don't use errno ENOENT - it may not be thread-safe */
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
"%s%d", audiodev, instance++);
exists = 0;
if (stat(audiopath, &sb) == 0) {
exists = 1;
audio_fd = open(audiopath, flags, 0);
}
}
while (exists && (audio_fd < 0));
audiodev = audiopath;
}
if (path != NULL) {
SDL_strlcpy(path, audiodev, maxlen);
path[maxlen - 1] = '\0';
}
return (audio_fd);
}
#elif SDL_AUDIO_DRIVER_PAUD
@ -110,70 +113,71 @@ int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
#define _PATH_DEV_DSP "/dev/%caud%c/%c"
#endif
char devsettings[][3] =
{
{ 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' },
{ 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' },
{ 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' },
{ 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' },
{ 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' },
{ 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' },
{ 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' },
{ 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' },
{ '\0', '\0', '\0' }
char devsettings[][3] = {
{'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'},
{'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'},
{'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'},
{'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'},
{'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'},
{'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'},
{'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'},
{'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'},
{'\0', '\0', '\0'}
};
static int OpenUserDefinedDevice(char *path, int maxlen, int flags)
static int
OpenUserDefinedDevice(char *path, int maxlen, int flags)
{
const char *audiodev;
int audio_fd;
const char *audiodev;
int audio_fd;
/* Figure out what our audio device is */
if ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) {
audiodev=SDL_getenv("AUDIODEV");
}
if ( audiodev == NULL ) {
return -1;
}
audio_fd = open(audiodev, flags, 0);
if ( path != NULL ) {
SDL_strlcpy(path, audiodev, maxlen);
path[maxlen-1] = '\0';
}
return audio_fd;
/* Figure out what our audio device is */
if ((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) {
audiodev = SDL_getenv("AUDIODEV");
}
if (audiodev == NULL) {
return -1;
}
audio_fd = open(audiodev, flags, 0);
if (path != NULL) {
SDL_strlcpy(path, audiodev, maxlen);
path[maxlen - 1] = '\0';
}
return audio_fd;
}
int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
int
SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic)
{
struct stat sb;
int audio_fd;
char audiopath[1024];
int cycle;
int audio_fd;
char audiopath[1024];
int cycle;
audio_fd = OpenUserDefinedDevice(path,maxlen,flags);
if ( audio_fd != -1 ) {
audio_fd = OpenUserDefinedDevice(path, maxlen, flags);
if (audio_fd != -1) {
return audio_fd;
}
cycle = 0;
while( devsettings[cycle][0] != '\0' ) {
SDL_snprintf( audiopath, SDL_arraysize(audiopath),
_PATH_DEV_DSP,
devsettings[cycle][0],
devsettings[cycle][1],
devsettings[cycle][2]);
cycle = 0;
while (devsettings[cycle][0] != '\0') {
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
_PATH_DEV_DSP,
devsettings[cycle][0],
devsettings[cycle][1], devsettings[cycle][2]);
if ( stat(audiopath, &sb) == 0 ) {
audio_fd = open(audiopath, flags, 0);
if ( audio_fd > 0 ) {
if ( path != NULL ) {
SDL_strlcpy( path, audiopath, maxlen );
}
return audio_fd;
}
}
if (stat(audiopath, &sb) == 0) {
audio_fd = open(audiopath, flags, 0);
if (audio_fd > 0) {
if (path != NULL) {
SDL_strlcpy(path, audiopath, maxlen);
}
return audio_fd;
}
}
}
return -1;
}
#endif /* Audio driver selection */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -23,4 +23,4 @@
/* Open the audio device, storing the pathname in 'path' */
extern int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic);
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -23,3 +23,4 @@
#define SDL_AllocAudioMem SDL_malloc
#define SDL_FreeAudioMem SDL_free
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -35,224 +35,227 @@
* the value to avoid overflow. (used with permission from ARDI)
* Changed to use 0xFE instead of 0xFF for better sound quality.
*/
static const Uint8 mix8[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B,
0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D,
0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3,
0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4,
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE
static const Uint8 mix8[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B,
0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D,
0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3,
0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4,
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE
};
/* The volume ranges from 0 - 128 */
#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)
void SDL_MixAudio (Uint8 *dst, const Uint8 *src, Uint32 len, int volume)
void
SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)
{
Uint16 format;
Uint16 format;
if ( volume == 0 ) {
return;
}
/* Mix the user-level audio format */
if ( current_audio ) {
if ( current_audio->convert.needed ) {
format = current_audio->convert.src_format;
} else {
format = current_audio->spec.format;
}
} else {
/* HACK HACK HACK */
format = AUDIO_S16;
}
switch (format) {
if (volume == 0) {
return;
}
/* Mix the user-level audio format */
if (current_audio) {
if (current_audio->convert.needed) {
format = current_audio->convert.src_format;
} else {
format = current_audio->spec.format;
}
} else {
/* HACK HACK HACK */
format = AUDIO_S16;
}
switch (format) {
case AUDIO_U8: {
case AUDIO_U8:
{
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
SDL_MixAudio_m68k_U8((char*)dst,(char*)src,(unsigned long)len,(long)volume,(char *)mix8);
SDL_MixAudio_m68k_U8((char *) dst, (char *) src,
(unsigned long) len, (long) volume,
(char *) mix8);
#else
Uint8 src_sample;
Uint8 src_sample;
while ( len-- ) {
src_sample = *src;
ADJUST_VOLUME_U8(src_sample, volume);
*dst = mix8[*dst+src_sample];
++dst;
++src;
}
while (len--) {
src_sample = *src;
ADJUST_VOLUME_U8(src_sample, volume);
*dst = mix8[*dst + src_sample];
++dst;
++src;
}
#endif
}
break;
}
break;
case AUDIO_S8: {
case AUDIO_S8:
{
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
if (SDL_HasMMX())
{
SDL_MixAudio_MMX_S8((char*)dst,(char*)src,(unsigned int)len,(int)volume);
}
else
if (SDL_HasMMX()) {
SDL_MixAudio_MMX_S8((char *) dst, (char *) src,
(unsigned int) len, (int) volume);
} else
#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
if (SDL_HasMMX())
{
SDL_MixAudio_MMX_S8_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume);
}
else
if (SDL_HasMMX()) {
SDL_MixAudio_MMX_S8_VC((char *) dst, (char *) src,
(unsigned int) len, (int) volume);
} else
#endif
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
SDL_MixAudio_m68k_S8((char*)dst,(char*)src,(unsigned long)len,(long)volume);
SDL_MixAudio_m68k_S8((char *) dst, (char *) src,
(unsigned long) len, (long) volume);
#else
{
Sint8 *dst8, *src8;
Sint8 src_sample;
int dst_sample;
const int max_audioval = ((1<<(8-1))-1);
const int min_audioval = -(1<<(8-1));
{
Sint8 *dst8, *src8;
Sint8 src_sample;
int dst_sample;
const int max_audioval = ((1 << (8 - 1)) - 1);
const int min_audioval = -(1 << (8 - 1));
src8 = (Sint8 *)src;
dst8 = (Sint8 *)dst;
while ( len-- ) {
src_sample = *src8;
ADJUST_VOLUME(src_sample, volume);
dst_sample = *dst8 + src_sample;
if ( dst_sample > max_audioval ) {
*dst8 = max_audioval;
} else
if ( dst_sample < min_audioval ) {
*dst8 = min_audioval;
} else {
*dst8 = dst_sample;
}
++dst8;
++src8;
}
}
src8 = (Sint8 *) src;
dst8 = (Sint8 *) dst;
while (len--) {
src_sample = *src8;
ADJUST_VOLUME(src_sample, volume);
dst_sample = *dst8 + src_sample;
if (dst_sample > max_audioval) {
*dst8 = max_audioval;
} else if (dst_sample < min_audioval) {
*dst8 = min_audioval;
} else {
*dst8 = dst_sample;
}
++dst8;
++src8;
}
}
#endif
}
break;
}
break;
case AUDIO_S16LSB: {
case AUDIO_S16LSB:
{
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
if (SDL_HasMMX())
{
SDL_MixAudio_MMX_S16((char*)dst,(char*)src,(unsigned int)len,(int)volume);
}
else
if (SDL_HasMMX()) {
SDL_MixAudio_MMX_S16((char *) dst, (char *) src,
(unsigned int) len, (int) volume);
} else
#elif ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
if (SDL_HasMMX())
{
SDL_MixAudio_MMX_S16_VC((char*)dst,(char*)src,(unsigned int)len,(int)volume);
}
else
if (SDL_HasMMX()) {
SDL_MixAudio_MMX_S16_VC((char *) dst, (char *) src,
(unsigned int) len, (int) volume);
} else
#endif
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
SDL_MixAudio_m68k_S16LSB((short*)dst,(short*)src,(unsigned long)len,(long)volume);
SDL_MixAudio_m68k_S16LSB((short *) dst, (short *) src,
(unsigned long) len, (long) volume);
#else
{
Sint16 src1, src2;
int dst_sample;
const int max_audioval = ((1<<(16-1))-1);
const int min_audioval = -(1<<(16-1));
{
Sint16 src1, src2;
int dst_sample;
const int max_audioval = ((1 << (16 - 1)) - 1);
const int min_audioval = -(1 << (16 - 1));
len /= 2;
while ( len-- ) {
src1 = ((src[1])<<8|src[0]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[1])<<8|dst[0]);
src += 2;
dst_sample = src1+src2;
if ( dst_sample > max_audioval ) {
dst_sample = max_audioval;
} else
if ( dst_sample < min_audioval ) {
dst_sample = min_audioval;
}
dst[0] = dst_sample&0xFF;
dst_sample >>= 8;
dst[1] = dst_sample&0xFF;
dst += 2;
}
}
len /= 2;
while (len--) {
src1 = ((src[1]) << 8 | src[0]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[1]) << 8 | dst[0]);
src += 2;
dst_sample = src1 + src2;
if (dst_sample > max_audioval) {
dst_sample = max_audioval;
} else if (dst_sample < min_audioval) {
dst_sample = min_audioval;
}
dst[0] = dst_sample & 0xFF;
dst_sample >>= 8;
dst[1] = dst_sample & 0xFF;
dst += 2;
}
}
#endif
}
break;
}
break;
case AUDIO_S16MSB: {
case AUDIO_S16MSB:
{
#if defined(__GNUC__) && defined(__M68000__) && defined(SDL_ASSEMBLY_ROUTINES)
SDL_MixAudio_m68k_S16MSB((short*)dst,(short*)src,(unsigned long)len,(long)volume);
SDL_MixAudio_m68k_S16MSB((short *) dst, (short *) src,
(unsigned long) len, (long) volume);
#else
Sint16 src1, src2;
int dst_sample;
const int max_audioval = ((1<<(16-1))-1);
const int min_audioval = -(1<<(16-1));
Sint16 src1, src2;
int dst_sample;
const int max_audioval = ((1 << (16 - 1)) - 1);
const int min_audioval = -(1 << (16 - 1));
len /= 2;
while ( len-- ) {
src1 = ((src[0])<<8|src[1]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[0])<<8|dst[1]);
src += 2;
dst_sample = src1+src2;
if ( dst_sample > max_audioval ) {
dst_sample = max_audioval;
} else
if ( dst_sample < min_audioval ) {
dst_sample = min_audioval;
}
dst[1] = dst_sample&0xFF;
dst_sample >>= 8;
dst[0] = dst_sample&0xFF;
dst += 2;
}
len /= 2;
while (len--) {
src1 = ((src[0]) << 8 | src[1]);
ADJUST_VOLUME(src1, volume);
src2 = ((dst[0]) << 8 | dst[1]);
src += 2;
dst_sample = src1 + src2;
if (dst_sample > max_audioval) {
dst_sample = max_audioval;
} else if (dst_sample < min_audioval) {
dst_sample = min_audioval;
}
dst[1] = dst_sample & 0xFF;
dst_sample >>= 8;
dst[0] = dst_sample & 0xFF;
dst += 2;
}
#endif
}
break;
}
break;
default: /* If this happens... FIXME! */
SDL_SetError("SDL_MixAudio(): unknown audio format");
return;
}
default: /* If this happens... FIXME! */
SDL_SetError("SDL_MixAudio(): unknown audio format");
return;
}
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -36,100 +36,50 @@
***********************************************/
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume)
void
SDL_MixAudio_MMX_S16(char *dst, char *src, unsigned int size, int volume)
{
__asm__ __volatile__ (
" movl %3,%%eax\n" /* eax = volume */
" movl %2,%%edx\n" /* edx = size */
" shrl $4,%%edx\n" /* process 16 bytes per iteration = 8 samples */
" jz .endS16\n"
" pxor %%mm0,%%mm0\n"
" movd %%eax,%%mm0\n"
" movq %%mm0,%%mm1\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n" /* mm0 = vol|vol|vol|vol */
".align 8\n"
" .mixloopS16:\n"
" movq (%1),%%mm1\n" /* mm1 = a|b|c|d */
" movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */
" movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */
/* pré charger le buffer dst dans mm7 */
" movq (%0),%%mm7\n" /* mm7 = dst[0] */
/* multiplier par le volume */
" pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
" pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */
" movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */
" pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
" pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */
" movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
" punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */
" movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
" punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */
" punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */
" punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */
/* pré charger le buffer dst dans mm5 */
" movq 8(%0),%%mm5\n" /* mm5 = dst[1] */
/* diviser par 128 */
" psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */
" add $16,%1\n"
" psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */
" psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */
/* mm1 = le sample avec le volume modifié */
" packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */
" psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */
" paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */
/* mm4 = le sample avec le volume modifié */
" packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */
" movq %%mm3,(%0)\n"
" paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */
" movq %%mm6,8(%0)\n"
" add $16,%0\n"
" dec %%edx\n"
" jnz .mixloopS16\n"
" emms\n"
".endS16:\n"
:
: "r" (dst), "r"(src),"m"(size),
"m"(volume)
: "eax","edx","memory"
);
__asm__ __volatile__(" movl %3,%%eax\n" /* eax = volume */
" movl %2,%%edx\n" /* edx = size */
" shrl $4,%%edx\n" /* process 16 bytes per iteration = 8 samples */
" jz .endS16\n" " pxor %%mm0,%%mm0\n" " movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" /* mm0 = vol|vol|vol|vol */
".align 8\n" " .mixloopS16:\n" " movq (%1),%%mm1\n" /* mm1 = a|b|c|d */
" movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */
" movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */
/* pré charger le buffer dst dans mm7 */
" movq (%0),%%mm7\n" /* mm7 = dst[0] */
/* multiplier par le volume */
" pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
" pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */
" movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */
" pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
" pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */
" movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
" punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */
" movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
" punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */
" punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */
" punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */
/* pré charger le buffer dst dans mm5 */
" movq 8(%0),%%mm5\n" /* mm5 = dst[1] */
/* diviser par 128 */
" psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */
" add $16,%1\n" " psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */
" psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */
/* mm1 = le sample avec le volume modifié */
" packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */
" psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */
" paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */
/* mm4 = le sample avec le volume modifié */
" packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */
" movq %%mm3,(%0)\n" " paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */
" movq %%mm6,8(%0)\n"
" add $16,%0\n"
" dec %%edx\n"
" jnz .mixloopS16\n"
" emms\n"
".endS16:\n"::"r"(dst), "r"(src),
"m"(size), "m"(volume):"eax", "edx", "memory");
}
@ -138,69 +88,33 @@ void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume)
/* Mixing for 8 bit signed buffers */
/*////////////////////////////////////////////// */
void SDL_MixAudio_MMX_S8(char* dst,char* src,unsigned int size,int volume)
void
SDL_MixAudio_MMX_S8(char *dst, char *src, unsigned int size, int volume)
{
__asm__ __volatile__ (
" movl %3,%%eax\n" /* eax = volume */
" movd %%eax,%%mm0\n"
" movq %%mm0,%%mm1\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n"
" psllq $16,%%mm0\n"
" por %%mm1,%%mm0\n"
" movl %2,%%edx\n" /* edx = size */
" shr $3,%%edx\n" /* process 8 bytes per iteration = 8 samples */
" cmp $0,%%edx\n"
" je .endS8\n"
".align 8\n"
" .mixloopS8:\n"
" pxor %%mm2,%%mm2\n" /* mm2 = 0 */
" movq (%1),%%mm1\n" /* mm1 = a|b|c|d|e|f|g|h */
" movq %%mm1,%%mm3\n" /* mm3 = a|b|c|d|e|f|g|h */
/* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */
" pcmpgtb %%mm1,%%mm2\n" /* mm2 = 11111111|00000000|00000000.... */
" punpckhbw %%mm2,%%mm1\n" /* mm1 = 0|a|0|b|0|c|0|d */
" punpcklbw %%mm2,%%mm3\n" /* mm3 = 0|e|0|f|0|g|0|h */
" movq (%0),%%mm2\n" /* mm2 = destination */
" pmullw %%mm0,%%mm1\n" /* mm1 = v*a|v*b|v*c|v*d */
" add $8,%1\n"
" pmullw %%mm0,%%mm3\n" /* mm3 = v*e|v*f|v*g|v*h */
" psraw $7,%%mm1\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128 */
" psraw $7,%%mm3\n" /* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */
" packsswb %%mm1,%%mm3\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 */
" paddsb %%mm2,%%mm3\n" /* add to destination buffer */
" movq %%mm3,(%0)\n" /* store back to ram */
" add $8,%0\n"
" dec %%edx\n"
" jnz .mixloopS8\n"
".endS8:\n"
" emms\n"
:
: "r" (dst), "r"(src),"m"(size),
"m"(volume)
: "eax","edx","memory"
);
__asm__ __volatile__(" movl %3,%%eax\n" /* eax = volume */
" movd %%eax,%%mm0\n" " movq %%mm0,%%mm1\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " psllq $16,%%mm0\n" " por %%mm1,%%mm0\n" " movl %2,%%edx\n" /* edx = size */
" shr $3,%%edx\n" /* process 8 bytes per iteration = 8 samples */
" cmp $0,%%edx\n" " je .endS8\n" ".align 8\n" " .mixloopS8:\n" " pxor %%mm2,%%mm2\n" /* mm2 = 0 */
" movq (%1),%%mm1\n" /* mm1 = a|b|c|d|e|f|g|h */
" movq %%mm1,%%mm3\n" /* mm3 = a|b|c|d|e|f|g|h */
/* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */
" pcmpgtb %%mm1,%%mm2\n" /* mm2 = 11111111|00000000|00000000.... */
" punpckhbw %%mm2,%%mm1\n" /* mm1 = 0|a|0|b|0|c|0|d */
" punpcklbw %%mm2,%%mm3\n" /* mm3 = 0|e|0|f|0|g|0|h */
" movq (%0),%%mm2\n" /* mm2 = destination */
" pmullw %%mm0,%%mm1\n" /* mm1 = v*a|v*b|v*c|v*d */
" add $8,%1\n" " pmullw %%mm0,%%mm3\n" /* mm3 = v*e|v*f|v*g|v*h */
" psraw $7,%%mm1\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128 */
" psraw $7,%%mm3\n" /* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */
" packsswb %%mm1,%%mm3\n" /* mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128 */
" paddsb %%mm2,%%mm3\n" /* add to destination buffer */
" movq %%mm3,(%0)\n" /* store back to ram */
" add $8,%0\n"
" dec %%edx\n"
" jnz .mixloopS8\n"
".endS8:\n"
" emms\n"::"r"(dst), "r"(src), "m"(size),
"m"(volume):"eax", "edx", "memory");
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -9,7 +9,7 @@
#include "SDL_config.h"
#if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
void SDL_MixAudio_MMX_S16(char* ,char* ,unsigned int ,int );
void SDL_MixAudio_MMX_S8(char* ,char* ,unsigned int ,int );
void SDL_MixAudio_MMX_S16(char *, char *, unsigned int, int);
void SDL_MixAudio_MMX_S8(char *, char *, unsigned int, int);
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -37,8 +37,10 @@
// Mixing for 16 bit signed buffers
////////////////////////////////////////////////
void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume)
void
SDL_MixAudio_MMX_S16_VC(char *dst, char *src, unsigned int nSize, int volume)
{
/* *INDENT-OFF* */
__asm
{
@ -111,15 +113,17 @@ ends16:
pop esi
pop edi
}
/* *INDENT-ON* */
}
////////////////////////////////////////////////
// Mixing for 8 bit signed buffers
////////////////////////////////////////////////
void SDL_MixAudio_MMX_S8_VC(char* dst,char* src,unsigned int nSize,int volume)
void
SDL_MixAudio_MMX_S8_VC(char *dst, char *src, unsigned int nSize, int volume)
{
/* *INDENT-OFF* */
_asm
{
@ -176,6 +180,9 @@ endS8:
pop esi
pop edi
}
/* *INDENT-ON* */
}
#endif /* SDL_ASSEMBLY_ROUTINES */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,6 +31,7 @@
Assumes buffer size in bytes is a multiple of 16
Assumes SDL_MIX_MAXVOLUME = 128
*/
void SDL_MixAudio_MMX_S16_VC(char* ,char* ,unsigned int ,int );
void SDL_MixAudio_MMX_S8_VC(char* ,char* ,unsigned int ,int );
void SDL_MixAudio_MMX_S16_VC(char *, char *, unsigned int, int);
void SDL_MixAudio_MMX_S8_VC(char *, char *, unsigned int, int);
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -28,184 +28,113 @@
*/
#if defined(__M68000__) && defined(__GNUC__)
void SDL_MixAudio_m68k_U8(char* dst, char* src, long len, long volume, char* mix8)
void
SDL_MixAudio_m68k_U8(char *dst, char *src, long len, long volume, char *mix8)
{
__asm__ __volatile__ (
"tstl %2\n"
" beqs stoploop_u8\n"
"mixloop_u8:\n"
/* Mix a sample */
" moveq #0,%%d0\n"
" moveq #0,%%d1\n"
" moveb %1@+,%%d0\n" /* d0 = *src++ */
" sub #128,%%d0\n" /* d0 -= 128 */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" moveb %0@,%%d1\n" /* d1 = *dst */
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" add #128,%%d0\n" /* d0 += 128 */
" add %%d1,%%d0\n"
" moveb %4@(%%d0:w),%0@+\n"
/* Loop till done */
" subql #1,%2\n"
" bhis mixloop_u8\n"
"stoploop_u8:\n"
: /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8)
: /* clobbered registers */
"d0", "d1", "cc", "memory"
);
__asm__ __volatile__("tstl %2\n" " beqs stoploop_u8\n" "mixloop_u8:\n"
/* Mix a sample */
" moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */
" sub #128,%%d0\n" /* d0 -= 128 */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" moveb %0@,%%d1\n" /* d1 = *dst */
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" add #128,%%d0\n" /* d0 += 128 */
" add %%d1,%%d0\n"
" moveb %4@(%%d0:w),%0@+\n"
/* Loop till done */
" subql #1,%2\n" " bhis mixloop_u8\n" "stoploop_u8:\n": /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume), "a"(mix8): /* clobbered registers */
"d0", "d1", "cc", "memory");
}
void SDL_MixAudio_m68k_S8(char* dst, char* src, long len, long volume)
void
SDL_MixAudio_m68k_S8(char *dst, char *src, long len, long volume)
{
__asm__ __volatile__ (
"tstl %2\n"
" beqs stoploop_s8\n"
" moveq #-128,%%d2\n"
" moveq #127,%%d3\n"
"mixloop_s8:\n"
/* Mix a sample */
" moveq #0,%%d0\n"
" moveq #0,%%d1\n"
" moveb %1@+,%%d0\n" /* d0 = *src++ */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" moveb %0@,%%d1\n" /* d1 = *dst */
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" add %%d1,%%d0\n"
" cmp %%d2,%%d0\n"
" bges lower_limit_s8\n"
" move %%d2,%%d0\n"
"lower_limit_s8:\n"
" cmp %%d3,%%d0\n"
" bles upper_limit_s8\n"
" move %%d3,%%d0\n"
"upper_limit_s8:\n"
" moveb %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n"
" bhis mixloop_s8\n"
"stoploop_s8:\n"
: /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume)
: /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory"
);
__asm__ __volatile__("tstl %2\n"
" beqs stoploop_s8\n"
" moveq #-128,%%d2\n"
" moveq #127,%%d3\n" "mixloop_s8:\n"
/* Mix a sample */
" moveq #0,%%d0\n" " moveq #0,%%d1\n" " moveb %1@+,%%d0\n" /* d0 = *src++ */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" moveb %0@,%%d1\n" /* d1 = *dst */
" asr #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" add %%d1,%%d0\n"
" cmp %%d2,%%d0\n"
" bges lower_limit_s8\n"
" move %%d2,%%d0\n"
"lower_limit_s8:\n"
" cmp %%d3,%%d0\n"
" bles upper_limit_s8\n"
" move %%d3,%%d0\n"
"upper_limit_s8:\n" " moveb %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n" " bhis mixloop_s8\n" "stoploop_s8:\n": /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory");
}
void SDL_MixAudio_m68k_S16MSB(short* dst, short* src, long len, long volume)
void
SDL_MixAudio_m68k_S16MSB(short *dst, short *src, long len, long volume)
{
__asm__ __volatile__ (
"tstl %2\n"
" beqs stoploop_s16msb\n"
" movel #-32768,%%d2\n"
" movel #32767,%%d3\n"
" lsrl #1,%2\n"
"mixloop_s16msb:\n"
/* Mix a sample */
" move %1@+,%%d0\n" /* d0 = *src++ */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" move %0@,%%d1\n" /* d1 = *dst */
" extl %%d1\n" /* extend d1 to 32 bits */
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" addl %%d1,%%d0\n"
" cmpl %%d2,%%d0\n"
" bges lower_limit_s16msb\n"
" move %%d2,%%d0\n"
"lower_limit_s16msb:\n"
" cmpl %%d3,%%d0\n"
" bles upper_limit_s16msb\n"
" move %%d3,%%d0\n"
"upper_limit_s16msb:\n"
" move %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n"
" bhis mixloop_s16msb\n"
"stoploop_s16msb:\n"
: /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume)
: /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory"
);
__asm__ __volatile__("tstl %2\n"
" beqs stoploop_s16msb\n"
" movel #-32768,%%d2\n"
" movel #32767,%%d3\n"
" lsrl #1,%2\n" "mixloop_s16msb:\n"
/* Mix a sample */
" move %1@+,%%d0\n" /* d0 = *src++ */
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" move %0@,%%d1\n" /* d1 = *dst */
" extl %%d1\n" /* extend d1 to 32 bits */
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" addl %%d1,%%d0\n"
" cmpl %%d2,%%d0\n"
" bges lower_limit_s16msb\n"
" move %%d2,%%d0\n"
"lower_limit_s16msb:\n"
" cmpl %%d3,%%d0\n"
" bles upper_limit_s16msb\n"
" move %%d3,%%d0\n"
"upper_limit_s16msb:\n" " move %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n" " bhis mixloop_s16msb\n" "stoploop_s16msb:\n": /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory");
}
void SDL_MixAudio_m68k_S16LSB(short* dst, short* src, long len, long volume)
void
SDL_MixAudio_m68k_S16LSB(short *dst, short *src, long len, long volume)
{
__asm__ __volatile__ (
"tstl %2\n"
" beqs stoploop_s16lsb\n"
" movel #-32768,%%d2\n"
" movel #32767,%%d3\n"
" lsrl #1,%2\n"
"mixloop_s16lsb:\n"
/* Mix a sample */
" move %1@+,%%d0\n" /* d0 = *src++ */
" rorw #8,%%d0\n"
" muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" move %0@,%%d1\n" /* d1 = *dst */
" rorw #8,%%d1\n"
" extl %%d1\n" /* extend d1 to 32 bits */
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" addl %%d1,%%d0\n"
" cmpl %%d2,%%d0\n"
" bges lower_limit_s16lsb\n"
" move %%d2,%%d0\n"
"lower_limit_s16lsb:\n"
" cmpl %%d3,%%d0\n"
" bles upper_limit_s16lsb\n"
" move %%d3,%%d0\n"
"upper_limit_s16lsb:\n"
" rorw #8,%%d0\n"
" move %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n"
" bhis mixloop_s16lsb\n"
"stoploop_s16lsb:\n"
: /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume)
: /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory"
);
__asm__ __volatile__("tstl %2\n"
" beqs stoploop_s16lsb\n"
" movel #-32768,%%d2\n"
" movel #32767,%%d3\n"
" lsrl #1,%2\n" "mixloop_s16lsb:\n"
/* Mix a sample */
" move %1@+,%%d0\n" /* d0 = *src++ */
" rorw #8,%%d0\n" " muls %3,%%d0\n" /* d0 *= volume (0<=volume<=128) */
" move %0@,%%d1\n" /* d1 = *dst */
" rorw #8,%%d1\n" " extl %%d1\n" /* extend d1 to 32 bits */
" asrl #7,%%d0\n" /* d0 /= 128 (SDL_MIX_MAXVOLUME) */
" addl %%d1,%%d0\n"
" cmpl %%d2,%%d0\n"
" bges lower_limit_s16lsb\n"
" move %%d2,%%d0\n"
"lower_limit_s16lsb:\n"
" cmpl %%d3,%%d0\n"
" bles upper_limit_s16lsb\n"
" move %%d3,%%d0\n"
"upper_limit_s16lsb:\n"
" rorw #8,%%d0\n" " move %%d0,%0@+\n"
/* Loop till done */
" subql #1,%2\n" " bhis mixloop_s16lsb\n" "stoploop_s16lsb:\n": /* no return value */
: /* input */
"a"(dst), "a"(src), "d"(len), "d"(volume): /* clobbered registers */
"d0", "d1", "d2", "d3", "cc", "memory");
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -28,9 +28,11 @@
*/
#if defined(__M68000__) && defined(__GNUC__)
void SDL_MixAudio_m68k_U8(char* dst,char* src, long len, long volume, char* mix8);
void SDL_MixAudio_m68k_S8(char* dst,char* src, long len, long volume);
void SDL_MixAudio_m68k_U8(char *dst, char *src, long len, long volume,
char *mix8);
void SDL_MixAudio_m68k_S8(char *dst, char *src, long len, long volume);
void SDL_MixAudio_m68k_S16MSB(short* dst,short* src, long len, long volume);
void SDL_MixAudio_m68k_S16LSB(short* dst,short* src, long len, long volume);
void SDL_MixAudio_m68k_S16MSB(short *dst, short *src, long len, long volume);
void SDL_MixAudio_m68k_S16LSB(short *dst, short *src, long len, long volume);
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -35,69 +35,71 @@ typedef struct SDL_AudioDevice SDL_AudioDevice;
#ifndef _STATUS
#define _STATUS SDL_status *status
#endif
struct SDL_AudioDevice {
/* * * */
/* The name of this audio driver */
const char *name;
struct SDL_AudioDevice
{
/* * * */
/* The name of this audio driver */
const char *name;
/* * * */
/* The description of this audio driver */
const char *desc;
/* * * */
/* The description of this audio driver */
const char *desc;
/* * * */
/* Public driver functions */
int (*OpenAudio)(_THIS, SDL_AudioSpec *spec);
void (*ThreadInit)(_THIS); /* Called by audio thread at start */
void (*WaitAudio)(_THIS);
void (*PlayAudio)(_THIS);
Uint8 *(*GetAudioBuf)(_THIS);
void (*WaitDone)(_THIS);
void (*CloseAudio)(_THIS);
/* * * */
/* Public driver functions */
int (*OpenAudio) (_THIS, SDL_AudioSpec * spec);
void (*ThreadInit) (_THIS); /* Called by audio thread at start */
void (*WaitAudio) (_THIS);
void (*PlayAudio) (_THIS);
Uint8 *(*GetAudioBuf) (_THIS);
void (*WaitDone) (_THIS);
void (*CloseAudio) (_THIS);
/* * * */
/* Lock / Unlock functions added for the Mac port */
void (*LockAudio)(_THIS);
void (*UnlockAudio)(_THIS);
/* * * */
/* Lock / Unlock functions added for the Mac port */
void (*LockAudio) (_THIS);
void (*UnlockAudio) (_THIS);
/* * * */
/* Data common to all devices */
/* * * */
/* Data common to all devices */
/* The current audio specification (shared with audio thread) */
SDL_AudioSpec spec;
/* The current audio specification (shared with audio thread) */
SDL_AudioSpec spec;
/* An audio conversion block for audio format emulation */
SDL_AudioCVT convert;
/* An audio conversion block for audio format emulation */
SDL_AudioCVT convert;
/* Current state flags */
int enabled;
int paused;
int opened;
/* Current state flags */
int enabled;
int paused;
int opened;
/* Fake audio buffer for when the audio hardware is busy */
Uint8 *fake_stream;
/* Fake audio buffer for when the audio hardware is busy */
Uint8 *fake_stream;
/* A semaphore for locking the mixing buffers */
SDL_mutex *mixer_lock;
/* A semaphore for locking the mixing buffers */
SDL_mutex *mixer_lock;
/* A thread to feed the audio device */
SDL_Thread *thread;
Uint32 threadid;
/* A thread to feed the audio device */
SDL_Thread *thread;
Uint32 threadid;
/* * * */
/* Data private to this driver */
struct SDL_PrivateAudioData *hidden;
/* * * */
/* Data private to this driver */
struct SDL_PrivateAudioData *hidden;
/* * * */
/* The function used to dispose of this structure */
void (*free)(_THIS);
/* * * */
/* The function used to dispose of this structure */
void (*free) (_THIS);
};
#undef _THIS
typedef struct AudioBootStrap {
const char *name;
const char *desc;
int (*available)(void);
SDL_AudioDevice *(*create)(int devindex);
typedef struct AudioBootStrap
{
const char *name;
const char *desc;
int (*available) (void);
SDL_AudioDevice *(*create) (int devindex);
} AudioBootStrap;
#if SDL_AUDIO_DRIVER_BSD
@ -176,3 +178,4 @@ extern AudioBootStrap DART_bootstrap;
extern SDL_AudioDevice *current_audio;
#endif /* _SDL_sysaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -26,12 +26,12 @@
/*******************************************/
/* Define values for Microsoft WAVE format */
/*******************************************/
#define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */
#define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */
#define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */
#define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */
#define PCM_CODE 0x0001
#define MS_ADPCM_CODE 0x0002
#define IMA_ADPCM_CODE 0x0011
@ -40,23 +40,25 @@
#define WAVE_STEREO 2
/* Normally, these three chunks come consecutively in a WAVE file */
typedef struct WaveFMT {
typedef struct WaveFMT
{
/* Not saved in the chunk we read:
Uint32 FMTchunk;
Uint32 fmtlen;
*/
Uint16 encoding;
Uint16 channels; /* 1 = mono, 2 = stereo */
Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */
Uint32 byterate; /* Average bytes per second */
Uint16 blockalign; /* Bytes per sample block */
Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */
Uint16 encoding;
Uint16 channels; /* 1 = mono, 2 = stereo */
Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */
Uint32 byterate; /* Average bytes per second */
Uint16 blockalign; /* Bytes per sample block */
Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */
} WaveFMT;
/* The general chunk found in the WAVE file */
typedef struct Chunk {
Uint32 magic;
Uint32 length;
Uint8 *data;
typedef struct Chunk
{
Uint32 magic;
Uint32 length;
Uint8 *data;
} Chunk;
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -24,7 +24,7 @@
/* Allow access to a raw mixing buffer */
#include <sys/types.h>
#include <signal.h> /* For kill() */
#include <signal.h> /* For kill() */
#include "SDL_timer.h"
#include "SDL_audio.h"
@ -48,7 +48,7 @@
#define DEFAULT_DEVICE "default"
/* Audio driver functions */
static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int ALSA_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void ALSA_WaitAudio(_THIS);
static void ALSA_PlayAudio(_THIS);
static Uint8 *ALSA_GetAudioBuf(_THIS);
@ -60,208 +60,295 @@ static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
static void *alsa_handle = NULL;
static int alsa_loaded = 0;
static int (*SDL_snd_pcm_open)(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode);
static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode);
static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm);
static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
static int (*SDL_NAME(snd_pcm_resume))(snd_pcm_t *pcm);
static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm);
static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm);
static const char *(*SDL_NAME(snd_strerror))(int errnum);
static size_t (*SDL_NAME(snd_pcm_hw_params_sizeof))(void);
static size_t (*SDL_NAME(snd_pcm_sw_params_sizeof))(void);
static int (*SDL_NAME(snd_pcm_hw_params_any))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
static int (*SDL_NAME(snd_pcm_hw_params_set_access))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
static int (*SDL_NAME(snd_pcm_hw_params_set_format))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
static int (*SDL_NAME(snd_pcm_hw_params_set_channels))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
static int (*SDL_NAME(snd_pcm_hw_params_get_channels))(const snd_pcm_hw_params_t *params);
static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_rate_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir);
static snd_pcm_uframes_t (*SDL_NAME(snd_pcm_hw_params_set_period_size_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int *dir);
static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_hw_params_get_period_size))(const snd_pcm_hw_params_t *params);
static unsigned int (*SDL_NAME(snd_pcm_hw_params_set_periods_near))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int *dir);
static int (*SDL_NAME(snd_pcm_hw_params_get_periods))(snd_pcm_hw_params_t *params);
static int (*SDL_NAME(snd_pcm_hw_params))(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
static int (*SDL_snd_pcm_open) (snd_pcm_t ** pcm, const char *name,
snd_pcm_stream_t stream, int mode);
static int (*SDL_NAME(snd_pcm_open)) (snd_pcm_t ** pcm, const char *name,
snd_pcm_stream_t stream, int mode);
static int (*SDL_NAME(snd_pcm_close)) (snd_pcm_t * pcm);
static snd_pcm_sframes_t(*SDL_NAME(snd_pcm_writei)) (snd_pcm_t * pcm,
const void *buffer,
snd_pcm_uframes_t size);
static int (*SDL_NAME(snd_pcm_resume)) (snd_pcm_t * pcm);
static int (*SDL_NAME(snd_pcm_prepare)) (snd_pcm_t * pcm);
static int (*SDL_NAME(snd_pcm_drain)) (snd_pcm_t * pcm);
static const char *(*SDL_NAME(snd_strerror)) (int errnum);
static size_t(*SDL_NAME(snd_pcm_hw_params_sizeof)) (void);
static size_t(*SDL_NAME(snd_pcm_sw_params_sizeof)) (void);
static int (*SDL_NAME(snd_pcm_hw_params_any)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t * params);
static int (*SDL_NAME(snd_pcm_hw_params_set_access)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t *
params,
snd_pcm_access_t
access);
static int (*SDL_NAME(snd_pcm_hw_params_set_format)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t *
params,
snd_pcm_format_t val);
static int (*SDL_NAME(snd_pcm_hw_params_set_channels)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t *
params,
unsigned int val);
static int (*SDL_NAME(snd_pcm_hw_params_get_channels)) (const
snd_pcm_hw_params_t *
params);
static unsigned int
(*SDL_NAME(snd_pcm_hw_params_set_rate_near)) (snd_pcm_t *
pcm,
snd_pcm_hw_params_t
* params,
unsigned int val, int *dir);
static snd_pcm_uframes_t
(*SDL_NAME(snd_pcm_hw_params_set_period_size_near)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t
* params,
snd_pcm_uframes_t
val, int *dir);
static snd_pcm_sframes_t
(*SDL_NAME(snd_pcm_hw_params_get_period_size)) (const
snd_pcm_hw_params_t
* params);
static unsigned int
(*SDL_NAME(snd_pcm_hw_params_set_periods_near)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t
* params,
unsigned int val,
int *dir);
static int (*SDL_NAME(snd_pcm_hw_params_get_periods)) (snd_pcm_hw_params_t *
params);
static int (*SDL_NAME(snd_pcm_hw_params)) (snd_pcm_t * pcm,
snd_pcm_hw_params_t * params);
/*
*/
static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams);
static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
static int (*SDL_NAME(snd_pcm_sw_params_set_avail_min))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
static int (*SDL_NAME(snd_pcm_nonblock))(snd_pcm_t *pcm, int nonblock);
static int (*SDL_NAME(snd_pcm_sw_params_current)) (snd_pcm_t * pcm,
snd_pcm_sw_params_t *
swparams);
static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold)) (snd_pcm_t *
pcm,
snd_pcm_sw_params_t
* params,
snd_pcm_uframes_t
val);
static int (*SDL_NAME(snd_pcm_sw_params_set_avail_min)) (snd_pcm_t * pcm,
snd_pcm_sw_params_t
* params,
snd_pcm_uframes_t
val);
static int (*SDL_NAME(snd_pcm_sw_params)) (snd_pcm_t * pcm,
snd_pcm_sw_params_t * params);
static int (*SDL_NAME(snd_pcm_nonblock)) (snd_pcm_t * pcm, int nonblock);
#define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof)
#define snd_pcm_sw_params_sizeof SDL_NAME(snd_pcm_sw_params_sizeof)
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
static struct {
const char *name;
void **func;
static struct
{
const char *name;
void **func;
} alsa_functions[] = {
{ "snd_pcm_open", (void**)(char*)&SDL_NAME(snd_pcm_open) },
{ "snd_pcm_close", (void**)(char*)&SDL_NAME(snd_pcm_close) },
{ "snd_pcm_writei", (void**)(char*)&SDL_NAME(snd_pcm_writei) },
{ "snd_pcm_resume", (void**)(char*)&SDL_NAME(snd_pcm_resume) },
{ "snd_pcm_prepare", (void**)(char*)&SDL_NAME(snd_pcm_prepare) },
{ "snd_pcm_drain", (void**)(char*)&SDL_NAME(snd_pcm_drain) },
{ "snd_strerror", (void**)(char*)&SDL_NAME(snd_strerror) },
{ "snd_pcm_hw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_sizeof) },
{ "snd_pcm_sw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_sizeof) },
{ "snd_pcm_hw_params_any", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_any) },
{ "snd_pcm_hw_params_set_access", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_access) },
{ "snd_pcm_hw_params_set_format", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_format) },
{ "snd_pcm_hw_params_set_channels", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_channels) },
{ "snd_pcm_hw_params_get_channels", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_channels) },
{ "snd_pcm_hw_params_set_rate_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_rate_near) },
{ "snd_pcm_hw_params_set_period_size_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_period_size_near) },
{ "snd_pcm_hw_params_get_period_size", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_period_size) },
{ "snd_pcm_hw_params_set_periods_near", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_set_periods_near) },
{ "snd_pcm_hw_params_get_periods", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_get_periods) },
{ "snd_pcm_hw_params", (void**)(char*)&SDL_NAME(snd_pcm_hw_params) },
{ "snd_pcm_sw_params_current", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_current) },
{ "snd_pcm_sw_params_set_start_threshold", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold) },
{ "snd_pcm_sw_params_set_avail_min", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_avail_min) },
{ "snd_pcm_sw_params", (void**)(char*)&SDL_NAME(snd_pcm_sw_params) },
{ "snd_pcm_nonblock", (void**)(char*)&SDL_NAME(snd_pcm_nonblock) },
};
{
"snd_pcm_open", (void **) (char *) &SDL_NAME(snd_pcm_open)}, {
"snd_pcm_close", (void **) (char *) &SDL_NAME(snd_pcm_close)}, {
"snd_pcm_writei", (void **) (char *) &SDL_NAME(snd_pcm_writei)}, {
"snd_pcm_resume", (void **) (char *) &SDL_NAME(snd_pcm_resume)}, {
"snd_pcm_prepare", (void **) (char *) &SDL_NAME(snd_pcm_prepare)}, {
"snd_pcm_drain", (void **) (char *) &SDL_NAME(snd_pcm_drain)}, {
"snd_strerror", (void **) (char *) &SDL_NAME(snd_strerror)}, {
"snd_pcm_hw_params_sizeof",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_sizeof)}, {
"snd_pcm_sw_params_sizeof",
(void **) (char *) &SDL_NAME(snd_pcm_sw_params_sizeof)}, {
"snd_pcm_hw_params_any",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_any)}, {
"snd_pcm_hw_params_set_access",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_access)}, {
"snd_pcm_hw_params_set_format",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_format)}, {
"snd_pcm_hw_params_set_channels",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_channels)}, {
"snd_pcm_hw_params_get_channels",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_channels)}, {
"snd_pcm_hw_params_set_rate_near",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_set_rate_near)}, {
"snd_pcm_hw_params_set_period_size_near", (void **) (char *)
&SDL_NAME(snd_pcm_hw_params_set_period_size_near)}, {
"snd_pcm_hw_params_get_period_size",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_period_size)},
{
"snd_pcm_hw_params_set_periods_near", (void **) (char *)
&SDL_NAME(snd_pcm_hw_params_set_periods_near)}, {
"snd_pcm_hw_params_get_periods",
(void **) (char *) &SDL_NAME(snd_pcm_hw_params_get_periods)}, {
"snd_pcm_hw_params", (void **) (char *) &SDL_NAME(snd_pcm_hw_params)}, {
"snd_pcm_sw_params_current",
(void **) (char *) &SDL_NAME(snd_pcm_sw_params_current)}, {
"snd_pcm_sw_params_set_start_threshold", (void **) (char *)
&SDL_NAME(snd_pcm_sw_params_set_start_threshold)}, {
"snd_pcm_sw_params_set_avail_min",
(void **) (char *) &SDL_NAME(snd_pcm_sw_params_set_avail_min)}, {
"snd_pcm_sw_params", (void **) (char *) &SDL_NAME(snd_pcm_sw_params)}, {
"snd_pcm_nonblock", (void **) (char *) &SDL_NAME(snd_pcm_nonblock)},};
static void UnloadALSALibrary(void) {
if (alsa_loaded) {
static void
UnloadALSALibrary(void)
{
if (alsa_loaded) {
/* SDL_UnloadObject(alsa_handle);*/
dlclose(alsa_handle);
alsa_handle = NULL;
alsa_loaded = 0;
}
dlclose(alsa_handle);
alsa_handle = NULL;
alsa_loaded = 0;
}
}
static int LoadALSALibrary(void) {
int i, retval = -1;
static int
LoadALSALibrary(void)
{
int i, retval = -1;
/* alsa_handle = SDL_LoadObject(alsa_library);*/
alsa_handle = dlopen(alsa_library,RTLD_NOW);
if (alsa_handle) {
alsa_loaded = 1;
retval = 0;
for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
alsa_handle = dlopen(alsa_library, RTLD_NOW);
if (alsa_handle) {
alsa_loaded = 1;
retval = 0;
for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
/* *alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/
#if HAVE_DLVSYM
*alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9");
if (!*alsa_functions[i].func)
*alsa_functions[i].func =
dlvsym(alsa_handle, alsa_functions[i].name, "ALSA_0.9");
if (!*alsa_functions[i].func)
#endif
*alsa_functions[i].func = dlsym(alsa_handle,alsa_functions[i].name);
if (!*alsa_functions[i].func) {
retval = -1;
UnloadALSALibrary();
break;
}
}
}
return retval;
*alsa_functions[i].func =
dlsym(alsa_handle, alsa_functions[i].name);
if (!*alsa_functions[i].func) {
retval = -1;
UnloadALSALibrary();
break;
}
}
}
return retval;
}
#else
static void UnloadALSALibrary(void) {
return;
static void
UnloadALSALibrary(void)
{
return;
}
static int LoadALSALibrary(void) {
return 0;
static int
LoadALSALibrary(void)
{
return 0;
}
#endif /* SDL_AUDIO_DRIVER_ALSA_DYNAMIC */
static const char *get_audio_device(int channels)
static const char *
get_audio_device(int channels)
{
const char *device;
device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */
if ( device == NULL ) {
if (channels == 6) device = "surround51";
else if (channels == 4) device = "surround40";
else device = DEFAULT_DEVICE;
}
return device;
const char *device;
device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */
if (device == NULL) {
if (channels == 6)
device = "surround51";
else if (channels == 4)
device = "surround40";
else
device = DEFAULT_DEVICE;
}
return device;
}
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int available;
int status;
snd_pcm_t *handle;
int available;
int status;
snd_pcm_t *handle;
available = 0;
if (LoadALSALibrary() < 0) {
return available;
}
status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if ( status >= 0 ) {
available = 1;
SDL_NAME(snd_pcm_close)(handle);
}
UnloadALSALibrary();
return(available);
available = 0;
if (LoadALSALibrary() < 0) {
return available;
}
status =
SDL_NAME(snd_pcm_open) (&handle, get_audio_device(2),
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (status >= 0) {
available = 1;
SDL_NAME(snd_pcm_close) (handle);
}
UnloadALSALibrary();
return (available);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
UnloadALSALibrary();
SDL_free(device->hidden);
SDL_free(device);
UnloadALSALibrary();
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
LoadALSALibrary();
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
LoadALSALibrary();
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = ALSA_OpenAudio;
this->WaitAudio = ALSA_WaitAudio;
this->PlayAudio = ALSA_PlayAudio;
this->GetAudioBuf = ALSA_GetAudioBuf;
this->CloseAudio = ALSA_CloseAudio;
/* Set the function pointers */
this->OpenAudio = ALSA_OpenAudio;
this->WaitAudio = ALSA_WaitAudio;
this->PlayAudio = ALSA_PlayAudio;
this->GetAudioBuf = ALSA_GetAudioBuf;
this->CloseAudio = ALSA_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap ALSA_bootstrap = {
DRIVER_NAME, "ALSA 0.9 PCM audio",
Audio_Available, Audio_CreateDevice
DRIVER_NAME, "ALSA 0.9 PCM audio",
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void ALSA_WaitAudio(_THIS)
static void
ALSA_WaitAudio(_THIS)
{
/* Check to see if the thread-parent process is still alive */
{ static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
if ( kill(parent, 0) < 0 ) {
this->enabled = 0;
}
}
}
/* Check to see if the thread-parent process is still alive */
{
static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
if (kill(parent, 0) < 0) {
this->enabled = 0;
}
}
}
}
@ -280,10 +367,26 @@ static void ALSA_WaitAudio(_THIS)
tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
}
static __inline__ void swizzle_alsa_channels_6_64bit(_THIS) { SWIZ6(Uint64); }
static __inline__ void swizzle_alsa_channels_6_32bit(_THIS) { SWIZ6(Uint32); }
static __inline__ void swizzle_alsa_channels_6_16bit(_THIS) { SWIZ6(Uint16); }
static __inline__ void swizzle_alsa_channels_6_8bit(_THIS) { SWIZ6(Uint8); }
static __inline__ void
swizzle_alsa_channels_6_64bit(_THIS)
{
SWIZ6(Uint64);
}
static __inline__ void
swizzle_alsa_channels_6_32bit(_THIS)
{
SWIZ6(Uint32);
}
static __inline__ void
swizzle_alsa_channels_6_16bit(_THIS)
{
SWIZ6(Uint16);
}
static __inline__ void
swizzle_alsa_channels_6_8bit(_THIS)
{
SWIZ6(Uint8);
}
#undef SWIZ6
@ -292,10 +395,11 @@ static __inline__ void swizzle_alsa_channels_6_8bit(_THIS) { SWIZ6(Uint8); }
* Called right before feeding this->mixbuf to the hardware. Swizzle channels
* from Windows/Mac order to the format alsalib will want.
*/
static __inline__ void swizzle_alsa_channels(_THIS)
static __inline__ void
swizzle_alsa_channels(_THIS)
{
if (this->spec.channels == 6) {
const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
if (fmtsize == 16)
swizzle_alsa_channels_6_16bit(this);
else if (fmtsize == 8)
@ -310,173 +414,198 @@ static __inline__ void swizzle_alsa_channels(_THIS)
}
static void ALSA_PlayAudio(_THIS)
static void
ALSA_PlayAudio(_THIS)
{
int status;
int sample_len;
signed short *sample_buf;
int status;
int sample_len;
signed short *sample_buf;
swizzle_alsa_channels(this);
swizzle_alsa_channels(this);
sample_len = this->spec.samples;
sample_buf = (signed short *)mixbuf;
sample_len = this->spec.samples;
sample_buf = (signed short *) mixbuf;
while ( sample_len > 0 ) {
status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len);
if ( status < 0 ) {
if ( status == -EAGAIN ) {
SDL_Delay(1);
continue;
}
if ( status == -ESTRPIPE ) {
do {
SDL_Delay(1);
status = SDL_NAME(snd_pcm_resume)(pcm_handle);
} while ( status == -EAGAIN );
}
if ( status < 0 ) {
status = SDL_NAME(snd_pcm_prepare)(pcm_handle);
}
if ( status < 0 ) {
/* Hmm, not much we can do - abort */
this->enabled = 0;
return;
}
continue;
}
sample_buf += status * this->spec.channels;
sample_len -= status;
}
while (sample_len > 0) {
status =
SDL_NAME(snd_pcm_writei) (pcm_handle, sample_buf, sample_len);
if (status < 0) {
if (status == -EAGAIN) {
SDL_Delay(1);
continue;
}
if (status == -ESTRPIPE) {
do {
SDL_Delay(1);
status = SDL_NAME(snd_pcm_resume) (pcm_handle);
} while (status == -EAGAIN);
}
if (status < 0) {
status = SDL_NAME(snd_pcm_prepare) (pcm_handle);
}
if (status < 0) {
/* Hmm, not much we can do - abort */
this->enabled = 0;
return;
}
continue;
}
sample_buf += status * this->spec.channels;
sample_len -= status;
}
}
static Uint8 *ALSA_GetAudioBuf(_THIS)
static Uint8 *
ALSA_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void ALSA_CloseAudio(_THIS)
static void
ALSA_CloseAudio(_THIS)
{
if ( mixbuf != NULL ) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if ( pcm_handle ) {
SDL_NAME(snd_pcm_drain)(pcm_handle);
SDL_NAME(snd_pcm_close)(pcm_handle);
pcm_handle = NULL;
}
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if (pcm_handle) {
SDL_NAME(snd_pcm_drain) (pcm_handle);
SDL_NAME(snd_pcm_close) (pcm_handle);
pcm_handle = NULL;
}
}
static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
ALSA_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
int status;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_format_t format;
snd_pcm_uframes_t frames;
Uint16 test_format;
int status;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
snd_pcm_format_t format;
snd_pcm_uframes_t frames;
Uint16 test_format;
/* Open the audio device */
/* Name of device should depend on # channels in spec */
status = SDL_NAME(snd_pcm_open)(&pcm_handle, get_audio_device(spec->channels), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
/* Open the audio device */
/* Name of device should depend on # channels in spec */
status =
SDL_NAME(snd_pcm_open) (&pcm_handle,
get_audio_device(spec->channels),
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if ( status < 0 ) {
SDL_SetError("Couldn't open audio device: %s", SDL_NAME(snd_strerror)(status));
return(-1);
}
if (status < 0) {
SDL_SetError("Couldn't open audio device: %s",
SDL_NAME(snd_strerror) (status));
return (-1);
}
/* Figure out what the hardware is capable of */
snd_pcm_hw_params_alloca(&hwparams);
status = SDL_NAME(snd_pcm_hw_params_any)(pcm_handle, hwparams);
if ( status < 0 ) {
SDL_SetError("Couldn't get hardware config: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
/* Figure out what the hardware is capable of */
snd_pcm_hw_params_alloca(&hwparams);
status = SDL_NAME(snd_pcm_hw_params_any) (pcm_handle, hwparams);
if (status < 0) {
SDL_SetError("Couldn't get hardware config: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
/* SDL only uses interleaved sample output */
status = SDL_NAME(snd_pcm_hw_params_set_access)(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
if ( status < 0 ) {
SDL_SetError("Couldn't set interleaved access: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
/* SDL only uses interleaved sample output */
status =
SDL_NAME(snd_pcm_hw_params_set_access) (pcm_handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (status < 0) {
SDL_SetError("Couldn't set interleaved access: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
/* Try for a closest match on audio format */
status = -1;
for ( test_format = SDL_FirstAudioFormat(spec->format);
test_format && (status < 0); ) {
switch ( test_format ) {
case AUDIO_U8:
format = SND_PCM_FORMAT_U8;
break;
case AUDIO_S8:
format = SND_PCM_FORMAT_S8;
break;
case AUDIO_S16LSB:
format = SND_PCM_FORMAT_S16_LE;
break;
case AUDIO_S16MSB:
format = SND_PCM_FORMAT_S16_BE;
break;
case AUDIO_U16LSB:
format = SND_PCM_FORMAT_U16_LE;
break;
case AUDIO_U16MSB:
format = SND_PCM_FORMAT_U16_BE;
break;
default:
format = 0;
break;
}
if ( format != 0 ) {
status = SDL_NAME(snd_pcm_hw_params_set_format)(pcm_handle, hwparams, format);
}
if ( status < 0 ) {
test_format = SDL_NextAudioFormat();
}
}
if ( status < 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
ALSA_CloseAudio(this);
return(-1);
}
spec->format = test_format;
/* Try for a closest match on audio format */
status = -1;
for (test_format = SDL_FirstAudioFormat(spec->format);
test_format && (status < 0);) {
switch (test_format) {
case AUDIO_U8:
format = SND_PCM_FORMAT_U8;
break;
case AUDIO_S8:
format = SND_PCM_FORMAT_S8;
break;
case AUDIO_S16LSB:
format = SND_PCM_FORMAT_S16_LE;
break;
case AUDIO_S16MSB:
format = SND_PCM_FORMAT_S16_BE;
break;
case AUDIO_U16LSB:
format = SND_PCM_FORMAT_U16_LE;
break;
case AUDIO_U16MSB:
format = SND_PCM_FORMAT_U16_BE;
break;
default:
format = 0;
break;
}
if (format != 0) {
status =
SDL_NAME(snd_pcm_hw_params_set_format) (pcm_handle,
hwparams, format);
}
if (status < 0) {
test_format = SDL_NextAudioFormat();
}
}
if (status < 0) {
SDL_SetError("Couldn't find any hardware audio formats");
ALSA_CloseAudio(this);
return (-1);
}
spec->format = test_format;
/* Set the number of channels */
status = SDL_NAME(snd_pcm_hw_params_set_channels)(pcm_handle, hwparams, spec->channels);
if ( status < 0 ) {
status = SDL_NAME(snd_pcm_hw_params_get_channels)(hwparams);
if ( (status <= 0) || (status > 2) ) {
SDL_SetError("Couldn't set audio channels");
ALSA_CloseAudio(this);
return(-1);
}
spec->channels = status;
}
/* Set the number of channels */
status =
SDL_NAME(snd_pcm_hw_params_set_channels) (pcm_handle, hwparams,
spec->channels);
if (status < 0) {
status = SDL_NAME(snd_pcm_hw_params_get_channels) (hwparams);
if ((status <= 0) || (status > 2)) {
SDL_SetError("Couldn't set audio channels");
ALSA_CloseAudio(this);
return (-1);
}
spec->channels = status;
}
/* Set the audio rate */
status = SDL_NAME(snd_pcm_hw_params_set_rate_near)(pcm_handle, hwparams, spec->freq, NULL);
if ( status < 0 ) {
SDL_SetError("Couldn't set audio frequency: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
spec->freq = status;
/* Set the audio rate */
status =
SDL_NAME(snd_pcm_hw_params_set_rate_near) (pcm_handle, hwparams,
spec->freq, NULL);
if (status < 0) {
SDL_SetError("Couldn't set audio frequency: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
spec->freq = status;
/* Set the buffer size, in samples */
frames = spec->samples;
frames = SDL_NAME(snd_pcm_hw_params_set_period_size_near)(pcm_handle, hwparams, frames, NULL);
spec->samples = frames;
SDL_NAME(snd_pcm_hw_params_set_periods_near)(pcm_handle, hwparams, 2, NULL);
/* Set the buffer size, in samples */
frames = spec->samples;
frames =
SDL_NAME(snd_pcm_hw_params_set_period_size_near) (pcm_handle,
hwparams, frames,
NULL);
spec->samples = frames;
SDL_NAME(snd_pcm_hw_params_set_periods_near) (pcm_handle, hwparams, 2,
NULL);
/* "set" the hardware with the desired parameters */
status = SDL_NAME(snd_pcm_hw_params)(pcm_handle, hwparams);
if ( status < 0 ) {
SDL_SetError("Couldn't set hardware audio parameters: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
/* "set" the hardware with the desired parameters */
status = SDL_NAME(snd_pcm_hw_params) (pcm_handle, hwparams);
if (status < 0) {
SDL_SetError("Couldn't set hardware audio parameters: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
/* This is useful for debugging... */
/*
@ -488,51 +617,61 @@ static int ALSA_OpenAudio(_THIS, SDL_AudioSpec *spec)
}
*/
/* Set the software parameters */
snd_pcm_sw_params_alloca(&swparams);
status = SDL_NAME(snd_pcm_sw_params_current)(pcm_handle, swparams);
if ( status < 0 ) {
SDL_SetError("Couldn't get software config: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
status = SDL_NAME(snd_pcm_sw_params_set_start_threshold)(pcm_handle, swparams, 0);
if ( status < 0 ) {
SDL_SetError("Couldn't set start threshold: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
status = SDL_NAME(snd_pcm_sw_params_set_avail_min)(pcm_handle, swparams, frames);
if ( status < 0 ) {
SDL_SetError("Couldn't set avail min: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
status = SDL_NAME(snd_pcm_sw_params)(pcm_handle, swparams);
if ( status < 0 ) {
SDL_SetError("Couldn't set software audio parameters: %s", SDL_NAME(snd_strerror)(status));
ALSA_CloseAudio(this);
return(-1);
}
/* Set the software parameters */
snd_pcm_sw_params_alloca(&swparams);
status = SDL_NAME(snd_pcm_sw_params_current) (pcm_handle, swparams);
if (status < 0) {
SDL_SetError("Couldn't get software config: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
status =
SDL_NAME(snd_pcm_sw_params_set_start_threshold) (pcm_handle,
swparams, 0);
if (status < 0) {
SDL_SetError("Couldn't set start threshold: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
status =
SDL_NAME(snd_pcm_sw_params_set_avail_min) (pcm_handle, swparams,
frames);
if (status < 0) {
SDL_SetError("Couldn't set avail min: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
status = SDL_NAME(snd_pcm_sw_params) (pcm_handle, swparams);
if (status < 0) {
SDL_SetError("Couldn't set software audio parameters: %s",
SDL_NAME(snd_strerror) (status));
ALSA_CloseAudio(this);
return (-1);
}
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
if ( mixbuf == NULL ) {
ALSA_CloseAudio(this);
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
if (mixbuf == NULL) {
ALSA_CloseAudio(this);
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Switch to blocking mode for playback */
SDL_NAME(snd_pcm_nonblock)(pcm_handle, 0);
/* Switch to blocking mode for playback */
SDL_NAME(snd_pcm_nonblock) (pcm_handle, 0);
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -33,16 +33,17 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The audio device handle */
snd_pcm_t *pcm_handle;
struct SDL_PrivateAudioData
{
/* The audio device handle */
snd_pcm_t *pcm_handle;
/* The parent process id, to detect when application quits */
pid_t parent;
/* The parent process id, to detect when application quits */
pid_t parent;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
};
/* Old variable names */
@ -52,3 +53,4 @@ struct SDL_PrivateAudioData {
#define mixlen (this->hidden->mixlen)
#endif /* _ALSA_PCM_audio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -28,310 +28,321 @@
#include "SDL_ahiaudio.h"
/* Audio driver functions */
static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int AHI_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void AHI_WaitAudio(_THIS);
static void AHI_PlayAudio(_THIS);
static Uint8 *AHI_GetAudioBuf(_THIS);
static void AHI_CloseAudio(_THIS);
#ifndef __SASC
#define mymalloc(x) AllocVec(x,MEMF_PUBLIC)
#define myfree FreeVec
#define mymalloc(x) AllocVec(x,MEMF_PUBLIC)
#define myfree FreeVec
#else
#define mymalloc malloc
#define myfree free
#define mymalloc malloc
#define myfree free
#endif
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int ok=0;
struct MsgPort *p;
struct AHIRequest *req;
int ok = 0;
struct MsgPort *p;
struct AHIRequest *req;
if(p=CreateMsgPort())
{
if(req=(struct AHIRequest *)CreateIORequest(p,sizeof(struct AHIRequest)))
{
req->ahir_Version=4;
if (p = CreateMsgPort()) {
if (req =
(struct AHIRequest *) CreateIORequest(p,
sizeof(struct
AHIRequest))) {
req->ahir_Version = 4;
if(!OpenDevice(AHINAME,0,(struct IORequest *)req,NULL))
{
D(bug("AHI available.\n"));
ok=1;
CloseDevice((struct IORequest *)req);
}
DeleteIORequest((struct IORequest *)req);
}
DeleteMsgPort(p);
}
if (!OpenDevice(AHINAME, 0, (struct IORequest *) req, NULL)) {
D(bug("AHI available.\n"));
ok = 1;
CloseDevice((struct IORequest *) req);
}
DeleteIORequest((struct IORequest *) req);
}
DeleteMsgPort(p);
}
D(if(!ok) bug("AHI not available\n"));
return ok;
D(if (!ok) bug("AHI not available\n"));
return ok;
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
#ifndef NO_AMIGADEBUG
D(bug("AHI created...\n"));
D(bug("AHI created...\n"));
#endif
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = AHI_OpenAudio;
this->WaitAudio = AHI_WaitAudio;
this->PlayAudio = AHI_PlayAudio;
this->GetAudioBuf = AHI_GetAudioBuf;
this->CloseAudio = AHI_CloseAudio;
/* Set the function pointers */
this->OpenAudio = AHI_OpenAudio;
this->WaitAudio = AHI_WaitAudio;
this->PlayAudio = AHI_PlayAudio;
this->GetAudioBuf = AHI_GetAudioBuf;
this->CloseAudio = AHI_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap AHI_bootstrap = {
"AHI", Audio_Available, Audio_CreateDevice
"AHI", Audio_Available, Audio_CreateDevice
};
void static AHI_WaitAudio(_THIS)
void static
AHI_WaitAudio(_THIS)
{
if(!CheckIO((struct IORequest *)audio_req[current_buffer]))
{
WaitIO((struct IORequest *)audio_req[current_buffer]);
// AbortIO((struct IORequest *)audio_req[current_buffer]);
}
if (!CheckIO((struct IORequest *) audio_req[current_buffer])) {
WaitIO((struct IORequest *) audio_req[current_buffer]);
// AbortIO((struct IORequest *)audio_req[current_buffer]);
}
}
static void AHI_PlayAudio(_THIS)
static void
AHI_PlayAudio(_THIS)
{
if(playing>1)
WaitIO((struct IORequest *)audio_req[current_buffer]);
if (playing > 1)
WaitIO((struct IORequest *) audio_req[current_buffer]);
/* Write the audio data out */
audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60;
audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer];
audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size;
audio_req[current_buffer] -> ahir_Std. io_Offset = 0;
audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE;
audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq;
audio_req[current_buffer] -> ahir_Volume = 0x10000;
audio_req[current_buffer] -> ahir_Type = this->hidden->type;
audio_req[current_buffer] -> ahir_Position = 0x8000;
audio_req[current_buffer] -> ahir_Link = (playing>0 ? audio_req[current_buffer^1] : NULL);
/* Write the audio data out */
audio_req[current_buffer]->ahir_Std.io_Message.mn_Node.ln_Pri = 60;
audio_req[current_buffer]->ahir_Std.io_Data = mixbuf[current_buffer];
audio_req[current_buffer]->ahir_Std.io_Length = this->hidden->size;
audio_req[current_buffer]->ahir_Std.io_Offset = 0;
audio_req[current_buffer]->ahir_Std.io_Command = CMD_WRITE;
audio_req[current_buffer]->ahir_Frequency = this->hidden->freq;
audio_req[current_buffer]->ahir_Volume = 0x10000;
audio_req[current_buffer]->ahir_Type = this->hidden->type;
audio_req[current_buffer]->ahir_Position = 0x8000;
audio_req[current_buffer]->ahir_Link =
(playing > 0 ? audio_req[current_buffer ^ 1] : NULL);
SendIO((struct IORequest *)audio_req[current_buffer]);
current_buffer^=1;
SendIO((struct IORequest *) audio_req[current_buffer]);
current_buffer ^= 1;
playing++;
playing++;
}
static Uint8 *AHI_GetAudioBuf(_THIS)
static Uint8 *
AHI_GetAudioBuf(_THIS)
{
return(mixbuf[current_buffer]);
return (mixbuf[current_buffer]);
}
static void AHI_CloseAudio(_THIS)
static void
AHI_CloseAudio(_THIS)
{
D(bug("Closing audio...\n"));
D(bug("Closing audio...\n"));
playing=0;
playing = 0;
if(audio_req[0])
{
if(audio_req[1])
{
D(bug("Break req[1]...\n"));
if (audio_req[0]) {
if (audio_req[1]) {
D(bug("Break req[1]...\n"));
AbortIO((struct IORequest *)audio_req[1]);
WaitIO((struct IORequest *)audio_req[1]);
}
AbortIO((struct IORequest *) audio_req[1]);
WaitIO((struct IORequest *) audio_req[1]);
}
D(bug("Break req[0]...\n"));
D(bug("Break req[0]...\n"));
AbortIO((struct IORequest *)audio_req[0]);
WaitIO((struct IORequest *)audio_req[0]);
AbortIO((struct IORequest *) audio_req[0]);
WaitIO((struct IORequest *) audio_req[0]);
if(audio_req[1])
{
D(bug("Break AGAIN req[1]...\n"));
AbortIO((struct IORequest *)audio_req[1]);
WaitIO((struct IORequest *)audio_req[1]);
}
if (audio_req[1]) {
D(bug("Break AGAIN req[1]...\n"));
AbortIO((struct IORequest *) audio_req[1]);
WaitIO((struct IORequest *) audio_req[1]);
}
// Double abort to be sure to break the dbuffering process.
SDL_Delay(200);
SDL_Delay(200);
D(bug("Reqs breaked, closing device...\n"));
CloseDevice((struct IORequest *)audio_req[0]);
D(bug("Device closed, freeing memory...\n"));
myfree(audio_req[1]);
D(bug("Memory freed, deleting IOReq...\n"));
DeleteIORequest((struct IORequest *)audio_req[0]);
audio_req[0]=audio_req[1]=NULL;
}
D(bug("Reqs breaked, closing device...\n"));
CloseDevice((struct IORequest *) audio_req[0]);
D(bug("Device closed, freeing memory...\n"));
myfree(audio_req[1]);
D(bug("Memory freed, deleting IOReq...\n"));
DeleteIORequest((struct IORequest *) audio_req[0]);
audio_req[0] = audio_req[1] = NULL;
}
D(bug("Freeing mixbuf[0]...\n"));
if ( mixbuf[0] != NULL ) {
myfree(mixbuf[0]);
// SDL_FreeAudioMem(mixbuf[0]);
mixbuf[0] = NULL;
}
D(bug("Freeing mixbuf[0]...\n"));
if (mixbuf[0] != NULL) {
myfree(mixbuf[0]);
// SDL_FreeAudioMem(mixbuf[0]);
mixbuf[0] = NULL;
}
D(bug("Freeing mixbuf[1]...\n"));
if ( mixbuf[1] != NULL ) {
myfree(mixbuf[1]);
// SDL_FreeAudioMem(mixbuf[1]);
mixbuf[1] = NULL;
}
D(bug("Freeing mixbuf[1]...\n"));
if (mixbuf[1] != NULL) {
myfree(mixbuf[1]);
// SDL_FreeAudioMem(mixbuf[1]);
mixbuf[1] = NULL;
}
D(bug("Freeing audio_port...\n"));
D(bug("Freeing audio_port...\n"));
if ( audio_port != NULL ) {
DeleteMsgPort(audio_port);
audio_port = NULL;
}
D(bug("...done!\n"));
if (audio_port != NULL) {
DeleteMsgPort(audio_port);
audio_port = NULL;
}
D(bug("...done!\n"));
}
static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
// int width;
static int
AHI_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
// int width;
D(bug("AHI opening...\n"));
D(bug("AHI opening...\n"));
/* Determine the audio parameters from the AudioSpec */
switch ( spec->format & 0xFF ) {
/* Determine the audio parameters from the AudioSpec */
switch (spec->format & 0xFF) {
case 8: { /* Signed 8 bit audio data */
D(bug("Samples a 8 bit...\n"));
spec->format = AUDIO_S8;
this->hidden->bytespersample=1;
if(spec->channels<2)
this->hidden->type = AHIST_M8S;
else
this->hidden->type = AHIST_S8S;
}
break;
case 8:
{ /* Signed 8 bit audio data */
D(bug("Samples a 8 bit...\n"));
spec->format = AUDIO_S8;
this->hidden->bytespersample = 1;
if (spec->channels < 2)
this->hidden->type = AHIST_M8S;
else
this->hidden->type = AHIST_S8S;
}
break;
case 16: { /* Signed 16 bit audio data */
D(bug("Samples a 16 bit...\n"));
spec->format = AUDIO_S16MSB;
this->hidden->bytespersample=2;
if(spec->channels<2)
this->hidden->type = AHIST_M16S;
else
this->hidden->type = AHIST_S16S;
}
break;
case 16:
{ /* Signed 16 bit audio data */
D(bug("Samples a 16 bit...\n"));
spec->format = AUDIO_S16MSB;
this->hidden->bytespersample = 2;
if (spec->channels < 2)
this->hidden->type = AHIST_M16S;
else
this->hidden->type = AHIST_S16S;
}
break;
default: {
SDL_SetError("Unsupported audio format");
return(-1);
}
}
default:
{
SDL_SetError("Unsupported audio format");
return (-1);
}
}
if(spec->channels!=1 && spec->channels!=2)
{
D(bug("Wrong channel number!\n"));
SDL_SetError("Channel number non supported");
return -1;
}
if (spec->channels != 1 && spec->channels != 2) {
D(bug("Wrong channel number!\n"));
SDL_SetError("Channel number non supported");
return -1;
}
D(bug("Before CalculateAudioSpec\n"));
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
D(bug("Before CalculateAudioSpec\n"));
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
D(bug("Before CreateMsgPort\n"));
D(bug("Before CreateMsgPort\n"));
if(!(audio_port=CreateMsgPort()))
{
SDL_SetError("Unable to create a MsgPort");
return -1;
}
if (!(audio_port = CreateMsgPort())) {
SDL_SetError("Unable to create a MsgPort");
return -1;
}
D(bug("Before CreateIORequest\n"));
D(bug("Before CreateIORequest\n"));
if(!(audio_req[0]=(struct AHIRequest *)CreateIORequest(audio_port,sizeof(struct AHIRequest))))
{
SDL_SetError("Unable to create an AHIRequest");
DeleteMsgPort(audio_port);
return -1;
}
if (!
(audio_req[0] =
(struct AHIRequest *) CreateIORequest(audio_port,
sizeof(struct AHIRequest)))) {
SDL_SetError("Unable to create an AHIRequest");
DeleteMsgPort(audio_port);
return -1;
}
audio_req[0]->ahir_Version = 4;
audio_req[0]->ahir_Version = 4;
if(OpenDevice(AHINAME,0,(struct IORequest *)audio_req[0],NULL))
{
SDL_SetError("Unable to open AHI device!\n");
DeleteIORequest((struct IORequest *)audio_req[0]);
DeleteMsgPort(audio_port);
return -1;
}
D(bug("AFTER opendevice\n"));
if (OpenDevice(AHINAME, 0, (struct IORequest *) audio_req[0], NULL)) {
SDL_SetError("Unable to open AHI device!\n");
DeleteIORequest((struct IORequest *) audio_req[0]);
DeleteMsgPort(audio_port);
return -1;
}
/* Set output frequency and size */
this->hidden->freq = spec->freq;
this->hidden->size = spec->size;
D(bug("AFTER opendevice\n"));
D(bug("Before buffer allocation\n"));
/* Set output frequency and size */
this->hidden->freq = spec->freq;
this->hidden->size = spec->size;
/* Allocate mixing buffer */
mixbuf[0] = (Uint8 *)mymalloc(spec->size);
mixbuf[1] = (Uint8 *)mymalloc(spec->size);
D(bug("Before buffer allocation\n"));
D(bug("Before audio_req allocation\n"));
/* Allocate mixing buffer */
mixbuf[0] = (Uint8 *) mymalloc(spec->size);
mixbuf[1] = (Uint8 *) mymalloc(spec->size);
if(!(audio_req[1]=mymalloc(sizeof(struct AHIRequest))))
{
SDL_OutOfMemory();
return(-1);
}
D(bug("Before audio_req memcpy\n"));
D(bug("Before audio_req allocation\n"));
SDL_memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest));
if (!(audio_req[1] = mymalloc(sizeof(struct AHIRequest)))) {
SDL_OutOfMemory();
return (-1);
}
if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) {
SDL_OutOfMemory();
return(-1);
}
D(bug("Before audio_req memcpy\n"));
D(bug("Before mixbuf memset\n"));
SDL_memcpy(audio_req[1], audio_req[0], sizeof(struct AHIRequest));
SDL_memset(mixbuf[0], spec->silence, spec->size);
SDL_memset(mixbuf[1], spec->silence, spec->size);
if (mixbuf[0] == NULL || mixbuf[1] == NULL) {
SDL_OutOfMemory();
return (-1);
}
current_buffer=0;
playing=0;
D(bug("Before mixbuf memset\n"));
D(bug("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",spec->freq,mixbuf[0],mixbuf[1],spec->size,this->hidden->bytespersample*8,spec->channels));
SDL_memset(mixbuf[0], spec->silence, spec->size);
SDL_memset(mixbuf[1], spec->silence, spec->size);
/* We're ready to rock and roll. :-) */
return(0);
current_buffer = 0;
playing = 0;
D(bug
("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",
spec->freq, mixbuf[0], mixbuf[1], spec->size,
this->hidden->bytespersample * 8, spec->channels));
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -40,14 +40,15 @@
/* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The handle for the audio device */
struct AHIRequest *audio_req[2];
struct MsgPort *audio_port;
Sint32 freq,type,bytespersample,size;
Uint8 *mixbuf[2]; /* The app mixing buffer */
int current_buffer;
Uint32 playing;
struct SDL_PrivateAudioData
{
/* The handle for the audio device */
struct AHIRequest *audio_req[2];
struct MsgPort *audio_port;
Sint32 freq, type, bytespersample, size;
Uint8 *mixbuf[2]; /* The app mixing buffer */
int current_buffer;
Uint32 playing;
};
/* Old variable names */
@ -58,3 +59,4 @@ struct SDL_PrivateAudioData {
#define playing (this->hidden->playing)
#endif /* _SDL_ahiaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -41,7 +41,7 @@
#define ARTS_DRIVER_NAME "arts"
/* Audio driver functions */
static int ARTS_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int ARTS_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void ARTS_WaitAudio(_THIS);
static void ARTS_PlayAudio(_THIS);
static Uint8 *ARTS_GetAudioBuf(_THIS);
@ -53,281 +53,305 @@ static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC;
static void *arts_handle = NULL;
static int arts_loaded = 0;
static int (*SDL_NAME(arts_init))(void);
static void (*SDL_NAME(arts_free))(void);
static arts_stream_t (*SDL_NAME(arts_play_stream))(int rate, int bits, int channels, const char *name);
static int (*SDL_NAME(arts_stream_set))(arts_stream_t s, arts_parameter_t param, int value);
static int (*SDL_NAME(arts_stream_get))(arts_stream_t s, arts_parameter_t param);
static int (*SDL_NAME(arts_write))(arts_stream_t s, const void *buffer, int count);
static void (*SDL_NAME(arts_close_stream))(arts_stream_t s);
static int (*SDL_NAME(arts_init)) (void);
static void (*SDL_NAME(arts_free)) (void);
static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
int channels,
const char *name);
static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
arts_parameter_t param, int value);
static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
arts_parameter_t param);
static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
int count);
static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
static struct {
const char *name;
void **func;
} arts_functions[] = {
{ "arts_init", (void **)&SDL_NAME(arts_init) },
{ "arts_free", (void **)&SDL_NAME(arts_free) },
{ "arts_play_stream", (void **)&SDL_NAME(arts_play_stream) },
{ "arts_stream_set", (void **)&SDL_NAME(arts_stream_set) },
{ "arts_stream_get", (void **)&SDL_NAME(arts_stream_get) },
{ "arts_write", (void **)&SDL_NAME(arts_write) },
{ "arts_close_stream", (void **)&SDL_NAME(arts_close_stream) },
};
static void UnloadARTSLibrary()
static struct
{
if ( arts_loaded ) {
SDL_UnloadObject(arts_handle);
arts_handle = NULL;
arts_loaded = 0;
}
const char *name;
void **func;
} arts_functions[] = {
{
"arts_init", (void **) &SDL_NAME(arts_init)}, {
"arts_free", (void **) &SDL_NAME(arts_free)}, {
"arts_play_stream", (void **) &SDL_NAME(arts_play_stream)}, {
"arts_stream_set", (void **) &SDL_NAME(arts_stream_set)}, {
"arts_stream_get", (void **) &SDL_NAME(arts_stream_get)}, {
"arts_write", (void **) &SDL_NAME(arts_write)}, {
"arts_close_stream", (void **) &SDL_NAME(arts_close_stream)},};
static void
UnloadARTSLibrary()
{
if (arts_loaded) {
SDL_UnloadObject(arts_handle);
arts_handle = NULL;
arts_loaded = 0;
}
}
static int LoadARTSLibrary(void)
static int
LoadARTSLibrary(void)
{
int i, retval = -1;
int i, retval = -1;
arts_handle = SDL_LoadObject(arts_library);
if ( arts_handle ) {
arts_loaded = 1;
retval = 0;
for ( i=0; i<SDL_arraysize(arts_functions); ++i ) {
*arts_functions[i].func = SDL_LoadFunction(arts_handle, arts_functions[i].name);
if ( !*arts_functions[i].func ) {
retval = -1;
UnloadARTSLibrary();
break;
}
}
}
return retval;
arts_handle = SDL_LoadObject(arts_library);
if (arts_handle) {
arts_loaded = 1;
retval = 0;
for (i = 0; i < SDL_arraysize(arts_functions); ++i) {
*arts_functions[i].func =
SDL_LoadFunction(arts_handle, arts_functions[i].name);
if (!*arts_functions[i].func) {
retval = -1;
UnloadARTSLibrary();
break;
}
}
}
return retval;
}
#else
static void UnloadARTSLibrary()
static void
UnloadARTSLibrary()
{
return;
return;
}
static int LoadARTSLibrary(void)
static int
LoadARTSLibrary(void)
{
return 0;
return 0;
}
#endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int available = 0;
int available = 0;
if ( LoadARTSLibrary() < 0 ) {
return available;
}
if ( SDL_NAME(arts_init)() == 0 ) {
#define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */
if (LoadARTSLibrary() < 0) {
return available;
}
if (SDL_NAME(arts_init) () == 0) {
#define ARTS_CRASH_HACK /* Play a stream so aRts doesn't crash */
#ifdef ARTS_CRASH_HACK
arts_stream_t stream2;
stream2=SDL_NAME(arts_play_stream)(44100, 16, 2, "SDL");
SDL_NAME(arts_write)(stream2, "", 0);
SDL_NAME(arts_close_stream)(stream2);
arts_stream_t stream2;
stream2 = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
SDL_NAME(arts_write) (stream2, "", 0);
SDL_NAME(arts_close_stream) (stream2);
#endif
available = 1;
SDL_NAME(arts_free)();
}
UnloadARTSLibrary();
available = 1;
SDL_NAME(arts_free) ();
}
UnloadARTSLibrary();
return available;
return available;
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
UnloadARTSLibrary();
SDL_free(device->hidden);
SDL_free(device);
UnloadARTSLibrary();
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
LoadARTSLibrary();
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
stream = 0;
/* Initialize all variables that we clean on shutdown */
LoadARTSLibrary();
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
stream = 0;
/* Set the function pointers */
this->OpenAudio = ARTS_OpenAudio;
this->WaitAudio = ARTS_WaitAudio;
this->PlayAudio = ARTS_PlayAudio;
this->GetAudioBuf = ARTS_GetAudioBuf;
this->CloseAudio = ARTS_CloseAudio;
/* Set the function pointers */
this->OpenAudio = ARTS_OpenAudio;
this->WaitAudio = ARTS_WaitAudio;
this->PlayAudio = ARTS_PlayAudio;
this->GetAudioBuf = ARTS_GetAudioBuf;
this->CloseAudio = ARTS_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap ARTS_bootstrap = {
ARTS_DRIVER_NAME, "Analog Realtime Synthesizer",
Audio_Available, Audio_CreateDevice
ARTS_DRIVER_NAME, "Analog Realtime Synthesizer",
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void ARTS_WaitAudio(_THIS)
static void
ARTS_WaitAudio(_THIS)
{
Sint32 ticks;
Sint32 ticks;
/* Check to see if the thread-parent process is still alive */
{ static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
if ( kill(parent, 0) < 0 ) {
this->enabled = 0;
}
}
}
/* Check to see if the thread-parent process is still alive */
{
static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
if (kill(parent, 0) < 0) {
this->enabled = 0;
}
}
}
/* Use timer for general audio synchronization */
ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
if ( ticks > 0 ) {
SDL_Delay(ticks);
}
/* Use timer for general audio synchronization */
ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
if (ticks > 0) {
SDL_Delay(ticks);
}
}
static void ARTS_PlayAudio(_THIS)
static void
ARTS_PlayAudio(_THIS)
{
int written;
int written;
/* Write the audio data */
written = SDL_NAME(arts_write)(stream, mixbuf, mixlen);
/* If timer synchronization is enabled, set the next write frame */
if ( frame_ticks ) {
next_frame += frame_ticks;
}
/* Write the audio data */
written = SDL_NAME(arts_write) (stream, mixbuf, mixlen);
/* If we couldn't write, assume fatal error for now */
if ( written < 0 ) {
this->enabled = 0;
}
/* If timer synchronization is enabled, set the next write frame */
if (frame_ticks) {
next_frame += frame_ticks;
}
/* If we couldn't write, assume fatal error for now */
if (written < 0) {
this->enabled = 0;
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
#endif
}
static Uint8 *ARTS_GetAudioBuf(_THIS)
static Uint8 *
ARTS_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void ARTS_CloseAudio(_THIS)
static void
ARTS_CloseAudio(_THIS)
{
if ( mixbuf != NULL ) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if ( stream ) {
SDL_NAME(arts_close_stream)(stream);
stream = 0;
}
SDL_NAME(arts_free)();
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if (stream) {
SDL_NAME(arts_close_stream) (stream);
stream = 0;
}
SDL_NAME(arts_free) ();
}
static int ARTS_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
ARTS_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
int bits, frag_spec;
Uint16 test_format, format;
int bits, frag_spec;
Uint16 test_format, format;
/* Reset the timer synchronization flag */
frame_ticks = 0.0;
/* Reset the timer synchronization flag */
frame_ticks = 0.0;
mixbuf = NULL;
mixbuf = NULL;
/* Try for a closest match on audio format */
format = 0;
bits = 0;
for ( test_format = SDL_FirstAudioFormat(spec->format);
! format && test_format; ) {
/* Try for a closest match on audio format */
format = 0;
bits = 0;
for (test_format = SDL_FirstAudioFormat(spec->format);
!format && test_format;) {
#ifdef DEBUG_AUDIO
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
#endif
switch ( test_format ) {
case AUDIO_U8:
bits = 8;
format = 1;
break;
case AUDIO_S16LSB:
bits = 16;
format = 1;
break;
default:
format = 0;
break;
}
if ( ! format ) {
test_format = SDL_NextAudioFormat();
}
}
if ( format == 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
return(-1);
}
spec->format = test_format;
switch (test_format) {
case AUDIO_U8:
bits = 8;
format = 1;
break;
case AUDIO_S16LSB:
bits = 16;
format = 1;
break;
default:
format = 0;
break;
}
if (!format) {
test_format = SDL_NextAudioFormat();
}
}
if (format == 0) {
SDL_SetError("Couldn't find any hardware audio formats");
return (-1);
}
spec->format = test_format;
if ( SDL_NAME(arts_init)() != 0 ) {
SDL_SetError("Unable to initialize ARTS");
return(-1);
}
stream = SDL_NAME(arts_play_stream)(spec->freq, bits, spec->channels, "SDL");
if (SDL_NAME(arts_init) () != 0) {
SDL_SetError("Unable to initialize ARTS");
return (-1);
}
stream =
SDL_NAME(arts_play_stream) (spec->freq, bits, spec->channels, "SDL");
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Determine the power of two of the fragment size */
for ( frag_spec = 0; (0x01<<frag_spec) < spec->size; ++frag_spec );
if ( (0x01<<frag_spec) != spec->size ) {
SDL_SetError("Fragment size must be a power of two");
return(-1);
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
/* Determine the power of two of the fragment size */
for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec);
if ((0x01 << frag_spec) != spec->size) {
SDL_SetError("Fragment size must be a power of two");
return (-1);
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
#ifdef ARTS_P_PACKET_SETTINGS
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
SDL_NAME(arts_stream_set) (stream, ARTS_P_PACKET_SETTINGS, frag_spec);
#else
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_SIZE, frag_spec&0xffff);
SDL_NAME(arts_stream_set)(stream, ARTS_P_PACKET_COUNT, frag_spec>>16);
SDL_NAME(arts_stream_set) (stream, ARTS_P_PACKET_SIZE,
frag_spec & 0xffff);
SDL_NAME(arts_stream_set) (stream, ARTS_P_PACKET_COUNT, frag_spec >> 16);
#endif
spec->size = SDL_NAME(arts_stream_get)(stream, ARTS_P_PACKET_SIZE);
spec->size = SDL_NAME(arts_stream_get) (stream, ARTS_P_PACKET_SIZE);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
if ( mixbuf == NULL ) {
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
if (mixbuf == NULL) {
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,22 +31,23 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The stream descriptor for the audio device */
arts_stream_t stream;
struct SDL_PrivateAudioData
{
/* The stream descriptor for the audio device */
arts_stream_t stream;
/* The parent process id, to detect when application quits */
pid_t parent;
/* The parent process id, to detect when application quits */
pid_t parent;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Support for audio timing using a timer, in addition to select() */
float frame_ticks;
float next_frame;
/* Support for audio timing using a timer, in addition to select() */
float frame_ticks;
float next_frame;
};
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
/* Old variable names */
#define stream (this->hidden->stream)
@ -57,4 +58,4 @@ struct SDL_PrivateAudioData {
#define next_frame (this->hidden->next_frame)
#endif /* _SDL_artscaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -27,7 +27,8 @@
#include "../../main/beos/SDL_BeApp.h"
extern "C" {
extern "C"
{
#include "SDL_audio.h"
#include "../SDL_audio_c.h"
@ -37,172 +38,177 @@ extern "C" {
/* Audio driver functions */
static int BE_OpenAudio(_THIS, SDL_AudioSpec *spec);
static void BE_WaitAudio(_THIS);
static void BE_PlayAudio(_THIS);
static Uint8 *BE_GetAudioBuf(_THIS);
static void BE_CloseAudio(_THIS);
static int BE_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void BE_WaitAudio(_THIS);
static void BE_PlayAudio(_THIS);
static Uint8 *BE_GetAudioBuf(_THIS);
static void BE_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int Audio_Available(void)
{
return(1);
}
static int Audio_Available(void)
{
return (1);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
{
SDL_free(device->hidden);
SDL_free(device);
}
static void Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *device;
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( device ) {
SDL_memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *device->hidden));
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
SDL_free(device);
}
return(0);
}
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
/* Initialize all variables that we clean on shutdown */
device = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (device) {
SDL_memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *device->hidden));
}
if ((device == NULL) || (device->hidden == NULL)) {
SDL_OutOfMemory();
if (device) {
SDL_free(device);
}
return (0);
}
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->OpenAudio = BE_OpenAudio;
device->WaitAudio = BE_WaitAudio;
device->PlayAudio = BE_PlayAudio;
device->GetAudioBuf = BE_GetAudioBuf;
device->CloseAudio = BE_CloseAudio;
/* Set the function pointers */
device->OpenAudio = BE_OpenAudio;
device->WaitAudio = BE_WaitAudio;
device->PlayAudio = BE_PlayAudio;
device->GetAudioBuf = BE_GetAudioBuf;
device->CloseAudio = BE_CloseAudio;
device->free = Audio_DeleteDevice;
device->free = Audio_DeleteDevice;
return device;
}
return device;
}
AudioBootStrap BAUDIO_bootstrap = {
"baudio", "BeOS BSoundPlayer",
Audio_Available, Audio_CreateDevice
};
AudioBootStrap BAUDIO_bootstrap = {
"baudio", "BeOS BSoundPlayer",
Audio_Available, Audio_CreateDevice
};
/* The BeOS callback for handling the audio buffer */
static void FillSound(void *device, void *stream, size_t len,
const media_raw_audio_format &format)
{
SDL_AudioDevice *audio = (SDL_AudioDevice *)device;
static void FillSound(void *device, void *stream, size_t len,
const media_raw_audio_format & format)
{
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
/* Silence the buffer, since it's ours */
SDL_memset(stream, audio->spec.silence, len);
/* Silence the buffer, since it's ours */
SDL_memset(stream, audio->spec.silence, len);
/* Only do soemthing if audio is enabled */
if ( ! audio->enabled )
return;
/* Only do soemthing if audio is enabled */
if (!audio->enabled)
return;
if ( ! audio->paused ) {
if ( audio->convert.needed ) {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback)(audio->spec.userdata,
(Uint8 *)audio->convert.buf,audio->convert.len);
SDL_mutexV(audio->mixer_lock);
SDL_ConvertAudio(&audio->convert);
SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
} else {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback)(audio->spec.userdata,
(Uint8 *)stream, len);
SDL_mutexV(audio->mixer_lock);
}
}
return;
}
if (!audio->paused) {
if (audio->convert.needed) {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) audio->convert.buf,
audio->convert.len);
SDL_mutexV(audio->mixer_lock);
SDL_ConvertAudio(&audio->convert);
SDL_memcpy(stream, audio->convert.buf,
audio->convert.len_cvt);
} else {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) stream, len);
SDL_mutexV(audio->mixer_lock);
}
}
return;
}
/* Dummy functions -- we don't use thread-based audio */
void BE_WaitAudio(_THIS)
{
return;
}
void BE_PlayAudio(_THIS)
{
return;
}
Uint8 *BE_GetAudioBuf(_THIS)
{
return(NULL);
}
void BE_WaitAudio(_THIS)
{
return;
}
void BE_PlayAudio(_THIS)
{
return;
}
Uint8 *BE_GetAudioBuf(_THIS)
{
return (NULL);
}
void BE_CloseAudio(_THIS)
{
if ( audio_obj ) {
audio_obj->Stop();
delete audio_obj;
audio_obj = NULL;
}
void BE_CloseAudio(_THIS)
{
if (audio_obj) {
audio_obj->Stop();
delete audio_obj;
audio_obj = NULL;
}
/* Quit the Be Application, if there's nothing left to do */
SDL_QuitBeApp();
}
/* Quit the Be Application, if there's nothing left to do */
SDL_QuitBeApp();
}
int BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
media_raw_audio_format format;
int BE_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
media_raw_audio_format format;
/* Initialize the Be Application, if it's not already started */
if ( SDL_InitBeApp() < 0 ) {
return(-1);
}
/* Initialize the Be Application, if it's not already started */
if (SDL_InitBeApp() < 0) {
return (-1);
}
/* Parse the audio format and fill the Be raw audio format */
format.frame_rate = (float)spec->freq;
format.channel_count = spec->channels;
switch (spec->format&~0x1000) {
case AUDIO_S8:
/* Signed 8-bit audio unsupported, convert to U8 */
spec->format = AUDIO_U8;
case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
format.byte_order = 0;
break;
case AUDIO_U16:
/* Unsigned 16-bit audio unsupported, convert to S16 */
spec->format ^= 0x8000;
case AUDIO_S16:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
if ( spec->format & 0x1000 ) {
format.byte_order = 1; /* Big endian */
} else {
format.byte_order = 2; /* Little endian */
}
break;
}
format.buffer_size = spec->samples;
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Parse the audio format and fill the Be raw audio format */
format.frame_rate = (float) spec->freq;
format.channel_count = spec->channels;
switch (spec->format & ~0x1000) {
case AUDIO_S8:
/* Signed 8-bit audio unsupported, convert to U8 */
spec->format = AUDIO_U8;
case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
format.byte_order = 0;
break;
case AUDIO_U16:
/* Unsigned 16-bit audio unsupported, convert to S16 */
spec->format ^= 0x8000;
case AUDIO_S16:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
if (spec->format & 0x1000) {
format.byte_order = 1; /* Big endian */
} else {
format.byte_order = 2; /* Little endian */
}
break;
}
format.buffer_size = spec->samples;
/* Subscribe to the audio stream (creates a new thread) */
{ sigset_t omask;
SDL_MaskSignals(&omask);
audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
NULL, _this);
SDL_UnmaskSignals(&omask);
}
if ( audio_obj->Start() == B_NO_ERROR ) {
audio_obj->SetHasData(true);
} else {
SDL_SetError("Unable to start Be audio");
return(-1);
}
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* We're running! */
return(1);
}
/* Subscribe to the audio stream (creates a new thread) */
{
sigset_t omask;
SDL_MaskSignals(&omask);
audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
NULL, _this);
SDL_UnmaskSignals(&omask);
}
if (audio_obj->Start() == B_NO_ERROR) {
audio_obj->SetHasData(true);
} else {
SDL_SetError("Unable to start Be audio");
return (-1);
}
}; /* Extern C */
/* We're running! */
return (1);
}
}; /* Extern C */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,11 +29,13 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *_this
struct SDL_PrivateAudioData {
BSoundPlayer *audio_obj;
struct SDL_PrivateAudioData
{
BSoundPlayer *audio_obj;
};
/* Old variable names */
#define audio_obj (_this->hidden->audio_obj)
#endif /* _SDL_lowaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -68,7 +68,7 @@
/* Audio driver functions */
static void OBSD_WaitAudio(_THIS);
static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void OBSD_PlayAudio(_THIS);
static Uint8 *OBSD_GetAudioBuf(_THIS);
static void OBSD_CloseAudio(_THIS);
@ -87,36 +87,37 @@ Audio_Available(void)
available = 0;
fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if(fd >= 0) {
available = 1;
close(fd);
if (fd >= 0) {
available = 1;
close(fd);
}
return(available);
return (available);
}
static void
Audio_DeleteDevice(SDL_AudioDevice *device)
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice
*Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
if(this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden =
(struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden));
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if(this) SDL_free(this);
return(0);
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this)
SDL_free(this);
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
@ -129,115 +130,116 @@ static SDL_AudioDevice
this->CloseAudio = OBSD_CloseAudio;
this->free = Audio_DeleteDevice;
return this;
}
AudioBootStrap BSD_AUDIO_bootstrap = {
BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
Audio_Available, Audio_CreateDevice
BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void
OBSD_WaitAudio(_THIS)
{
#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
/* See if we need to use timed audio synchronization */
if ( frame_ticks ) {
/* Use timer for general audio synchronization */
Sint32 ticks;
#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
/* See if we need to use timed audio synchronization */
if (frame_ticks) {
/* Use timer for general audio synchronization */
Sint32 ticks;
ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
if ( ticks > 0 ) {
SDL_Delay(ticks);
}
} else {
/* Use select() for audio synchronization */
fd_set fdset;
struct timeval timeout;
ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
if (ticks > 0) {
SDL_Delay(ticks);
}
} else {
/* Use select() for audio synchronization */
fd_set fdset;
struct timeval timeout;
FD_ZERO(&fdset);
FD_SET(audio_fd, &fdset);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(audio_fd, &fdset);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
#ifdef DEBUG_AUDIO
fprintf(stderr, "Waiting for audio to get ready\n");
fprintf(stderr, "Waiting for audio to get ready\n");
#endif
if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) {
const char *message =
"Audio timeout - buggy audio driver? (disabled)";
/* In general we should never print to the screen,
but in this case we have no other way of letting
the user know what happened.
*/
fprintf(stderr, "SDL: %s\n", message);
this->enabled = 0;
/* Don't try to close - may hang */
audio_fd = -1;
if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
const char *message =
"Audio timeout - buggy audio driver? (disabled)";
/* In general we should never print to the screen,
but in this case we have no other way of letting
the user know what happened.
*/
fprintf(stderr, "SDL: %s\n", message);
this->enabled = 0;
/* Don't try to close - may hang */
audio_fd = -1;
#ifdef DEBUG_AUDIO
fprintf(stderr, "Done disabling audio\n");
fprintf(stderr, "Done disabling audio\n");
#endif
}
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Ready!\n");
fprintf(stderr, "Ready!\n");
#endif
}
}
#endif /* !USE_BLOCKING_WRITES */
}
static void
OBSD_PlayAudio(_THIS)
{
int written, p=0;
int written, p = 0;
/* Write the audio data, checking for EAGAIN on broken audio drivers */
do {
written = write(audio_fd, &mixbuf[p], mixlen-p);
if (written>0)
p += written;
if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
{
/* Non recoverable error has occurred. It should be reported!!! */
perror("audio");
break;
}
/* Write the audio data, checking for EAGAIN on broken audio drivers */
do {
written = write(audio_fd, &mixbuf[p], mixlen - p);
if (written > 0)
p += written;
if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
/* Non recoverable error has occurred. It should be reported!!! */
perror("audio");
break;
}
if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
SDL_Delay(1); /* Let a little CPU time go by */
}
} while ( p < written );
if (p < written
|| ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while (p < written);
/* If timer synchronization is enabled, set the next write frame */
if ( frame_ticks ) {
next_frame += frame_ticks;
}
/* If timer synchronization is enabled, set the next write frame */
if (frame_ticks) {
next_frame += frame_ticks;
}
/* If we couldn't write, assume fatal error for now */
if ( written < 0 ) {
this->enabled = 0;
}
/* If we couldn't write, assume fatal error for now */
if (written < 0) {
this->enabled = 0;
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
#endif
}
static Uint8
*OBSD_GetAudioBuf(_THIS)
static Uint8 *
OBSD_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void
OBSD_CloseAudio(_THIS)
{
if(mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if(audio_fd >= 0) {
close(audio_fd);
audio_fd = -1;
if (audio_fd >= 0) {
close(audio_fd);
audio_fd = -1;
}
}
@ -247,66 +249,93 @@ OBSD_Status(_THIS)
{
audio_info_t info;
if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
fprintf(stderr,"AUDIO_GETINFO failed.\n");
return;
if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
fprintf(stderr, "AUDIO_GETINFO failed.\n");
return;
}
fprintf(stderr,"\n"
"[play/record info]\n"
"buffer size : %d bytes\n"
"sample rate : %i Hz\n"
"channels : %i\n"
"precision : %i-bit\n"
"encoding : 0x%x\n"
"seek : %i\n"
"sample count : %i\n"
"EOF count : %i\n"
"paused : %s\n"
"error occured : %s\n"
"waiting : %s\n"
"active : %s\n"
"",
info.play.buffer_size,
info.play.sample_rate,
info.play.channels,
info.play.precision,
info.play.encoding,
info.play.seek,
info.play.samples,
info.play.eof,
info.play.pause ? "yes" : "no",
info.play.error ? "yes" : "no",
info.play.waiting ? "yes" : "no",
info.play.active ? "yes": "no");
fprintf(stderr, "\n"
"[play/record info]\n"
"buffer size : %d bytes\n"
"sample rate : %i Hz\n"
"channels : %i\n"
"precision : %i-bit\n"
"encoding : 0x%x\n"
"seek : %i\n"
"sample count : %i\n"
"EOF count : %i\n"
"paused : %s\n"
"error occured : %s\n"
"waiting : %s\n"
"active : %s\n"
"",
info.
play.
buffer_size,
info.
play.
sample_rate,
info.
play.
channels,
info.
play.
precision,
info.
play.
encoding,
info.
play.
seek,
info.
play.
samples,
info.
play.
eof,
info.
play.
pause
?
"yes"
:
"no",
info.
play.
error
?
"yes"
:
"no",
info.
play.waiting ? "yes" : "no", info.play.active ? "yes" : "no");
fprintf(stderr,"\n"
"[audio info]\n"
"monitor_gain : %i\n"
"hw block size : %d bytes\n"
"hi watermark : %i\n"
"lo watermark : %i\n"
"audio mode : %s\n"
"",
info.monitor_gain,
info.blocksize,
info.hiwat, info.lowat,
(info.mode == AUMODE_PLAY) ? "PLAY"
: (info.mode = AUMODE_RECORD) ? "RECORD"
: (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL"
: "?"));
fprintf(stderr, "\n"
"[audio info]\n"
"monitor_gain : %i\n"
"hw block size : %d bytes\n"
"hi watermark : %i\n"
"lo watermark : %i\n"
"audio mode : %s\n"
"",
info.monitor_gain,
info.blocksize,
info.hiwat, info.lowat,
(info.mode == AUMODE_PLAY) ? "PLAY"
: (info.mode = AUMODE_RECORD) ? "RECORD"
: (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
}
#endif /* DEBUG_AUDIO */
static int
OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
char audiodev[64];
Uint16 format;
audio_info_t info;
AUDIO_INITINFO(&info);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
@ -316,58 +345,57 @@ OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if(audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return(-1);
}
/* Set to play mode */
info.mode = AUMODE_PLAY;
if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
SDL_SetError("Couldn't put device into play mode");
return(-1);
}
mixbuf = NULL;
AUDIO_INITINFO(&info);
for (format = SDL_FirstAudioFormat(spec->format);
format; format = SDL_NextAudioFormat())
{
switch(format) {
case AUDIO_U8:
info.play.encoding = AUDIO_ENCODING_ULINEAR;
info.play.precision = 8;
break;
case AUDIO_S8:
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 8;
break;
case AUDIO_S16LSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_S16MSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
info.play.precision = 16;
break;
case AUDIO_U16LSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_U16MSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
info.play.precision = 16;
break;
default:
continue;
}
if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
break;
if (audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return (-1);
}
if(!format) {
SDL_SetError("No supported encoding for 0x%x", spec->format);
return(-1);
/* Set to play mode */
info.mode = AUMODE_PLAY;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
SDL_SetError("Couldn't put device into play mode");
return (-1);
}
mixbuf = NULL;
AUDIO_INITINFO(&info);
for (format = SDL_FirstAudioFormat(spec->format);
format; format = SDL_NextAudioFormat()) {
switch (format) {
case AUDIO_U8:
info.play.encoding = AUDIO_ENCODING_ULINEAR;
info.play.precision = 8;
break;
case AUDIO_S8:
info.play.encoding = AUDIO_ENCODING_SLINEAR;
info.play.precision = 8;
break;
case AUDIO_S16LSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_S16MSB:
info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
info.play.precision = 16;
break;
case AUDIO_U16LSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
info.play.precision = 16;
break;
case AUDIO_U16MSB:
info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
info.play.precision = 16;
break;
default:
continue;
}
if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
break;
}
if (!format) {
SDL_SetError("No supported encoding for 0x%x", spec->format);
return (-1);
}
spec->format = format;
@ -375,23 +403,23 @@ OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
AUDIO_INITINFO(&info);
info.play.channels = spec->channels;
if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
spec->channels = 1;
spec->channels = 1;
AUDIO_INITINFO(&info);
info.play.sample_rate = spec->freq;
info.blocksize = spec->size;
info.hiwat = 5;
info.lowat = 3;
(void)ioctl(audio_fd, AUDIO_SETINFO, &info);
(void)ioctl(audio_fd, AUDIO_GETINFO, &info);
spec->freq = info.play.sample_rate;
(void) ioctl(audio_fd, AUDIO_SETINFO, &info);
(void) ioctl(audio_fd, AUDIO_GETINFO, &info);
spec->freq = info.play.sample_rate;
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen);
if(mixbuf == NULL) {
return(-1);
mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
if (mixbuf == NULL) {
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
@ -400,5 +428,7 @@ OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
#endif
/* We're ready to rock and roll. :-) */
return(0);
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -38,14 +38,14 @@ struct SDL_PrivateAudioData
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
int mixlen;
/* Support for audio timing using a timer, in addition to select() */
float frame_ticks;
float next_frame;
};
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
/* Old variable names */
#define audio_fd (this->hidden->audio_fd)
@ -56,3 +56,4 @@ struct SDL_PrivateAudioData
#define next_frame (this->hidden->next_frame)
#endif /* _SDL_openbsdaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -32,9 +32,10 @@
#define BUFFER_EMPTY 0
#define BUFFER_USED 1
typedef struct _tMixBufferDesc {
int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED
SDL_AudioDevice *pSDLAudioDevice;
typedef struct _tMixBufferDesc
{
int iBufferUsage; // BUFFER_EMPTY or BUFFER_USED
SDL_AudioDevice *pSDLAudioDevice;
} tMixBufferDesc, *pMixBufferDesc;
@ -44,70 +45,67 @@ typedef struct _tMixBufferDesc {
// This function is called by DART, when an event occures, like end of
// playback of a buffer, etc...
//---------------------------------------------------------------------
LONG APIENTRY DARTEventFunc(ULONG ulStatus,
PMCI_MIX_BUFFER pBuffer,
ULONG ulFlags)
LONG APIENTRY
DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
{
if (ulFlags && MIX_WRITE_COMPLETE)
{ // Playback of buffer completed!
if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed!
// Get pointer to buffer description
pMixBufferDesc pBufDesc;
// Get pointer to buffer description
pMixBufferDesc pBufDesc;
if (pBuffer)
{
pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
if (pBuffer) {
pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
if (pBufDesc)
{
SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
// Set the buffer to be empty
pBufDesc->iBufferUsage = BUFFER_EMPTY;
// And notify DART feeder thread that it will have to work a bit.
if (pSDLAudioDevice)
DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed);
}
if (pBufDesc) {
SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
// Set the buffer to be empty
pBufDesc->iBufferUsage = BUFFER_EMPTY;
// And notify DART feeder thread that it will have to work a bit.
if (pSDLAudioDevice)
DosPostEventSem(pSDLAudioDevice->hidden->
hevAudioBufferPlayed);
}
}
}
}
return TRUE;
return TRUE;
}
int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
int
DART_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
MCI_AMP_OPEN_PARMS AmpOpenParms;
MCI_GENERIC_PARMS GenericParms;
int iDeviceOrd = 0; // Default device to be used
int bOpenShared = 1; // Try opening it shared
int iBits = 16; // Default is 16 bits signed
int iFreq = 44100; // Default is 44KHz
int iChannels = 2; // Default is 2 channels (Stereo)
int iNumBufs = 2; // Number of audio buffers: 2
int iBufSize;
int iOpenMode;
int iSilence;
int rc;
MCI_AMP_OPEN_PARMS AmpOpenParms;
MCI_GENERIC_PARMS GenericParms;
int iDeviceOrd = 0; // Default device to be used
int bOpenShared = 1; // Try opening it shared
int iBits = 16; // Default is 16 bits signed
int iFreq = 44100; // Default is 44KHz
int iChannels = 2; // Default is 2 channels (Stereo)
int iNumBufs = 2; // Number of audio buffers: 2
int iBufSize;
int iOpenMode;
int iSilence;
int rc;
// First thing is to try to open a given DART device!
SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
// pszDeviceType should contain the device type in low word, and device ordinal in high word!
AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
// First thing is to try to open a given DART device!
SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
// pszDeviceType should contain the device type in low word, and device ordinal in high word!
AmpOpenParms.pszDeviceType =
(PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE;
iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
if (bOpenShared)
iOpenMode |= MCI_OPEN_SHAREABLE;
rc = mciSendCommand( 0, MCI_OPEN,
iOpenMode,
(PVOID) &AmpOpenParms, 0);
if (rc!=MCIERR_SUCCESS) // No audio available??
return (-1);
// Save the device ID we got from DART!
// We will use this in the next calls!
iDeviceOrd = AmpOpenParms.usDeviceID;
rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0);
if (rc != MCIERR_SUCCESS) // No audio available??
return (-1);
// Save the device ID we got from DART!
// We will use this in the next calls!
iDeviceOrd = AmpOpenParms.usDeviceID;
// Determine the audio parameters from the AudioSpec
switch ( spec->format & 0xFF )
{
// Determine the audio parameters from the AudioSpec
switch (spec->format & 0xFF) {
case 8:
/* Unsigned 8 bit audio data */
spec->format = AUDIO_U8;
@ -124,303 +122,333 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Unsupported audio format");
return(-1);
}
iFreq = spec->freq;
iChannels = spec->channels;
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
iBufSize = spec->size;
return (-1);
}
iFreq = spec->freq;
iChannels = spec->channels;
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
iBufSize = spec->size;
// Now query this device if it supports the given freq/bits/channels!
SDL_memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS));
_this->hidden->MixSetupParms.ulBitsPerSample = iBits;
_this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
_this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
_this->hidden->MixSetupParms.ulChannels = iChannels;
_this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
_this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
_this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&(_this->hidden->MixSetupParms), 0);
if (rc!=MCIERR_SUCCESS)
{ // The device cannot handle this format!
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Audio device doesn't support requested audio format");
return(-1);
}
// The device can handle this format, so initialize!
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_INIT,
&(_this->hidden->MixSetupParms), 0);
if (rc!=MCIERR_SUCCESS)
{ // The device could not be opened!
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Audio device could not be set up");
return(-1);
}
// Ok, the device is initialized.
// Now we should allocate buffers. For this, we need a place where
// the buffer descriptors will be:
_this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs);
if (!(_this->hidden->pMixBuffers))
{ // Not enough memory!
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Not enough memory for audio buffer descriptors");
return(-1);
}
// Now that we have the place for buffer list, we can ask DART for the
// buffers!
_this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers
_this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size
_this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
// Allocate buffers!
rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
MCI_WAIT | MCI_ALLOCATE_MEMORY,
&(_this->hidden->BufferParms), 0);
if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0))
{ // Could not allocate memory!
// Close DART, and exit with error code!
SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("DART could not allocate buffers");
return(-1);
}
// Ok, we have all the buffers allocated, let's mark them!
{
int i;
for (i=0; i<iNumBufs; i++)
{
pMixBufferDesc pBufferDesc = (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
// Check if this buffer was really allocated by DART
if ((!(_this->hidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc))
{ // Wrong buffer!
// Now query this device if it supports the given freq/bits/channels!
SDL_memset(&(_this->hidden->MixSetupParms), 0,
sizeof(MCI_MIXSETUP_PARMS));
_this->hidden->MixSetupParms.ulBitsPerSample = iBits;
_this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
_this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
_this->hidden->MixSetupParms.ulChannels = iChannels;
_this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
_this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
_this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&(_this->hidden->MixSetupParms), 0);
if (rc != MCIERR_SUCCESS) { // The device cannot handle this format!
// Close DART, and exit with error code!
// Free buffer descriptions
{ int j;
for (j=0; j<i; j++) SDL_free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
}
// and cleanup
mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Error at internal buffer check");
return(-1);
}
pBufferDesc->iBufferUsage = BUFFER_EMPTY;
pBufferDesc->pSDLAudioDevice = _this;
_this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize;
_this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
_this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
// audio data, but as we will continously send
// audio data, there will be no end.:)
SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
SDL_SetError("Audio device doesn't support requested audio format");
return (-1);
}
}
_this->hidden->iNextFreeBuffer = 0;
_this->hidden->iLastPlayedBuf = -1;
// Create event semaphore
if (DosCreateEventSem(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE)!=NO_ERROR)
{
// Could not create event semaphore!
// The device can handle this format, so initialize!
rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_INIT,
&(_this->hidden->MixSetupParms), 0);
if (rc != MCIERR_SUCCESS) { // The device could not be opened!
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Audio device could not be set up");
return (-1);
}
// Ok, the device is initialized.
// Now we should allocate buffers. For this, we need a place where
// the buffer descriptors will be:
_this->hidden->pMixBuffers =
(MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER) * iNumBufs);
if (!(_this->hidden->pMixBuffers)) { // Not enough memory!
// Close DART, and exit with error code!
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Not enough memory for audio buffer descriptors");
return (-1);
}
// Now that we have the place for buffer list, we can ask DART for the
// buffers!
_this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers
_this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size
_this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
// Allocate buffers!
rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
MCI_WAIT | MCI_ALLOCATE_MEMORY,
&(_this->hidden->BufferParms), 0);
if ((rc != MCIERR_SUCCESS)
|| (iNumBufs != _this->hidden->BufferParms.ulNumBuffers)
|| (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory!
// Close DART, and exit with error code!
SDL_free(_this->hidden->pMixBuffers);
_this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("DART could not allocate buffers");
return (-1);
}
// Ok, we have all the buffers allocated, let's mark them!
{
int i;
for (i=0; i<iNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
int i;
for (i = 0; i < iNumBufs; i++) {
pMixBufferDesc pBufferDesc =
(pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
// Check if this buffer was really allocated by DART
if ((!(_this->hidden->pMixBuffers[i].pBuffer))
|| (!pBufferDesc)) { // Wrong buffer!
// Close DART, and exit with error code!
// Free buffer descriptions
{
int j;
for (j = 0; j < i; j++)
SDL_free((void *) (_this->hidden->pMixBuffers[j].
ulUserParm));
}
// and cleanup
mciSendCommand(iDeviceOrd, MCI_BUFFER,
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
&(_this->hidden->BufferParms), 0);
SDL_free(_this->hidden->pMixBuffers);
_this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT,
&GenericParms, 0);
SDL_SetError("Error at internal buffer check");
return (-1);
}
pBufferDesc->iBufferUsage = BUFFER_EMPTY;
pBufferDesc->pSDLAudioDevice = _this;
_this->hidden->pMixBuffers[i].ulBufferLength =
_this->hidden->BufferParms.ulBufferSize;
_this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
_this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
// audio data, but as we will continously send
// audio data, there will be no end.:)
SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence,
iBufSize);
}
}
mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Could not create event semaphore");
return(-1);
}
_this->hidden->iNextFreeBuffer = 0;
_this->hidden->iLastPlayedBuf = -1;
// Create event semaphore
if (DosCreateEventSem
(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE) != NO_ERROR)
{
// Could not create event semaphore!
{
int i;
for (i = 0; i < iNumBufs; i++)
SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
}
mciSendCommand(iDeviceOrd, MCI_BUFFER,
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
&(_this->hidden->BufferParms), 0);
SDL_free(_this->hidden->pMixBuffers);
_this->hidden->pMixBuffers = NULL;
mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
SDL_SetError("Could not create event semaphore");
return (-1);
}
// Store the new settings in global variables
_this->hidden->iCurrDeviceOrd = iDeviceOrd;
_this->hidden->iCurrFreq = iFreq;
_this->hidden->iCurrBits = iBits;
_this->hidden->iCurrChannels = iChannels;
_this->hidden->iCurrNumBufs = iNumBufs;
_this->hidden->iCurrBufSize = iBufSize;
// Store the new settings in global variables
_this->hidden->iCurrDeviceOrd = iDeviceOrd;
_this->hidden->iCurrFreq = iFreq;
_this->hidden->iCurrBits = iBits;
_this->hidden->iCurrChannels = iChannels;
_this->hidden->iCurrNumBufs = iNumBufs;
_this->hidden->iCurrBufSize = iBufSize;
return (0);
return (0);
}
void DART_ThreadInit(_THIS)
void
DART_ThreadInit(_THIS)
{
return;
return;
}
/* This function waits until it is possible to write a full sound buffer */
void DART_WaitAudio(_THIS)
void
DART_WaitAudio(_THIS)
{
int i;
pMixBufferDesc pBufDesc;
ULONG ulPostCount;
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
// If there is already an empty buffer, then return now!
for (i=0; i<_this->hidden->iCurrNumBufs; i++)
{
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
return;
}
// If there is no empty buffer, wait for one to be empty!
DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
return;
}
void DART_PlayAudio(_THIS)
{
int iFreeBuf = _this->hidden->iNextFreeBuffer;
pMixBufferDesc pBufDesc;
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
pBufDesc->iBufferUsage = BUFFER_USED;
// Send it to DART to be queued
_this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.ulMixHandle,
&(_this->hidden->pMixBuffers[iFreeBuf]), 1);
_this->hidden->iLastPlayedBuf = iFreeBuf;
iFreeBuf = (iFreeBuf+1) % _this->hidden->iCurrNumBufs;
_this->hidden->iNextFreeBuffer = iFreeBuf;
}
Uint8 *DART_GetAudioBuf(_THIS)
{
int iFreeBuf;
Uint8 *pResult;
pMixBufferDesc pBufDesc;
if (_this)
{
if (_this->hidden)
{
iFreeBuf = _this->hidden->iNextFreeBuffer;
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
if (pBufDesc)
{
if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
{
pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
return pResult;
}
} else
printf("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n", pBufDesc);
} else
printf("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n", _this->hidden);
} else
printf("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this);
return NULL;
}
void DART_WaitDone(_THIS)
{
pMixBufferDesc pBufDesc;
ULONG ulPostCount;
APIRET rc;
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm;
rc = NO_ERROR;
while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc==NO_ERROR))
{
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
}
}
void DART_CloseAudio(_THIS)
{
MCI_GENERIC_PARMS GenericParms;
int rc;
// Stop DART playback
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT, &GenericParms, 0);
if (rc!=MCIERR_SUCCESS)
{
#ifdef SFX_DEBUG_BUILD
printf("Could not stop DART playback!\n");
fflush(stdout);
#endif
}
// Close event semaphore
DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
// Free memory of buffer descriptions
{
int i;
for (i=0; i<_this->hidden->iCurrNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
}
pMixBufferDesc pBufDesc;
ULONG ulPostCount;
// Deallocate buffers
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
// If there is already an empty buffer, then return now!
for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
return;
}
// If there is no empty buffer, wait for one to be empty!
DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
return;
}
// Free bufferlist
SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
void
DART_PlayAudio(_THIS)
{
int iFreeBuf = _this->hidden->iNextFreeBuffer;
pMixBufferDesc pBufDesc;
// Close dart
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, &(GenericParms), 0);
pBufDesc =
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
pBufDesc->iBufferUsage = BUFFER_USED;
// Send it to DART to be queued
_this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
ulMixHandle,
&(_this->hidden->
pMixBuffers[iFreeBuf]), 1);
_this->hidden->iLastPlayedBuf = iFreeBuf;
iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
_this->hidden->iNextFreeBuffer = iFreeBuf;
}
Uint8 *
DART_GetAudioBuf(_THIS)
{
int iFreeBuf;
Uint8 *pResult;
pMixBufferDesc pBufDesc;
if (_this) {
if (_this->hidden) {
iFreeBuf = _this->hidden->iNextFreeBuffer;
pBufDesc =
(pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].
ulUserParm;
if (pBufDesc) {
if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
return pResult;
}
} else
printf("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n",
pBufDesc);
} else
printf("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n",
_this->hidden);
} else
printf("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this);
return NULL;
}
void
DART_WaitDone(_THIS)
{
pMixBufferDesc pBufDesc;
ULONG ulPostCount;
APIRET rc;
pBufDesc =
(pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden->
iLastPlayedBuf].
ulUserParm;
rc = NO_ERROR;
while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) {
DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
}
}
void
DART_CloseAudio(_THIS)
{
MCI_GENERIC_PARMS GenericParms;
int rc;
// Stop DART playback
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT,
&GenericParms, 0);
if (rc != MCIERR_SUCCESS) {
#ifdef SFX_DEBUG_BUILD
printf("Could not stop DART playback!\n");
fflush(stdout);
#endif
}
// Close event semaphore
DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
// Free memory of buffer descriptions
{
int i;
for (i = 0; i < _this->hidden->iCurrNumBufs; i++)
SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
}
// Deallocate buffers
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER,
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
&(_this->hidden->BufferParms), 0);
// Free bufferlist
SDL_free(_this->hidden->pMixBuffers);
_this->hidden->pMixBuffers = NULL;
// Close dart
rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT,
&(GenericParms), 0);
}
/* Audio driver bootstrap functions */
int Audio_Available(void)
int
Audio_Available(void)
{
return(1);
return (1);
}
void Audio_DeleteDevice(SDL_AudioDevice *device)
void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
SDL_AudioDevice *Audio_CreateDevice(int devindex)
SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this )
{
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) )
{
SDL_OutOfMemory();
if ( this )
SDL_free(this);
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this)
SDL_free(this);
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = DART_OpenAudio;
this->ThreadInit = DART_ThreadInit;
this->WaitAudio = DART_WaitAudio;
this->PlayAudio = DART_PlayAudio;
this->GetAudioBuf = DART_GetAudioBuf;
this->WaitDone = DART_WaitDone;
this->CloseAudio = DART_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DART_OpenAudio;
this->ThreadInit = DART_ThreadInit;
this->WaitAudio = DART_WaitAudio;
this->PlayAudio = DART_PlayAudio;
this->GetAudioBuf = DART_GetAudioBuf;
this->WaitDone = DART_WaitDone;
this->CloseAudio = DART_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap DART_bootstrap = {
"dart", "OS/2 Direct Audio RouTines (DART)",
Audio_Available, Audio_CreateDevice
"dart", "OS/2 Direct Audio RouTines (DART)",
Audio_Available, Audio_CreateDevice
};
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -34,7 +34,7 @@
#define INCL_MMIOOS2
#define INCL_MCIOS2
#include <os2.h>
#include <os2me.h> // DART stuff and MMIO stuff
#include <os2me.h> // DART stuff and MMIO stuff
#include "../SDL_sysaudio.h"
@ -44,20 +44,21 @@
/* The DirectSound objects */
struct SDL_PrivateAudioData
{
int iCurrDeviceOrd;
int iCurrFreq;
int iCurrBits;
int iCurrChannels;
int iCurrNumBufs;
int iCurrBufSize;
int iCurrDeviceOrd;
int iCurrFreq;
int iCurrBits;
int iCurrChannels;
int iCurrNumBufs;
int iCurrBufSize;
int iLastPlayedBuf;
int iNextFreeBuffer;
int iLastPlayedBuf;
int iNextFreeBuffer;
MCI_BUFFER_PARMS BufferParms; // Sound buffer parameters
MCI_MIX_BUFFER *pMixBuffers; // Sound buffers
MCI_MIXSETUP_PARMS MixSetupParms; // Mixer setup parameters
HEV hevAudioBufferPlayed; // Event semaphore to indicate that an audio buffer has been played by DART
MCI_BUFFER_PARMS BufferParms; // Sound buffer parameters
MCI_MIX_BUFFER *pMixBuffers; // Sound buffers
MCI_MIXSETUP_PARMS MixSetupParms; // Mixer setup parameters
HEV hevAudioBufferPlayed; // Event semaphore to indicate that an audio buffer has been played by DART
};
#endif /* _SDL_lowaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -35,195 +35,220 @@
#include <dc/spu.h>
/* Audio driver functions */
static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void DCAUD_WaitAudio(_THIS);
static void DCAUD_PlayAudio(_THIS);
static Uint8 *DCAUD_GetAudioBuf(_THIS);
static void DCAUD_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int DCAUD_Available(void)
static int
DCAUD_Available(void)
{
return 1;
return 1;
}
static void DCAUD_DeleteDevice(SDL_AudioDevice *device)
static void
DCAUD_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *DCAUD_CreateDevice(int devindex)
static SDL_AudioDevice *
DCAUD_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = DCAUD_OpenAudio;
this->WaitAudio = DCAUD_WaitAudio;
this->PlayAudio = DCAUD_PlayAudio;
this->GetAudioBuf = DCAUD_GetAudioBuf;
this->CloseAudio = DCAUD_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DCAUD_OpenAudio;
this->WaitAudio = DCAUD_WaitAudio;
this->PlayAudio = DCAUD_PlayAudio;
this->GetAudioBuf = DCAUD_GetAudioBuf;
this->CloseAudio = DCAUD_CloseAudio;
this->free = DCAUD_DeleteDevice;
this->free = DCAUD_DeleteDevice;
spu_init();
spu_init();
return this;
return this;
}
AudioBootStrap DCAUD_bootstrap = {
"dcaudio", "Dreamcast AICA audio",
DCAUD_Available, DCAUD_CreateDevice
"dcaudio", "Dreamcast AICA audio",
DCAUD_Available, DCAUD_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void DCAUD_WaitAudio(_THIS)
static void
DCAUD_WaitAudio(_THIS)
{
if (this->hidden->playing) {
/* wait */
while(aica_get_pos(0)/this->spec.samples == this->hidden->nextbuf) {
thd_pass();
}
}
if (this->hidden->playing) {
/* wait */
while (aica_get_pos(0) / this->spec.samples == this->hidden->nextbuf) {
thd_pass();
}
}
}
#define SPU_RAM_BASE 0xa0800000
static void spu_memload_stereo8(int leftpos,int rightpos,void *src0,size_t size)
static void
spu_memload_stereo8(int leftpos, int rightpos, void *src0, size_t size)
{
uint8 *src = src0;
uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE);
uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
size = (size+7)/8;
while(size--) {
unsigned lval,rval;
lval = *src++;
rval = *src++;
lval|= (*src++)<<8;
rval|= (*src++)<<8;
lval|= (*src++)<<16;
rval|= (*src++)<<16;
lval|= (*src++)<<24;
rval|= (*src++)<<24;
g2_write_32(left++,lval);
g2_write_32(right++,rval);
g2_fifo_wait();
}
uint8 *src = src0;
uint32 *left = (uint32 *) (leftpos + SPU_RAM_BASE);
uint32 *right = (uint32 *) (rightpos + SPU_RAM_BASE);
size = (size + 7) / 8;
while (size--) {
unsigned lval, rval;
lval = *src++;
rval = *src++;
lval |= (*src++) << 8;
rval |= (*src++) << 8;
lval |= (*src++) << 16;
rval |= (*src++) << 16;
lval |= (*src++) << 24;
rval |= (*src++) << 24;
g2_write_32(left++, lval);
g2_write_32(right++, rval);
g2_fifo_wait();
}
}
static void spu_memload_stereo16(int leftpos,int rightpos,void *src0,size_t size)
static void
spu_memload_stereo16(int leftpos, int rightpos, void *src0, size_t size)
{
uint16 *src = src0;
uint32 *left = (uint32*)(leftpos +SPU_RAM_BASE);
uint32 *right = (uint32*)(rightpos+SPU_RAM_BASE);
size = (size+7)/8;
while(size--) {
unsigned lval,rval;
lval = *src++;
rval = *src++;
lval|= (*src++)<<16;
rval|= (*src++)<<16;
g2_write_32(left++,lval);
g2_write_32(right++,rval);
g2_fifo_wait();
}
uint16 *src = src0;
uint32 *left = (uint32 *) (leftpos + SPU_RAM_BASE);
uint32 *right = (uint32 *) (rightpos + SPU_RAM_BASE);
size = (size + 7) / 8;
while (size--) {
unsigned lval, rval;
lval = *src++;
rval = *src++;
lval |= (*src++) << 16;
rval |= (*src++) << 16;
g2_write_32(left++, lval);
g2_write_32(right++, rval);
g2_fifo_wait();
}
}
static void DCAUD_PlayAudio(_THIS)
static void
DCAUD_PlayAudio(_THIS)
{
SDL_AudioSpec *spec = &this->spec;
unsigned int offset;
SDL_AudioSpec *spec = &this->spec;
unsigned int offset;
if (this->hidden->playing) {
/* wait */
while(aica_get_pos(0)/spec->samples == this->hidden->nextbuf) {
thd_pass();
}
}
if (this->hidden->playing) {
/* wait */
while (aica_get_pos(0) / spec->samples == this->hidden->nextbuf) {
thd_pass();
}
}
offset = this->hidden->nextbuf*spec->size;
this->hidden->nextbuf^=1;
/* Write the audio data, checking for EAGAIN on broken audio drivers */
if (spec->channels==1) {
spu_memload(this->hidden->leftpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
} else {
offset/=2;
if ((this->spec.format&255)==8) {
spu_memload_stereo8(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
} else {
spu_memload_stereo16(this->hidden->leftpos+offset,this->hidden->rightpos+offset,this->hidden->mixbuf,this->hidden->mixlen);
}
}
offset = this->hidden->nextbuf * spec->size;
this->hidden->nextbuf ^= 1;
/* Write the audio data, checking for EAGAIN on broken audio drivers */
if (spec->channels == 1) {
spu_memload(this->hidden->leftpos + offset, this->hidden->mixbuf,
this->hidden->mixlen);
} else {
offset /= 2;
if ((this->spec.format & 255) == 8) {
spu_memload_stereo8(this->hidden->leftpos + offset,
this->hidden->rightpos + offset,
this->hidden->mixbuf, this->hidden->mixlen);
} else {
spu_memload_stereo16(this->hidden->leftpos + offset,
this->hidden->rightpos + offset,
this->hidden->mixbuf, this->hidden->mixlen);
}
}
if (!this->hidden->playing) {
int mode;
this->hidden->playing = 1;
mode = (spec->format==AUDIO_S8)?SM_8BIT:SM_16BIT;
if (spec->channels==1) {
aica_play(0,mode,this->hidden->leftpos,0,spec->samples*2,spec->freq,255,128,1);
} else {
aica_play(0,mode,this->hidden->leftpos ,0,spec->samples*2,spec->freq,255,0,1);
aica_play(1,mode,this->hidden->rightpos,0,spec->samples*2,spec->freq,255,255,1);
}
}
if (!this->hidden->playing) {
int mode;
this->hidden->playing = 1;
mode = (spec->format == AUDIO_S8) ? SM_8BIT : SM_16BIT;
if (spec->channels == 1) {
aica_play(0, mode, this->hidden->leftpos, 0,
spec->samples * 2, spec->freq, 255, 128, 1);
} else {
aica_play(0, mode, this->hidden->leftpos, 0,
spec->samples * 2, spec->freq, 255, 0, 1);
aica_play(1, mode, this->hidden->rightpos, 0,
spec->samples * 2, spec->freq, 255, 255, 1);
}
}
}
static Uint8 *DCAUD_GetAudioBuf(_THIS)
static Uint8 *
DCAUD_GetAudioBuf(_THIS)
{
return(this->hidden->mixbuf);
return (this->hidden->mixbuf);
}
static void DCAUD_CloseAudio(_THIS)
static void
DCAUD_CloseAudio(_THIS)
{
aica_stop(0);
if (this->spec.channels==2) aica_stop(1);
if ( this->hidden->mixbuf != NULL ) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
aica_stop(0);
if (this->spec.channels == 2)
aica_stop(1);
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
}
static int DCAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
DCAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
switch(spec->format&0xff) {
case 8: spec->format = AUDIO_S8; break;
case 16: spec->format = AUDIO_S16LSB; break;
default:
SDL_SetError("Unsupported audio format");
return(-1);
}
switch (spec->format & 0xff) {
case 8:
spec->format = AUDIO_S8;
break;
case 16:
spec->format = AUDIO_S16LSB;
break;
default:
SDL_SetError("Unsupported audio format");
return (-1);
}
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if ( this->hidden->mixbuf == NULL ) {
return(-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
this->hidden->leftpos = 0x11000;
this->hidden->rightpos = 0x11000+spec->size;
this->hidden->playing = 0;
this->hidden->nextbuf = 0;
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
return (-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
this->hidden->leftpos = 0x11000;
this->hidden->rightpos = 0x11000 + spec->size;
this->hidden->playing = 0;
this->hidden->nextbuf = 0;
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,13 +29,15 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
Uint8 *mixbuf;
Uint32 mixlen;
int playing;
int leftpos,rightpos;
int nextbuf;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
Uint8 *mixbuf;
Uint32 mixlen;
int playing;
int leftpos, rightpos;
int nextbuf;
};
#endif /* _SDL_dcaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -9,8 +9,10 @@
#include <arch/irq.h>
#include <dc/spu.h>
/* #define dc_snd_base ((volatile unsigned char *)0x00800000) */ /* arm side */
#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */
#if 0
#define dc_snd_base ((volatile unsigned char *)0x00800000) /* arm side */
#endif
#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */
/* Some convienence macros */
#define SNDREGADDR(x) (0xa0700000 + (x))
@ -39,26 +41,29 @@
} while(0)
void aica_init() {
int i, j, old = 0;
/* Initialize AICA channels */
G2_LOCK(old);
SNDREG32(0x2800) = 0x0000;
for (i=0; i<64; i++) {
for (j=0; j<0x80; j+=4) {
if ((j&31)==0) g2_fifo_wait();
CHNREG32(i, j) = 0;
}
g2_fifo_wait();
CHNREG32(i,0) = 0x8000;
CHNREG32(i,20) = 0x1f;
}
void
aica_init()
{
int i, j, old = 0;
SNDREG32(0x2800) = 0x000f;
g2_fifo_wait();
G2_UNLOCK(old);
/* Initialize AICA channels */
G2_LOCK(old);
SNDREG32(0x2800) = 0x0000;
for (i = 0; i < 64; i++) {
for (j = 0; j < 0x80; j += 4) {
if ((j & 31) == 0)
g2_fifo_wait();
CHNREG32(i, j) = 0;
}
g2_fifo_wait();
CHNREG32(i, 0) = 0x8000;
CHNREG32(i, 20) = 0x1f;
}
SNDREG32(0x2800) = 0x000f;
g2_fifo_wait();
G2_UNLOCK(old);
}
/* Translates a volume from linear form to logarithmic form (required by
@ -86,25 +91,25 @@ void aica_init() {
}; */
const static unsigned char logs[] = {
0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61,
63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88,
90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106,
108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146,
146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156,
157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167,
167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176,
177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185,
186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194,
195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202,
203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210,
211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218,
219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225,
226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233,
233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240,
240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246,
247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255
0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61,
63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88,
90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106,
108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146,
146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156,
157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167,
167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176,
177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185,
186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194,
195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202,
203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210,
211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218,
219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225,
226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233,
233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240,
240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246,
247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255
};
/* For the moment this is going to have to suffice, until we really
@ -113,23 +118,25 @@ const static unsigned char logs[] = {
#define AICA_VOL(x) (0xff - logs[128 + (((x) & 0xff) / 2)])
//#define AICA_VOL(x) (0xff - logs[x&255])
static inline unsigned AICA_FREQ(unsigned freq) {
unsigned long freq_lo, freq_base = 5644800;
int freq_hi = 7;
static inline unsigned
AICA_FREQ(unsigned freq)
{
unsigned long freq_lo, freq_base = 5644800;
int freq_hi = 7;
/* Need to convert frequency to floating point format
(freq_hi is exponent, freq_lo is mantissa)
Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */
while (freq < freq_base && freq_hi > -8) {
freq_base >>= 1;
--freq_hi;
}
while (freq < freq_base && freq_hi > -8) {
freq_base >>= 1;
freq_hi--;
}
freq_lo = (freq<<10) / freq_base;
return (freq_hi << 11) | (freq_lo & 1023);
/* Need to convert frequency to floating point format
(freq_hi is exponent, freq_lo is mantissa)
Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */
while (freq < freq_base && freq_hi > -8) {
freq_base >>= 1;
--freq_hi;
}
while (freq < freq_base && freq_hi > -8) {
freq_base >>= 1;
freq_hi--;
}
freq_lo = (freq << 10) / freq_base;
return (freq_hi << 11) | (freq_lo & 1023);
}
/* Sets up a sound channel completely. This is generally good if you want
@ -148,15 +155,18 @@ static inline unsigned AICA_FREQ(unsigned freq) {
This routine (and the similar ones) owe a lot to Marcus' sound example --
I hadn't gotten quite this far into dissecting the individual regs yet. */
void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int freq,int vol,int pan,int loopflag) {
void
aica_play(int ch, int mode, unsigned long smpptr, int loopst, int loopend,
int freq, int vol, int pan, int loopflag)
{
/* int i;
*/
int val;
int old = 0;
int val;
int old = 0;
/* Stop the channel (if it's already playing) */
aica_stop(ch);
/* doesn't seem to be needed, but it's here just in case */
/* Stop the channel (if it's already playing) */
aica_stop(ch);
/* doesn't seem to be needed, but it's here just in case */
/*
for (i=0; i<256; i++) {
asm("nop");
@ -165,107 +175,127 @@ void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int f
asm("nop");
}
*/
G2_LOCK(old);
/* Envelope setup. The first of these is the loop point,
e.g., where the sample starts over when it loops. The second
is the loop end. This is the full length of the sample when
you are not looping, or the loop end point when you are (though
storing more than that is a waste of memory if you're not doing
volume enveloping). */
CHNREG32(ch, 8) = loopst & 0xffff;
CHNREG32(ch, 12) = loopend & 0xffff;
/* Write resulting values */
CHNREG32(ch, 24) = AICA_FREQ(freq);
/* Set volume, pan, and some other things that we don't know what
they do =) */
CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf<<8);
/* Convert the incoming volume and pan into hardware values */
/* Vol starts at zero so we can ramp */
vol = AICA_VOL(vol);
CHNREG32(ch, 40) = 0x24 | (vol<<8);
/* Convert the incoming volume and pan into hardware values */
/* Vol starts at zero so we can ramp */
G2_LOCK(old);
/* Envelope setup. The first of these is the loop point,
e.g., where the sample starts over when it loops. The second
is the loop end. This is the full length of the sample when
you are not looping, or the loop end point when you are (though
storing more than that is a waste of memory if you're not doing
volume enveloping). */
CHNREG32(ch, 8) = loopst & 0xffff;
CHNREG32(ch, 12) = loopend & 0xffff;
/* If we supported volume envelopes (which we don't yet) then
this value would set that up. The top 4 bits determine the
envelope speed. f is the fastest, 1 is the slowest, and 0
seems to be an invalid value and does weird things). The
default (below) sets it into normal mode (play and terminate/loop).
CHNREG32(ch, 16) = 0xf010;
*/
CHNREG32(ch, 16) = 0x1f; /* No volume envelope */
/* Set sample format, buffer address, and looping control. If
0x0200 mask is set on reg 0, the sample loops infinitely. If
it's not set, the sample plays once and terminates. We'll
also set the bits to start playback here. */
CHNREG32(ch, 4) = smpptr & 0xffff;
val = 0xc000 | 0x0000 | (mode<<7) | (smpptr >> 16);
if (loopflag) val|=0x200;
CHNREG32(ch, 0) = val;
G2_UNLOCK(old);
/* Write resulting values */
CHNREG32(ch, 24) = AICA_FREQ(freq);
/* Enable playback */
/* CHNREG32(ch, 0) |= 0xc000; */
g2_fifo_wait();
/* Set volume, pan, and some other things that we don't know what
they do =) */
CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf << 8);
/* Convert the incoming volume and pan into hardware values */
/* Vol starts at zero so we can ramp */
vol = AICA_VOL(vol);
CHNREG32(ch, 40) = 0x24 | (vol << 8);
/* Convert the incoming volume and pan into hardware values */
/* Vol starts at zero so we can ramp */
/* If we supported volume envelopes (which we don't yet) then
this value would set that up. The top 4 bits determine the
envelope speed. f is the fastest, 1 is the slowest, and 0
seems to be an invalid value and does weird things). The
default (below) sets it into normal mode (play and terminate/loop).
CHNREG32(ch, 16) = 0xf010;
*/
CHNREG32(ch, 16) = 0x1f; /* No volume envelope */
/* Set sample format, buffer address, and looping control. If
0x0200 mask is set on reg 0, the sample loops infinitely. If
it's not set, the sample plays once and terminates. We'll
also set the bits to start playback here. */
CHNREG32(ch, 4) = smpptr & 0xffff;
val = 0xc000 | 0x0000 | (mode << 7) | (smpptr >> 16);
if (loopflag)
val |= 0x200;
CHNREG32(ch, 0) = val;
G2_UNLOCK(old);
/* Enable playback */
/* CHNREG32(ch, 0) |= 0xc000; */
g2_fifo_wait();
#if 0
for (i=0xff; i>=vol; i--) {
if ((i&7)==0) g2_fifo_wait();
CHNREG32(ch, 40) = 0x24 | (i<<8);;
}
for (i = 0xff; i >= vol; i--) {
if ((i & 7) == 0)
g2_fifo_wait();
CHNREG32(ch, 40) = 0x24 | (i << 8);;
}
g2_fifo_wait();
g2_fifo_wait();
#endif
}
/* Stop the sound on a given channel */
void aica_stop(int ch) {
g2_write_32(CHNREGADDR(ch, 0),(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000);
g2_fifo_wait();
void
aica_stop(int ch)
{
g2_write_32(CHNREGADDR(ch, 0),
(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000);
g2_fifo_wait();
}
/* The rest of these routines can change the channel in mid-stride so you
can do things like vibrato and panning effects. */
/* Set channel volume */
void aica_vol(int ch,int vol) {
// g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol));
g2_write_32(CHNREGADDR(ch, 40),(g2_read_32(CHNREGADDR(ch, 40))&0xffff00ff)|(AICA_VOL(vol)<<8) );
g2_fifo_wait();
void
aica_vol(int ch, int vol)
{
// g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol));
g2_write_32(CHNREGADDR(ch, 40),
(g2_read_32(CHNREGADDR(ch, 40)) & 0xffff00ff) |
(AICA_VOL(vol) << 8));
g2_fifo_wait();
}
/* Set channel pan */
void aica_pan(int ch,int pan) {
// g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan));
g2_write_32(CHNREGADDR(ch, 36),(g2_read_32(CHNREGADDR(ch, 36))&0xffffff00)|(AICA_PAN(pan)) );
g2_fifo_wait();
void
aica_pan(int ch, int pan)
{
// g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan));
g2_write_32(CHNREGADDR(ch, 36),
(g2_read_32(CHNREGADDR(ch, 36)) & 0xffffff00) |
(AICA_PAN(pan)));
g2_fifo_wait();
}
/* Set channel frequency */
void aica_freq(int ch,int freq) {
g2_write_32(CHNREGADDR(ch, 24),AICA_FREQ(freq));
g2_fifo_wait();
void
aica_freq(int ch, int freq)
{
g2_write_32(CHNREGADDR(ch, 24), AICA_FREQ(freq));
g2_fifo_wait();
}
/* Get channel position */
int aica_get_pos(int ch) {
int
aica_get_pos(int ch)
{
#if 1
/* Observe channel ch */
g2_write_32(SNDREGADDR(0x280c),(g2_read_32(SNDREGADDR(0x280c))&0xffff00ff) | (ch<<8));
g2_fifo_wait();
/* Update position counters */
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
/* Observe channel ch */
g2_write_32(SNDREGADDR(0x280c),
(g2_read_32(SNDREGADDR(0x280c)) & 0xffff00ff) | (ch << 8));
g2_fifo_wait();
/* Update position counters */
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
#else
/* Observe channel ch */
g2_write_8(SNDREGADDR(0x280d),ch);
/* Update position counters */
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
/* Observe channel ch */
g2_write_8(SNDREGADDR(0x280d), ch);
/* Update position counters */
return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
#endif
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -30,11 +30,13 @@
#define SM_16BIT 0
#define SM_ADPCM 2
void aica_play(int ch,int mode,unsigned long smpptr,int looptst,int loopend,int freq,int vol,int pan,int loopflag);
void aica_play(int ch, int mode, unsigned long smpptr, int looptst,
int loopend, int freq, int vol, int pan, int loopflag);
void aica_stop(int ch);
void aica_vol(int ch,int vol);
void aica_pan(int ch,int pan);
void aica_freq(int ch,int freq);
void aica_vol(int ch, int vol);
void aica_pan(int ch, int pan);
void aica_freq(int ch, int freq);
int aica_get_pos(int ch);
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -47,140 +47,149 @@
#define DISKDEFAULT_WRITEDELAY 150
/* Audio driver functions */
static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void DISKAUD_WaitAudio(_THIS);
static void DISKAUD_PlayAudio(_THIS);
static Uint8 *DISKAUD_GetAudioBuf(_THIS);
static void DISKAUD_CloseAudio(_THIS);
static const char *DISKAUD_GetOutputFilename(void)
static const char *
DISKAUD_GetOutputFilename(void)
{
const char *envr = SDL_getenv(DISKENVR_OUTFILE);
return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
const char *envr = SDL_getenv(DISKENVR_OUTFILE);
return ((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
}
/* Audio driver bootstrap functions */
static int DISKAUD_Available(void)
static int
DISKAUD_Available(void)
{
const char *envr = SDL_getenv("SDL_AUDIODRIVER");
if (envr && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
return(1);
}
return(0);
const char *envr = SDL_getenv("SDL_AUDIODRIVER");
if (envr && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
return (1);
}
return (0);
}
static void DISKAUD_DeleteDevice(SDL_AudioDevice *device)
static void
DISKAUD_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *DISKAUD_CreateDevice(int devindex)
static SDL_AudioDevice *
DISKAUD_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
const char *envr;
SDL_AudioDevice *this;
const char *envr;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
envr = SDL_getenv(DISKENVR_WRITEDELAY);
this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
envr = SDL_getenv(DISKENVR_WRITEDELAY);
this->hidden->write_delay =
(envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;
/* Set the function pointers */
this->OpenAudio = DISKAUD_OpenAudio;
this->WaitAudio = DISKAUD_WaitAudio;
this->PlayAudio = DISKAUD_PlayAudio;
this->GetAudioBuf = DISKAUD_GetAudioBuf;
this->CloseAudio = DISKAUD_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DISKAUD_OpenAudio;
this->WaitAudio = DISKAUD_WaitAudio;
this->PlayAudio = DISKAUD_PlayAudio;
this->GetAudioBuf = DISKAUD_GetAudioBuf;
this->CloseAudio = DISKAUD_CloseAudio;
this->free = DISKAUD_DeleteDevice;
this->free = DISKAUD_DeleteDevice;
return this;
return this;
}
AudioBootStrap DISKAUD_bootstrap = {
DISKAUD_DRIVER_NAME, "direct-to-disk audio",
DISKAUD_Available, DISKAUD_CreateDevice
DISKAUD_DRIVER_NAME, "direct-to-disk audio",
DISKAUD_Available, DISKAUD_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void DISKAUD_WaitAudio(_THIS)
static void
DISKAUD_WaitAudio(_THIS)
{
SDL_Delay(this->hidden->write_delay);
SDL_Delay(this->hidden->write_delay);
}
static void DISKAUD_PlayAudio(_THIS)
static void
DISKAUD_PlayAudio(_THIS)
{
int written;
int written;
/* Write the audio data */
written = SDL_RWwrite(this->hidden->output,
this->hidden->mixbuf, 1,
this->hidden->mixlen);
/* Write the audio data */
written = SDL_RWwrite(this->hidden->output,
this->hidden->mixbuf, 1, this->hidden->mixlen);
/* If we couldn't write, assume fatal error for now */
if ( (Uint32)written != this->hidden->mixlen ) {
this->enabled = 0;
}
/* If we couldn't write, assume fatal error for now */
if ((Uint32) written != this->hidden->mixlen) {
this->enabled = 0;
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
#endif
}
static Uint8 *DISKAUD_GetAudioBuf(_THIS)
static Uint8 *
DISKAUD_GetAudioBuf(_THIS)
{
return(this->hidden->mixbuf);
return (this->hidden->mixbuf);
}
static void DISKAUD_CloseAudio(_THIS)
static void
DISKAUD_CloseAudio(_THIS)
{
if ( this->hidden->mixbuf != NULL ) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if ( this->hidden->output != NULL ) {
SDL_RWclose(this->hidden->output);
this->hidden->output = NULL;
}
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if (this->hidden->output != NULL) {
SDL_RWclose(this->hidden->output);
this->hidden->output = NULL;
}
}
static int DISKAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
DISKAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
const char *fname = DISKAUD_GetOutputFilename();
/* Open the audio device */
this->hidden->output = SDL_RWFromFile(fname, "wb");
if ( this->hidden->output == NULL ) {
return(-1);
}
const char *fname = DISKAUD_GetOutputFilename();
/* Open the audio device */
this->hidden->output = SDL_RWFromFile(fname, "wb");
if (this->hidden->output == NULL) {
return (-1);
}
#if HAVE_STDIO_H
fprintf(stderr, "WARNING: You are using the SDL disk writer"
" audio driver!\n Writing to file [%s].\n", fname);
fprintf(stderr, "WARNING: You are using the SDL disk writer"
" audio driver!\n Writing to file [%s].\n", fname);
#endif
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if ( this->hidden->mixbuf == NULL ) {
return(-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
return (-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -30,12 +30,14 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
SDL_RWops *output;
Uint8 *mixbuf;
Uint32 mixlen;
Uint32 write_delay;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
SDL_RWops *output;
Uint8 *mixbuf;
Uint32 mixlen;
Uint32 write_delay;
};
#endif /* _SDL_diskaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -24,7 +24,7 @@
/* Allow access to a raw mixing buffer */
#include <stdio.h>
#include <string.h> /* For strerror() */
#include <string.h> /* For strerror() */
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
@ -60,7 +60,7 @@
#define OPEN_FLAGS (O_RDWR|O_NONBLOCK)
/* Audio driver functions */
static int DMA_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int DMA_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void DMA_WaitAudio(_THIS);
static void DMA_PlayAudio(_THIS);
static Uint8 *DMA_GetAudioBuf(_THIS);
@ -68,388 +68,400 @@ static void DMA_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int available;
int fd;
int available;
int fd;
available = 0;
available = 0;
fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if ( fd >= 0 ) {
int caps;
struct audio_buf_info info;
fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if (fd >= 0) {
int caps;
struct audio_buf_info info;
if ( (ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) &&
(caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
(ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0) ) {
available = 1;
}
close(fd);
}
return(available);
if ((ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) == 0) &&
(caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
(ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) == 0)) {
available = 1;
}
close(fd);
}
return (available);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Set the function pointers */
this->OpenAudio = DMA_OpenAudio;
this->WaitAudio = DMA_WaitAudio;
this->PlayAudio = DMA_PlayAudio;
this->GetAudioBuf = DMA_GetAudioBuf;
this->CloseAudio = DMA_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DMA_OpenAudio;
this->WaitAudio = DMA_WaitAudio;
this->PlayAudio = DMA_PlayAudio;
this->GetAudioBuf = DMA_GetAudioBuf;
this->CloseAudio = DMA_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap DMA_bootstrap = {
DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio",
Audio_Available, Audio_CreateDevice
DMA_DRIVER_NAME, "OSS /dev/dsp DMA audio",
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void DMA_WaitAudio(_THIS)
static void
DMA_WaitAudio(_THIS)
{
fd_set fdset;
fd_set fdset;
/* Check to see if the thread-parent process is still alive */
{ static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
if ( kill(parent, 0) < 0 ) {
this->enabled = 0;
}
}
}
/* Check to see if the thread-parent process is still alive */
{
static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
if (kill(parent, 0) < 0) {
this->enabled = 0;
}
}
}
/* See if we need to use timed audio synchronization */
if ( frame_ticks ) {
/* Use timer for general audio synchronization */
Sint32 ticks;
/* See if we need to use timed audio synchronization */
if (frame_ticks) {
/* Use timer for general audio synchronization */
Sint32 ticks;
ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
if ( ticks > 0 ) {
SDL_Delay(ticks);
}
} else {
/* Use select() for audio synchronization */
struct timeval timeout;
FD_ZERO(&fdset);
FD_SET(audio_fd, &fdset);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
if (ticks > 0) {
SDL_Delay(ticks);
}
} else {
/* Use select() for audio synchronization */
struct timeval timeout;
FD_ZERO(&fdset);
FD_SET(audio_fd, &fdset);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
#ifdef DEBUG_AUDIO
fprintf(stderr, "Waiting for audio to get ready\n");
fprintf(stderr, "Waiting for audio to get ready\n");
#endif
if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) {
const char *message =
if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
const char *message =
#ifdef AUDIO_OSPACE_HACK
"Audio timeout - buggy audio driver? (trying ospace)";
"Audio timeout - buggy audio driver? (trying ospace)";
#else
"Audio timeout - buggy audio driver? (disabled)";
"Audio timeout - buggy audio driver? (disabled)";
#endif
/* In general we should never print to the screen,
but in this case we have no other way of letting
the user know what happened.
*/
fprintf(stderr, "SDL: %s\n", message);
/* In general we should never print to the screen,
but in this case we have no other way of letting
the user know what happened.
*/
fprintf(stderr, "SDL: %s\n", message);
#ifdef AUDIO_OSPACE_HACK
/* We may be able to use GET_OSPACE trick */
frame_ticks = (float)(this->spec->samples*1000) /
this->spec->freq;
next_frame = SDL_GetTicks()+frame_ticks;
/* We may be able to use GET_OSPACE trick */
frame_ticks = (float) (this->spec->samples * 1000) /
this->spec->freq;
next_frame = SDL_GetTicks() + frame_ticks;
#else
this->enabled = 0;
/* Don't try to close - may hang */
audio_fd = -1;
this->enabled = 0;
/* Don't try to close - may hang */
audio_fd = -1;
#ifdef DEBUG_AUDIO
fprintf(stderr, "Done disabling audio\n");
fprintf(stderr, "Done disabling audio\n");
#endif
#endif /* AUDIO_OSPACE_HACK */
}
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Ready!\n");
fprintf(stderr, "Ready!\n");
#endif
}
}
}
static void DMA_PlayAudio(_THIS)
static void
DMA_PlayAudio(_THIS)
{
/* If timer synchronization is enabled, set the next write frame */
if ( frame_ticks ) {
next_frame += frame_ticks;
}
return;
/* If timer synchronization is enabled, set the next write frame */
if (frame_ticks) {
next_frame += frame_ticks;
}
return;
}
static Uint8 *DMA_GetAudioBuf(_THIS)
static Uint8 *
DMA_GetAudioBuf(_THIS)
{
count_info info;
int playing;
int filling;
count_info info;
int playing;
int filling;
/* Get number of blocks, looping if we're not using select() */
do {
if ( ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) < 0 ) {
/* Uh oh... */
this->enabled = 0;
return(NULL);
}
} while ( frame_ticks && (info.blocks < 1) );
/* Get number of blocks, looping if we're not using select() */
do {
if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &info) < 0) {
/* Uh oh... */
this->enabled = 0;
return (NULL);
}
}
while (frame_ticks && (info.blocks < 1));
#ifdef DEBUG_AUDIO
if ( info.blocks > 1 ) {
printf("Warning: audio underflow (%d frags)\n", info.blocks-1);
}
if (info.blocks > 1) {
printf("Warning: audio underflow (%d frags)\n", info.blocks - 1);
}
#endif
playing = info.ptr / this->spec.size;
filling = (playing + 1)%num_buffers;
return (dma_buf + (filling * this->spec.size));
playing = info.ptr / this->spec.size;
filling = (playing + 1) % num_buffers;
return (dma_buf + (filling * this->spec.size));
}
static void DMA_CloseAudio(_THIS)
static void
DMA_CloseAudio(_THIS)
{
if ( dma_buf != NULL ) {
munmap(dma_buf, dma_len);
dma_buf = NULL;
}
if ( audio_fd >= 0 ) {
close(audio_fd);
audio_fd = -1;
}
if (dma_buf != NULL) {
munmap(dma_buf, dma_len);
dma_buf = NULL;
}
if (audio_fd >= 0) {
close(audio_fd);
audio_fd = -1;
}
}
static int DMA_ReopenAudio(_THIS, const char *audiodev, int format, int stereo,
SDL_AudioSpec *spec)
static int
DMA_ReopenAudio(_THIS, const char *audiodev, int format, int stereo,
SDL_AudioSpec * spec)
{
int frag_spec;
int value;
int frag_spec;
int value;
/* Close and then reopen the audio device */
close(audio_fd);
audio_fd = open(audiodev, O_RDWR, 0);
if ( audio_fd < 0 ) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return(-1);
}
/* Close and then reopen the audio device */
close(audio_fd);
audio_fd = open(audiodev, O_RDWR, 0);
if (audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return (-1);
}
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Determine the power of two of the fragment size */
for ( frag_spec = 0; (0x01<<frag_spec) < spec->size; ++frag_spec );
if ( (0x01<<frag_spec) != spec->size ) {
SDL_SetError("Fragment size must be a power of two");
return(-1);
}
/* Determine the power of two of the fragment size */
for (frag_spec = 0; (0x01 << frag_spec) < spec->size; ++frag_spec);
if ((0x01 << frag_spec) != spec->size) {
SDL_SetError("Fragment size must be a power of two");
return (-1);
}
/* Set the audio buffering parameters */
if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) {
SDL_SetError("Couldn't set audio fragment spec");
return(-1);
}
/* Set the audio buffering parameters */
if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
SDL_SetError("Couldn't set audio fragment spec");
return (-1);
}
/* Set the audio format */
value = format;
if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
(value != format) ) {
SDL_SetError("Couldn't set audio format");
return(-1);
}
/* Set the audio format */
value = format;
if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
SDL_SetError("Couldn't set audio format");
return (-1);
}
/* Set mono or stereo audio */
value = (spec->channels > 1);
if ( (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) ||
(value != stereo) ) {
SDL_SetError("Couldn't set audio channels");
return(-1);
}
/* Set mono or stereo audio */
value = (spec->channels > 1);
if ((ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) ||
(value != stereo)) {
SDL_SetError("Couldn't set audio channels");
return (-1);
}
/* Set the DSP frequency */
value = spec->freq;
if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) {
SDL_SetError("Couldn't set audio frequency");
return(-1);
}
spec->freq = value;
/* Set the DSP frequency */
value = spec->freq;
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
SDL_SetError("Couldn't set audio frequency");
return (-1);
}
spec->freq = value;
/* We successfully re-opened the audio */
return(0);
/* We successfully re-opened the audio */
return (0);
}
static int DMA_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
DMA_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
char audiodev[1024];
int format;
int stereo;
int value;
Uint16 test_format;
struct audio_buf_info info;
char audiodev[1024];
int format;
int stereo;
int value;
Uint16 test_format;
struct audio_buf_info info;
/* Reset the timer synchronization flag */
frame_ticks = 0.0;
/* Reset the timer synchronization flag */
frame_ticks = 0.0;
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if ( audio_fd < 0 ) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return(-1);
}
dma_buf = NULL;
ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if (audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return (-1);
}
dma_buf = NULL;
ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
/* Get a list of supported hardware formats */
if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) {
SDL_SetError("Couldn't get audio format list");
return(-1);
}
/* Get a list of supported hardware formats */
if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
SDL_SetError("Couldn't get audio format list");
return (-1);
}
/* Try for a closest match on audio format */
format = 0;
for ( test_format = SDL_FirstAudioFormat(spec->format);
! format && test_format; ) {
/* Try for a closest match on audio format */
format = 0;
for (test_format = SDL_FirstAudioFormat(spec->format);
!format && test_format;) {
#ifdef DEBUG_AUDIO
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
#endif
switch ( test_format ) {
case AUDIO_U8:
if ( value & AFMT_U8 ) {
format = AFMT_U8;
}
break;
case AUDIO_S8:
if ( value & AFMT_S8 ) {
format = AFMT_S8;
}
break;
case AUDIO_S16LSB:
if ( value & AFMT_S16_LE ) {
format = AFMT_S16_LE;
}
break;
case AUDIO_S16MSB:
if ( value & AFMT_S16_BE ) {
format = AFMT_S16_BE;
}
break;
case AUDIO_U16LSB:
if ( value & AFMT_U16_LE ) {
format = AFMT_U16_LE;
}
break;
case AUDIO_U16MSB:
if ( value & AFMT_U16_BE ) {
format = AFMT_U16_BE;
}
break;
default:
format = 0;
break;
}
if ( ! format ) {
test_format = SDL_NextAudioFormat();
}
}
if ( format == 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
return(-1);
}
spec->format = test_format;
switch (test_format) {
case AUDIO_U8:
if (value & AFMT_U8) {
format = AFMT_U8;
}
break;
case AUDIO_S8:
if (value & AFMT_S8) {
format = AFMT_S8;
}
break;
case AUDIO_S16LSB:
if (value & AFMT_S16_LE) {
format = AFMT_S16_LE;
}
break;
case AUDIO_S16MSB:
if (value & AFMT_S16_BE) {
format = AFMT_S16_BE;
}
break;
case AUDIO_U16LSB:
if (value & AFMT_U16_LE) {
format = AFMT_U16_LE;
}
break;
case AUDIO_U16MSB:
if (value & AFMT_U16_BE) {
format = AFMT_U16_BE;
}
break;
default:
format = 0;
break;
}
if (!format) {
test_format = SDL_NextAudioFormat();
}
}
if (format == 0) {
SDL_SetError("Couldn't find any hardware audio formats");
return (-1);
}
spec->format = test_format;
/* Set the audio format */
value = format;
if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
(value != format) ) {
SDL_SetError("Couldn't set audio format");
return(-1);
}
/* Set the audio format */
value = format;
if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
SDL_SetError("Couldn't set audio format");
return (-1);
}
/* Set mono or stereo audio (currently only two channels supported) */
stereo = (spec->channels > 1);
ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
if ( stereo ) {
spec->channels = 2;
} else {
spec->channels = 1;
}
/* Set mono or stereo audio (currently only two channels supported) */
stereo = (spec->channels > 1);
ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
if (stereo) {
spec->channels = 2;
} else {
spec->channels = 1;
}
/* Because some drivers don't allow setting the buffer size
after setting the format, we must re-open the audio device
once we know what format and channels are supported
*/
if ( DMA_ReopenAudio(this, audiodev, format, stereo, spec) < 0 ) {
/* Error is set by DMA_ReopenAudio() */
return(-1);
}
/* Because some drivers don't allow setting the buffer size
after setting the format, we must re-open the audio device
once we know what format and channels are supported
*/
if (DMA_ReopenAudio(this, audiodev, format, stereo, spec) < 0) {
/* Error is set by DMA_ReopenAudio() */
return (-1);
}
/* Memory map the audio buffer */
if ( ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0 ) {
SDL_SetError("Couldn't get OSPACE parameters");
return(-1);
}
spec->size = info.fragsize;
spec->samples = spec->size / ((spec->format & 0xFF) / 8);
spec->samples /= spec->channels;
num_buffers = info.fragstotal;
dma_len = num_buffers*spec->size;
dma_buf = (Uint8 *)mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED,
audio_fd, 0);
if ( dma_buf == MAP_FAILED ) {
SDL_SetError("DMA memory map failed");
dma_buf = NULL;
return(-1);
}
SDL_memset(dma_buf, spec->silence, dma_len);
/* Memory map the audio buffer */
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
SDL_SetError("Couldn't get OSPACE parameters");
return (-1);
}
spec->size = info.fragsize;
spec->samples = spec->size / ((spec->format & 0xFF) / 8);
spec->samples /= spec->channels;
num_buffers = info.fragstotal;
dma_len = num_buffers * spec->size;
dma_buf = (Uint8 *) mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED,
audio_fd, 0);
if (dma_buf == MAP_FAILED) {
SDL_SetError("DMA memory map failed");
dma_buf = NULL;
return (-1);
}
SDL_memset(dma_buf, spec->silence, dma_len);
/* Check to see if we need to use select() workaround */
{ char *workaround;
workaround = SDL_getenv("SDL_DSP_NOSELECT");
if ( workaround ) {
frame_ticks = (float)(spec->samples*1000)/spec->freq;
next_frame = SDL_GetTicks()+frame_ticks;
}
}
/* Check to see if we need to use select() workaround */
{
char *workaround;
workaround = SDL_getenv("SDL_DSP_NOSELECT");
if (workaround) {
frame_ticks = (float) (spec->samples * 1000) / spec->freq;
next_frame = SDL_GetTicks() + frame_ticks;
}
}
/* Trigger audio playback */
value = 0;
ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value);
value = PCM_ENABLE_OUTPUT;
if ( ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0 ) {
SDL_SetError("Couldn't trigger audio output");
return(-1);
}
/* Trigger audio playback */
value = 0;
ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value);
value = PCM_ENABLE_OUTPUT;
if (ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) {
SDL_SetError("Couldn't trigger audio output");
return (-1);
}
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,23 +29,24 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
int audio_fd;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
int audio_fd;
/* The parent process id, to detect when application quits */
pid_t parent;
/* The parent process id, to detect when application quits */
pid_t parent;
/* Raw mixing buffer */
Uint8 *dma_buf;
int dma_len;
int num_buffers;
/* Raw mixing buffer */
Uint8 *dma_buf;
int dma_len;
int num_buffers;
/* Support for audio timing using a timer, in addition to select() */
float frame_ticks;
float next_frame;
/* Support for audio timing using a timer, in addition to select() */
float frame_ticks;
float next_frame;
};
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
/* Old variable names */
#define audio_fd (this->hidden->audio_fd)
@ -57,3 +58,4 @@ struct SDL_PrivateAudioData {
#define next_frame (this->hidden->next_frame)
#endif /* _SDL_dspaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,7 +31,7 @@
#include "SDL_irixaudio.h"
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
#ifndef AL_RESOURCE /* as a test whether we use the old IRIX audio libraries */
#define OLD_IRIX_AUDIO
#define alClosePort(x) ALcloseport(x)
#define alFreeConfig(x) ALfreeconfig(x)
@ -45,7 +45,7 @@
#endif
/* Audio driver functions */
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void AL_WaitAudio(_THIS);
static void AL_PlayAudio(_THIS);
static Uint8 *AL_GetAudioBuf(_THIS);
@ -53,164 +53,177 @@ static void AL_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
return 1;
return 1;
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = AL_OpenAudio;
this->WaitAudio = AL_WaitAudio;
this->PlayAudio = AL_PlayAudio;
this->GetAudioBuf = AL_GetAudioBuf;
this->CloseAudio = AL_CloseAudio;
/* Set the function pointers */
this->OpenAudio = AL_OpenAudio;
this->WaitAudio = AL_WaitAudio;
this->PlayAudio = AL_PlayAudio;
this->GetAudioBuf = AL_GetAudioBuf;
this->CloseAudio = AL_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap DMEDIA_bootstrap = {
"AL", "IRIX DMedia audio",
Audio_Available, Audio_CreateDevice
"AL", "IRIX DMedia audio",
Audio_Available, Audio_CreateDevice
};
void static AL_WaitAudio(_THIS)
void static
AL_WaitAudio(_THIS)
{
Sint32 timeleft;
Sint32 timeleft;
timeleft = this->spec.samples - alGetFillable(audio_port);
if ( timeleft > 0 ) {
timeleft /= (this->spec.freq/1000);
SDL_Delay((Uint32)timeleft);
}
timeleft = this->spec.samples - alGetFillable(audio_port);
if (timeleft > 0) {
timeleft /= (this->spec.freq / 1000);
SDL_Delay((Uint32) timeleft);
}
}
static void AL_PlayAudio(_THIS)
static void
AL_PlayAudio(_THIS)
{
/* Write the audio data out */
if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) {
/* Assume fatal error, for now */
this->enabled = 0;
}
/* Write the audio data out */
if (alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0) {
/* Assume fatal error, for now */
this->enabled = 0;
}
}
static Uint8 *AL_GetAudioBuf(_THIS)
static Uint8 *
AL_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void AL_CloseAudio(_THIS)
static void
AL_CloseAudio(_THIS)
{
if ( mixbuf != NULL ) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if ( audio_port != NULL ) {
alClosePort(audio_port);
audio_port = NULL;
}
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if (audio_port != NULL) {
alClosePort(audio_port);
audio_port = NULL;
}
}
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
ALconfig audio_config;
ALconfig audio_config;
#ifdef OLD_IRIX_AUDIO
long audio_param[2];
long audio_param[2];
#else
ALpv audio_param;
ALpv audio_param;
#endif
int width;
int width;
/* Determine the audio parameters from the AudioSpec */
switch ( spec->format & 0xFF ) {
/* Determine the audio parameters from the AudioSpec */
switch (spec->format & 0xFF) {
case 8: { /* Signed 8 bit audio data */
spec->format = AUDIO_S8;
width = AL_SAMPLE_8;
}
break;
case 8:
{ /* Signed 8 bit audio data */
spec->format = AUDIO_S8;
width = AL_SAMPLE_8;
}
break;
case 16: { /* Signed 16 bit audio data */
spec->format = AUDIO_S16MSB;
width = AL_SAMPLE_16;
}
break;
case 16:
{ /* Signed 16 bit audio data */
spec->format = AUDIO_S16MSB;
width = AL_SAMPLE_16;
}
break;
default: {
SDL_SetError("Unsupported audio format");
return(-1);
}
}
default:
{
SDL_SetError("Unsupported audio format");
return (-1);
}
}
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
/* Set output frequency */
/* Set output frequency */
#ifdef OLD_IRIX_AUDIO
audio_param[0] = AL_OUTPUT_RATE;
audio_param[1] = spec->freq;
if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) {
audio_param[0] = AL_OUTPUT_RATE;
audio_param[1] = spec->freq;
if (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0) {
#else
audio_param.param = AL_RATE;
audio_param.value.i = spec->freq;
if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) {
audio_param.param = AL_RATE;
audio_param.value.i = spec->freq;
if (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) {
#endif
SDL_SetError("alSetParams failed");
return(-1);
}
SDL_SetError("alSetParams failed");
return (-1);
}
/* Open the audio port with the requested frequency */
audio_port = NULL;
audio_config = alNewConfig();
if ( audio_config &&
(alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
(alSetWidth(audio_config, width) >= 0) &&
(alSetQueueSize(audio_config, spec->samples*2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0) ) {
audio_port = alOpenPort("SDL audio", "w", audio_config);
}
alFreeConfig(audio_config);
if( audio_port == NULL ) {
SDL_SetError("Unable to open audio port");
return(-1);
}
/* Open the audio port with the requested frequency */
audio_port = NULL;
audio_config = alNewConfig();
if (audio_config &&
(alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
(alSetWidth(audio_config, width) >= 0) &&
(alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0)) {
audio_port = alOpenPort("SDL audio", "w", audio_config);
}
alFreeConfig(audio_config);
if (audio_port == NULL) {
SDL_SetError("Unable to open audio port");
return (-1);
}
/* Allocate mixing buffer */
mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size);
if ( mixbuf == NULL ) {
SDL_OutOfMemory();
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
if (mixbuf == NULL) {
SDL_OutOfMemory();
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,11 +31,12 @@
/* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The handle for the audio device */
ALport audio_port;
struct SDL_PrivateAudioData
{
/* The handle for the audio device */
ALport audio_port;
Uint8 *mixbuf; /* The app mixing buffer */
Uint8 *mixbuf; /* The app mixing buffer */
};
/* Old variable names */
@ -43,3 +44,4 @@ struct SDL_PrivateAudioData {
#define mixbuf (this->hidden->mixbuf)
#endif /* _SDL_lowaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -26,8 +26,8 @@
/* Allow access to a raw mixing buffer */
#include <stdio.h> /* For perror() */
#include <string.h> /* For strerror() */
#include <stdio.h> /* For perror() */
#include <string.h> /* For strerror() */
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
@ -58,7 +58,7 @@
#define OPEN_FLAGS (O_WRONLY|O_NONBLOCK)
/* Audio driver functions */
static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int DSP_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void DSP_WaitAudio(_THIS);
static void DSP_PlayAudio(_THIS);
static Uint8 *DSP_GetAudioBuf(_THIS);
@ -66,266 +66,275 @@ static void DSP_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int fd;
int available;
int fd;
int available;
available = 0;
fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if ( fd >= 0 ) {
available = 1;
close(fd);
}
return(available);
available = 0;
fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if (fd >= 0) {
available = 1;
close(fd);
}
return (available);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Set the function pointers */
this->OpenAudio = DSP_OpenAudio;
this->WaitAudio = DSP_WaitAudio;
this->PlayAudio = DSP_PlayAudio;
this->GetAudioBuf = DSP_GetAudioBuf;
this->CloseAudio = DSP_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DSP_OpenAudio;
this->WaitAudio = DSP_WaitAudio;
this->PlayAudio = DSP_PlayAudio;
this->GetAudioBuf = DSP_GetAudioBuf;
this->CloseAudio = DSP_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap DSP_bootstrap = {
DSP_DRIVER_NAME, "OSS /dev/dsp standard audio",
Audio_Available, Audio_CreateDevice
DSP_DRIVER_NAME, "OSS /dev/dsp standard audio",
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void DSP_WaitAudio(_THIS)
static void
DSP_WaitAudio(_THIS)
{
/* Not needed at all since OSS handles waiting automagically */
/* Not needed at all since OSS handles waiting automagically */
}
static void DSP_PlayAudio(_THIS)
static void
DSP_PlayAudio(_THIS)
{
if (write(audio_fd, mixbuf, mixlen)==-1)
{
perror("Audio write");
this->enabled = 0;
}
if (write(audio_fd, mixbuf, mixlen) == -1) {
perror("Audio write");
this->enabled = 0;
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen);
fprintf(stderr, "Wrote %d bytes of audio data\n", mixlen);
#endif
}
static Uint8 *DSP_GetAudioBuf(_THIS)
static Uint8 *
DSP_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void DSP_CloseAudio(_THIS)
static void
DSP_CloseAudio(_THIS)
{
if ( mixbuf != NULL ) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if ( audio_fd >= 0 ) {
close(audio_fd);
audio_fd = -1;
}
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if (audio_fd >= 0) {
close(audio_fd);
audio_fd = -1;
}
}
static int DSP_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
DSP_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
char audiodev[1024];
int format;
int value;
int frag_spec;
Uint16 test_format;
char audiodev[1024];
int format;
int value;
int frag_spec;
Uint16 test_format;
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if ( audio_fd < 0 ) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return(-1);
}
mixbuf = NULL;
/* Open the audio device */
audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
if (audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return (-1);
}
mixbuf = NULL;
/* Make the file descriptor use blocking writes with fcntl() */
{ long flags;
flags = fcntl(audio_fd, F_GETFL);
flags &= ~O_NONBLOCK;
if ( fcntl(audio_fd, F_SETFL, flags) < 0 ) {
SDL_SetError("Couldn't set audio blocking mode");
DSP_CloseAudio(this);
return(-1);
}
}
/* Make the file descriptor use blocking writes with fcntl() */
{
long flags;
flags = fcntl(audio_fd, F_GETFL);
flags &= ~O_NONBLOCK;
if (fcntl(audio_fd, F_SETFL, flags) < 0) {
SDL_SetError("Couldn't set audio blocking mode");
DSP_CloseAudio(this);
return (-1);
}
}
/* Get a list of supported hardware formats */
if ( ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0 ) {
perror("SNDCTL_DSP_GETFMTS");
SDL_SetError("Couldn't get audio format list");
DSP_CloseAudio(this);
return(-1);
}
/* Get a list of supported hardware formats */
if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
perror("SNDCTL_DSP_GETFMTS");
SDL_SetError("Couldn't get audio format list");
DSP_CloseAudio(this);
return (-1);
}
/* Try for a closest match on audio format */
format = 0;
for ( test_format = SDL_FirstAudioFormat(spec->format);
! format && test_format; ) {
/* Try for a closest match on audio format */
format = 0;
for (test_format = SDL_FirstAudioFormat(spec->format);
!format && test_format;) {
#ifdef DEBUG_AUDIO
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
#endif
switch ( test_format ) {
case AUDIO_U8:
if ( value & AFMT_U8 ) {
format = AFMT_U8;
}
break;
case AUDIO_S16LSB:
if ( value & AFMT_S16_LE ) {
format = AFMT_S16_LE;
}
break;
case AUDIO_S16MSB:
if ( value & AFMT_S16_BE ) {
format = AFMT_S16_BE;
}
break;
switch (test_format) {
case AUDIO_U8:
if (value & AFMT_U8) {
format = AFMT_U8;
}
break;
case AUDIO_S16LSB:
if (value & AFMT_S16_LE) {
format = AFMT_S16_LE;
}
break;
case AUDIO_S16MSB:
if (value & AFMT_S16_BE) {
format = AFMT_S16_BE;
}
break;
#if 0
/*
* These formats are not used by any real life systems so they are not
* needed here.
*/
case AUDIO_S8:
if ( value & AFMT_S8 ) {
format = AFMT_S8;
}
break;
case AUDIO_U16LSB:
if ( value & AFMT_U16_LE ) {
format = AFMT_U16_LE;
}
break;
case AUDIO_U16MSB:
if ( value & AFMT_U16_BE ) {
format = AFMT_U16_BE;
}
break;
case AUDIO_S8:
if (value & AFMT_S8) {
format = AFMT_S8;
}
break;
case AUDIO_U16LSB:
if (value & AFMT_U16_LE) {
format = AFMT_U16_LE;
}
break;
case AUDIO_U16MSB:
if (value & AFMT_U16_BE) {
format = AFMT_U16_BE;
}
break;
#endif
default:
format = 0;
break;
}
if ( ! format ) {
test_format = SDL_NextAudioFormat();
}
}
if ( format == 0 ) {
SDL_SetError("Couldn't find any hardware audio formats");
DSP_CloseAudio(this);
return(-1);
}
spec->format = test_format;
default:
format = 0;
break;
}
if (!format) {
test_format = SDL_NextAudioFormat();
}
}
if (format == 0) {
SDL_SetError("Couldn't find any hardware audio formats");
DSP_CloseAudio(this);
return (-1);
}
spec->format = test_format;
/* Set the audio format */
value = format;
if ( (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
(value != format) ) {
perror("SNDCTL_DSP_SETFMT");
SDL_SetError("Couldn't set audio format");
DSP_CloseAudio(this);
return(-1);
}
/* Set the audio format */
value = format;
if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
perror("SNDCTL_DSP_SETFMT");
SDL_SetError("Couldn't set audio format");
DSP_CloseAudio(this);
return (-1);
}
/* Set the number of channels of output */
value = spec->channels;
if ( ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0 ) {
perror("SNDCTL_DSP_CHANNELS");
SDL_SetError("Cannot set the number of channels");
DSP_CloseAudio(this);
return(-1);
}
spec->channels = value;
/* Set the number of channels of output */
value = spec->channels;
if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
perror("SNDCTL_DSP_CHANNELS");
SDL_SetError("Cannot set the number of channels");
DSP_CloseAudio(this);
return (-1);
}
spec->channels = value;
/* Set the DSP frequency */
value = spec->freq;
if ( ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0 ) {
perror("SNDCTL_DSP_SPEED");
SDL_SetError("Couldn't set audio frequency");
DSP_CloseAudio(this);
return(-1);
}
spec->freq = value;
/* Set the DSP frequency */
value = spec->freq;
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
perror("SNDCTL_DSP_SPEED");
SDL_SetError("Couldn't set audio frequency");
DSP_CloseAudio(this);
return (-1);
}
spec->freq = value;
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Determine the power of two of the fragment size */
for ( frag_spec = 0; (0x01U<<frag_spec) < spec->size; ++frag_spec );
if ( (0x01U<<frag_spec) != spec->size ) {
SDL_SetError("Fragment size must be a power of two");
DSP_CloseAudio(this);
return(-1);
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
/* Determine the power of two of the fragment size */
for (frag_spec = 0; (0x01U << frag_spec) < spec->size; ++frag_spec);
if ((0x01U << frag_spec) != spec->size) {
SDL_SetError("Fragment size must be a power of two");
DSP_CloseAudio(this);
return (-1);
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
/* Set the audio buffering parameters */
/* Set the audio buffering parameters */
#ifdef DEBUG_AUDIO
fprintf(stderr, "Requesting %d fragments of size %d\n",
(frag_spec >> 16), 1<<(frag_spec&0xFFFF));
fprintf(stderr, "Requesting %d fragments of size %d\n",
(frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
#endif
if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) {
perror("SNDCTL_DSP_SETFRAGMENT");
}
if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
perror("SNDCTL_DSP_SETFRAGMENT");
}
#ifdef DEBUG_AUDIO
{ audio_buf_info info;
ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info);
fprintf(stderr, "fragments = %d\n", info.fragments);
fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
fprintf(stderr, "fragsize = %d\n", info.fragsize);
fprintf(stderr, "bytes = %d\n", info.bytes);
}
{
audio_buf_info info;
ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info);
fprintf(stderr, "fragments = %d\n", info.fragments);
fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
fprintf(stderr, "fragsize = %d\n", info.fragsize);
fprintf(stderr, "bytes = %d\n", info.bytes);
}
#endif
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
if ( mixbuf == NULL ) {
DSP_CloseAudio(this);
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
if (mixbuf == NULL) {
DSP_CloseAudio(this);
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,18 +29,19 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
int audio_fd;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
int audio_fd;
/* The parent process id, to detect when application quits */
pid_t parent;
/* The parent process id, to detect when application quits */
pid_t parent;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
};
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
/* Old variable names */
#define audio_fd (this->hidden->audio_fd)
@ -51,3 +52,4 @@ struct SDL_PrivateAudioData {
#define next_frame (this->hidden->next_frame)
#endif /* _SDL_dspaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -37,120 +37,129 @@
#define DUMMYAUD_DRIVER_NAME "dummy"
/* Audio driver functions */
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void DUMMYAUD_WaitAudio(_THIS);
static void DUMMYAUD_PlayAudio(_THIS);
static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
static void DUMMYAUD_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int DUMMYAUD_Available(void)
static int
DUMMYAUD_Available(void)
{
const char *envr = SDL_getenv("SDL_AUDIODRIVER");
if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
return(1);
}
return(0);
const char *envr = SDL_getenv("SDL_AUDIODRIVER");
if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
return (1);
}
return (0);
}
static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device)
static void
DUMMYAUD_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex)
static SDL_AudioDevice *
DUMMYAUD_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Set the function pointers */
this->OpenAudio = DUMMYAUD_OpenAudio;
this->WaitAudio = DUMMYAUD_WaitAudio;
this->PlayAudio = DUMMYAUD_PlayAudio;
this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
this->CloseAudio = DUMMYAUD_CloseAudio;
/* Set the function pointers */
this->OpenAudio = DUMMYAUD_OpenAudio;
this->WaitAudio = DUMMYAUD_WaitAudio;
this->PlayAudio = DUMMYAUD_PlayAudio;
this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
this->CloseAudio = DUMMYAUD_CloseAudio;
this->free = DUMMYAUD_DeleteDevice;
this->free = DUMMYAUD_DeleteDevice;
return this;
return this;
}
AudioBootStrap DUMMYAUD_bootstrap = {
DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
DUMMYAUD_Available, DUMMYAUD_CreateDevice
DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
DUMMYAUD_Available, DUMMYAUD_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void DUMMYAUD_WaitAudio(_THIS)
static void
DUMMYAUD_WaitAudio(_THIS)
{
/* Don't block on first calls to simulate initial fragment filling. */
if (this->hidden->initial_calls)
this->hidden->initial_calls--;
else
SDL_Delay(this->hidden->write_delay);
/* Don't block on first calls to simulate initial fragment filling. */
if (this->hidden->initial_calls)
this->hidden->initial_calls--;
else
SDL_Delay(this->hidden->write_delay);
}
static void DUMMYAUD_PlayAudio(_THIS)
static void
DUMMYAUD_PlayAudio(_THIS)
{
/* no-op...this is a null driver. */
/* no-op...this is a null driver. */
}
static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
static Uint8 *
DUMMYAUD_GetAudioBuf(_THIS)
{
return(this->hidden->mixbuf);
return (this->hidden->mixbuf);
}
static void DUMMYAUD_CloseAudio(_THIS)
static void
DUMMYAUD_CloseAudio(_THIS)
{
if ( this->hidden->mixbuf != NULL ) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
}
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
float bytes_per_sec = 0.0f;
float bytes_per_sec = 0.0f;
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if ( this->hidden->mixbuf == NULL ) {
return(-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
this->hidden->mixlen = spec->size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
return (-1);
}
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
spec->channels * spec->freq);
bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
spec->channels * spec->freq);
/*
* We try to make this request more audio at the correct rate for
* a given audio spec, so timing stays fairly faithful.
* Also, we have it not block at all for the first two calls, so
* it seems like we're filling two audio fragments right out of the
* gate, like other SDL drivers tend to do.
*/
this->hidden->initial_calls = 2;
this->hidden->write_delay =
(Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
/*
* We try to make this request more audio at the correct rate for
* a given audio spec, so timing stays fairly faithful.
* Also, we have it not block at all for the first two calls, so
* it seems like we're filling two audio fragments right out of the
* gate, like other SDL drivers tend to do.
*/
this->hidden->initial_calls = 2;
this->hidden->write_delay =
(Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,12 +29,14 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
Uint8 *mixbuf;
Uint32 mixlen;
Uint32 write_delay;
Uint32 initial_calls;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
Uint8 *mixbuf;
Uint32 mixlen;
Uint32 write_delay;
Uint32 initial_calls;
};
#endif /* _SDL_dummyaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -47,7 +47,7 @@
#define ESD_DRIVER_NAME "esd"
/* Audio driver functions */
static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int ESD_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void ESD_WaitAudio(_THIS);
static void ESD_PlayAudio(_THIS);
static Uint8 *ESD_GetAudioBuf(_THIS);
@ -59,265 +59,285 @@ static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
static void *esd_handle = NULL;
static int esd_loaded = 0;
static int (*SDL_NAME(esd_open_sound))( const char *host );
static int (*SDL_NAME(esd_close))( int esd );
static int (*SDL_NAME(esd_play_stream))( esd_format_t format, int rate,
const char *host, const char *name );
static struct {
const char *name;
void **func;
} esd_functions[] = {
{ "esd_open_sound", (void **)&SDL_NAME(esd_open_sound) },
{ "esd_close", (void **)&SDL_NAME(esd_close) },
{ "esd_play_stream", (void **)&SDL_NAME(esd_play_stream) },
};
static void UnloadESDLibrary()
static int (*SDL_NAME(esd_open_sound)) (const char *host);
static int (*SDL_NAME(esd_close)) (int esd);
static int (*SDL_NAME(esd_play_stream)) (esd_format_t format, int rate,
const char *host, const char *name);
static struct
{
if ( esd_loaded ) {
SDL_UnloadObject(esd_handle);
esd_handle = NULL;
esd_loaded = 0;
}
const char *name;
void **func;
} esd_functions[] = {
{
"esd_open_sound", (void **) &SDL_NAME(esd_open_sound)}, {
"esd_close", (void **) &SDL_NAME(esd_close)}, {
"esd_play_stream", (void **) &SDL_NAME(esd_play_stream)},};
static void
UnloadESDLibrary()
{
if (esd_loaded) {
SDL_UnloadObject(esd_handle);
esd_handle = NULL;
esd_loaded = 0;
}
}
static int LoadESDLibrary(void)
static int
LoadESDLibrary(void)
{
int i, retval = -1;
int i, retval = -1;
esd_handle = SDL_LoadObject(esd_library);
if ( esd_handle ) {
esd_loaded = 1;
retval = 0;
for ( i=0; i<SDL_arraysize(esd_functions); ++i ) {
*esd_functions[i].func = SDL_LoadFunction(esd_handle, esd_functions[i].name);
if ( !*esd_functions[i].func ) {
retval = -1;
UnloadESDLibrary();
break;
}
}
}
return retval;
esd_handle = SDL_LoadObject(esd_library);
if (esd_handle) {
esd_loaded = 1;
retval = 0;
for (i = 0; i < SDL_arraysize(esd_functions); ++i) {
*esd_functions[i].func =
SDL_LoadFunction(esd_handle, esd_functions[i].name);
if (!*esd_functions[i].func) {
retval = -1;
UnloadESDLibrary();
break;
}
}
}
return retval;
}
#else
static void UnloadESDLibrary()
static void
UnloadESDLibrary()
{
return;
return;
}
static int LoadESDLibrary(void)
static int
LoadESDLibrary(void)
{
return 0;
return 0;
}
#endif /* SDL_AUDIO_DRIVER_ESD_DYNAMIC */
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
int connection;
int available;
int connection;
int available;
available = 0;
if ( LoadESDLibrary() < 0 ) {
return available;
}
connection = SDL_NAME(esd_open_sound)(NULL);
if ( connection >= 0 ) {
available = 1;
SDL_NAME(esd_close)(connection);
}
UnloadESDLibrary();
return(available);
available = 0;
if (LoadESDLibrary() < 0) {
return available;
}
connection = SDL_NAME(esd_open_sound) (NULL);
if (connection >= 0) {
available = 1;
SDL_NAME(esd_close) (connection);
}
UnloadESDLibrary();
return (available);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
UnloadESDLibrary();
SDL_free(device->hidden);
SDL_free(device);
UnloadESDLibrary();
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
LoadESDLibrary();
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
SDL_OutOfMemory();
if ( this ) {
SDL_free(this);
}
return(0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Initialize all variables that we clean on shutdown */
LoadESDLibrary();
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
}
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if (this) {
SDL_free(this);
}
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
audio_fd = -1;
/* Set the function pointers */
this->OpenAudio = ESD_OpenAudio;
this->WaitAudio = ESD_WaitAudio;
this->PlayAudio = ESD_PlayAudio;
this->GetAudioBuf = ESD_GetAudioBuf;
this->CloseAudio = ESD_CloseAudio;
/* Set the function pointers */
this->OpenAudio = ESD_OpenAudio;
this->WaitAudio = ESD_WaitAudio;
this->PlayAudio = ESD_PlayAudio;
this->GetAudioBuf = ESD_GetAudioBuf;
this->CloseAudio = ESD_CloseAudio;
this->free = Audio_DeleteDevice;
this->free = Audio_DeleteDevice;
return this;
return this;
}
AudioBootStrap ESD_bootstrap = {
ESD_DRIVER_NAME, "Enlightened Sound Daemon",
Audio_Available, Audio_CreateDevice
ESD_DRIVER_NAME, "Enlightened Sound Daemon",
Audio_Available, Audio_CreateDevice
};
/* This function waits until it is possible to write a full sound buffer */
static void ESD_WaitAudio(_THIS)
static void
ESD_WaitAudio(_THIS)
{
Sint32 ticks;
Sint32 ticks;
/* Check to see if the thread-parent process is still alive */
{ static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
if ( kill(parent, 0) < 0 ) {
this->enabled = 0;
}
}
}
/* Check to see if the thread-parent process is still alive */
{
static int cnt = 0;
/* Note that this only works with thread implementations
that use a different process id for each thread.
*/
if (parent && (((++cnt) % 10) == 0)) { /* Check every 10 loops */
if (kill(parent, 0) < 0) {
this->enabled = 0;
}
}
}
/* Use timer for general audio synchronization */
ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
if ( ticks > 0 ) {
SDL_Delay(ticks);
}
/* Use timer for general audio synchronization */
ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
if (ticks > 0) {
SDL_Delay(ticks);
}
}
static void ESD_PlayAudio(_THIS)
static void
ESD_PlayAudio(_THIS)
{
int written;
int written;
/* Write the audio data, checking for EAGAIN on broken audio drivers */
do {
written = write(audio_fd, mixbuf, mixlen);
if ( (written < 0) && ((errno == 0) || (errno == EAGAIN)) ) {
SDL_Delay(1); /* Let a little CPU time go by */
}
} while ( (written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)) );
/* Write the audio data, checking for EAGAIN on broken audio drivers */
do {
written = write(audio_fd, mixbuf, mixlen);
if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
/* Set the next write frame */
next_frame += frame_ticks;
/* Set the next write frame */
next_frame += frame_ticks;
/* If we couldn't write, assume fatal error for now */
if ( written < 0 ) {
this->enabled = 0;
}
/* If we couldn't write, assume fatal error for now */
if (written < 0) {
this->enabled = 0;
}
}
static Uint8 *ESD_GetAudioBuf(_THIS)
static Uint8 *
ESD_GetAudioBuf(_THIS)
{
return(mixbuf);
return (mixbuf);
}
static void ESD_CloseAudio(_THIS)
static void
ESD_CloseAudio(_THIS)
{
if ( mixbuf != NULL ) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if ( audio_fd >= 0 ) {
SDL_NAME(esd_close)(audio_fd);
audio_fd = -1;
}
if (mixbuf != NULL) {
SDL_FreeAudioMem(mixbuf);
mixbuf = NULL;
}
if (audio_fd >= 0) {
SDL_NAME(esd_close) (audio_fd);
audio_fd = -1;
}
}
/* Try to get the name of the program */
static char *get_progname(void)
static char *
get_progname(void)
{
char *progname = NULL;
char *progname = NULL;
#ifdef __LINUX__
FILE *fp;
static char temp[BUFSIZ];
FILE *fp;
static char temp[BUFSIZ];
SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
fp = fopen(temp, "r");
if ( fp != NULL ) {
if ( fgets(temp, sizeof(temp)-1, fp) ) {
progname = SDL_strrchr(temp, '/');
if ( progname == NULL ) {
progname = temp;
} else {
progname = progname+1;
}
}
fclose(fp);
}
SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
fp = fopen(temp, "r");
if (fp != NULL) {
if (fgets(temp, sizeof(temp) - 1, fp)) {
progname = SDL_strrchr(temp, '/');
if (progname == NULL) {
progname = temp;
} else {
progname = progname + 1;
}
}
fclose(fp);
}
#endif
return(progname);
return (progname);
}
static int ESD_OpenAudio(_THIS, SDL_AudioSpec *spec)
static int
ESD_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
esd_format_t format;
esd_format_t format;
/* Convert audio spec to the ESD audio format */
format = (ESD_STREAM | ESD_PLAY);
switch ( spec->format & 0xFF ) {
case 8:
format |= ESD_BITS8;
break;
case 16:
format |= ESD_BITS16;
break;
default:
SDL_SetError("Unsupported ESD audio format");
return(-1);
}
if ( spec->channels == 1 ) {
format |= ESD_MONO;
} else {
format |= ESD_STEREO;
}
/* Convert audio spec to the ESD audio format */
format = (ESD_STREAM | ESD_PLAY);
switch (spec->format & 0xFF) {
case 8:
format |= ESD_BITS8;
break;
case 16:
format |= ESD_BITS16;
break;
default:
SDL_SetError("Unsupported ESD audio format");
return (-1);
}
if (spec->channels == 1) {
format |= ESD_MONO;
} else {
format |= ESD_STEREO;
}
#if 0
spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
spec->samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
#endif
/* Open a connection to the ESD audio server */
audio_fd = SDL_NAME(esd_play_stream)(format, spec->freq, NULL, get_progname());
if ( audio_fd < 0 ) {
SDL_SetError("Couldn't open ESD connection");
return(-1);
}
/* Open a connection to the ESD audio server */
audio_fd =
SDL_NAME(esd_play_stream) (format, spec->freq, NULL, get_progname());
if (audio_fd < 0) {
SDL_SetError("Couldn't open ESD connection");
return (-1);
}
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
frame_ticks = (float)(spec->samples*1000)/spec->freq;
next_frame = SDL_GetTicks()+frame_ticks;
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
frame_ticks = (float) (spec->samples * 1000) / spec->freq;
next_frame = SDL_GetTicks() + frame_ticks;
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
if ( mixbuf == NULL ) {
return(-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Allocate mixing buffer */
mixlen = spec->size;
mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
if (mixbuf == NULL) {
return (-1);
}
SDL_memset(mixbuf, spec->silence, spec->size);
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* We're ready to rock and roll. :-) */
return(0);
/* We're ready to rock and roll. :-) */
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -29,22 +29,23 @@
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_AudioDevice *this
struct SDL_PrivateAudioData {
/* The file descriptor for the audio device */
int audio_fd;
struct SDL_PrivateAudioData
{
/* The file descriptor for the audio device */
int audio_fd;
/* The parent process id, to detect when application quits */
pid_t parent;
/* The parent process id, to detect when application quits */
pid_t parent;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Raw mixing buffer */
Uint8 *mixbuf;
int mixlen;
/* Support for audio timing using a timer */
float frame_ticks;
float next_frame;
/* Support for audio timing using a timer */
float frame_ticks;
float next_frame;
};
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
/* Old variable names */
#define audio_fd (this->hidden->audio_fd)
@ -55,3 +56,4 @@ struct SDL_PrivateAudioData {
#define next_frame (this->hidden->next_frame)
#endif /* _SDL_esdaudio_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -31,7 +31,7 @@
/* Audio driver functions */
static int Core_OpenAudio(_THIS, SDL_AudioSpec *spec);
static int Core_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void Core_WaitAudio(_THIS);
static void Core_PlayAudio(_THIS);
static Uint8 *Core_GetAudioBuf(_THIS);
@ -39,34 +39,37 @@ static void Core_CloseAudio(_THIS);
/* Audio driver bootstrap functions */
static int Audio_Available(void)
static int
Audio_Available(void)
{
return(1);
return (1);
}
static void Audio_DeleteDevice(SDL_AudioDevice *device)
static void
Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
static SDL_AudioDevice *
Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
if ( this ) {
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
SDL_memset(this, 0, (sizeof *this));
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
SDL_malloc((sizeof *this->hidden));
}
if ( (this == NULL) || (this->hidden == NULL) ) {
if ((this == NULL) || (this->hidden == NULL)) {
SDL_OutOfMemory();
if ( this ) {
if (this) {
SDL_free(this);
}
return(0);
return (0);
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -88,30 +91,30 @@ AudioBootStrap COREAUDIO_bootstrap = {
};
/* The CoreAudio callback */
static OSStatus audioCallback (void *inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
AudioBuffer *ioData)
static OSStatus
audioCallback(void *inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber, AudioBuffer * ioData)
{
SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon;
SDL_AudioDevice *this = (SDL_AudioDevice *) inRefCon;
UInt32 remaining, len;
void *ptr;
/* Only do anything if audio is enabled and not paused */
if ( ! this->enabled || this->paused ) {
if (!this->enabled || this->paused) {
SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
return 0;
}
/* No SDL conversion should be needed here, ever, since we accept
any input format in OpenAudio, and leave the conversion to CoreAudio.
*/
/*
assert(!this->convert.needed);
assert(this->spec.channels == ioData->mNumberChannels);
assert(!this->convert.needed);
assert(this->spec.channels == ioData->mNumberChannels);
*/
remaining = ioData->mDataByteSize;
ptr = ioData->mData;
while (remaining > 0) {
@ -119,47 +122,50 @@ static OSStatus audioCallback (void *inRefCon,
/* Generate the data */
SDL_memset(buffer, this->spec.silence, bufferSize);
SDL_mutexP(this->mixer_lock);
(*this->spec.callback)(this->spec.userdata,
buffer, bufferSize);
(*this->spec.callback) (this->spec.userdata, buffer, bufferSize);
SDL_mutexV(this->mixer_lock);
bufferOffset = 0;
}
len = bufferSize - bufferOffset;
if (len > remaining)
len = remaining;
SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
ptr = (char *)ptr + len;
SDL_memcpy(ptr, (char *) buffer + bufferOffset, len);
ptr = (char *) ptr + len;
remaining -= len;
bufferOffset += len;
}
return 0;
}
/* Dummy functions -- we don't use thread-based audio */
void Core_WaitAudio(_THIS)
void
Core_WaitAudio(_THIS)
{
return;
}
void Core_PlayAudio(_THIS)
void
Core_PlayAudio(_THIS)
{
return;
}
Uint8 *Core_GetAudioBuf(_THIS)
Uint8 *
Core_GetAudioBuf(_THIS)
{
return(NULL);
return (NULL);
}
void Core_CloseAudio(_THIS)
void
Core_CloseAudio(_THIS)
{
OSStatus result;
struct AudioUnitInputCallback callback;
/* stop processing the audio unit */
result = AudioOutputUnitStop (outputAudioUnit);
result = AudioOutputUnitStop(outputAudioUnit);
if (result != noErr) {
SDL_SetError("Core_CloseAudio: AudioOutputUnitStop");
return;
@ -168,14 +174,13 @@ void Core_CloseAudio(_THIS)
/* Remove the input callback */
callback.inputProc = 0;
callback.inputProcRefCon = 0;
result = AudioUnitSetProperty (outputAudioUnit,
kAudioUnitProperty_SetInputCallback,
kAudioUnitScope_Input,
0,
&callback,
sizeof(callback));
result = AudioUnitSetProperty(outputAudioUnit,
kAudioUnitProperty_SetInputCallback,
kAudioUnitScope_Input,
0, &callback, sizeof(callback));
if (result != noErr) {
SDL_SetError("Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
SDL_SetError
("Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)");
return;
}
@ -184,7 +189,7 @@ void Core_CloseAudio(_THIS)
SDL_SetError("Core_CloseAudio: CloseComponent");
return;
}
SDL_free(buffer);
}
@ -195,7 +200,8 @@ void Core_CloseAudio(_THIS)
}
int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
int
Core_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
OSStatus result = noErr;
Component comp;
@ -208,7 +214,7 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
requestedDesc.mChannelsPerFrame = spec->channels;
requestedDesc.mSampleRate = spec->freq;
requestedDesc.mBitsPerChannel = spec->format & 0xFF;
if (spec->format & 0x8000)
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
@ -216,8 +222,10 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
requestedDesc.mFramesPerPacket = 1;
requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
requestedDesc.mBytesPerPacket = requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket;
requestedDesc.mBytesPerFrame =
requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
requestedDesc.mBytesPerPacket =
requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket;
/* Locate the default output audio unit */
@ -226,52 +234,46 @@ int Core_OpenAudio(_THIS, SDL_AudioSpec *spec)
desc.componentManufacturer = kAudioUnitID_DefaultOutput;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent (NULL, &desc);
comp = FindNextComponent(NULL, &desc);
if (comp == NULL) {
SDL_SetError ("Failed to start CoreAudio: FindNextComponent returned NULL");
SDL_SetError
("Failed to start CoreAudio: FindNextComponent returned NULL");
return -1;
}
/* Open & initialize the default output audio unit */
result = OpenAComponent (comp, &outputAudioUnit);
result = OpenAComponent(comp, &outputAudioUnit);
CHECK_RESULT("OpenAComponent")
result = AudioUnitInitialize (outputAudioUnit);
result = AudioUnitInitialize(outputAudioUnit);
CHECK_RESULT("AudioUnitInitialize")
/* Set the input format of the audio unit. */
result = AudioUnitSetProperty (outputAudioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&requestedDesc,
sizeof (requestedDesc));
/* Set the input format of the audio unit. */
result = AudioUnitSetProperty(outputAudioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&requestedDesc, sizeof(requestedDesc));
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)")
/* Set the audio callback */
callback.inputProc = audioCallback;
/* Set the audio callback */
callback.inputProc = audioCallback;
callback.inputProcRefCon = this;
result = AudioUnitSetProperty (outputAudioUnit,
kAudioUnitProperty_SetInputCallback,
kAudioUnitScope_Input,
0,
&callback,
sizeof(callback));
result = AudioUnitSetProperty(outputAudioUnit,
kAudioUnitProperty_SetInputCallback,
kAudioUnitScope_Input,
0, &callback, sizeof(callback));
CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)")
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Allocate a sample buffer */
bufferOffset = bufferSize = this->spec.size;
buffer = SDL_malloc(bufferSize);
/* Finally, start processing of the audio unit */
result = AudioOutputUnitStart (outputAudioUnit);
CHECK_RESULT("AudioOutputUnitStart")
/* We're running! */
return(1);
result = AudioOutputUnitStart(outputAudioUnit);
CHECK_RESULT("AudioOutputUnitStart")
/* We're running! */
return (1);
}
/* vi: set ts=4 sw=4 expandtab: */

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