Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
indent is evil
  • Loading branch information
slouken committed Oct 28, 2006
1 parent 7a9dd46 commit 5bcee32
Show file tree
Hide file tree
Showing 35 changed files with 597 additions and 508 deletions.
10 changes: 4 additions & 6 deletions include/SDL_thread.h
Expand Up @@ -91,12 +91,10 @@ typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
#endif

extern DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(int (SDLCALL * f) (void *),
void *data,
pfnSDL_CurrentBeginThread
pfnBeginThread,
pfnSDL_CurrentEndThread
pfnEndThread);
extern DECLSPEC SDL_Thread *SDLCALL
SDL_CreateThread(int (SDLCALL * f) (void *), void *data,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread);

#ifdef __OS2__
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
Expand Down
135 changes: 82 additions & 53 deletions src/audio/SDL_audio.c
Expand Up @@ -144,10 +144,11 @@ static AudioBootStrap *bootstrap[] = {
NULL
};

static SDL_AudioDevice *get_audio_device(SDL_AudioDeviceID id)
static SDL_AudioDevice *
get_audio_device(SDL_AudioDeviceID id)
{
id--;
if ( (id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL) ) {
if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
SDL_SetError("Invalid audio device ID");
return NULL;
}
Expand All @@ -157,22 +158,49 @@ static SDL_AudioDevice *get_audio_device(SDL_AudioDeviceID id)


/* stubs for audio drivers that don't need a specific entry point... */
static int SDL_AudioDetectDevices_Default(int iscapture) { return -1; }
static void SDL_AudioThreadInit_Default(_THIS) { /* no-op. */ }
static void SDL_AudioWaitDevice_Default(_THIS) { /* no-op. */ }
static void SDL_AudioPlayDevice_Default(_THIS) { /* no-op. */ }
static Uint8 *SDL_AudioGetDeviceBuf_Default(_THIS) { return NULL; }
static void SDL_AudioWaitDone_Default(_THIS) { /* no-op. */ }
static void SDL_AudioCloseDevice_Default(_THIS) { /* no-op. */ }
static void SDL_AudioDeinitialize_Default(void) { /* no-op. */ }
static int
SDL_AudioDetectDevices_Default(int iscapture)
{
return -1;
}
static void
SDL_AudioThreadInit_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioWaitDevice_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioPlayDevice_Default(_THIS)
{ /* no-op. */
}
static Uint8 *
SDL_AudioGetDeviceBuf_Default(_THIS)
{
return NULL;
}
static void
SDL_AudioWaitDone_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioCloseDevice_Default(_THIS)
{ /* no-op. */
}
static void
SDL_AudioDeinitialize_Default(void)
{ /* no-op. */
}

static int
SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
{
return 0;
}

static const char *SDL_AudioGetDeviceName_Default(int index, int iscapture)
static const char *
SDL_AudioGetDeviceName_Default(int index, int iscapture)
{
SDL_SetError("No such device");
return NULL;
Expand All @@ -197,14 +225,15 @@ SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
}


static void finalize_audio_entry_points(void)
static void
finalize_audio_entry_points(void)
{
/*
* Fill in stub functions for unused driver entry points. This lets us
* blindly call them without having to check for validity first.
*/

#define FILL_STUB(x) \
#define FILL_STUB(x) \
if (current_audio.impl.x == NULL) { \
current_audio.impl.x = SDL_Audio##x##_Default; \
}
Expand All @@ -220,7 +249,7 @@ static void finalize_audio_entry_points(void)
FILL_STUB(LockDevice);
FILL_STUB(UnlockDevice);
FILL_STUB(Deinitialize);
#undef FILL_STUB
#undef FILL_STUB
}


Expand Down Expand Up @@ -317,7 +346,7 @@ SDL_RunAudio(void *devicep)
static SDL_AudioFormat
SDL_ParseAudioFormat(const char *string)
{
#define CHECK_FMT_STRING(x) if (strcmp(string, #x) == 0) return AUDIO_##x
#define CHECK_FMT_STRING(x) if (strcmp(string, #x) == 0) return AUDIO_##x
CHECK_FMT_STRING(U8);
CHECK_FMT_STRING(S8);
CHECK_FMT_STRING(U16LSB);
Expand All @@ -336,7 +365,7 @@ SDL_ParseAudioFormat(const char *string)
CHECK_FMT_STRING(F32MSB);
CHECK_FMT_STRING(F32SYS);
CHECK_FMT_STRING(F32);
#undef CHECK_FMT_STRING
#undef CHECK_FMT_STRING
return 0;
}

Expand All @@ -363,11 +392,11 @@ SDL_AudioInit(const char *driver_name)
int tried_to_init = 0;

if (SDL_WasInit(SDL_INIT_AUDIO)) {
SDL_AudioQuit(); /* shutdown driver if already running. */
SDL_AudioQuit(); /* shutdown driver if already running. */
}

SDL_memset(&current_audio, '\0', sizeof (current_audio));
SDL_memset(open_devices, '\0', sizeof (open_devices));
SDL_memset(&current_audio, '\0', sizeof(current_audio));
SDL_memset(open_devices, '\0', sizeof(open_devices));

/* Select the proper audio driver */
if (driver_name == NULL) {
Expand All @@ -377,13 +406,13 @@ SDL_AudioInit(const char *driver_name)
for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
/* make sure we should even try this driver before doing so... */
const AudioBootStrap *backend = bootstrap[i];
if ( ((driver_name) && (SDL_strcasecmp(backend->name, driver_name))) ||
((!driver_name) && (backend->demand_only)) ) {
if (((driver_name) && (SDL_strcasecmp(backend->name, driver_name))) ||
((!driver_name) && (backend->demand_only))) {
continue;
}

tried_to_init = 1;
SDL_memset(&current_audio, 0, sizeof (current_audio));
SDL_memset(&current_audio, 0, sizeof(current_audio));
current_audio.name = backend->name;
current_audio.desc = backend->desc;
initialized = backend->init(&current_audio.impl);
Expand All @@ -399,8 +428,8 @@ SDL_AudioInit(const char *driver_name)
}
}

SDL_memset(&current_audio, 0, sizeof (current_audio));
return (-1); /* No driver was available, so fail. */
SDL_memset(&current_audio, 0, sizeof(current_audio));
return (-1); /* No driver was available, so fail. */
}

