annotate src/audio/nas/SDL_nasaudio.c @ 4396:f5d3f7fa071d SDL-1.2

1.2 pulseaudio: make some function pointers static.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 17 Jan 2010 05:17:59 +0000
parents 2f5e884f0a9d
children
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22 This driver was written by:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 Erik Inge Bolsų
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 knan@mo.himolde.no
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
26 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 /* Allow access to a raw mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
33 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
36 #include "../SDL_audio_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
37 #include "../SDL_audiodev_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include "SDL_nasaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
40 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
41 #include "SDL_loadso.h"
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
42 #endif
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
43
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 /* The tag name used by artsc audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #define NAS_DRIVER_NAME "nas"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 static struct SDL_PrivateAudioData *this2 = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
49 static void (*NAS_AuCloseServer) (AuServer *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
50 static void (*NAS_AuNextEvent) (AuServer *, AuBool, AuEvent *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
51 static AuBool(*NAS_AuDispatchEvent) (AuServer *, AuEvent *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
52 static AuFlowID(*NAS_AuCreateFlow) (AuServer *, AuStatus *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
53 static void (*NAS_AuStartFlow) (AuServer *, AuFlowID, AuStatus *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
54 static void (*NAS_AuSetElements)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
55 (AuServer *, AuFlowID, AuBool, int, AuElement *, AuStatus *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
56 static void (*NAS_AuWriteElement)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
57 (AuServer *, AuFlowID, int, AuUint32, AuPointer, AuBool, AuStatus *);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
58 static AuServer *(*NAS_AuOpenServer)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
59 (_AuConst char *, int, _AuConst char *, int, _AuConst char *, char **);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
60 static AuEventHandlerRec *(*NAS_AuRegisterEventHandler)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
61 (AuServer *, AuMask, int, AuID, AuEventHandlerCallback, AuPointer);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
62
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
63
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
64 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
65
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
66 static const char *nas_library = SDL_AUDIO_DRIVER_NAS_DYNAMIC;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
67 static void *nas_handle = NULL;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
68
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
69 static int
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
70 load_nas_sym(const char *fn, void **addr)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
71 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
72 *addr = SDL_LoadFunction(nas_handle, fn);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
73 if (*addr == NULL) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
74 return 0;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
75 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
76 return 1;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
77 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
78
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
79 /* cast funcs to char* first, to please GCC's strict aliasing rules. */
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
80 #define SDL_NAS_SYM(x) \
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
81 if (!load_nas_sym(#x, (void **) (char *) &NAS_##x)) return -1
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
82 #else
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
83 #define SDL_NAS_SYM(x) NAS_##x = x
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
84 #endif
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
85
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
86 static int
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
87 load_nas_syms(void)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
88 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
89 SDL_NAS_SYM(AuCloseServer);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
90 SDL_NAS_SYM(AuNextEvent);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
91 SDL_NAS_SYM(AuDispatchEvent);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
92 SDL_NAS_SYM(AuCreateFlow);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
93 SDL_NAS_SYM(AuStartFlow);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
94 SDL_NAS_SYM(AuSetElements);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
95 SDL_NAS_SYM(AuWriteElement);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
96 SDL_NAS_SYM(AuOpenServer);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
97 SDL_NAS_SYM(AuRegisterEventHandler);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
98 return 0;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
99 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
100
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
101 #undef SDL_NAS_SYM
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
102
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
103 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
104
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
105 static void
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
106 UnloadNASLibrary(void)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
107 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
108 if (nas_handle != NULL) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
109 SDL_UnloadObject(nas_handle);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
110 nas_handle = NULL;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
111 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
112 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
113
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
114 static int
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
115 LoadNASLibrary(void)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
116 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
117 int retval = 0;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
118 if (nas_handle == NULL) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
119 nas_handle = SDL_LoadObject(nas_library);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
120 if (nas_handle == NULL) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
121 /* Copy error string so we can use it in a new SDL_SetError(). */
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
122 char *origerr = SDL_GetError();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
123 size_t len = SDL_strlen(origerr) + 1;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
124 char *err = (char *) alloca(len);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
125 SDL_strlcpy(err, origerr, len);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
126 retval = -1;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
127 SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s\n",
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
128 nas_library, err);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
129 } else {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
130 retval = load_nas_syms();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
131 if (retval < 0) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
132 UnloadNASLibrary();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
133 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
134 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
135 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
136 return retval;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
137 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
138
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
139 #else
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
140
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
141 static void
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
142 UnloadNASLibrary(void)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
143 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
144 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
145
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
146 static int
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
147 LoadNASLibrary(void)
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
148 {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
149 load_nas_syms();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
150 return 0;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
151 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
152
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
153 #endif /* SDL_AUDIO_DRIVER_NAS_DYNAMIC */
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
154
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
155
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 /* Audio driver functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 static void NAS_WaitAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 static void NAS_PlayAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 static Uint8 *NAS_GetAudioBuf(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 static void NAS_CloseAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 /* Audio driver bootstrap functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 static int Audio_Available(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 {
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
167 if (LoadNASLibrary() == 0) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
168 AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
169 if (!aud) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
170 UnloadNASLibrary();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
171 return 0;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
172 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
173 NAS_AuCloseServer(aud);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
174 UnloadNASLibrary();
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
175 return 1;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
176 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
177 return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 static void Audio_DeleteDevice(SDL_AudioDevice *device)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 {
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
182 UnloadNASLibrary();
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
183 SDL_free(device->hidden);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
184 SDL_free(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 SDL_AudioDevice *this;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
191 if (LoadNASLibrary() < 0) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
192 return NULL;
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
193 }
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
194
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 /* Initialize all variables that we clean on shutdown */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
196 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 if ( this ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
198 SDL_memset(this, 0, (sizeof *this));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 this->hidden = (struct SDL_PrivateAudioData *)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
200 SDL_malloc((sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 if ( (this == NULL) || (this->hidden == NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 if ( this ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
205 SDL_free(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 }
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
207 return NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
209 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 /* Set the function pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 this->OpenAudio = NAS_OpenAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 this->WaitAudio = NAS_WaitAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 this->PlayAudio = NAS_PlayAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 this->GetAudioBuf = NAS_GetAudioBuf;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 this->CloseAudio = NAS_CloseAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 this->free = Audio_DeleteDevice;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 return this;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 AudioBootStrap NAS_bootstrap = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 NAS_DRIVER_NAME, "Network Audio System",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 Audio_Available, Audio_CreateDevice
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 /* This function waits until it is possible to write a full sound buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 static void NAS_WaitAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 while ( this->hidden->buf_free < this->hidden->mixlen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 AuEvent ev;
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
233 NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
234 NAS_AuDispatchEvent(this->hidden->aud, &ev);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 static void NAS_PlayAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 while (this->hidden->mixlen > this->hidden->buf_free) { /* We think the buffer is full? Yikes! Ask the server for events,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 in the hope that some of them is LowWater events telling us more
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 of the buffer is free now than what we think. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 AuEvent ev;
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
244 NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
245 NAS_AuDispatchEvent(this->hidden->aud, &ev);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 this->hidden->buf_free -= this->hidden->mixlen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 /* Write the audio data */
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
250 NAS_AuWriteElement(this->hidden->aud, this->hidden->flow, 0, this->hidden->mixlen, this->hidden->mixbuf, AuFalse, NULL);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 this->hidden->written += this->hidden->mixlen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 #ifdef DEBUG_AUDIO
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 static Uint8 *NAS_GetAudioBuf(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 return(this->hidden->mixbuf);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 static void NAS_CloseAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 if ( this->hidden->mixbuf != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 SDL_FreeAudioMem(this->hidden->mixbuf);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 this->hidden->mixbuf = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 if ( this->hidden->aud ) {
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
271 NAS_AuCloseServer(this->hidden->aud);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 this->hidden->aud = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 static unsigned char sdlformat_to_auformat(unsigned int fmt)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 switch (fmt)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 case AUDIO_U8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 return AuFormatLinearUnsigned8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 case AUDIO_S8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 return AuFormatLinearSigned8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 case AUDIO_U16LSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 return AuFormatLinearUnsigned16LSB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 case AUDIO_U16MSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 return AuFormatLinearUnsigned16MSB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288 case AUDIO_S16LSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 return AuFormatLinearSigned16LSB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 case AUDIO_S16MSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 return AuFormatLinearSigned16MSB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 return AuNone;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 static AuBool
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 event_handler(AuServer* aud, AuEvent* ev, AuEventHandlerRec* hnd)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 switch (ev->type) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 case AuEventTypeElementNotify: {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 AuElementNotifyEvent* event = (AuElementNotifyEvent *)ev;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 switch (event->kind) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 case AuElementNotifyKindLowWater:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 if (this2->buf_free >= 0) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 this2->really += event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 gettimeofday(&this2->last_tv, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 this2->buf_free += event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 this2->buf_free = event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 case AuElementNotifyKindState:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 switch (event->cur_state) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 case AuStatePause:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 if (event->reason != AuReasonUser) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 if (this2->buf_free >= 0) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 this2->really += event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 gettimeofday(&this2->last_tv, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 this2->buf_free += event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 this2->buf_free = event->num_bytes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 return AuTrue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 static AuDeviceID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 find_device(_THIS, int nch)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 {
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
336 /* These "Au" things are all macros, not functions... */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) ==
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 AuComponentKindPhysicalOutput) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 return AuNone;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 AuElement elms[3];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 int buffer_size;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 Uint16 test_format, format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 this->hidden->mixbuf = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 /* Try for a closest match on audio format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 format = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 for ( test_format = SDL_FirstAudioFormat(spec->format);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 ! format && test_format; ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 format = sdlformat_to_auformat(test_format);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 if (format == AuNone) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 test_format = SDL_NextAudioFormat();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 if ( format == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 SDL_SetError("Couldn't find any hardware audio formats");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 spec->format = test_format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
372 this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 if (this->hidden->aud == 0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 SDL_SetError("Couldn't open connection to NAS server");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 return (-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 this->hidden->dev = find_device(this, spec->channels);
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
380 if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, NULL)))) {
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
381 NAS_AuCloseServer(this->hidden->aud);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 this->hidden->aud = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 SDL_SetError("Couldn't find a fitting playback device on NAS server");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 return (-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 buffer_size = spec->freq;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 if (buffer_size < 4096)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 buffer_size = 4096;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 if (buffer_size > 32768)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 buffer_size = 32768; /* So that the buffer won't get unmanageably big. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 /* Calculate the final parameters for this audio specification */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 SDL_CalculateAudioSpec(spec);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 this2 = this->hidden;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
399 /* These "Au" things without a NAS_ prefix are macros, not functions... */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 AuMakeElementImportClient(elms, spec->freq, format, spec->channels, AuTrue,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 buffer_size, buffer_size / 4, 0, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 AuMakeElementExportDevice(elms+1, 0, this->hidden->dev, spec->freq,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 AuUnlimitedSamples, 0, NULL);
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
404 NAS_AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL);
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
405 NAS_AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 event_handler, (AuPointer) NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407
4192
2f5e884f0a9d Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
408 NAS_AuStartFlow(this->hidden->aud, this->hidden->flow, NULL);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 /* Allocate mixing buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 this->hidden->mixlen = spec->size;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 if ( this->hidden->mixbuf == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
416 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 /* Get the parent process id (we're the parent of the audio thread) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419 this->hidden->parent = getpid();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 /* We're ready to rock and roll. :-) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 }