finalize_audio_entry_points();
Expand Down Expand Up @@ -471,7 +500,7 @@ SDL_GetAudioDeviceName(int index, int iscapture)


static void
close_audio_device(SDL_AudioDevice *device)
close_audio_device(SDL_AudioDevice * device)
{
device->enabled = 0;
if (device->thread != NULL) {
Expand Down Expand Up @@ -500,9 +529,9 @@ close_audio_device(SDL_AudioDevice *device)
* Returns non-zero if okay, zero on fatal parameters in (orig).
*/
static int
prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)
prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared)
{
SDL_memcpy(prepared, orig, sizeof (SDL_AudioSpec));
SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));

if (orig->callback == NULL) {
SDL_SetError("SDL_OpenAudio() passed a NULL callback");
Expand All @@ -511,26 +540,26 @@ prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)

if (orig->freq == 0) {
const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
if ( (!env) || ((prepared->freq = SDL_atoi(env)) == 0) ) {
prepared->freq = 22050; /* a reasonable default */
if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
prepared->freq = 22050; /* a reasonable default */
}
}

if (orig->format == 0) {
const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
prepared->format = AUDIO_S16; /* a reasonable default */
prepared->format = AUDIO_S16; /* a reasonable default */
}
}

switch (orig->channels) {
case 0: {
const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
if ( (!env) || ((prepared->channels = SDL_atoi(env)) == 0) ) {
prepared->channels = 2; /* a reasonable default */
case 0:{
const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
if ((!env) || ((prepared->channels = SDL_atoi(env)) == 0)) {
prepared->channels = 2; /* a reasonable default */
}
break;
}
break;
}
case 1: /* Mono */
case 2: /* Stereo */
case 4: /* surround */
Expand All @@ -543,7 +572,7 @@ prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)

if (orig->samples == 0) {
const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
if ( (!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0) ) {
if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
/* Pick a default of ~46 ms at desired frequency */
/* !!! FIXME: remove this when the non-Po2 resampling is in. */
const int samples = (prepared->freq / 1000) * 46;
Expand All @@ -564,8 +593,8 @@ prepare_audiospec(const SDL_AudioSpec *orig, SDL_AudioSpec *prepared)

static SDL_AudioDeviceID
open_audio_device(const char *devname, int iscapture,
const SDL_AudioSpec *_desired, SDL_AudioSpec *obtained,
int min_id)
const SDL_AudioSpec * _desired, SDL_AudioSpec * obtained,
int min_id)
{
SDL_AudioDeviceID id = 0;
SDL_AudioSpec desired;
Expand Down Expand Up @@ -631,13 +660,13 @@ open_audio_device(const char *devname, int iscapture,
}
}

device = (SDL_AudioDevice *) SDL_AllocAudioMem(sizeof (SDL_AudioDevice));
device = (SDL_AudioDevice *) SDL_AllocAudioMem(sizeof(SDL_AudioDevice));
if (device == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(device, '\0', sizeof (SDL_AudioDevice));
SDL_memcpy(&device->spec, &desired, sizeof (SDL_AudioSpec));
SDL_memset(device, '\0', sizeof(SDL_AudioDevice));
SDL_memcpy(&device->spec, &desired, sizeof(SDL_AudioSpec));
device->enabled = 1;
device->paused = 1;
device->iscapture = iscapture;
Expand Down Expand Up @@ -688,8 +717,8 @@ open_audio_device(const char *devname, int iscapture,
return 0;
}
if (device->convert.needed) {
device->convert.len = (int) ( ((double) desired.size) /
device->convert.len_ratio );
device->convert.len = (int) (((double) desired.size) /
device->convert.len_ratio);

device->convert.buf =
(Uint8 *) SDL_AllocAudioMem(device->convert.len *
Expand All @@ -703,7 +732,7 @@ open_audio_device(const char *devname, int iscapture,
}

/* Find an available device ID and store the structure... */
for (id = min_id-1; id < SDL_arraysize(open_devices); id++) {
for (id = min_id - 1; id < SDL_arraysize(open_devices); id++) {
if (open_devices[id] == NULL) {
open_devices[id] = device;
break;
Expand All @@ -727,13 +756,13 @@ open_audio_device(const char *devname, int iscapture,
device->thread = SDL_CreateThread(SDL_RunAudio, device);
#endif
if (device->thread == NULL) {
SDL_CloseAudioDevice(id+1);
SDL_CloseAudioDevice(id + 1);
SDL_SetError("Couldn't create audio thread");
return 0;
}
}

return id+1;
return id + 1;
}


Expand All @@ -756,9 +785,9 @@ SDL_OpenAudio(const SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
}

id = open_audio_device(NULL, 0, desired, obtained, 1);
if (id > 1) { /* this should never happen in theory... */
if (id > 1) { /* this should never happen in theory... */
SDL_CloseAudioDevice(id);
SDL_SetError("Internal error"); /* MUST be Device ID #1! */
SDL_SetError("Internal error"); /* MUST be Device ID #1! */
return (-1);
}

Expand All @@ -767,7 +796,7 @@ SDL_OpenAudio(const SDL_AudioSpec * desired, SDL_AudioSpec * obtained)

SDL_AudioDeviceID
SDL_OpenAudioDevice(const char *device, int iscapture,
const SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
const SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
{
return open_audio_device(device, iscapture, desired, obtained, 2);
}
Expand Down Expand Up @@ -848,7 +877,7 @@ SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
close_audio_device(device);
open_devices[devid-1] = NULL;
open_devices[devid - 1] = NULL;
}
}

Expand All @@ -868,8 +897,8 @@ SDL_AudioQuit(void)

/* Free the driver data */
current_audio.impl.Deinitialize();
SDL_memset(&current_audio, '\0', sizeof (current_audio));
SDL_memset(open_devices, '\0', sizeof (open_devices));
SDL_memset(&current_audio, '\0', sizeof(current_audio));
SDL_memset(open_devices, '\0', sizeof(open_devices));
}

#define NUM_FORMATS 10
Expand Down
13 changes: 7 additions & 6 deletions src/audio/SDL_audiodev.c
Expand Up @@ -47,14 +47,15 @@
#endif

static inline void
test_device(const char *fname, int flags, int (*test)(int fd),
test_device(const char *fname, int flags, int (*test) (int fd),
char ***devices, int *devCount)
{
struct stat sb;
if ( (stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode)) ) {
if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
int audio_fd = open(fname, flags, 0);
if ( (audio_fd >= 0) && (test(audio_fd)) ) {
void *p = SDL_realloc(*devices, ((*devCount)+1) * sizeof (char *));
if ((audio_fd >= 0) && (test(audio_fd))) {
void *p =
SDL_realloc(*devices, ((*devCount) + 1) * sizeof(char *));
if (p != NULL) {
size_t len = strlen(fname) + 1;
char *str = (char *) SDL_malloc(len);
Expand All @@ -75,7 +76,7 @@ SDL_FreeUnixAudioDevices(char ***devices, int *devCount)
int i = *devCount;
if ((i > 0) && (*devices != NULL)) {
while (i--) {
SDL_free( (*devices)[*devCount] );
SDL_free((*devices)[*devCount]);
}
}

Expand All @@ -94,7 +95,7 @@ test_stub(int fd)
}

void
SDL_EnumUnixAudioDevices(int flags, int classic, int (*test)(int fd),
SDL_EnumUnixAudioDevices(int flags, int classic, int (*test) (int fd),
char ***devices, int *devCount)
{
const char *audiodev;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/SDL_audiodev_c.h
Expand Up @@ -21,7 +21,7 @@
*/
#include "SDL_config.h"

void SDL_EnumUnixAudioDevices(int flags, int classic, int (*test)(int fd),
void SDL_EnumUnixAudioDevices(int flags, int classic, int (*test) (int fd),
char ***devs, int *count);
void SDL_FreeUnixAudioDevices(char ***devices, int *devCount);

Expand Down

0 comments on commit 5bcee32

Please sign in to comment.