Mercurial > almixer_isolated
annotate ALmixer.c @ 12:bfe90b4f3d87
Bug fixes to FadeIn.
Documentation fixes
Minor API changes w.r.t. return types. (ALboolean instead of ALint)
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Fri, 05 Nov 2010 20:59:13 -0700 |
parents | c808684660a7 |
children | 54aa96ae8912 |
rev | line source |
---|---|
0 | 1 |
2 /* Here's an OpenAL implementation modeled after | |
3 * the SDL_SoundMixer which was built ontop of SDL_Mixer | |
4 * and SDL_Sound. | |
5 * Eric Wing | |
6 */ | |
7 | |
3
a929285e1db0
Added CMake build system.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
2
diff
changeset
|
8 #include "ALmixer.h" |
0 | 9 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
10 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
11 #include "ALmixer_rwops.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
12 #include "SoundDecoder.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
13 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
14 #include "SDL_sound.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
15 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
16 |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
17 #ifdef ANDROID_NDK |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
18 #include <AL/al.h> |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
19 #include <AL/alc.h> |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
20 #else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
21 #include "al.h" /* OpenAL */ |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
22 #include "alc.h" /* For creating OpenAL contexts */ |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
23 #endif |
0 | 24 |
1 | 25 #ifdef __APPLE__ |
26 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
27 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
28 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
29 * define was moved to a new header file and renamed to | |
30 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
31 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #include <TargetConditionals.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
35 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
36 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
37 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
38 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
39 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
40 |
1 | 41 #endif |
42 | |
0 | 43 /* For malloc, bsearch, qsort */ |
44 #include <stdlib.h> | |
45 | |
46 /* For memcpy */ | |
47 #include <string.h> | |
48 | |
49 #if 0 | |
50 /* for toupper */ | |
51 #include <ctype.h> | |
52 /* for strrchr */ | |
53 #include <string.h> | |
54 #endif | |
55 | |
56 /* Currently used in the output debug functions */ | |
57 #include <stdio.h> | |
58 | |
59 /* My own CircularQueue implementation needed | |
60 * to work around the Nvidia problem of the | |
61 * lack of a buffer query. | |
62 */ | |
63 #include "CircularQueue.h" | |
64 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
65 #ifdef ENABLE_ALMIXER_THREADS |
0 | 66 /* Needed for the Mutex locks (and threads if enabled) */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
67 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
68 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
69 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
70 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
72 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
73 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
78 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
79 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
80 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
81 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
82 #endif |
0 | 83 |
84 /* Because of the API differences between the Loki | |
85 * and Creative distributions, we need to know which | |
86 * version to use. The LOKI distribution currently | |
87 * has AL_BYTE_LOKI defined in altypes.h which | |
88 * I will use as a flag to identify the distributions. | |
89 * If this is ever removed, I might revert back to the | |
90 * if defined(_WIN32) or defined(__APPLE__) test to | |
91 * identify the Creative dist. | |
92 * I'm not sure if or how the Nvidia distribution differs | |
93 * from the Creative distribution. So for | |
94 * now, the Nvidia distribution gets lumped with the | |
95 * Creative dist and I hope nothing will break. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
96 * My alGetString may be the most vulnerable. |
0 | 97 */ |
98 #ifdef AL_BYTE_LOKI | |
99 #define USING_LOKI_AL_DIST | |
100 /* This is a short term fix to get around the | |
101 * queuing problem with non-power of two buffer sizes. | |
102 * Hopefully the maintainers will fix this before | |
103 * we're ready to ship. | |
104 */ | |
105 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
106 | |
107 /* The AL_GAIN in the Loki dist doesn't seem to do | |
108 * what I want/expect it to do. I want to use it for | |
109 * Fading, but it seems to work like an off/on switch. | |
110 * 0 = off, >0 = on. | |
111 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
112 * I want, so I'll redefine it here so the code is consistent | |
113 */ | |
114 /* Update: I've changed the source volume implementations | |
115 * to use AL_MAX_GAIN, so I don't think I need this block | |
116 * of code anymore. The listener uses AL_GAIN, but I | |
117 * hope they got this one right since there isn't a AL_MAX_GAIN | |
118 * for the listener. | |
119 */ | |
120 /* | |
121 #undef AL_GAIN | |
122 #include "alexttypes.h" | |
123 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
124 */ | |
125 #else | |
126 /* Might need to run other tests to figure out the DIST */ | |
127 /* I've been told that Nvidia doesn't define constants | |
128 * in the headers like Creative. Instead of | |
129 * #define AL_REFERENCE_DISTANCE 0x1020, | |
130 * Nvidia prefers you query OpenAL for a value. | |
131 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
132 * So I'm assuming this means the Nvidia lacks this value. | |
133 * If this is the case, | |
134 * I guess we can use it to identify the Nvidia dist | |
135 */ | |
136 #ifdef AL_REFERENCE_DISTANCE | |
137 #define USING_CREATIVE_AL_DIST | |
138 #else | |
139 #define USING_NVIDIA_AL_DIST | |
140 #endif | |
141 #endif | |
142 | |
143 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
144 /* Need memset to zero out data */ | |
145 #include <string.h> | |
146 #endif | |
147 | |
148 | |
149 /* Seek issues for predecoded samples: | |
150 * The problem is that OpenAL makes us copy an | |
151 * entire buffer if we want to use it. This | |
152 * means we potentially have two copies of the | |
153 * same data. For predecoded data, this can be a | |
154 * large amount of memory. However, for seek | |
155 * support, I need to be able to get access to | |
156 * the original data so I can set byte positions. | |
157 * The following flags let you disable seek support | |
158 * if you don't want the memory hit, keep everything, | |
159 * or let you try to minimize the memory wasted by | |
160 * fetching it from the OpenAL buffer if needed | |
161 * and making a copy of it. | |
162 * Update: I don't think I need this flag anymore. I've made the | |
163 * effects of this user customizable by the access_data flag on load. | |
164 * If set to true, then seek and data callbacks work, with the | |
165 * cost of more memory and possibly CPU for copying the data through | |
166 * the callbacks. If false, then the extra memory is freed, but | |
167 * you don't get the features. | |
168 */ | |
169 /* | |
170 #define DISABLE_PREDECODED_SEEK | |
171 */ | |
172 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
173 * is in the Creative Programmer's reference, | |
174 * it actually isn't in the dist. (Invalid enum | |
175 * in Creative, can't compile in Loki.) | |
176 * So we have to keep it disabled | |
177 */ | |
178 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
179 | |
180 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
181 /* Needed for memcpy */ | |
182 #include <string.h> | |
183 #endif | |
184 | |
185 /* Old way of doing things: | |
186 #if defined(_WIN32) || defined(__APPLE__) | |
187 #define USING_CREATIVE_AL_DIST | |
188 #else | |
189 #define USING_LOKI_AL_DIST | |
190 #endif | |
191 */ | |
192 | |
193 /************ REMOVE ME (Don't need anymore) ********/ | |
194 #if 0 | |
195 /* Let's get fancy and see if triple buffering | |
196 * does anything good for us | |
197 * Must be 2 or more or things will probably break | |
198 */ | |
199 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
200 /* This is the number of buffers that are queued up | |
201 * when play first starts up. This should be at least 1 | |
202 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
203 */ | |
204 #define NUMBER_OF_START_UP_BUFFERS 2 | |
205 #endif | |
206 /************ END REMOVE ME (Don't need anymore) ********/ | |
207 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
208 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
209 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
210 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
211 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
212 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
213 static ALboolean ALmixer_Initialized = 0; |
0 | 214 /* This should be set correctly by Init */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
215 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 216 |
217 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
218 static ALint Number_of_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
219 static ALint Number_of_Reserve_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
220 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
221 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
222 #ifdef ENABLE_ALMIXER_THREADS |
0 | 223 /* This is for a simple lock system. It is not meant to be good, |
224 * but just sufficient to minimize/avoid threading issues | |
225 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
226 static SDL_mutex* s_simpleLock; |
0 | 227 static SDL_Thread* Stream_Thread_global = NULL; |
228 #endif | |
229 | |
230 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
231 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
232 static ALvoid Internal_alcMacOSXMixerOutputRate(const ALdouble sample_rate) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
233 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
234 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
235 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
236 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
237 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
238 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
239 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
240 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
243 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
245 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
249 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
250 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
252 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
254 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
255 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
256 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
257 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
258 if(NULL != alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
259 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
260 return alcMacOSXGetMixerOutputRateProcPtr(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
261 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
262 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 return 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
266 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
267 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
268 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
269 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
271 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
272 static CFTimeInterval s_ticksBaseTime = 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
273 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
274 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 LARGE_INTEGER hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 if(TRUE == QueryPerformanceFrequency(&hi_res_ticks_per_second)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 s_hiResSecondsPerTick = 1.0 / hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
298 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 ALMixer_SetError("Windows error: High resolution clock failed."); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 fprintf(stderr, "Windows error: High resolution clock failed. Audio will not work correctly.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
302 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
303 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
306 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
308 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 return (ALuint)((CACurrentMediaTime()-s_ticksBaseTime)*1000.0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
317 #elif ANDROID_NDK |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
320 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
323 return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nsec - s_ticksBaseTime.tv_nsec) / 1000000); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
326 static void ALmixer_Delay(ALuint milliseconds_delay) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
327 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
328 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
330 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
332 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
334 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 #include "SDL.h" /* For SDL_GetTicks(), SDL_Delay */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
336 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
337 #define ALmixer_Delay SDL_Delay |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
339 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
341 |
0 | 342 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
343 * these values will be reset on Init() | |
344 * Consider these values Read-Only. | |
345 */ | |
346 | |
347 #define ALMIXER_SIGNED_VALUE 127 | |
348 #define ALMIXER_UNSIGNED_VALUE 255 | |
349 | |
350 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
351 static ALushort SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
352 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 353 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
354 static const ALushort SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
355 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 356 #endif |
357 | |
1 | 358 |
359 /* This can be private instead of being in the header now that I moved | |
360 * ALmixer_Data inside here. | |
361 */ | |
362 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
363 | |
364 | |
365 struct ALmixer_Data | |
366 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
367 ALboolean decoded_all; /* dictates different behaviors */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
368 ALint total_time; /* total playing time of sample (msec) */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
369 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
370 ALuint in_use; /* needed to prevent sharing for streams */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
371 ALboolean eof; /* flag for eof, only used for streams */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
372 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
373 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
374 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 375 |
376 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
377 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
378 | |
379 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
380 ALuint max_queue_buffers; /* Max number of queue buffers */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
381 ALuint num_startup_buffers; /* Number of ramp-up buffers */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
382 ALuint num_buffers_in_use; /* number of buffers in use */ |
1 | 383 |
384 /* This stuff is for streamed buffers that require data access */ | |
385 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
386 and holds pointer to copy of data for | |
387 data access */ | |
388 ALuint current_buffer; /* The current playing buffer */ | |
389 | |
390 /* Nvidia distribution refuses to recognize a simple buffer query command | |
391 * unlike all other distributions. It's forcing me to redo the code | |
392 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
393 * copy of what I think the buffer queue state looks like. | |
394 * A circular queue would a helpful data structure for this task, | |
395 * but I wanted to avoid making an additional header requirement, | |
396 * so I'm making it a void* | |
397 */ | |
398 void* circular_buffer_queue; | |
399 | |
400 | |
401 }; | |
402 | |
0 | 403 static struct ALmixer_Channel |
404 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
405 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
406 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
407 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
408 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
409 ALboolean paused; |
0 | 410 ALuint alsource; |
411 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
412 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
413 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
414 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
415 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
416 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
417 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
418 ALuint fade_start_time; |
0 | 419 ALfloat fade_inv_time; |
420 ALfloat fade_start_volume; | |
421 ALfloat fade_end_volume; | |
422 ALfloat max_volume; | |
423 ALfloat min_volume; | |
424 | |
425 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
426 ALbyte *samples; |
0 | 427 int volume; |
428 int looping; | |
429 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
430 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
431 ALuint start_time; |
0 | 432 Mix_Fading fading; |
433 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
434 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
435 ALuint ticks_fade; |
0 | 436 effect_info *effects; |
437 */ | |
438 } *ALmixer_Channel_List = NULL; | |
439 | |
1 | 440 struct ALmixer_Buffer_Map |
441 { | |
442 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
443 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
444 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
445 ALuint num_bytes; |
1 | 446 }; |
447 | |
0 | 448 /* This will be used to find a channel if the user supplies a source */ |
449 typedef struct Source_Map | |
450 { | |
451 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 ALint channel; |
0 | 453 } Source_Map; |
454 /* Keep an array of all sources with their associated channel */ | |
455 static Source_Map* Source_Map_List; | |
456 | |
457 static int Compare_Source_Map(const void* a, const void* b) | |
458 { | |
459 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
460 } | |
461 | |
462 /* Sort by channel instead of source */ | |
463 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
464 { | |
465 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
466 } | |
467 | |
468 /* Compare by albuffer */ | |
469 static int Compare_Buffer_Map(const void* a, const void* b) | |
470 { | |
1 | 471 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 472 } |
473 | |
474 /* This is for the user defined callback via | |
475 * ALmixer_ChannelFinished() | |
476 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
477 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 478 static void* Channel_Done_Callback_Userdata = NULL; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
479 static void (*Channel_Data_Callback)(ALint which_channel, ALuint al_source, ALbyte* data, ALuint num_bytes, ALuint frequency, ALubyte channels, ALubyte bit_depth, ALboolean is_unsigned, ALboolean decode_mode_is_predecoded, ALuint length_in_msec, void* user_data) = NULL; |
1 | 480 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 481 |
482 | |
483 static void PrintQueueStatus(ALuint source) | |
484 { | |
485 ALint buffers_queued = 0; | |
486 ALint buffers_processed = 0; | |
487 ALenum error; | |
488 | |
489 /* Get the number of buffers still queued */ | |
490 alGetSourcei( | |
491 source, | |
492 AL_BUFFERS_QUEUED, | |
493 &buffers_queued | |
494 ); | |
495 | |
496 if((error = alGetError()) != AL_NO_ERROR) | |
497 { | |
498 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_queued: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
499 alGetString(error)); |
0 | 500 } |
501 /* Get the number of buffers processed | |
502 * so we know if we need to refill | |
503 */ | |
504 alGetSourcei( | |
505 source, | |
506 AL_BUFFERS_PROCESSED, | |
507 &buffers_processed | |
508 ); | |
509 if((error = alGetError()) != AL_NO_ERROR) | |
510 { | |
511 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_processed: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
512 alGetString(error)); |
0 | 513 } |
514 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
515 /* |
0 | 516 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
517 source, | |
518 buffers_queued, | |
519 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
520 */ |
0 | 521 } |
522 | |
523 | |
524 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
525 static void Init_Channel(ALint channel) |
0 | 526 { |
527 ALmixer_Channel_List[channel].channel_in_use = 0; | |
528 ALmixer_Channel_List[channel].callback_update = 0; | |
529 ALmixer_Channel_List[channel].needs_stream = 0; | |
530 ALmixer_Channel_List[channel].paused = 0; | |
531 ALmixer_Channel_List[channel].halted = 0; | |
532 ALmixer_Channel_List[channel].loops = 0; | |
533 | |
534 ALmixer_Channel_List[channel].expire_ticks = 0; | |
535 ALmixer_Channel_List[channel].start_time = 0; | |
536 | |
537 ALmixer_Channel_List[channel].fade_enabled = 0; | |
538 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
539 ALmixer_Channel_List[channel].fade_start_time = 0; | |
540 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
541 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
542 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
543 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
544 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
545 | |
546 ALmixer_Channel_List[channel].almixer_data = NULL; | |
547 } | |
548 /* Quick helper function to clean up a channel | |
549 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
550 static void Clean_Channel(ALint channel) |
0 | 551 { |
552 ALenum error; | |
553 ALmixer_Channel_List[channel].channel_in_use = 0; | |
554 ALmixer_Channel_List[channel].callback_update = 0; | |
555 ALmixer_Channel_List[channel].needs_stream = 0; | |
556 ALmixer_Channel_List[channel].paused = 0; | |
557 ALmixer_Channel_List[channel].halted = 0; | |
558 ALmixer_Channel_List[channel].loops = 0; | |
559 | |
560 | |
561 ALmixer_Channel_List[channel].expire_ticks = 0; | |
562 ALmixer_Channel_List[channel].start_time = 0; | |
563 | |
564 ALmixer_Channel_List[channel].fade_enabled = 0; | |
565 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
566 ALmixer_Channel_List[channel].fade_start_time = 0; | |
567 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
568 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
569 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
570 | |
571 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
572 ALmixer_Channel_List[channel].max_volume); | |
573 | |
574 if((error = alGetError()) != AL_NO_ERROR) | |
575 { | |
576 fprintf(stderr, "10Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
577 alGetString(error)); |
0 | 578 } |
579 | |
580 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
581 ALmixer_Channel_List[channel].min_volume); | |
582 if((error = alGetError()) != AL_NO_ERROR) | |
583 { | |
584 fprintf(stderr, "11Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
585 alGetString(error)); |
0 | 586 } |
587 | |
588 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
589 { | |
590 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
591 { | |
592 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
593 } | |
594 } | |
595 /* Needed to determine if rewind is needed, can't reset */ | |
596 /* | |
597 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
598 */ | |
599 | |
600 ALmixer_Channel_List[channel].almixer_data = NULL; | |
601 } | |
602 | |
603 | |
604 #if 0 | |
605 /* Not needed anymore because not doing any fileext checks. | |
606 * | |
607 * Unfortunately, strcasecmp isn't portable so here's a | |
608 * reimplementation of it (taken from SDL_sound) | |
609 */ | |
610 static int ALmixer_strcasecmp(const char* x, const char* y) | |
611 { | |
612 int ux, uy; | |
613 | |
614 if (x == y) /* same pointer? Both NULL? */ | |
615 return(0); | |
616 | |
617 if (x == NULL) | |
618 return(-1); | |
619 | |
620 if (y == NULL) | |
621 return(1); | |
622 | |
623 do | |
624 { | |
625 ux = toupper((int) *x); | |
626 uy = toupper((int) *y); | |
627 if (ux > uy) | |
628 return(1); | |
629 else if (ux < uy) | |
630 return(-1); | |
631 x++; | |
632 y++; | |
633 } while ((ux) && (uy)); | |
634 | |
635 return(0); | |
636 } | |
637 #endif | |
638 | |
639 | |
640 /* What shoud this return? | |
641 * 127 for signed, 255 for unsigned | |
642 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
643 static ALubyte GetSignednessValue(ALushort format) |
0 | 644 { |
645 switch(format) | |
646 { | |
647 case AUDIO_U8: | |
648 case AUDIO_U16LSB: | |
649 case AUDIO_U16MSB: | |
650 return ALMIXER_UNSIGNED_VALUE; | |
651 break; | |
652 case AUDIO_S8: | |
653 case AUDIO_S16LSB: | |
654 case AUDIO_S16MSB: | |
655 return ALMIXER_SIGNED_VALUE; | |
656 break; | |
657 default: | |
658 return 0; | |
659 } | |
660 return 0; | |
661 } | |
662 | |
663 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
664 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
665 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
666 ALubyte bit_depth = 16; |
0 | 667 |
668 switch(format) | |
669 { | |
670 case AUDIO_U8: | |
671 case AUDIO_S8: | |
672 bit_depth = 8; | |
673 break; | |
674 | |
675 case AUDIO_U16LSB: | |
676 /* | |
677 case AUDIO_U16: | |
678 */ | |
679 case AUDIO_S16LSB: | |
680 /* | |
681 case AUDIO_S16: | |
682 */ | |
683 case AUDIO_U16MSB: | |
684 case AUDIO_S16MSB: | |
685 /* | |
686 case AUDIO_U16SYS: | |
687 case AUDIO_S16SYS: | |
688 */ | |
689 bit_depth = 16; | |
690 break; | |
691 default: | |
692 bit_depth = 0; | |
693 } | |
694 return bit_depth; | |
695 } | |
696 | |
697 /* Need to translate between SDL/SDL_Sound audiospec | |
698 * and OpenAL conventions */ | |
699 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
700 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
701 ALubyte bit_depth; |
0 | 702 |
703 bit_depth = GetBitDepth(info->format); | |
704 if(0 == bit_depth) | |
705 { | |
706 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
707 bit_depth = 16; | |
708 } | |
709 | |
710 if(2 == info->channels) | |
711 { | |
712 if(16 == bit_depth) | |
713 { | |
714 return AL_FORMAT_STEREO16; | |
715 } | |
716 else | |
717 { | |
718 return AL_FORMAT_STEREO8; | |
719 } | |
720 } | |
721 else | |
722 { | |
723 if(16 == bit_depth) | |
724 { | |
725 return AL_FORMAT_MONO16; | |
726 } | |
727 else | |
728 { | |
729 return AL_FORMAT_MONO8; | |
730 } | |
731 } | |
732 /* Make compiler happy. Shouldn't get here */ | |
733 return AL_FORMAT_STEREO16; | |
734 } | |
735 | |
1 | 736 |
737 /* This will compute the total playing time | |
738 * based upon the number of bytes and audio info. | |
739 * (In prinicple, it should compute the time for any given length) | |
740 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
741 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 742 { |
743 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
744 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
745 ALuint bytes_per_sec; |
1 | 746 |
747 if(0 == total_bytes) | |
748 { | |
749 return 0; | |
750 } | |
751 /* To compute Bytes per second, do | |
752 * samples_per_sec * bytes_per_sample * number_of_channels | |
753 */ | |
754 bytes_per_sec = frequency * bytes_per_sample * channels; | |
755 | |
756 /* Now to get total time (sec), do | |
757 * total_bytes / bytes_per_sec | |
758 */ | |
759 total_sec = total_bytes / (double)bytes_per_sec; | |
760 | |
761 /* Now convert seconds to milliseconds | |
762 * Add .5 to the float to do rounding before the final cast | |
763 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
764 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 765 /* |
766 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
767 */ | |
768 return total_msec; | |
769 } | |
770 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
771 static ALuint Compute_Total_Time(Sound_AudioInfo *info, size_t total_bytes) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
772 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
773 ALuint bytes_per_sample; |
1 | 774 |
775 if(0 == total_bytes) | |
776 { | |
777 return 0; | |
778 } | |
779 /* SDL has a mask trick I was not aware of. Mask the upper bits | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
780 * of the format, and you get 8 or 16 which is the bits per sample. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
781 * Divide by 8bits_per_bytes and you get bytes_per_sample |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
782 * I tested this under 32-bit and 64-bit and big and little endian |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
783 * to make sure this still works since I have since moved from |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
784 * Uint32 to unspecified size types like ALuint. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
785 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
786 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 787 |
788 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
789 } /* End Compute_Total_Time */ | |
790 | |
791 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
792 static size_t Compute_Total_Bytes_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, ALuint total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
793 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
794 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
795 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
796 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
797 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
798 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
803 * samples_per_sec * bytes_per_sample * number_of_channels |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
805 bytes_per_sec = frequency * bytes_per_sample * channels; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
806 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
807 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
808 total_sec = total_msec / 1000.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
809 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 total_bytes = (size_t)(((double)bytes_per_sec * total_sec) + 0.5); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
813 /* fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d, total_bytes=%d\n", frequency, bytes_per_sample, channels, total_msec, total_bytes); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
814 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
815 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
816 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
818 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
819 static size_t Compute_Total_Bytes(Sound_AudioInfo *info, ALuint total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
820 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
821 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
822 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
823 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
824 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
826 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
827 /* SDL has a mask trick I was not aware of. Mask the upper bits |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
828 * of the format, and you get 8 or 16 which is the bits per sample. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
829 * Divide by 8bits_per_bytes and you get bytes_per_sample |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
830 * I tested this under 32-bit and 64-bit and big and little endian |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
831 * to make sure this still works since I have since moved from |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
832 * Uint32 to unspecified size types like ALuint. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
833 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
834 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
835 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
836 return Compute_Total_Bytes_Decomposed(bytes_per_sample, info->rate, info->channels, total_msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
837 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
838 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
839 /* The back-end decoders seem to need to decode in quantized frame sizes. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 * So if I can pad the bytes to the next quanta, things might go more smoothly. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
841 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
842 static size_t Compute_Total_Bytes_With_Frame_Padding(Sound_AudioInfo *info, ALuint total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
843 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
844 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
845 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
846 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
849 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 size_t total_bytes = Compute_Total_Bytes(info, total_msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
852 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
854 bytes_per_frame = bytes_per_sample * info->channels; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
856 evenly_divisible_frames = total_bytes / bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
857 remainder_frames = total_bytes % bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
859 return_bytes = (evenly_divisible_frames * bytes_per_frame) + (remainder_frames * bytes_per_frame); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
860 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
861 /* Experimentally, some times I see to come up short in |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
862 * actual bytes decoded and I see a second pass is needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
863 * I'm worried this may have additional performance implications. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
864 * Sometimes in the second pass (depending on file), |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
865 * I have seen between 0 and 18 bytes. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
866 * I'm tempted to pad the bytes by some arbitrary amount. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
867 * However, I think currently the way SDL_sound is implemented, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
868 * there is a big waste of memory up front instead of per-pass, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
869 * so maybe I shouldn't worry about this. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
870 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
871 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
872 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
873 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
874 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
875 fprintf(stderr, "remainder_frames=%d, padded_total_bytes=%d\n", remainder_frames, return_bytes); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
876 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
877 return return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
878 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
879 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
880 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
881 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
882 |
1 | 883 |
0 | 884 /**************** REMOVED ****************************/ |
885 /* This was removed because I originally thought | |
886 * OpenAL could return a pointer to the buffer data, | |
887 * but I was wrong. If something like that is ever | |
888 * implemented, then this might become useful. | |
889 */ | |
890 #if 0 | |
891 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
892 * are needed if the Seek memory optimization is | |
893 * used. Also, the Loki dist doesn't seem to support | |
894 * AL_DATA which I need for it. | |
895 */ | |
896 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
897 | |
898 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
899 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
900 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
901 info->channels = (ALubyte)channels; |
0 | 902 |
903 /* Not sure if it should be signed or unsigned. Hopefully | |
904 * that detail won't be needed. | |
905 */ | |
906 if(8 == bits) | |
907 { | |
908 info->format = AUDIO_U8; | |
909 } | |
910 else | |
911 { | |
912 info->format = AUDIO_U16SYS; | |
913 } | |
914 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
915 info->rate, info->channels, info->format); | |
916 | |
917 } | |
918 | |
919 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
920 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 921 { |
922 ALenum error; | |
923 ALint* data_from_albuffer; | |
924 ALint freq; | |
925 ALint bits; | |
926 ALint channels; | |
927 ALint size; | |
928 | |
929 /* Create memory all initiallized to 0. */ | |
930 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
931 if(NULL == data->sample) | |
932 { | |
933 ALmixer_SetError("Out of memory for Sound_Sample"); | |
934 return -1; | |
935 } | |
936 | |
937 /* Clear errors */ | |
938 alGetError(); | |
939 | |
940 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
941 if((error = alGetError()) != AL_NO_ERROR) | |
942 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
943 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 944 free(data->sample); |
945 data->sample = NULL; | |
946 return -1; | |
947 } | |
948 | |
949 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
950 if((error = alGetError()) != AL_NO_ERROR) | |
951 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
952 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 953 free(data->sample); |
954 data->sample = NULL; | |
955 return -1; | |
956 } | |
957 | |
958 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
959 if((error = alGetError()) != AL_NO_ERROR) | |
960 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
961 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 962 free(data->sample); |
963 data->sample = NULL; | |
964 return -1; | |
965 } | |
966 | |
967 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
968 if((error = alGetError()) != AL_NO_ERROR) | |
969 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
970 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 971 free(data->sample); |
972 data->sample = NULL; | |
973 return -1; | |
974 } | |
975 | |
976 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
977 if((error = alGetError()) != AL_NO_ERROR) | |
978 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
979 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 980 free(data->sample); |
981 data->sample = NULL; | |
982 return -1; | |
983 } | |
984 | |
985 if(size <= 0) | |
986 { | |
987 ALmixer_SetError("No data in al buffer"); | |
988 free(data->sample); | |
989 data->sample = NULL; | |
990 return -1; | |
991 } | |
992 | |
993 /* Now that we have all the attributes, we need to | |
994 * allocate memory for the buffer and reconstruct | |
995 * the AudioInfo attributes. | |
996 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
997 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 998 if(NULL == data->sample->buffer) |
999 { | |
1000 ALmixer_SetError("Out of memory for sample->buffer"); | |
1001 free(data->sample); | |
1002 data->sample = NULL; | |
1003 return -1; | |
1004 } | |
1005 | |
1006 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1007 data->sample->buffer_size = size; | |
1008 | |
1009 /* Fill up the Sound_AudioInfo structures */ | |
1010 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1011 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1012 | |
1013 return 0; | |
1014 } | |
1015 | |
1016 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1017 #endif | |
1018 /*************** END REMOVED *************************/ | |
1019 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1020 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1021 { |
1022 if(NULL == Channel_Done_Callback) | |
1023 { | |
1024 return; | |
1025 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1026 Channel_Done_Callback(which_channel, ALmixer_Channel_List[which_channel].alsource, ALmixer_Channel_List[which_channel].almixer_data, did_finish_naturally, Channel_Done_Callback_Userdata); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1027 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1028 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1029 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1030 { |
1031 /* Only the first value is used for the key */ | |
1 | 1032 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1033 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1034 key.albuffer = buffer; |
1035 | |
1036 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1037 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1038 if(NULL == found_item) |
1039 { | |
1040 ALmixer_SetError("Can't find buffer"); | |
1041 return -1; | |
1042 } | |
1043 return found_item->index; | |
1044 } | |
1045 | |
1046 | |
1047 /* FIXME: Need to pass back additional info to be useful. | |
1048 * Bit rate, stereo/mono (num chans), time in msec? | |
1049 * Precoded/streamed flag so user can plan for future data? | |
1050 */ | |
1 | 1051 /* |
1052 * channels: 1 for mono, 2 for stereo | |
1053 * | |
1054 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1055 static void Invoke_Channel_Data_Callback(ALint which_channel, ALbyte* data, ALuint num_bytes, ALuint frequency, ALubyte channels, ALushort format, ALboolean decode_mode_is_predecoded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1056 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1057 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1058 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1059 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1060 ALuint length_in_msec; |
1 | 1061 |
1062 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1063 { | |
1064 is_unsigned = 1; | |
1065 } | |
1066 else | |
1067 { | |
1068 is_unsigned = 0; | |
1069 } | |
1070 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1071 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1072 |
1073 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1074 | |
0 | 1075 /* |
1076 fprintf(stderr, "%x %x %x %x, bytes=%d, whichchan=%d, freq=%d, channels=%d\n", data[0], data[1], data[2], data[3], num_bytes, channels, frequency, channels); | |
1077 */ | |
1078 if(NULL == Channel_Data_Callback) | |
1079 { | |
1080 return; | |
1081 } | |
1 | 1082 /* |
1083 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1084 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1085 Channel_Data_Callback(which_channel, ALmixer_Channel_List[which_channel].alsource, data, num_bytes, frequency, channels, bits_per_sample, is_unsigned, decode_mode_is_predecoded, length_in_msec, Channel_Data_Callback_Userdata); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1086 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1087 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1088 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1089 { |
1090 if(NULL == data->sample) | |
1091 { | |
1092 return; | |
1093 } | |
1094 /* The buffer position is complicated because if the current data was seeked, | |
1095 * we must adjust the buffer to the seek position | |
1096 */ | |
1097 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1098 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1099 data->loaded_bytes, |
1100 data->sample->desired.rate, | |
1101 data->sample->desired.channels, | |
1102 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1103 AL_TRUE |
0 | 1104 ); |
1105 } | |
1106 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1107 static void Invoke_Streamed_Channel_Data_Callback(ALint channel, ALmixer_Data* data, ALuint buffer) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1108 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1109 ALint index; |
0 | 1110 if(NULL == data->buffer_map_list) |
1111 { | |
1112 return; | |
1113 } | |
1114 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1115 /* This should catch the case where all buffers are unqueued | |
1116 * and the "current" buffer is id: 0 | |
1117 */ | |
1118 if(-1 == index) | |
1119 { | |
1120 return; | |
1121 } | |
1122 Invoke_Channel_Data_Callback(channel, | |
1123 data->buffer_map_list[index].data, | |
1124 data->buffer_map_list[index].num_bytes, | |
1125 data->sample->desired.rate, | |
1126 data->sample->desired.channels, | |
1127 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1128 AL_FALSE |
0 | 1129 ); |
1130 } | |
1131 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1132 /* Converts milliseconds to byte positions. |
0 | 1133 * This is needed for seeking on predecoded samples |
1134 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1135 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, ALuint ms) |
0 | 1136 { |
1137 float frames_per_ms; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1138 ALuint frame_offset; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1139 ALuint frame_size; |
0 | 1140 if(info == NULL) |
1141 { | |
1142 fprintf(stderr, "Error, info is NULL\n"); | |
1143 } | |
1144 | |
1145 /* "frames" == "sample frames" */ | |
1146 frames_per_ms = ((float) info->rate) / 1000.0f; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1147 frame_offset = (ALuint) (frames_per_ms * ((float) ms)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1148 frame_size = (ALuint) ((info->format & 0xFF) / 8) * info->channels; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1149 return frame_offset * frame_size; |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1150 } |
0 | 1151 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1152 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1153 { |
1154 ALenum error; | |
1155 /* clear error */ | |
1156 alGetError(); | |
1157 | |
1158 /* Is it greater than, or greater-than or equal to ?? */ | |
1159 if(byte_position > data->total_bytes) | |
1160 { | |
1161 /* We can't go past the end, so set to end? */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1162 /* |
0 | 1163 fprintf(stderr, "Error, can't seek past end\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1164 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1165 |
0 | 1166 /* In case the below thing doesn't work, |
1167 * just rewind the whole thing. | |
1168 * | |
1169 alBufferData(data->buffer[0], | |
1170 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1171 (ALbyte*) data->sample->buffer, |
0 | 1172 data->total_bytes, |
1173 data->sample->desired.rate | |
1174 ); | |
1175 */ | |
1176 | |
1177 /* I was trying to set to the end, (1 byte remaining), | |
1178 * but I was getting freezes. I'm thinking it might be | |
1179 * another Power of 2 bug in the Loki dist. I tried 2, | |
1180 * and it still hung. 4 didn't hang, but I got a clip | |
1181 * artifact. 8 seemed to work okay. | |
1182 */ | |
1183 alBufferData(data->buffer[0], | |
1184 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1185 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1186 8, |
1187 data->sample->desired.rate | |
1188 ); | |
1189 if( (error = alGetError()) != AL_NO_ERROR) | |
1190 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1191 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1192 return -1; |
1193 } | |
1194 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1195 * query command to work because I don't know if it will mutilate the | |
1196 * size for its own purposes or return the original size | |
1197 */ | |
1198 data->loaded_bytes = 8; | |
1199 | |
1200 /* Not sure if this should be an error or not */ | |
1201 /* | |
1202 ALmixer_SetError("Can't Seek past end"); | |
1203 return -1; | |
1204 */ | |
1205 return 0; | |
1206 } | |
1207 | |
1208 alBufferData(data->buffer[0], | |
1209 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1210 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1211 data->total_bytes - byte_position, |
1212 data->sample->desired.rate | |
1213 ); | |
1214 if( (error = alGetError()) != AL_NO_ERROR) | |
1215 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1216 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1217 return -1; |
1218 } | |
1219 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1220 * query command to work because I don't know if it will mutilate the | |
1221 * size for its own purposes or return the original size | |
1222 */ | |
1223 data->loaded_bytes = data->total_bytes - byte_position; | |
1224 | |
1225 return 0; | |
1226 } | |
1227 | |
1228 /* Because we have multiple queue buffers and OpenAL won't let | |
1229 * us access them, we need to keep copies of each buffer around | |
1230 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1231 static ALint CopyDataToAccessBuffer(ALmixer_Data* data, ALuint num_bytes, ALuint buffer) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1232 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1233 ALint index; |
0 | 1234 /* We only want to copy if access_data is true. |
1235 * This is determined by whether memory has been | |
1236 * allocated in the buffer_map_list or not | |
1237 */ | |
1238 if(NULL == data->buffer_map_list) | |
1239 { | |
1240 return -1; | |
1241 } | |
1242 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1243 if(-1 == index) | |
1244 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1245 /* |
0 | 1246 fprintf(stderr, ">>>>>>>CopyData catch, albuffer=%d\n",buffer); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1247 */ |
0 | 1248 return -1; |
1249 } | |
1250 /* Copy the data to the access buffer */ | |
1251 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1252 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1253 | |
1254 return 0; | |
1255 } | |
1256 | |
1257 | |
1258 /* For streamed data, gets more data | |
1259 * and prepares it in the active Mix_chunk | |
1260 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1261 static ALuint GetMoreData(ALmixer_Data* data, ALuint buffer) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1262 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1263 ALuint bytes_decoded; |
0 | 1264 ALenum error; |
1265 if(NULL == data) | |
1266 { | |
1267 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1268 return 0; | |
1269 } | |
1270 | |
1271 bytes_decoded = Sound_Decode(data->sample); | |
1272 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1273 { | |
1274 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1275 ALmixer_SetError(Sound_GetError()); | |
1276 /* Force cleanup through FreeData | |
1277 Sound_FreeSample(data->sample); | |
1278 */ | |
1279 return 0; | |
1280 } | |
1281 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1282 /* fprintf(stderr, "GetMoreData bytes_decoded=%d\n", bytes_decoded); */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1283 |
0 | 1284 /* Don't forget to add check for EOF */ |
1285 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1286 if(0 == bytes_decoded) | |
1287 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1288 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1289 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1290 #if 0 |
0 | 1291 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1292 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1293 { | |
1294 fprintf(stderr, "\tEOF flag\n"); | |
1295 } | |
1296 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1297 { | |
1298 fprintf(stderr, "\tCanSeek flag\n"); | |
1299 } | |
1300 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1301 { | |
1302 fprintf(stderr, "\tEAGAIN flag\n"); | |
1303 } | |
1304 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1305 { | |
1306 fprintf(stderr, "\tNONE flag\n"); | |
1307 } | |
1308 #endif | |
1309 return 0; | |
1310 } | |
1311 | |
1312 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1313 /******* REMOVE ME ********************************/ | |
1314 /***************** ANOTHER EXPERIEMENT *******************/ | |
1315 /* The PROBLEM: It seems that the Loki distribution has problems | |
1316 * with Queuing when the buffer size is not a power of two | |
1317 * and additional buffers must come after it. | |
1318 * The behavior is inconsistent, but one of several things | |
1319 * usually happens: | |
1320 * Playback is normal | |
1321 * Playback immediately stops after the non-pow2 buffer | |
1322 * Playback gets distorted on the non-pow2 buffer | |
1323 * The entire program segfaults. | |
1324 * The workaround is to always specify a power of two buffer size | |
1325 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1326 * I already submitted the Ogg fix.) However, this won't catch | |
1327 * cases where a loop happens because the read at the end of the | |
1328 * file is typically less than the buffer size. | |
1329 * | |
1330 * This fix addresses this issue, however it may break in | |
1331 * other conditions. Always decode in buffer sizes of powers of 2. | |
1332 * | |
1333 * The HACK: | |
1334 * If the buffer is short, try filling it up with 0's | |
1335 * to meet the user requested buffer_size which | |
1336 * is probably a nice number OpenAL likes, in | |
1337 * hopes to avoid a possible Loki bug with | |
1338 * short buffers. If looping (which is the main | |
1339 * reason for this), the negative side effect is | |
1340 * that it may take longer for the loop to start | |
1341 * because it must play dead silence. Or if the decoder | |
1342 * doesn't guarantee to return the requested bytes | |
1343 * (like Ogg), then you will get breakup in between | |
1344 * packets. | |
1345 */ | |
1346 if( (bytes_decoded) < data->sample->buffer_size) | |
1347 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1348 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1349 ALubyte signedness_value; |
0 | 1350 int silence_value; |
1351 /* Crap, memset value needs to be the "silent" value, | |
1352 * but it will differ for signed/unsigned and bit depth | |
1353 */ | |
1354 bit_depth = GetBitDepth(data->sample->desired.format); | |
1355 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1356 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1357 { | |
1358 /* I'm guessing that if it's signed, then 0 is the | |
1359 * "silent" value */ | |
1360 silence_value = 0; | |
1361 } | |
1362 else | |
1363 { | |
1364 if(8 == bit_depth) | |
1365 { | |
1366 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1367 silence_value = 127; | |
1368 } | |
1369 else | |
1370 { | |
1371 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1372 silence_value = 32767; | |
1373 } | |
1374 } | |
1375 /* Now fill up the rest of the data buffer with the | |
1376 * silence_value. | |
1377 * I don't think I have to worry about endian issues for | |
1378 * this part since the data is for internal use only | |
1379 * at this point. | |
1380 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1381 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1382 /* Now reset the bytes_decoded to reflect the entire |
1383 * buffer to tell alBufferData what our full size is. | |
1384 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1385 /* |
0 | 1386 fprintf(stderr, "ALTERED bytes decoded for silence: Original end was %d\n", bytes_decoded); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1387 */ |
0 | 1388 bytes_decoded = data->sample->buffer_size; |
1389 } | |
1390 /*********** END EXPERIMENT ******************************/ | |
1391 /******* END REMOVE ME ********************************/ | |
1392 #endif | |
1393 | |
1394 /* Now copy the data to the OpenAL buffer */ | |
1395 /* We can't just set a pointer because the API needs | |
1396 * its own copy to assist hardware acceleration */ | |
1397 alBufferData(buffer, | |
1398 TranslateFormat(&data->sample->desired), | |
1399 data->sample->buffer, | |
1400 bytes_decoded, | |
1401 data->sample->desired.rate | |
1402 ); | |
1403 if( (error = alGetError()) != AL_NO_ERROR) | |
1404 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1405 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1406 return 0; |
1407 } | |
1408 | |
1409 /* If we need to, copy the data also to the access area | |
1410 * (the function will do the check for us) | |
1411 */ | |
1412 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1413 return bytes_decoded; | |
1414 } | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 /******************** EXPERIEMENT **************************** | |
1420 * Test function to force maximum buffer filling during loops | |
1421 * REMOVE LATER | |
1422 *********************************************/ | |
1423 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1424 static ALint GetMoreData2(ALmixer_Data* data, ALuint buffer) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1425 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1426 ALint bytes_decoded; |
0 | 1427 ALenum error; |
1428 if(NULL == data) | |
1429 { | |
1430 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1431 return -1; | |
1432 } | |
1433 | |
1434 if(AL_FALSE == alIsBuffer(buffer)) | |
1435 { | |
1436 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1437 return -1; | |
1438 } | |
1439 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1440 | |
1441 /* | |
1442 fprintf(stderr, "Decode in GetMoreData\n"); | |
1443 */ | |
1444 | |
1445 #if 0 | |
1446 if(buffer%2 == 1) | |
1447 { | |
1448 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1449 Sound_SetBufferSize(data->sample, 16384); | |
1450 } | |
1451 else | |
1452 { | |
1453 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1454 Sound_SetBufferSize(data->sample, 8192); | |
1455 } | |
1456 #endif | |
1457 | |
1458 bytes_decoded = Sound_Decode(data->sample); | |
1459 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1460 { | |
1461 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1462 ALmixer_SetError(Sound_GetError()); | |
1463 /* | |
1464 Sound_FreeSample(data->sample); | |
1465 */ | |
1466 return -1; | |
1467 } | |
1468 /* Don't forget to add check for EOF */ | |
1469 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1470 if(0 == bytes_decoded) | |
1471 { | |
1472 #if 1 | |
1473 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1474 data->eof = 1; | |
1475 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1476 { | |
1477 fprintf(stderr, "\tEOF flag\n"); | |
1478 } | |
1479 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1480 { | |
1481 fprintf(stderr, "\tCanSeek flag\n"); | |
1482 } | |
1483 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1484 { | |
1485 fprintf(stderr, "\tEAGAIN flag\n"); | |
1486 } | |
1487 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1488 { | |
1489 fprintf(stderr, "\tNONE flag\n"); | |
1490 } | |
1491 #endif | |
1492 return 0; | |
1493 } | |
1494 | |
1495 if(bytes_decoded < 16384) | |
1496 { | |
1497 char* tempbuffer1 = (char*)malloc(16384); | |
1498 char* tempbuffer2 = (char*)malloc(16384); | |
1499 int retval; | |
1500 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1501 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1502 if(retval == 1) | |
1503 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1504 ALuint new_bytes; |
0 | 1505 Sound_Rewind(data->sample); |
1506 new_bytes = Sound_Decode(data->sample); | |
1507 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1508 | |
1509 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1510 | |
1511 retval = Sound_SetBufferSize(data->sample, 16384); | |
1512 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1513 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1514 | |
1515 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1516 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1517 | |
1518 fprintf(stderr, "Finished \n"); | |
1519 | |
1520 free(tempbuffer1); | |
1521 free(tempbuffer2); | |
1522 bytes_decoded += new_bytes; | |
1523 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1524 } | |
1525 else | |
1526 { | |
1527 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1528 } | |
1529 } | |
1530 | |
1531 /* Now copy the data to the OpenAL buffer */ | |
1532 /* We can't just set a pointer because the API needs | |
1533 * its own copy to assist hardware acceleration */ | |
1534 alBufferData(buffer, | |
1535 TranslateFormat(&data->sample->desired), | |
1536 data->sample->buffer, | |
1537 bytes_decoded, | |
1538 data->sample->desired.rate | |
1539 ); | |
1540 if( (error = alGetError()) != AL_NO_ERROR) | |
1541 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1542 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1543 return -1; |
1544 } | |
1545 | |
1546 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1547 return bytes_decoded; | |
1548 } | |
1549 #endif | |
1550 | |
1551 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | |
1557 | |
1558 | |
1559 | |
1560 | |
1561 /* This function will look up the source for the corresponding channel */ | |
1562 /* Must return 0 on error instead of -1 because of unsigned int */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1563 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1564 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1565 ALint i; |
0 | 1566 /* Make sure channel is in bounds */ |
1567 if(channel >= Number_of_Channels_global) | |
1568 { | |
1569 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
1570 return 0; | |
1571 } | |
1572 /* If the user specified -1, then return the an available source */ | |
1573 if(channel < 0) | |
1574 { | |
1575 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1576 { | |
1577 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1578 { | |
1579 return ALmixer_Channel_List[i].alsource; | |
1580 } | |
1581 } | |
1582 /* If we get here, all sources are in use */ | |
1583 /* Error message seems too harsh | |
1584 ALmixer_SetError("All sources are in use"); | |
1585 */ | |
1586 return 0; | |
1587 } | |
1588 /* Last case: Return the source for the channel */ | |
1589 return ALmixer_Channel_List[channel].alsource; | |
1590 } | |
1591 | |
1592 /* This function will look up the channel for the corresponding source */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1593 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1594 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1595 ALint i; |
0 | 1596 /* Only the first value is used for the key */ |
1597 Source_Map key = { 0, 0 }; | |
1598 Source_Map* found_item = NULL; | |
1599 key.source = source; | |
1600 | |
1601 /* If the source is 0, look up the first available channel */ | |
1602 if(0 == source) | |
1603 { | |
1604 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1605 { | |
1606 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1607 { | |
1608 return i; | |
1609 } | |
1610 } | |
1611 /* If we get here, all sources are in use */ | |
1612 /* Error message seems too harsh | |
1613 ALmixer_SetError("All channels are in use"); | |
1614 */ | |
1615 return -1; | |
1616 } | |
1617 | |
1618 | |
1619 /* Else, look up the source and return the channel */ | |
1620 if(AL_FALSE == alIsSource(source)) | |
1621 { | |
1622 ALmixer_SetError("Is not a source"); | |
1623 return -1; | |
1624 } | |
1625 | |
1626 /* Use the ANSI C binary search feature (yea!) */ | |
1627 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1628 if(NULL == found_item) | |
1629 { | |
1630 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1631 return -1; | |
1632 } | |
1633 return found_item->channel; | |
1634 } | |
1635 | |
1636 | |
1637 | |
1638 /* This function will find the first available channel (not in use) | |
1639 * from the specified start channel. Reserved channels to not qualify | |
1640 * as available. | |
1641 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1642 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1643 { |
1644 /* Start at the number of reserved so we skip over | |
1645 * all the reserved channels. | |
1646 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1647 ALint i = Number_of_Reserve_Channels_global; |
0 | 1648 /* Quick check to see if we're out of bounds */ |
1649 if(start_channel >= Number_of_Channels_global) | |
1650 { | |
1651 return -1; | |
1652 } | |
1653 | |
1654 /* If the start channel is even higher than the reserved, | |
1655 * then start at the higher value. | |
1656 */ | |
1657 if(start_channel > Number_of_Reserve_Channels_global) | |
1658 { | |
1659 i = start_channel; | |
1660 } | |
1661 | |
1662 /* i has already been set */ | |
1663 for( ; i<Number_of_Channels_global; i++) | |
1664 { | |
1665 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1666 { | |
1667 return i; | |
1668 } | |
1669 } | |
1670 /* If we get here, all sources are in use */ | |
1671 return -1; | |
1672 } | |
1673 | |
1674 | |
1675 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1676 /* Will return the number of channels halted |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1677 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1678 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1679 static ALint Internal_HaltChannel(ALint channel, ALboolean did_finish_naturally) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1681 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1682 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1683 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1684 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1685 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1686 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1687 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1689 ALmixer_SetError("Cannot halt channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1690 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1691 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 /* If the user specified a specific channel */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 /* only need to process channel if in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 if(ALmixer_Channel_List[channel].channel_in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1697 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1698 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1699 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1700 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1701 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1703 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1704 /* Here's the situation. My old method of using |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1705 * alSourceUnqueueBuffers() seemed to be invalid in light |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1706 * of all the problems I suffered through with getting |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1707 * the CoreData backend to work with this code. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 * As such, I'm changing all the code to set the buffer to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 * AL_NONE. Furthermore, the queued vs. non-queued issue |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 * doesn't need to apply here. For non-queued, Loki, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 * Creative Windows, and CoreAudio seem to leave the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 * buffer queued (Old Mac didn't.) For queued, we need to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 * remove the processed buffers and force remove the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1715 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1716 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1717 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1718 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1719 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1720 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1721 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1722 fprintf(stderr, "17Testing Error with buffers_still_queued: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1723 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1724 ALmixer_SetError("Failed detecting still queued buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1733 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1734 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1735 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1736 ALmixer_SetError("Failed detecting still processed buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 /* If either of these is greater than 0, it means we need |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 if((buffers_still_queued > 0) || (buffers_processed > 0)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1744 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1745 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1748 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1750 fprintf(stderr, "17Testing Error with clearing buffer from source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1751 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1752 ALmixer_SetError("Failed to clear buffer from source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1753 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1754 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 ALmixer_Channel_List[channel].almixer_data->num_buffers_in_use = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1760 /* Launch callback for consistency? */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1761 Invoke_Channel_Done_Callback(channel, did_finish_naturally); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1762 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1764 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1768 /* The user wants to halt all channels */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1769 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 for(i=0; i<Number_of_Channels_global; i++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 /* only need to process channel if in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 if(ALmixer_Channel_List[i].channel_in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1776 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1777 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1780 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1782 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1783 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1784 /* Here's the situation. My old method of using |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1785 * alSourceUnqueueBuffers() seemed to be invalid in light |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1786 * of all the problems I suffered through with getting |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1787 * the CoreData backend to work with this code. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 * As such, I'm changing all the code to set the buffer to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 * AL_NONE. Furthermore, the queued vs. non-queued issue |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 * doesn't need to apply here. For non-queued, Loki, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 * Creative Windows, and CoreAudio seem to leave the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 * buffer queued (Old Mac didn't.) For queued, we need to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 * remove the processed buffers and force remove the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1796 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1797 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1798 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1799 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1800 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1801 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1802 fprintf(stderr, "17Testing Error with buffers_still_queued: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1803 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 ALmixer_SetError("Failed detecting still queued buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1814 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1816 ALmixer_SetError("Failed detecting still processed buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 /* If either of these is greater than 0, it means we need |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 if((buffers_still_queued > 0) || (buffers_processed > 0)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1825 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1829 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1830 fprintf(stderr, "17Testing Error with clearing buffer from source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1832 ALmixer_SetError("Failed to clear buffer from source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1834 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1840 /* Launch callback for consistency? */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1841 Invoke_Channel_Done_Callback(i, did_finish_naturally); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1842 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1848 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1849 /* Let's halt everything just in case there |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1850 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1851 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1852 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 / * Can't clean because the in_use counter for |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1858 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1860 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1861 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1863 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1865 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1867 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 /* Will return the source halted or the total number of channels |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 * if all were halted or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 static ALint Internal_HaltSource(ALuint source, ALboolean did_finish_naturally) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1877 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1881 /* Will return the number of sources halted */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1882 return Internal_HaltChannel(-1, did_finish_naturally); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1883 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1884 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1885 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1886 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1887 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1888 ALmixer_SetError("Cannot halt source: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1890 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1891 return Internal_HaltChannel(channel, did_finish_naturally); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1892 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1893 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1894 |
0 | 1895 |
1896 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1897 * that there is no "music" channel anymore, so 0 | |
1898 * will remove everything. (Note, I no longer allow 0 | |
1899 * so it gets set to the default number.) | |
1900 * Also, callbacks for deleted channels will not be called. | |
1901 * I really need to do error checking, for realloc and | |
1902 * GenSources, but reversing the damage is too painful | |
1903 * for me to think about at the moment, so it's not in here. | |
1904 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1905 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1906 { |
1907 ALenum error; | |
1908 int i; | |
1909 /* Return info */ | |
1910 if(numchans < 0) | |
1911 { | |
1912 return Number_of_Channels_global; | |
1913 } | |
1914 if(0 == numchans) | |
1915 { | |
1916 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1917 } | |
1918 /* No change */ | |
1919 if(numchans == Number_of_Channels_global) | |
1920 { | |
1921 return Number_of_Channels_global; | |
1922 } | |
1923 /* We need to increase the number of channels */ | |
1924 if(numchans > Number_of_Channels_global) | |
1925 { | |
1926 /* Not sure how safe this is, but SDL_mixer does it | |
1927 * the same way */ | |
1928 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1929 | |
1930 /* Allocate memory for the list of sources that map to the channels */ | |
1931 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1932 | |
1933 for(i=Number_of_Channels_global; i<numchans; i++) | |
1934 { | |
1935 Init_Channel(i); | |
1936 /* Generate a new source and associate it with the channel */ | |
1937 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1938 if((error = alGetError()) != AL_NO_ERROR) | |
1939 { | |
1940 fprintf(stderr, "12Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1941 alGetString(error)); |
0 | 1942 } |
1943 /* Copy the source so the SourceMap has it too */ | |
1944 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1945 Source_Map_List[i].channel = i; | |
1946 /* Clean the channel because there are some things that need to | |
1947 * be done that can't happen until the source is set | |
1948 */ | |
1949 Clean_Channel(i); | |
1950 } | |
1951 | |
1952 /* The Source_Map_List must be sorted by source for binary searches | |
1953 */ | |
1954 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1955 | |
1956 Number_of_Channels_global = numchans; | |
1957 return numchans; | |
1958 } | |
1959 /* Need to remove channels. This might be dangerous */ | |
1960 if(numchans < Number_of_Channels_global) | |
1961 { | |
1962 for(i=numchans; i<Number_of_Channels_global; i++) | |
1963 { | |
1964 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1965 Internal_HaltChannel(i, AL_FALSE); |
0 | 1966 |
1967 /* Delete source associated with the channel */ | |
1968 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1969 if((error = alGetError()) != AL_NO_ERROR) | |
1970 { | |
1971 fprintf(stderr, "13Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1972 alGetString(error)); |
0 | 1973 } |
1974 } | |
1975 | |
1976 | |
1977 /* Not sure how safe this is, but SDL_mixer does it | |
1978 * the same way */ | |
1979 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1980 | |
1981 /* The tricky part is that we must remove the entries | |
1982 * in the source map that correspond to the deleted channels. | |
1983 * We'll resort the map by channels so we can pick them off | |
1984 * in order. | |
1985 */ | |
1986 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1987 | |
1988 /* Deallocate memory for the list of sources that map to the channels */ | |
1989 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1990 | |
1991 /* Now resort the map by source and the correct num of chans */ | |
1992 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1993 | |
1994 /* Reset the number of channels */ | |
1995 Number_of_Channels_global = numchans; | |
1996 return numchans; | |
1997 } | |
1998 /* Shouldn't ever reach here */ | |
1999 return -1; | |
2000 | |
2001 } | |
2002 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2003 static ALint Internal_ReserveChannels(ALint num) |
0 | 2004 { |
2005 /* Can't reserve more than the max num of channels */ | |
2006 /* Actually, I'll allow it for people who just want to | |
2007 * set the value really high to effectively disable | |
2008 * auto-assignment | |
2009 */ | |
2010 | |
2011 /* Return the current number of reserved channels */ | |
2012 if(num < 0) | |
2013 { | |
2014 return Number_of_Reserve_Channels_global; | |
2015 } | |
2016 Number_of_Reserve_Channels_global = num; | |
2017 return Number_of_Reserve_Channels_global; | |
2018 } | |
2019 | |
2020 | |
2021 /* This will rewind the SDL_Sound sample for streamed | |
2022 * samples and start buffering up the data for the next | |
2023 * playback. This may require samples to be halted | |
2024 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2025 static ALboolean Internal_RewindData(ALmixer_Data* data) |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2026 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2027 ALint retval = 0; |
0 | 2028 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2029 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2030 ALint i; |
0 | 2031 */ |
2032 if(NULL == data) | |
2033 { | |
2034 ALmixer_SetError("Cannot rewind because data is NULL\n"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2035 return AL_FALSE; |
0 | 2036 } |
2037 | |
2038 | |
2039 /* Might have to require Halt */ | |
2040 /* Okay, we assume Halt or natural stop has already | |
2041 * cleared the data buffers | |
2042 */ | |
2043 if(data->in_use) | |
2044 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2045 /* |
0 | 2046 fprintf(stderr, "Warning sample is in use. May not be able to rewind\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2047 */ |
0 | 2048 /* |
2049 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2050 return -1; | |
2051 */ | |
2052 } | |
2053 | |
2054 | |
2055 /* Because Seek can alter things even in predecoded data, | |
2056 * decoded data must also be rewound | |
2057 */ | |
2058 if(data->decoded_all) | |
2059 { | |
2060 data->eof = 0; | |
2061 | |
2062 #if 0 | |
2063 #if defined(DISABLE_PREDECODED_SEEK) | |
2064 /* Since we can't seek predecoded stuff, it should be rewound */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2065 return AL_TRUE; |
0 | 2066 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2067 /* This case is if the Sound_Sample has been deleted. | |
2068 * It assumes the data is already at the beginning. | |
2069 */ | |
2070 if(NULL == data->sample) | |
2071 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2072 return AL_TRUE; |
0 | 2073 } |
2074 /* Else, the sample has already been reallocated, | |
2075 * and we can fall to normal behavior | |
2076 */ | |
2077 #endif | |
2078 #endif | |
2079 /* If access_data, was enabled, the sound sample | |
2080 * still exists and we can do stuff. | |
2081 * If it's NULL, we can't do anything, but | |
2082 * it should already be "rewound". | |
2083 */ | |
2084 if(NULL == data->sample) | |
2085 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2086 return AL_TRUE; |
0 | 2087 } |
2088 /* Else, the sample has already been reallocated, | |
2089 * and we can fall to normal behavior | |
2090 */ | |
2091 | |
2092 Set_Predecoded_Seek_Position(data, 0); | |
2093 /* | |
2094 return data->total_bytes; | |
2095 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2096 return AL_TRUE; |
0 | 2097 } |
2098 | |
2099 /* Remaining stuff for streamed data */ | |
2100 | |
2101 data->eof = 0; | |
2102 retval = Sound_Rewind(data->sample); | |
2103 if(0 == retval) | |
2104 { | |
2105 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2106 return AL_FALSE; |
0 | 2107 } |
2108 #if 0 | |
2109 /* Clear error */ | |
2110 alGetError(); | |
2111 for(i=0; i<data->num_buffers; i++) | |
2112 { | |
2113 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2114 if(-1 == bytes_returned) | |
2115 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2116 return AL_FALSE; |
0 | 2117 } |
2118 else if(0 == bytes_returned) | |
2119 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2120 return AL_FALSE; |
0 | 2121 } |
2122 retval += bytes_returned; | |
2123 | |
2124 } | |
2125 #endif | |
2126 | |
2127 | |
2128 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2129 return AL_TRUE; |
0 | 2130 } |
2131 | |
2132 | |
2133 | |
2134 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2135 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2136 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2137 ALint retval = 0; |
0 | 2138 ALenum error; |
2139 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2140 ALint running_count = 0; |
0 | 2141 |
2142 if(channel >= Number_of_Channels_global) | |
2143 { | |
2144 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2145 return -1; | |
2146 } | |
2147 | |
2148 if((error = alGetError()) != AL_NO_ERROR) | |
2149 { | |
2150 fprintf(stderr, "24Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2151 alGetString(error)); |
0 | 2152 } |
2153 /* Clear error */ | |
2154 alGetError(); | |
2155 | |
2156 /* If the user specified a specific channel */ | |
2157 if(channel >= 0) | |
2158 { | |
2159 /* only need to process channel if in use */ | |
2160 if(ALmixer_Channel_List[channel].channel_in_use) | |
2161 { | |
2162 | |
2163 /* What should I do? Do I just rewind the channel | |
2164 * or also rewind the data? Since the data is | |
2165 * shared, let's make it the user's responsibility | |
2166 * to rewind the data. | |
2167 */ | |
2168 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2169 { | |
2170 alGetSourcei( | |
2171 ALmixer_Channel_List[channel].alsource, | |
2172 AL_SOURCE_STATE, &state | |
2173 ); | |
2174 if((error = alGetError()) != AL_NO_ERROR) | |
2175 { | |
2176 fprintf(stderr, "25Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2177 alGetString(error)); |
0 | 2178 } |
2179 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2180 if((error = alGetError()) != AL_NO_ERROR) | |
2181 { | |
2182 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2183 alGetString(error) ); |
0 | 2184 retval = -1; |
2185 } | |
2186 /* Need to resume playback if it was originally playing */ | |
2187 if(AL_PLAYING == state) | |
2188 { | |
2189 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2190 if((error = alGetError()) != AL_NO_ERROR) | |
2191 { | |
2192 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2193 alGetString(error) ); |
0 | 2194 retval = -1; |
2195 } | |
2196 } | |
2197 else if(AL_PAUSED == state) | |
2198 { | |
2199 /* HACK: The problem is that when paused, after | |
2200 * the Rewind, I can't get it off the INITIAL | |
2201 * state without restarting | |
2202 */ | |
2203 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2204 if((error = alGetError()) != AL_NO_ERROR) | |
2205 { | |
2206 fprintf(stderr, "25Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2207 alGetString(error)); |
0 | 2208 } |
2209 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2210 if((error = alGetError()) != AL_NO_ERROR) | |
2211 { | |
2212 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2213 alGetString(error) ); |
0 | 2214 retval = -1; |
2215 } | |
2216 } | |
2217 } | |
2218 else | |
2219 { | |
2220 /* Streamed data is different. Rewinding the channel | |
2221 * does no good. Rewinding the data will have an | |
2222 * effect, but it will be lagged based on how | |
2223 * much data is queued. Recommend users call Halt | |
2224 * before rewind if they want immediate results. | |
2225 */ | |
2226 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2227 } | |
2228 } | |
2229 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2230 /* The user wants to rewind all channels */ |
0 | 2231 else |
2232 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2233 ALint i; |
0 | 2234 for(i=0; i<Number_of_Channels_global; i++) |
2235 { | |
2236 /* only need to process channel if in use */ | |
2237 if(ALmixer_Channel_List[i].channel_in_use) | |
2238 { | |
2239 /* What should I do? Do I just rewind the channel | |
2240 * or also rewind the data? Since the data is | |
2241 * shared, let's make it the user's responsibility | |
2242 * to rewind the data. | |
2243 */ | |
2244 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2245 { | |
2246 alGetSourcei( | |
2247 ALmixer_Channel_List[i].alsource, | |
2248 AL_SOURCE_STATE, &state | |
2249 ); | |
2250 if((error = alGetError()) != AL_NO_ERROR) | |
2251 { | |
2252 fprintf(stderr, "26Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2253 alGetString(error)); |
0 | 2254 } |
2255 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2256 if((error = alGetError()) != AL_NO_ERROR) | |
2257 { | |
2258 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2259 alGetString(error) ); |
0 | 2260 retval = -1; |
2261 } | |
2262 /* Need to resume playback if it was originally playing */ | |
2263 if(AL_PLAYING == state) | |
2264 { | |
2265 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2266 if((error = alGetError()) != AL_NO_ERROR) | |
2267 { | |
2268 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2269 alGetString(error) ); |
0 | 2270 retval = -1; |
2271 } | |
2272 } | |
2273 else if(AL_PAUSED == state) | |
2274 { | |
2275 /* HACK: The problem is that when paused, after | |
2276 * the Rewind, I can't get it off the INITIAL | |
2277 * state without restarting | |
2278 */ | |
2279 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2280 if((error = alGetError()) != AL_NO_ERROR) | |
2281 { | |
2282 fprintf(stderr, "27Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2283 alGetString(error)); |
0 | 2284 } |
2285 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2286 if((error = alGetError()) != AL_NO_ERROR) | |
2287 { | |
2288 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2289 alGetString(error) ); |
0 | 2290 retval = -1; |
2291 } | |
2292 } | |
2293 } | |
2294 else | |
2295 { | |
2296 /* Streamed data is different. Rewinding the channel | |
2297 * does no good. Rewinding the data will have an | |
2298 * effect, but it will be lagged based on how | |
2299 * much data is queued. Recommend users call Halt | |
2300 * before rewind if they want immediate results. | |
2301 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2302 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2303 } |
2304 } | |
2305 } | |
2306 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2307 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2308 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2309 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2310 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2311 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2312 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2313 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2314 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2315 |
0 | 2316 } |
2317 | |
2318 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2319 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2320 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2321 ALint channel; |
0 | 2322 if(0 == source) |
2323 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2324 return Internal_RewindChannel(-1) + 1; |
0 | 2325 } |
2326 | |
2327 channel = Internal_GetChannel(source); | |
2328 if(-1 == channel) | |
2329 { | |
2330 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2331 return 0; | |
2332 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 return Internal_RewindChannel(channel) + 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2334 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2335 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2336 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2337 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2338 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2339 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2340 static ALint Internal_PlayChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2341 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2342 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2343 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2344 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2346 ALmixer_SetError("Can't play because data is NULL\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 /* There isn't a good way to share streamed files because |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 * the decoded data doesn't stick around. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 * You must "Load" a brand new instance of |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 * the data. If you try using the same data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 * bad things may happen. This check will attempt |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 if(0 == data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2358 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2360 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2361 ALmixer_SetError("Can't play shared streamed sample because it is already in use"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2362 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2363 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2364 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2365 /* Make sure SDL_sound sample is not at EOF. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2366 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2370 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2371 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2372 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 ALmixer_SetError("Can't play sample because it is at EOF and cannot rewind"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 /* We need to provide the user with the first available channel */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2381 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2382 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2383 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2384 if(0 == ALmixer_Channel_List[i].channel_in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2385 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2386 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2387 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2388 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2389 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 /* if we couldn't find a channel, return an error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 ALmixer_SetError("No channels available for playing"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2394 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2396 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 /* If we didn't assign the channel number, make sure it's not |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2400 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2401 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2402 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2404 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2405 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 else if(ALmixer_Channel_List[channel].channel_in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2407 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 ALmixer_SetError("Requested channel (%d) is in use", channel, Number_of_Channels_global-1, Number_of_Channels_global); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2411 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2412 /* Make sure the user doesn't enter some meaningless value */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2413 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2415 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2417 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2418 /* loops will probably have to change to be controlled by SDL_Sound */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 /* Set up the initial values for playing */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 ALmixer_Channel_List[channel].channel_in_use = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2422 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 /* Shouldn't need updating until a callback is fired |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 * (assuming that we call Play in this function |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2427 ALmixer_Channel_List[channel].needs_stream = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2428 ALmixer_Channel_List[channel].almixer_data = data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2429 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 /* If user entered -1 (or less), set to -1 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2433 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2434 ALmixer_Channel_List[channel].expire_ticks = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2435 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2436 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2437 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2438 ALmixer_Channel_List[channel].expire_ticks = ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2439 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2440 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2441 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 /* Ran just use OpenAL to control loops if predecoded and infinite */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2448 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2449 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2459 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2463 * files must add +1 to the loops. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2464 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 * because they can use the eof flag to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 * Sharing data chunks prevents the use of the eof flag. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 /* Corner Case: Now that play calls are pushed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 * off to update(), the start call must |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2475 * also come through here. So, start loops |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2476 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2477 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 if(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2479 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 /* -1 is a special case, and you don't want |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2481 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2483 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2484 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2485 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2486 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2487 ALmixer_Channel_List[channel].loops = loops+1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2488 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2489 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2490 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2491 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 /* Can we really loop on streamed data? */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2497 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2498 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2499 /* Should I start playing here or pass the buck to update? */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 /* Unlike SDL_SoundMixer, I think I'll do it here because |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 * this library isn't a *total* hack and OpenAL has more |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 * built in functionality I need, so less needs to be |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 * controlled and directed through the update function. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2504 * The downside is less functionality is centralized. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 * The upside is that the update function should be |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2509 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2510 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2511 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2512 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2513 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2514 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2515 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2516 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2517 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 ALmixer_SetError("Could not bind data to source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 /* Make data available if access_data is enabled */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 Invoke_Predecoded_Channel_Data_Callback(channel, data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 /* Need to use the streaming buffer for binding */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2532 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2536 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 /* Since buffer queuing is pushed off until here to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2538 * avoid buffer conflicts, we must start reading |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 * data here. First we make sure we have at least one |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2540 * packet. Then we queue up until we hit our limit. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2541 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2542 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2543 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2548 ALmixer_SetError("Could not get data for streamed PlayChannel: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2549 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2550 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2551 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2552 /* Increment the number of buffers in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2553 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 /* Now we need to fill up the rest of the buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 * There is a corner case where we run out of data |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 * Stop conditions are we run out of |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2560 * data or we max out our preload buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2561 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2562 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2563 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2564 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", 0, data->buffer[0]); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2565 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 for(j=1; j<data->num_startup_buffers; j++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2568 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2569 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", j, data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2570 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2571 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2572 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2573 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2574 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2575 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2576 * This might be a problem. I made a mistake with the types. I accidentally |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 * made the bytes returned an ALint and returned -1 on error. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2578 * Bytes returned should be a ALuint, so now I no longer have a -1 case |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 * to check. I hope I didn't break anything here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2583 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 ALmixer_SetError("Could not get data for additional startup buffers for PlayChannel: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 /* We'll continue on because we do have some valid data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2588 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2589 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2590 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2596 if( ALmixer_Channel_List[channel].loops != 0 ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2598 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 fprintf(stderr, "Need to rewind. In RAMPUP, handling loop\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2600 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 /* We'll continue on because we do have some valid data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 /* Remember to reset the data->eof flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 if(ALmixer_Channel_List[channel].loops > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2615 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 fprintf(stderr, "Inside 000 >>>>>>>>>>Loops=%d\n", ALmixer_Channel_List[channel].loops); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2617 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2618 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2619 /* Would like to redo the loop, but due to |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 * Sound_Rewind() bugs, we would risk falling |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2622 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2624 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2626 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2628 ALmixer_SetError("Could not get data: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 /* We'll continue on because we do have some valid data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2630 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 /* No loops to do so quit here */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2639 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2640 /* Increment the number of buffers in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2641 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2642 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 fprintf(stderr, "In PlayChannel, about to queue: source=%d, num_buffers_in_use=%d\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2646 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2647 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2648 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 ALmixer_SetError("Could not bind data to source: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2656 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2657 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 /* This is part of the hideous Nvidia workaround. In order to figure out |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 * which buffer to show during callbacks (for things like |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 * o-scopes), I must keep a copy of the buffers that are queued in my own |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 * data structure. This code will be called only if |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 * "access_data" was set, indicated by whether the queue is NULL. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2669 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2670 for(k=0; k<data->num_buffers_in_use; k++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2671 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2672 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2673 queue_ret_flag = CircularQueueUnsignedInt_PushBack(data->circular_buffer_queue, data->buffer[k]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2674 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2675 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2676 fprintf(stderr, "Serious internal error: CircularQueue could not push into queue.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2678 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2685 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2686 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2687 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2688 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 /* We have finished loading the data (predecoded or queued) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2695 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2697 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2698 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2701 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2702 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2703 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 /* Add to the counter that something is playing */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2711 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 /* In case the user wants to specify a source instead of a channel, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 * they may use this function. This function will look up the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 * source-to-channel map, and convert the call into a |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 * Returns the channel it's being played on. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 * Note: If you are prefer this method, then you need to be careful |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 * about using PlayChannel, particularly if you request the |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 * first available channels because source and channels have |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2723 * a one-to-one mapping in this API. It is quite easy for |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2724 * a channel/source to already be in use because of this. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2725 * In this event, an error message will be returned to you. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2726 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2727 static ALuint Internal_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2729 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2730 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2731 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2732 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2733 retval = Internal_PlayChannelTimed(-1, data, loops, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2734 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2735 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2736 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2737 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2738 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2739 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2741 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2742 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2746 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 ALmixer_SetError("Cannot Play source: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2749 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2750 retval = Internal_PlayChannelTimed(channel, data, loops, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2751 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2752 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2754 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2755 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2759 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2760 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2761 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2762 |
0 | 2763 |
2764 | |
2765 | |
2766 /* Returns the channel or number of channels actually paused */ | |
2767 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2768 static ALint Internal_PauseChannel(ALint channel) |
0 | 2769 { |
2770 ALenum error; | |
2771 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2772 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2773 ALint counter = 0; |
0 | 2774 |
2775 if(channel >= Number_of_Channels_global) | |
2776 { | |
2777 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2778 return -1; | |
2779 } | |
2780 | |
2781 if((error = alGetError()) != AL_NO_ERROR) | |
2782 { | |
2783 fprintf(stderr, "28Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2784 alGetString(error)); |
0 | 2785 } |
2786 /* Clear error */ | |
2787 alGetError(); | |
2788 | |
2789 /* If the user specified a specific channel */ | |
2790 if(channel >= 0) | |
2791 { | |
2792 /* only need to process channel if in use */ | |
2793 if(ALmixer_Channel_List[channel].channel_in_use) | |
2794 { | |
2795 /* We don't want to repause if already | |
2796 * paused because the fadeout/expire | |
2797 * timing will get messed up | |
2798 */ | |
2799 alGetSourcei( | |
2800 ALmixer_Channel_List[channel].alsource, | |
2801 AL_SOURCE_STATE, &state | |
2802 ); | |
2803 if((error = alGetError()) != AL_NO_ERROR) | |
2804 { | |
2805 fprintf(stderr, "29Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2806 alGetString(error)); |
0 | 2807 } |
2808 if(AL_PLAYING == state) | |
2809 { | |
2810 /* Count the actual number of channels being paused */ | |
2811 counter++; | |
2812 | |
2813 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2814 if((error = alGetError()) != AL_NO_ERROR) | |
2815 { | |
2816 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2817 alGetString(error) ); |
0 | 2818 retval = -1; |
2819 } | |
2820 /* We need to pause the expire time count down */ | |
2821 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2822 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2823 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2824 ALuint diff_time; |
0 | 2825 diff_time = current_time - |
2826 ALmixer_Channel_List[channel].start_time; | |
2827 /* When we unpause, we will want to reset | |
2828 * the start time so we can continue | |
2829 * to base calculations off GetTicks(). | |
2830 * This means we need to subtract the amount | |
2831 * of time already used up from expire_ticks. | |
2832 */ | |
2833 ALmixer_Channel_List[channel].expire_ticks = | |
2834 ALmixer_Channel_List[channel].expire_ticks - | |
2835 diff_time; | |
2836 /* Because -1 is a special value, we can't | |
2837 * allow the time to go negative | |
2838 */ | |
2839 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2840 { | |
2841 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2842 } | |
2843 } | |
2844 /* Do the same as expire time for fading */ | |
2845 if(ALmixer_Channel_List[channel].fade_enabled) | |
2846 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2847 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2848 ALuint diff_time; |
0 | 2849 diff_time = current_time - |
2850 ALmixer_Channel_List[channel].fade_start_time; | |
2851 /* When we unpause, we will want to reset | |
2852 * the start time so we can continue | |
2853 * to base calculations off GetTicks(). | |
2854 * This means we need to subtract the amount | |
2855 * of time already used up from expire_ticks. | |
2856 */ | |
2857 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2858 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2859 diff_time; | |
2860 /* Don't allow the time to go negative */ | |
2861 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2862 { | |
2863 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2864 } | |
2865 } /* End fade check */ | |
2866 } /* End if PLAYING */ | |
2867 } /* End If in use */ | |
2868 } /* End specific channel */ | |
2869 /* The user wants to halt all channels */ | |
2870 else | |
2871 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2872 ALint i; |
0 | 2873 for(i=0; i<Number_of_Channels_global; i++) |
2874 { | |
2875 /* only need to process channel if in use */ | |
2876 if(ALmixer_Channel_List[i].channel_in_use) | |
2877 { | |
2878 /* We don't want to repause if already | |
2879 * paused because the fadeout/expire | |
2880 * timing will get messed up | |
2881 */ | |
2882 alGetSourcei( | |
2883 ALmixer_Channel_List[i].alsource, | |
2884 AL_SOURCE_STATE, &state | |
2885 ); | |
2886 if((error = alGetError()) != AL_NO_ERROR) | |
2887 { | |
2888 fprintf(stderr, "30Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2889 alGetString(error)); |
0 | 2890 } |
2891 if(AL_PLAYING == state) | |
2892 { | |
2893 /* Count the actual number of channels being paused */ | |
2894 counter++; | |
2895 | |
2896 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2897 if((error = alGetError()) != AL_NO_ERROR) | |
2898 { | |
2899 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2900 alGetString(error) ); |
0 | 2901 retval = -1; |
2902 } | |
2903 /* We need to pause the expire time count down */ | |
2904 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2905 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2906 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2907 ALuint diff_time; |
0 | 2908 diff_time = current_time - |
2909 ALmixer_Channel_List[i].start_time; | |
2910 /* When we unpause, we will want to reset | |
2911 * the start time so we can continue | |
2912 * to base calculations off GetTicks(). | |
2913 * This means we need to subtract the amount | |
2914 * of time already used up from expire_ticks. | |
2915 */ | |
2916 ALmixer_Channel_List[i].expire_ticks = | |
2917 ALmixer_Channel_List[i].expire_ticks - | |
2918 diff_time; | |
2919 /* Because -1 is a special value, we can't | |
2920 * allow the time to go negative | |
2921 */ | |
2922 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2923 { | |
2924 ALmixer_Channel_List[i].expire_ticks = 0; | |
2925 } | |
2926 } | |
2927 /* Do the same as expire time for fading */ | |
2928 if(ALmixer_Channel_List[i].fade_enabled) | |
2929 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2930 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2931 ALuint diff_time; |
0 | 2932 diff_time = current_time - |
2933 ALmixer_Channel_List[i].fade_start_time; | |
2934 /* When we unpause, we will want to reset | |
2935 * the start time so we can continue | |
2936 * to base calculations off GetTicks(). | |
2937 * This means we need to subtract the amount | |
2938 * of time already used up from expire_ticks. | |
2939 */ | |
2940 ALmixer_Channel_List[i].fade_expire_ticks = | |
2941 ALmixer_Channel_List[i].fade_expire_ticks - | |
2942 diff_time; | |
2943 /* Don't allow the time to go negative */ | |
2944 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2945 { | |
2946 ALmixer_Channel_List[i].expire_ticks = 0; | |
2947 } | |
2948 } /* End fade check */ | |
2949 } /* End if PLAYING */ | |
2950 } /* End channel in use */ | |
2951 } /* End for-loop */ | |
2952 } | |
2953 if(-1 == retval) | |
2954 { | |
2955 return -1; | |
2956 } | |
2957 return counter; | |
2958 } | |
2959 | |
2960 /* Returns the channel or number of channels actually paused */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2961 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2962 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2963 ALint channel; |
0 | 2964 if(0 == source) |
2965 { | |
2966 return Internal_PauseChannel(-1); | |
2967 } | |
2968 | |
2969 channel = Internal_GetChannel(source); | |
2970 if(-1 == channel) | |
2971 { | |
2972 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2973 return -1; | |
2974 } | |
2975 return Internal_PauseChannel(channel); | |
2976 } | |
2977 | |
2978 | |
2979 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2980 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2981 { |
2982 ALint state; | |
2983 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2984 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2985 ALint counter = 0; |
0 | 2986 |
2987 if(channel >= Number_of_Channels_global) | |
2988 { | |
2989 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2990 return -1; | |
2991 } | |
2992 | |
2993 if((error = alGetError()) != AL_NO_ERROR) | |
2994 { | |
2995 fprintf(stderr, "31Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2996 alGetString(error)); |
0 | 2997 } |
2998 /* Clear error */ | |
2999 alGetError(); | |
3000 | |
3001 /* If the user specified a specific channel */ | |
3002 if(channel >= 0) | |
3003 { | |
3004 /* only need to process channel if in use */ | |
3005 if(ALmixer_Channel_List[channel].channel_in_use) | |
3006 { | |
3007 alGetSourcei( | |
3008 ALmixer_Channel_List[channel].alsource, | |
3009 AL_SOURCE_STATE, &state | |
3010 ); | |
3011 if((error = alGetError()) != AL_NO_ERROR) | |
3012 { | |
3013 fprintf(stderr, "32Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3014 alGetString(error)); |
0 | 3015 } |
3016 if(AL_PAUSED == state) | |
3017 { | |
3018 /* Count the actual number of channels resumed */ | |
3019 counter++; | |
3020 | |
3021 /* We need to resume the expire time count down */ | |
3022 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3023 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3024 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3025 } |
3026 /* Do the same as expire time for fading */ | |
3027 if(ALmixer_Channel_List[channel].fade_enabled) | |
3028 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3029 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3030 } |
3031 | |
3032 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3033 if((error = alGetError()) != AL_NO_ERROR) | |
3034 { | |
3035 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3036 alGetString(error) ); |
0 | 3037 retval = -1; |
3038 } | |
3039 } | |
3040 } | |
3041 } | |
3042 /* The user wants to halt all channels */ | |
3043 else | |
3044 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3045 ALint i; |
0 | 3046 for(i=0; i<Number_of_Channels_global; i++) |
3047 { | |
3048 /* only need to process channel if in use */ | |
3049 if(ALmixer_Channel_List[i].channel_in_use) | |
3050 { | |
3051 alGetSourcei( | |
3052 ALmixer_Channel_List[i].alsource, | |
3053 AL_SOURCE_STATE, &state | |
3054 ); | |
3055 if((error = alGetError()) != AL_NO_ERROR) | |
3056 { | |
3057 fprintf(stderr, "33Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3058 alGetString(error)); |
0 | 3059 } |
3060 if(AL_PAUSED == state) | |
3061 { | |
3062 /* Count the actual number of channels resumed */ | |
3063 counter++; | |
3064 | |
3065 /* We need to resume the expire time count down */ | |
3066 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3067 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3068 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3069 } |
3070 /* Do the same as expire time for fading */ | |
3071 if(ALmixer_Channel_List[i].fade_enabled) | |
3072 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3073 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3074 } |
3075 | |
3076 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3077 if((error = alGetError()) != AL_NO_ERROR) | |
3078 { | |
3079 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3080 alGetString(error) ); |
0 | 3081 retval = -1; |
3082 } | |
3083 } | |
3084 } | |
3085 } | |
3086 } | |
3087 if(-1 == retval) | |
3088 { | |
3089 return -1; | |
3090 } | |
3091 return counter; | |
3092 } | |
3093 | |
3094 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3095 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3096 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3097 ALint channel; |
0 | 3098 if(0 == source) |
3099 { | |
3100 return Internal_ResumeChannel(-1); | |
3101 } | |
3102 | |
3103 channel = Internal_GetChannel(source); | |
3104 if(-1 == channel) | |
3105 { | |
3106 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3107 return -1; | |
3108 } | |
3109 return Internal_ResumeChannel(channel); | |
3110 } | |
3111 | |
3112 | |
3113 /* Might consider setting eof to 0 as a "feature" | |
3114 * This will allow seek to end to stay there because | |
3115 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3116 static ALboolean Internal_SeekData(ALmixer_Data* data, ALuint msec) |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3117 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3118 ALint retval; |
0 | 3119 |
3120 if(NULL == data) | |
3121 { | |
3122 ALmixer_SetError("Cannot Seek because data is NULL"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3123 return AL_FALSE; |
0 | 3124 } |
3125 | |
3126 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3127 if(data->decoded_all) | |
3128 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3129 ALuint byte_position; |
0 | 3130 |
3131 /* OpenAL doesn't seem to like it if I change the buffer | |
3132 * while playing (crashes), so I must require that Seek only | |
3133 * be done when the data is not in use. | |
3134 * Since data may be shared among multiple sources, | |
3135 * I can't shut them down myself, so I have to return an error. | |
3136 */ | |
3137 if(data->in_use) | |
3138 { | |
3139 ALmixer_SetError("Cannot seek on predecoded data while instances are playing"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3140 return AL_FALSE; |
0 | 3141 } |
3142 #if 0 | |
3143 #if defined(DISABLE_PREDECODED_SEEK) | |
3144 ALmixer_SetError("Seek support for predecoded samples was not compiled in"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3145 return AL_FALSE; |
0 | 3146 |
3147 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3148 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3149 * samples because of the potential memory waste. | |
3150 * However, to seek a sample, we need to have a full | |
3151 * copy of the data around. So the strategy is to | |
3152 * recreate a hackish Sound_Sample to be used for seeking | |
3153 * purposes. If Sound_Sample is NULL, we will reallocate | |
3154 * memory for it and then procede as if everything | |
3155 * was normal. | |
3156 */ | |
3157 if(NULL == data->sample) | |
3158 { | |
3159 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3160 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3161 return AL_FALSE; |
0 | 3162 } |
3163 } | |
3164 #endif | |
3165 #endif | |
3166 /* If access_data was set, then we still have the | |
3167 * Sound_Sample and we can move around in the data. | |
3168 * If it was not set, the data has been freed and we | |
3169 * cannot do anything because there is no way to | |
3170 * recover the data because OpenAL won't let us | |
3171 * get access to the buffers | |
3172 */ | |
3173 if(NULL == data->sample) | |
3174 { | |
3175 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3176 return AL_FALSE; |
0 | 3177 } |
3178 | |
3179 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3180 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3181 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3182 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3183 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3184 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3185 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3186 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3187 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3188 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3189 |
0 | 3190 } |
3191 else | |
3192 { | |
3193 /* Reset eof flag?? */ | |
3194 data->eof = 0; | |
3195 retval = Sound_Seek(data->sample, msec); | |
3196 if(0 == retval) | |
3197 { | |
3198 ALmixer_SetError(Sound_GetError()); | |
3199 | |
3200 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3201 /* Try rewinding to clean up? */ | |
3202 /* | |
3203 Internal_RewindData(data); | |
3204 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3205 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3206 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3207 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3208 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3209 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3210 return AL_TRUE; |
0 | 3211 } |
3212 | |
3213 | |
3214 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3215 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3216 { |
3217 ALfloat value; | |
3218 ALenum error; | |
3219 ALfloat original_value; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3220 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3221 ALint retval; |
0 | 3222 |
3223 | |
3224 | |
3225 if(channel >= Number_of_Channels_global) | |
3226 { | |
3227 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
3228 return -1; | |
3229 } | |
3230 /* Let's call PlayChannelTimed to do the job. | |
3231 * There are two catches: | |
3232 * First is that we must set the volumes before the play call(s). | |
3233 * Second is that we must initialize the channel values | |
3234 */ | |
3235 | |
3236 if(channel < 0) | |
3237 { | |
3238 /* This might cause a problem for threads/race conditions. | |
3239 * We need to set the volume on an unknown channel, | |
3240 * so we need to request a channel first. Remember | |
3241 * that requesting a channel doesn't lock and it | |
3242 * could be surrendered to somebody else before we claim it. | |
3243 */ | |
3244 channel = Internal_GetChannel(0); | |
3245 if(-1 == channel) | |
3246 { | |
3247 return -1; | |
3248 } | |
3249 } | |
3250 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3251 { | |
3252 ALmixer_SetError("Channel %d is already in use", channel); | |
3253 return -1; | |
3254 } | |
3255 | |
3256 | |
3257 /* Get the original volume in case of a problem */ | |
3258 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3259 AL_GAIN, &original_value); |
0 | 3260 |
3261 if((error = alGetError()) != AL_NO_ERROR) | |
3262 { | |
3263 fprintf(stderr, "35Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3264 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3265 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3266 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3267 |
3268 /* Get the Min volume */ | |
3269 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3270 AL_MIN_GAIN, &value); | |
3271 if((error = alGetError()) != AL_NO_ERROR) | |
3272 { | |
3273 fprintf(stderr, "36Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3274 alGetString(error)); |
0 | 3275 } |
3276 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3277 | |
3278 /* Set the actual volume */ | |
3279 alSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3280 AL_GAIN, value); |
0 | 3281 if((error = alGetError()) != AL_NO_ERROR) |
3282 { | |
3283 fprintf(stderr, "37Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3284 alGetString(error)); |
0 | 3285 } |
3286 | |
3287 | |
3288 /* Now call PlayChannelTimed */ | |
3289 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3290 if(-1 == retval) | |
3291 { | |
3292 /* Chance of failure is actually pretty high since | |
3293 * a channel might already be in use or streamed | |
3294 * data can be shared | |
3295 */ | |
3296 /* Restore the original value to avoid accidental | |
3297 * distruption of playback | |
3298 */ | |
3299 alSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3300 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3301 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3302 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3303 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3304 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3305 } |
0 | 3306 return retval; |
3307 } | |
3308 | |
3309 /* We can't accept 0 as a value because of div-by-zero. | |
3310 * If zero, just call PlayChannelTimed at normal | |
3311 * volume | |
3312 */ | |
3313 if(0 == fade_ticks) | |
3314 { | |
3315 alSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3316 AL_GAIN, |
0 | 3317 ALmixer_Channel_List[channel].fade_end_volume |
3318 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3319 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3320 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3321 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3322 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3323 } |
0 | 3324 |
3325 return retval; | |
3326 } | |
3327 | |
3328 /* Enable fading effects via the flag */ | |
3329 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3330 /* Set fade start time */ | |
3331 ALmixer_Channel_List[channel].fade_start_time | |
3332 = ALmixer_Channel_List[channel].start_time; | |
3333 /* Set the fade expire ticks */ | |
3334 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3335 | |
3336 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3337 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3338 | |
3339 return retval; | |
3340 | |
3341 } | |
3342 | |
3343 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3344 static ALuint Internal_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3346 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3347 ALint retval; |
0 | 3348 if(0 == source) |
3349 { | |
3350 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3351 if(-1 == retval) | |
3352 { | |
3353 return 0; | |
3354 } | |
3355 else | |
3356 { | |
3357 return Internal_GetSource(retval); | |
3358 } | |
3359 } | |
3360 | |
3361 channel = Internal_GetChannel(source); | |
3362 if(-1 == channel) | |
3363 { | |
3364 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3365 return 0; | |
3366 } | |
3367 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3368 if(-1 == retval) | |
3369 { | |
3370 return 0; | |
3371 } | |
3372 else | |
3373 { | |
3374 return source; | |
3375 } | |
3376 /* make compiler happy */ | |
3377 return 0; | |
3378 } | |
3379 | |
3380 | |
3381 | |
3382 | |
3383 /* Will fade out currently playing channels. | |
3384 * It starts at the current volume level and goes down */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3385 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3386 { |
3387 ALfloat value; | |
3388 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3389 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3390 ALuint counter = 0; |
0 | 3391 |
3392 /* We can't accept 0 as a value because of div-by-zero. | |
3393 * If zero, just call Halt at normal | |
3394 * volume | |
3395 */ | |
3396 if(0 == ticks) | |
3397 { | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
3398 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3399 } |
3400 | |
3401 | |
3402 if(channel >= Number_of_Channels_global) | |
3403 { | |
3404 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
3405 return -1; | |
3406 } | |
3407 | |
3408 if(channel >= 0) | |
3409 { | |
3410 if(ALmixer_Channel_List[channel].channel_in_use) | |
3411 { | |
3412 /* Get the current volume */ | |
3413 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3414 AL_GAIN, &value); |
0 | 3415 ALmixer_Channel_List[channel].fade_start_volume = value; |
3416 if((error = alGetError()) != AL_NO_ERROR) | |
3417 { | |
3418 fprintf(stderr, "40Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3419 alGetString(error)); |
0 | 3420 } |
3421 | |
3422 /* Get the Min volume */ | |
3423 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3424 AL_MIN_GAIN, &value); | |
3425 if((error = alGetError()) != AL_NO_ERROR) | |
3426 { | |
3427 fprintf(stderr, "41Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3428 alGetString(error)); |
0 | 3429 } |
3430 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3431 | |
3432 /* Set expire start time */ | |
3433 ALmixer_Channel_List[channel].start_time = current_time; | |
3434 /* Set the expire ticks */ | |
3435 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3436 /* Set fade start time */ | |
3437 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3438 /* Set the fade expire ticks */ | |
3439 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3440 /* Enable fading effects via the flag */ | |
3441 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3442 | |
3443 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3444 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3445 | |
3446 counter++; | |
3447 } | |
3448 } | |
3449 /* Else need to fade out all channels */ | |
3450 else | |
3451 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3452 ALint i; |
0 | 3453 for(i=0; i<Number_of_Channels_global; i++) |
3454 { | |
3455 if(ALmixer_Channel_List[i].channel_in_use) | |
3456 { | |
3457 /* Get the current volume */ | |
3458 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3459 AL_GAIN, &value); |
0 | 3460 ALmixer_Channel_List[i].fade_start_volume = value; |
3461 if((error = alGetError()) != AL_NO_ERROR) | |
3462 { | |
3463 fprintf(stderr, "42Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3464 alGetString(error)); |
0 | 3465 } |
3466 | |
3467 /* Get the Min volume */ | |
3468 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3469 AL_MIN_GAIN, &value); | |
3470 if((error = alGetError()) != AL_NO_ERROR) | |
3471 { | |
3472 fprintf(stderr, "43Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3473 alGetString(error)); |
0 | 3474 } |
3475 ALmixer_Channel_List[i].fade_end_volume = value; | |
3476 | |
3477 /* Set expire start time */ | |
3478 ALmixer_Channel_List[i].start_time = current_time; | |
3479 /* Set the expire ticks */ | |
3480 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3481 /* Set fade start time */ | |
3482 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3483 /* Set the fade expire ticks */ | |
3484 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3485 /* Enable fading effects via the flag */ | |
3486 ALmixer_Channel_List[i].fade_enabled = 1; | |
3487 | |
3488 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3489 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3490 | |
3491 counter++; | |
3492 } | |
3493 } /* End for loop */ | |
3494 } | |
3495 return counter; | |
3496 } | |
3497 | |
3498 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3499 static ALint Internal_FadeOutSource(ALuint source, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3500 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3501 ALint channel; |
0 | 3502 if(0 == source) |
3503 { | |
3504 return Internal_FadeOutChannel(-1, ticks); | |
3505 } | |
3506 | |
3507 channel = Internal_GetChannel(source); | |
3508 if(-1 == channel) | |
3509 { | |
3510 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3511 return -1; | |
3512 } | |
3513 return Internal_FadeOutChannel(channel, ticks); | |
3514 } | |
3515 | |
3516 | |
3517 /* Will fade currently playing channels. | |
3518 * It starts at the current volume level and go to target | |
3519 * Only affects channels that are playing | |
3520 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3521 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3522 { |
3523 ALfloat value; | |
3524 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3525 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3526 ALuint counter = 0; |
0 | 3527 |
3528 if(channel >= Number_of_Channels_global) | |
3529 { | |
3530 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
3531 return -1; | |
3532 } | |
3533 | |
3534 if(channel >= 0) | |
3535 { | |
3536 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3537 { | |
3538 volume = ALmixer_Channel_List[channel].min_volume; | |
3539 } | |
3540 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3541 { | |
3542 volume = ALmixer_Channel_List[channel].max_volume; | |
3543 } | |
3544 | |
3545 if(ALmixer_Channel_List[channel].channel_in_use) | |
3546 { | |
3547 if(ticks > 0) | |
3548 { | |
3549 /* Get the current volume */ | |
3550 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3551 AL_GAIN, &value); |
0 | 3552 if((error = alGetError()) != AL_NO_ERROR) |
3553 { | |
3554 fprintf(stderr, "44Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3555 alGetString(error)); |
0 | 3556 } |
3557 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3558 | |
3559 /* Set the target volume */ | |
3560 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3561 | |
3562 /* Set fade start time */ | |
3563 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3564 /* Set the fade expire ticks */ | |
3565 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3566 /* Enable fading effects via the flag */ | |
3567 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3568 | |
3569 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3570 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3571 } | |
3572 else | |
3573 { | |
3574 alSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3575 AL_GAIN, volume); |
0 | 3576 if((error = alGetError()) != AL_NO_ERROR) |
3577 { | |
3578 fprintf(stderr, "45Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3579 alGetString(error)); |
0 | 3580 } |
3581 } | |
3582 counter++; | |
3583 } | |
3584 } | |
3585 /* Else need to fade out all channels */ | |
3586 else | |
3587 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3588 ALint i; |
0 | 3589 for(i=0; i<Number_of_Channels_global; i++) |
3590 { | |
3591 if(volume < ALmixer_Channel_List[i].min_volume) | |
3592 { | |
3593 volume = ALmixer_Channel_List[i].min_volume; | |
3594 } | |
3595 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3596 { | |
3597 volume = ALmixer_Channel_List[i].max_volume; | |
3598 } | |
3599 | |
3600 if(ALmixer_Channel_List[i].channel_in_use) | |
3601 { | |
3602 if(ticks > 0) | |
3603 { | |
3604 /* Get the current volume */ | |
3605 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3606 AL_GAIN, &value); |
0 | 3607 if((error = alGetError()) != AL_NO_ERROR) |
3608 { | |
3609 fprintf(stderr, "46Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3610 alGetString(error)); |
0 | 3611 } |
3612 ALmixer_Channel_List[i].fade_start_volume = value; | |
3613 | |
3614 /* Set target volume */ | |
3615 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3616 | |
3617 /* Set fade start time */ | |
3618 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3619 /* Set the fade expire ticks */ | |
3620 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3621 /* Enable fading effects via the flag */ | |
3622 ALmixer_Channel_List[i].fade_enabled = 1; | |
3623 | |
3624 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3625 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3626 } | |
3627 else | |
3628 { | |
3629 alSourcef(ALmixer_Channel_List[i].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3630 AL_GAIN, volume); |
0 | 3631 if((error = alGetError()) != AL_NO_ERROR) |
3632 { | |
3633 fprintf(stderr, "47Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3634 alGetString(error)); |
0 | 3635 } |
3636 } | |
3637 counter++; | |
3638 } | |
3639 } /* End for loop */ | |
3640 } | |
3641 return counter; | |
3642 } | |
3643 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3644 static ALint Internal_FadeSource(ALuint source, ALuint ticks, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3645 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3646 ALint channel; |
0 | 3647 if(0 == source) |
3648 { | |
3649 return Internal_FadeChannel(-1, ticks, volume); | |
3650 } | |
3651 | |
3652 channel = Internal_GetChannel(source); | |
3653 if(-1 == channel) | |
3654 { | |
3655 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3656 return -1; | |
3657 } | |
3658 return Internal_FadeChannel(channel, ticks, volume); | |
3659 } | |
3660 | |
3661 | |
3662 | |
3663 | |
3664 /* Set a volume regardless if it's in use or not. | |
3665 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3666 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3667 { |
3668 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3669 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3670 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3671 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3672 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3673 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3674 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3675 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3676 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3677 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3678 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3679 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3681 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3682 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3683 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3684 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3685 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3686 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3687 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3688 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3689 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3691 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3692 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3693 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3694 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3695 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3696 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3697 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3698 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3699 for(i=0; i<Number_of_Channels_global; i++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3700 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3701 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3702 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3703 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3704 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3705 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3707 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3708 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3709 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3710 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3711 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3712 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3713 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3714 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3715 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3716 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3717 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3718 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3719 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3720 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3721 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3722 static ALboolean Internal_SetVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3723 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3724 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3726 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3727 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3728 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3729 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3730 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3731 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3732 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3733 ALmixer_SetError("Cannot SetMaxVolume: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3734 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3735 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3736 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3737 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3738 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3739 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3740 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3741 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3742 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3743 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3744 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3745 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3746 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3747 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3748 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3750 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3751 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3752 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3753 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3754 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3755 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3756 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3757 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3758 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3759 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3760 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3761 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3762 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3763 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3764 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3765 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3767 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3768 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3769 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3770 for(i=0; i<Number_of_Channels_global; i++) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3771 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3772 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3773 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3774 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3775 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3776 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3777 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3778 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3779 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3780 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3781 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3782 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3783 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3784 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3785 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3786 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3787 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3788 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3789 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3790 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3791 retval = running_total / Number_of_Channels_global; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3792 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3793 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3794 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3795 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3796 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3797 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3798 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3799 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3800 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3801 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3802 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3803 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3804 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3805 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3806 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3807 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3808 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3809 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3810 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3812 return Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3813 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3814 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3815 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3816 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3817 /* Set a volume regardless if it's in use or not. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3818 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3819 static ALboolean Internal_SetMaxVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3820 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3821 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3822 ALboolean retval = AL_TRUE; |
0 | 3823 |
3824 if(channel >= Number_of_Channels_global) | |
3825 { | |
3826 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3827 return AL_FALSE; |
0 | 3828 } |
3829 | |
3830 if(channel >= 0) | |
3831 { | |
3832 if(volume < 0.0f) | |
3833 { | |
3834 volume = 0.0f; | |
3835 } | |
3836 else if(volume > 1.0f) | |
3837 { | |
3838 volume = 1.0f; | |
3839 } | |
3840 ALmixer_Channel_List[channel].max_volume = volume; | |
3841 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3842 AL_MAX_GAIN, volume); | |
3843 if((error = alGetError()) != AL_NO_ERROR) | |
3844 { | |
3845 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3846 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3847 retval = AL_FALSE; |
0 | 3848 } |
3849 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
3850 { | |
3851 ALmixer_Channel_List[channel].min_volume = volume; | |
3852 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3853 AL_MIN_GAIN, volume); | |
3854 if((error = alGetError()) != AL_NO_ERROR) | |
3855 { | |
3856 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3857 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3858 retval = AL_FALSE; |
0 | 3859 } |
3860 } | |
3861 } | |
3862 else | |
3863 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3864 ALint i; |
0 | 3865 for(i=0; i<Number_of_Channels_global; i++) |
3866 { | |
3867 if(volume < 0.0f) | |
3868 { | |
3869 volume = 0.0f; | |
3870 } | |
3871 else if(volume > 1.0f) | |
3872 { | |
3873 volume = 1.0f; | |
3874 } | |
3875 ALmixer_Channel_List[i].max_volume = volume; | |
3876 alSourcef(ALmixer_Channel_List[i].alsource, | |
3877 AL_MAX_GAIN, volume); | |
3878 if((error = alGetError()) != AL_NO_ERROR) | |
3879 { | |
3880 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3881 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3882 retval = AL_FALSE; |
0 | 3883 } |
3884 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
3885 { | |
3886 ALmixer_Channel_List[i].min_volume = volume; | |
3887 alSourcef(ALmixer_Channel_List[i].alsource, | |
3888 AL_MIN_GAIN, volume); | |
3889 if((error = alGetError()) != AL_NO_ERROR) | |
3890 { | |
3891 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3893 retval = AL_FALSE; |
0 | 3894 } |
3895 } | |
3896 } | |
3897 } | |
3898 return retval; | |
3899 } | |
3900 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 static ALint Internal_SetMaxVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3902 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3903 ALint channel; |
0 | 3904 if(0 == source) |
3905 { | |
3906 return Internal_SetMaxVolumeChannel(-1, volume); | |
3907 } | |
3908 | |
3909 channel = Internal_GetChannel(source); | |
3910 if(-1 == channel) | |
3911 { | |
3912 ALmixer_SetError("Cannot SetMaxVolume: %s", ALmixer_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 return AL_FALSE; |
0 | 3914 } |
3915 return Internal_SetMaxVolumeChannel(channel, volume); | |
3916 } | |
3917 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3918 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 3919 { |
3920 /* | |
3921 ALfloat value; | |
3922 ALenum error; | |
3923 */ | |
3924 ALfloat running_total = 0.0f; | |
3925 ALfloat retval = 0.0f; | |
3926 | |
3927 if(channel >= Number_of_Channels_global) | |
3928 { | |
3929 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
3930 return -1.0f; | |
3931 } | |
3932 | |
3933 if(channel >= 0) | |
3934 { | |
3935 /* | |
3936 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3937 AL_GAIN, &value); | |
3938 if((error = alGetError()) != AL_NO_ERROR) | |
3939 { | |
3940 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3941 alGetString(error) ); |
0 | 3942 retval = -1.0f; |
3943 } | |
3944 else | |
3945 { | |
3946 retval = value; | |
3947 } | |
3948 */ | |
3949 retval = ALmixer_Channel_List[channel].max_volume; | |
3950 | |
3951 } | |
3952 else | |
3953 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 ALint i; |
0 | 3955 for(i=0; i<Number_of_Channels_global; i++) |
3956 { | |
3957 /* | |
3958 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3959 AL_GAIN, &value); | |
3960 if((error = alGetError()) != AL_NO_ERROR) | |
3961 { | |
3962 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3963 alGetString(error) ); |
0 | 3964 retval = -1; |
3965 } | |
3966 else | |
3967 { | |
3968 running_total += value; | |
3969 } | |
3970 */ | |
3971 running_total += ALmixer_Channel_List[i].max_volume; | |
3972 } | |
3973 if(0 == Number_of_Channels_global) | |
3974 { | |
3975 ALmixer_SetError("No channels are allocated"); | |
3976 retval = -1.0f; | |
3977 } | |
3978 else | |
3979 { | |
3980 retval = running_total / Number_of_Channels_global; | |
3981 } | |
3982 } | |
3983 return retval; | |
3984 } | |
3985 | |
3986 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
3987 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3988 ALint channel; |
0 | 3989 if(0 == source) |
3990 { | |
3991 return Internal_GetMaxVolumeChannel(-1); | |
3992 } | |
3993 | |
3994 channel = Internal_GetChannel(source); | |
3995 if(-1 == channel) | |
3996 { | |
3997 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
3998 return -1.0f; | |
3999 } | |
4000 | |
4001 return Internal_GetMaxVolumeChannel(channel); | |
4002 } | |
4003 | |
4004 | |
4005 /* Set a volume regardless if it's in use or not. | |
4006 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4007 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4008 { |
4009 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4010 ALboolean retval = AL_TRUE; |
0 | 4011 |
4012 if(channel >= Number_of_Channels_global) | |
4013 { | |
4014 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4015 return AL_FALSE; |
0 | 4016 } |
4017 | |
4018 if(channel >= 0) | |
4019 { | |
4020 if(volume < 0.0f) | |
4021 { | |
4022 volume = 0.0f; | |
4023 } | |
4024 else if(volume > 1.0f) | |
4025 { | |
4026 volume = 1.0f; | |
4027 } | |
4028 ALmixer_Channel_List[channel].min_volume = volume; | |
4029 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4030 AL_MIN_GAIN, volume); | |
4031 if((error = alGetError()) != AL_NO_ERROR) | |
4032 { | |
4033 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4035 retval = AL_FALSE; |
0 | 4036 } |
4037 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4038 { | |
4039 ALmixer_Channel_List[channel].max_volume = volume; | |
4040 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4041 AL_MAX_GAIN, volume); | |
4042 if((error = alGetError()) != AL_NO_ERROR) | |
4043 { | |
4044 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4046 retval = AL_FALSE; |
0 | 4047 } |
4048 } | |
4049 } | |
4050 else | |
4051 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4052 ALint i; |
0 | 4053 for(i=0; i<Number_of_Channels_global; i++) |
4054 { | |
4055 if(volume < 0.0f) | |
4056 { | |
4057 volume = 0.0f; | |
4058 } | |
4059 else if(volume > 1.0f) | |
4060 { | |
4061 volume = 1.0f; | |
4062 } | |
4063 ALmixer_Channel_List[i].min_volume = volume; | |
4064 alSourcef(ALmixer_Channel_List[i].alsource, | |
4065 AL_MIN_GAIN, volume); | |
4066 if((error = alGetError()) != AL_NO_ERROR) | |
4067 { | |
4068 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4069 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4070 retval = AL_FALSE; |
0 | 4071 } |
4072 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4073 { | |
4074 ALmixer_Channel_List[i].max_volume = volume; | |
4075 alSourcef(ALmixer_Channel_List[i].alsource, | |
4076 AL_MAX_GAIN, volume); | |
4077 if((error = alGetError()) != AL_NO_ERROR) | |
4078 { | |
4079 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4080 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4081 retval = AL_FALSE; |
0 | 4082 } |
4083 } | |
4084 } | |
4085 } | |
4086 return retval; | |
4087 } | |
4088 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4089 static ALboolean Internal_SetMinVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4090 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4091 ALint channel; |
0 | 4092 if(0 == source) |
4093 { | |
4094 return Internal_SetMinVolumeChannel(-1, volume); | |
4095 } | |
4096 | |
4097 channel = Internal_GetChannel(source); | |
4098 if(-1 == channel) | |
4099 { | |
4100 ALmixer_SetError("Cannot SetMaxVolume: %s", ALmixer_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4101 return AL_FALSE; |
0 | 4102 } |
4103 return Internal_SetMinVolumeChannel(channel, volume); | |
4104 } | |
4105 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4106 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4107 { |
4108 /* | |
4109 ALfloat value; | |
4110 ALenum error; | |
4111 */ | |
4112 ALfloat running_total = 0.0f; | |
4113 ALfloat retval = 0.0f; | |
4114 | |
4115 if(channel >= Number_of_Channels_global) | |
4116 { | |
4117 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
4118 return -1.0f; | |
4119 } | |
4120 | |
4121 if(channel >= 0) | |
4122 { | |
4123 /* | |
4124 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4125 AL_GAIN, &value); | |
4126 if((error = alGetError()) != AL_NO_ERROR) | |
4127 { | |
4128 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4129 alGetString(error) ); |
0 | 4130 retval = -1.0f; |
4131 } | |
4132 else | |
4133 { | |
4134 retval = value; | |
4135 } | |
4136 */ | |
4137 retval = ALmixer_Channel_List[channel].min_volume; | |
4138 | |
4139 } | |
4140 else | |
4141 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4142 ALint i; |
0 | 4143 for(i=0; i<Number_of_Channels_global; i++) |
4144 { | |
4145 /* | |
4146 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4147 AL_GAIN, &value); | |
4148 if((error = alGetError()) != AL_NO_ERROR) | |
4149 { | |
4150 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4151 alGetString(error) ); |
0 | 4152 retval = -1; |
4153 } | |
4154 else | |
4155 { | |
4156 running_total += value; | |
4157 } | |
4158 */ | |
4159 running_total += ALmixer_Channel_List[i].min_volume; | |
4160 } | |
4161 if(0 == Number_of_Channels_global) | |
4162 { | |
4163 ALmixer_SetError("No channels are allocated"); | |
4164 retval = -1.0f; | |
4165 } | |
4166 else | |
4167 { | |
4168 retval = running_total / Number_of_Channels_global; | |
4169 } | |
4170 } | |
4171 return retval; | |
4172 } | |
4173 | |
4174 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4175 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4176 ALint channel; |
0 | 4177 if(0 == source) |
4178 { | |
4179 return Internal_GetMinVolumeChannel(-1); | |
4180 } | |
4181 | |
4182 channel = Internal_GetChannel(source); | |
4183 if(-1 == channel) | |
4184 { | |
4185 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4186 return -1.0f; | |
4187 } | |
4188 | |
4189 return Internal_GetMinVolumeChannel(channel); | |
4190 } | |
4191 | |
4192 | |
4193 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4194 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4195 { |
4196 ALenum error; | |
4197 alListenerf(AL_GAIN, volume); | |
4198 if((error = alGetError()) != AL_NO_ERROR) | |
4199 { | |
4200 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4201 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4202 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4203 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4204 return AL_TRUE; |
0 | 4205 } |
4206 | |
4207 static ALfloat Internal_GetMasterVolume() | |
4208 { | |
4209 ALenum error; | |
4210 ALfloat volume; | |
4211 alGetListenerf(AL_GAIN, &volume); | |
4212 if((error = alGetError()) != AL_NO_ERROR) | |
4213 { | |
4214 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4215 alGetString(error) ); |
0 | 4216 return -1.0f; |
4217 } | |
4218 return volume; | |
4219 } | |
4220 | |
4221 | |
4222 | |
4223 | |
4224 /* Will fade out currently playing channels. | |
4225 * It starts at the current volume level and goes down */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4226 static ALint Internal_ExpireChannel(ALint channel, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4227 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4228 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4229 ALuint counter = 0; |
0 | 4230 |
4231 /* We can't accept 0 as a value because of div-by-zero. | |
4232 * If zero, just call Halt at normal | |
4233 * volume | |
4234 */ | |
4235 if(0 == ticks) | |
4236 { | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4237 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4238 } |
4239 if(ticks < -1) | |
4240 { | |
4241 ticks = -1; | |
4242 } | |
4243 | |
4244 | |
4245 if(channel >= Number_of_Channels_global) | |
4246 { | |
4247 ALmixer_SetError("Requested channel (%d) exceeds maximum channel (%d) because only %d channels are allocated", channel, Number_of_Channels_global-1, Number_of_Channels_global); | |
4248 return -1; | |
4249 } | |
4250 | |
4251 if(channel >= 0) | |
4252 { | |
4253 if(ALmixer_Channel_List[channel].channel_in_use) | |
4254 { | |
4255 /* Set expire start time */ | |
4256 ALmixer_Channel_List[channel].start_time = current_time; | |
4257 /* Set the expire ticks */ | |
4258 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4259 | |
4260 counter++; | |
4261 } | |
4262 } | |
4263 /* Else need to fade out all channels */ | |
4264 else | |
4265 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4266 ALint i; |
0 | 4267 for(i=0; i<Number_of_Channels_global; i++) |
4268 { | |
4269 if(ALmixer_Channel_List[i].channel_in_use) | |
4270 { | |
4271 /* Set expire start time */ | |
4272 ALmixer_Channel_List[i].start_time = current_time; | |
4273 /* Set the expire ticks */ | |
4274 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4275 | |
4276 counter++; | |
4277 } | |
4278 } /* End for loop */ | |
4279 } | |
4280 return counter; | |
4281 } | |
4282 | |
4283 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4284 static ALint Internal_ExpireSource(ALuint source, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4285 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4286 ALint channel; |
0 | 4287 if(0 == source) |
4288 { | |
4289 return Internal_ExpireChannel(-1, ticks); | |
4290 } | |
4291 | |
4292 channel = Internal_GetChannel(source); | |
4293 if(-1 == channel) | |
4294 { | |
4295 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4296 return -1; | |
4297 } | |
4298 return Internal_ExpireChannel(channel, ticks); | |
4299 } | |
4300 | |
4301 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4302 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4303 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4304 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4305 ALint counter = 0; |
0 | 4306 if(channel >= Number_of_Channels_global) |
4307 { | |
4308 ALmixer_SetError("Invalid channel: %d", channel); | |
4309 return -1; | |
4310 } | |
4311 | |
4312 if(channel >= 0) | |
4313 { | |
4314 return ALmixer_Channel_List[channel].channel_in_use; | |
4315 } | |
4316 | |
4317 /* Else, return the number of channels in use */ | |
4318 for(i=0; i<Number_of_Channels_global; i++) | |
4319 { | |
4320 if(ALmixer_Channel_List[i].channel_in_use) | |
4321 { | |
4322 counter++; | |
4323 } | |
4324 } | |
4325 return counter; | |
4326 } | |
4327 | |
4328 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4329 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4331 ALint channel; |
0 | 4332 if(0 == source) |
4333 { | |
4334 return Internal_QueryChannel(-1); | |
4335 } | |
4336 | |
4337 channel = Internal_GetChannel(source); | |
4338 if(-1 == channel) | |
4339 { | |
4340 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4341 return -1; | |
4342 } | |
4343 | |
4344 return Internal_QueryChannel(channel); | |
4345 } | |
4346 | |
4347 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4348 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4349 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4350 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4351 ALuint counter = 0; |
0 | 4352 |
4353 | |
4354 /* Else, return the number of channels in use */ | |
4355 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4356 { | |
4357 if(ALmixer_Channel_List[i].channel_in_use) | |
4358 { | |
4359 counter++; | |
4360 } | |
4361 } | |
4362 return counter; | |
4363 } | |
4364 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4365 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4366 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4367 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4368 ALuint counter = 0; |
0 | 4369 |
4370 | |
4371 /* Else, return the number of channels in use */ | |
4372 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4373 { | |
4374 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4375 { | |
4376 counter++; | |
4377 } | |
4378 } | |
4379 return counter; | |
4380 } | |
4381 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4382 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4383 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4384 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4385 ALuint counter = 0; |
0 | 4386 |
4387 | |
4388 /* Else, return the number of channels in use */ | |
4389 for(i=0; i<Number_of_Channels_global; i++) | |
4390 { | |
4391 if(ALmixer_Channel_List[i].channel_in_use) | |
4392 { | |
4393 counter++; | |
4394 } | |
4395 } | |
4396 return counter; | |
4397 } | |
4398 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4399 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4400 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4401 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4402 ALuint counter = 0; |
0 | 4403 |
4404 | |
4405 /* Else, return the number of channels in use */ | |
4406 for(i=0; i<Number_of_Channels_global; i++) | |
4407 { | |
4408 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4409 { | |
4410 counter++; | |
4411 } | |
4412 } | |
4413 return counter; | |
4414 } | |
4415 | |
4416 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4417 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4418 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4419 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4420 ALint counter = 0; |
0 | 4421 ALint state; |
4422 | |
4423 if(channel >= Number_of_Channels_global) | |
4424 { | |
4425 ALmixer_SetError("Invalid channel: %d", channel); | |
4426 return -1; | |
4427 } | |
4428 | |
4429 if(channel >= 0) | |
4430 { | |
4431 if(ALmixer_Channel_List[channel].channel_in_use) | |
4432 { | |
4433 alGetSourcei( | |
4434 ALmixer_Channel_List[channel].alsource, | |
4435 AL_SOURCE_STATE, &state | |
4436 ); | |
4437 if(AL_PLAYING == state) | |
4438 { | |
4439 return 1; | |
4440 } | |
4441 } | |
4442 return 0; | |
4443 } | |
4444 | |
4445 /* Else, return the number of channels in use */ | |
4446 for(i=0; i<Number_of_Channels_global; i++) | |
4447 { | |
4448 if(ALmixer_Channel_List[i].channel_in_use) | |
4449 { | |
4450 alGetSourcei( | |
4451 ALmixer_Channel_List[i].alsource, | |
4452 AL_SOURCE_STATE, &state | |
4453 ); | |
4454 if(AL_PLAYING == state) | |
4455 { | |
4456 counter++; | |
4457 } | |
4458 } | |
4459 } | |
4460 return counter; | |
4461 } | |
4462 | |
4463 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4464 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4465 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4466 ALint channel; |
0 | 4467 if(0 == source) |
4468 { | |
4469 return Internal_PlayingChannel(-1); | |
4470 } | |
4471 | |
4472 channel = Internal_GetChannel(source); | |
4473 if(-1 == channel) | |
4474 { | |
4475 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4476 return -1; | |
4477 } | |
4478 | |
4479 return Internal_PlayingChannel(channel); | |
4480 } | |
4481 | |
4482 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4483 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4484 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4485 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4486 ALint counter = 0; |
0 | 4487 ALint state; |
4488 | |
4489 if(channel >= Number_of_Channels_global) | |
4490 { | |
4491 ALmixer_SetError("Invalid channel: %d", channel); | |
4492 return -1; | |
4493 } | |
4494 | |
4495 if(channel >= 0) | |
4496 { | |
4497 if(ALmixer_Channel_List[channel].channel_in_use) | |
4498 { | |
4499 alGetSourcei( | |
4500 ALmixer_Channel_List[channel].alsource, | |
4501 AL_SOURCE_STATE, &state | |
4502 ); | |
4503 if(AL_PAUSED == state) | |
4504 { | |
4505 return 1; | |
4506 } | |
4507 } | |
4508 return 0; | |
4509 } | |
4510 | |
4511 /* Else, return the number of channels in use */ | |
4512 for(i=0; i<Number_of_Channels_global; i++) | |
4513 { | |
4514 if(ALmixer_Channel_List[i].channel_in_use) | |
4515 { | |
4516 alGetSourcei( | |
4517 ALmixer_Channel_List[i].alsource, | |
4518 AL_SOURCE_STATE, &state | |
4519 ); | |
4520 if(AL_PAUSED == state) | |
4521 { | |
4522 counter++; | |
4523 } | |
4524 } | |
4525 } | |
4526 return counter; | |
4527 } | |
4528 | |
4529 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4530 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4531 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4532 ALint channel; |
0 | 4533 if(0 == source) |
4534 { | |
4535 return Internal_PausedChannel(-1); | |
4536 } | |
4537 | |
4538 channel = Internal_GetChannel(source); | |
4539 if(-1 == channel) | |
4540 { | |
4541 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4542 return -1; | |
4543 } | |
4544 | |
4545 return Internal_PausedChannel(channel); | |
4546 } | |
4547 | |
4548 | |
4549 | |
4550 | |
4551 | |
4552 | |
4553 /* Private function for Updating ALmixer. | |
4554 * This is a very big and ugly function. | |
4555 * It should return the number of buffers that were | |
4556 * queued during the call. The value might be | |
4557 * used to guage how long you might wait to | |
4558 * call the next update loop in case you are worried | |
4559 * about preserving CPU cycles. The idea is that | |
4560 * when a buffer is queued, there was probably some | |
4561 * CPU intensive looping which took awhile. | |
4562 * It's mainly provided as a convenience. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4563 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4564 * more accurate information. |
4565 * Returns a negative value if there was an error, | |
4566 * the value being the number of errors. | |
4567 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4568 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4569 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4570 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4571 ALint error_flag = 0; |
0 | 4572 ALenum error; |
4573 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4574 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4575 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4576 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4577 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4578 #endif |
0 | 4579 if(0 == ALmixer_Initialized) |
4580 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4581 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4582 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4583 #endif |
0 | 4584 return 0; |
4585 } | |
4586 | |
4587 /* Check the quick flag to see if anything needs updating */ | |
4588 /* If anything is playing, then we have to do work */ | |
4589 if( 0 == Is_Playing_global) | |
4590 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4591 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4592 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4593 #endif |
0 | 4594 return 0; |
4595 } | |
4596 /* Clear error */ | |
4597 if((error = alGetError()) != AL_NO_ERROR) | |
4598 { | |
4599 fprintf(stderr, "08Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4600 alGetString(error)); |
0 | 4601 } |
4602 alGetError(); | |
4603 | |
4604 for(i=0; i<Number_of_Channels_global; i++) | |
4605 { | |
4606 if( ALmixer_Channel_List[i].channel_in_use ) | |
4607 { | |
4608 | |
4609 /* For simplicity, before we do anything else, | |
4610 * we can check the timeout and fading values | |
4611 * and do the appropriate things | |
4612 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4613 ALuint current_time = ALmixer_GetTicks(); |
0 | 4614 |
4615 /* Check to see if we need to halt due to Timed play */ | |
4616 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4617 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4618 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4619 + ALmixer_Channel_List[i].start_time; |
4620 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4621 AL_SOURCE_STATE, &state); | |
4622 if((error = alGetError()) != AL_NO_ERROR) | |
4623 { | |
4624 fprintf(stderr, "06Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4625 alGetString(error)); |
0 | 4626 } |
4627 | |
4628 /* Check the time, and also make sure that it is not | |
4629 * paused (if paused, we don't want to make the | |
4630 * evaluation because when resumed, we will adjust | |
4631 * the times to compensate for the pause). | |
4632 */ | |
4633 if( (current_time >= target_time) | |
4634 && (state != AL_PAUSED) ) | |
4635 { | |
4636 /* Stop the playback */ | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4637 Internal_HaltChannel(i, AL_FALSE); |
0 | 4638 if((error = alGetError()) != AL_NO_ERROR) |
4639 { | |
4640 fprintf(stderr, "07Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4641 alGetString(error)); |
0 | 4642 } |
4643 | |
4644 /* Everything should be done so go on to the next loop */ | |
4645 continue; | |
4646 } | |
4647 } /* End if time expired check */ | |
4648 | |
4649 /* Check to see if we need to adjust the volume for fading */ | |
4650 if( ALmixer_Channel_List[i].fade_enabled ) | |
4651 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4652 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4653 + ALmixer_Channel_List[i].fade_start_time; |
4654 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4655 AL_SOURCE_STATE, &state); | |
4656 if((error = alGetError()) != AL_NO_ERROR) | |
4657 { | |
4658 fprintf(stderr, "05Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4659 alGetString(error)); |
0 | 4660 } |
4661 | |
4662 /* Check the time, and also make sure that it is not | |
4663 * paused (if paused, we don't want to make the | |
4664 * evaluation because when resumed, we will adjust | |
4665 * the times to compensate for the pause). | |
4666 */ | |
4667 if(state != AL_PAUSED) | |
4668 { | |
4669 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4670 ALuint delta_time; |
0 | 4671 ALfloat current_volume; |
4672 if(current_time >= target_time) | |
4673 { | |
4674 /* Need to constrain value to the end time | |
4675 * (can't go pass the value for calculations) | |
4676 */ | |
4677 current_time = target_time; | |
4678 /* We can disable the fade flag now */ | |
4679 ALmixer_Channel_List[i].fade_enabled = 0; | |
4680 } | |
4681 /* Use the linear interpolation formula: | |
4682 * X = (1-t)x0 + tx1 | |
4683 * where x0 would be the start value | |
4684 * and x1 is the final value | |
4685 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4686 * delta_time = current_time-start_time | |
4687 * inv_time = 1/ (end_time-start_time) | |
4688 * so t = current_time-start_time / (end_time-start_time) | |
4689 * | |
4690 */ | |
4691 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4692 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4693 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4694 + t * ALmixer_Channel_List[i].fade_end_volume; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4695 fprintf(stderr, "start_vol=%f, end_vol:%f, current_volume: %f\n", ALmixer_Channel_List[i].fade_start_volume, ALmixer_Channel_List[i].fade_end_volume, current_volume); |
0 | 4696 |
4697 /* Set the volume */ | |
4698 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4699 AL_GAIN, current_volume); |
0 | 4700 if((error = alGetError()) != AL_NO_ERROR) |
4701 { | |
4702 fprintf(stderr, "04Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4703 alGetString(error)); |
0 | 4704 } |
4705 | |
4706 /* | |
4707 fprintf(stderr, "Current time =%d\n", current_time); | |
4708 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4709 */ | |
4710 } /* End if not PAUSED */ | |
4711 } /* End if fade_enabled */ | |
4712 | |
4713 | |
4714 /* Okay, now that the time expired and fading stuff | |
4715 * is done, do the rest of the hard stuff | |
4716 */ | |
4717 | |
4718 | |
4719 /* For predecoded, check to see if done */ | |
4720 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4721 { | |
4722 | |
4723 #if 0 | |
4724 /********* Remove this **********/ | |
4725 ALint buffers_processed; | |
4726 ALint buffers_still_queued; | |
4727 fprintf(stderr, "For Predecoded\n"); | |
4728 | |
4729 alGetSourcei( | |
4730 ALmixer_Channel_List[i].alsource, | |
4731 AL_SOURCE_STATE, &state | |
4732 ); | |
4733 switch(state) { | |
4734 case AL_PLAYING: | |
4735 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4736 break; | |
4737 case AL_PAUSED: | |
4738 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4739 break; | |
4740 case AL_STOPPED: | |
4741 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4742 break; | |
4743 case AL_INITIAL: | |
4744 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4745 break; | |
4746 default: | |
4747 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4748 break; | |
4749 } | |
4750 | |
4751 alGetSourcei( | |
4752 ALmixer_Channel_List[i].alsource, | |
4753 AL_BUFFERS_PROCESSED, &buffers_processed | |
4754 ); | |
4755 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4756 | |
4757 alGetSourcei( | |
4758 ALmixer_Channel_List[i].alsource, | |
4759 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4760 ); | |
4761 | |
4762 /******** END REMOVE *******/ | |
4763 #endif | |
4764 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4765 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4766 * command I could find in the above loops, but the error doesn't seem to show | |
4767 * up until around here. I mistook it for a get queued buffers | |
4768 * error in OS X. I don't think there's an error down there. | |
4769 * For now, I'm clearing the error here. | |
4770 */ | |
4771 | |
4772 if((error = alGetError()) != AL_NO_ERROR) | |
4773 { | |
4774 fprintf(stderr, "03Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4775 alGetString(error)); |
0 | 4776 } |
4777 | |
4778 | |
4779 alGetSourcei( | |
4780 ALmixer_Channel_List[i].alsource, | |
4781 AL_SOURCE_STATE, &state | |
4782 ); | |
4783 if((error = alGetError()) != AL_NO_ERROR) | |
4784 { | |
4785 fprintf(stderr, "02Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4786 alGetString(error)); |
0 | 4787 } |
4788 | |
4789 | |
4790 if(AL_STOPPED == state) | |
4791 { | |
4792 /* Playback has ended. | |
4793 * Loop if necessary, or launch callback | |
4794 * and clear channel (or clear channel and | |
4795 * then launch callback?) | |
4796 */ | |
4797 | |
4798 | |
4799 /* Need to check for loops */ | |
4800 if(ALmixer_Channel_List[i].loops != 0) | |
4801 { | |
4802 /* Corner Case: If the buffer has | |
4803 * been modified using Seek, | |
4804 * the loop will start at the seek | |
4805 * position. | |
4806 */ | |
4807 if(ALmixer_Channel_List[i].loops != -1) | |
4808 { | |
4809 ALmixer_Channel_List[i].loops--; | |
4810 } | |
4811 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
4812 if((error = alGetError()) != AL_NO_ERROR) | |
4813 { | |
4814 fprintf(stderr, "50Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4815 alGetString(error)); |
0 | 4816 } |
4817 continue; | |
4818 } | |
4819 /* No loops. End play. */ | |
4820 else | |
4821 { | |
4822 /* Problem: It seems that when mixing | |
4823 * streamed and predecoded sources, | |
4824 * the previous instance lingers, | |
4825 * so we need to force remove | |
4826 * the data from the source. | |
4827 * The sharing problem | |
4828 * occurs when a previous predecoded buffer is played on | |
4829 * a source, and then a streamed source is played later | |
4830 * on that same source. OpenAL isn't consistently | |
4831 * removing the previous buffer so both get played. | |
4832 * (Different dists seem to have different quirks. | |
4833 * The problem might lead to crashes in the worst case.) | |
4834 */ | |
4835 /* Additional problem: There is another | |
4836 * inconsistency among OpenAL distributions. | |
4837 * Both Loki and Creative Windows seem to keep | |
4838 * the buffer queued which requires removing. | |
4839 * But the Creative Macintosh version does | |
4840 * not have any buffer queued after play | |
4841 * and it returns the error: Invalid Enum Value | |
4842 * if I try to unqueue it. | |
4843 * So I'm going to put in a check to see if I | |
4844 * can detect any buffers queued first | |
4845 * and then unqueue them if I can see them. | |
4846 * Additional note: The new CoreAudio based | |
4847 * implementation leaves it's buffer queued | |
4848 * like Loki and Creative Windows. But | |
4849 * considering all the problems I'm having | |
4850 * with the different distributions, this | |
4851 * check seems reasonable. | |
4852 */ | |
4853 ALint buffers_still_queued; | |
4854 if((error = alGetError()) != AL_NO_ERROR) | |
4855 { | |
4856 fprintf(stderr, "01Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4857 alGetString(error)); |
0 | 4858 } |
4859 | |
4860 alGetSourcei( | |
4861 ALmixer_Channel_List[i].alsource, | |
4862 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4863 ); | |
4864 if((error = alGetError()) != AL_NO_ERROR) | |
4865 { | |
4866 fprintf(stderr, "Error with unqueue, for OS X this is expected: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4867 alGetString(error)); |
0 | 4868 ALmixer_SetError("Failed detecting unqueued predecoded buffer (expected with OS X): %s", |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4869 alGetString(error) ); |
0 | 4870 error_flag--; |
4871 } | |
4872 if(buffers_still_queued > 0) | |
4873 { | |
1 | 4874 |
4875 #if 0 /* This triggers an error in OS X Core Audio. */ | |
4876 alSourceUnqueueBuffers( | |
4877 ALmixer_Channel_List[i].alsource, | |
4878 1, | |
4879 ALmixer_Channel_List[i].almixer_data->buffer | |
4880 ); | |
4881 #else | |
4882 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 4883 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 4884 */ |
0 | 4885 /* Rather than force unqueuing the buffer, let's see if |
4886 * setting the buffer to none works (the OpenAL 1.0 | |
4887 * Reference Annotation suggests this should work). | |
4888 */ | |
4889 alSourcei(ALmixer_Channel_List[i].alsource, | |
4890 AL_BUFFER, AL_NONE); | |
4891 /* | |
4892 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
4893 */ | |
1 | 4894 #endif |
0 | 4895 if((error = alGetError()) != AL_NO_ERROR) |
4896 { | |
4897 fprintf(stderr, "Error with unqueue, after alSourceUnqueueBuffers, buffers_still_queued=%d, error is: %s", buffers_still_queued, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4898 alGetString(error)); |
0 | 4899 ALmixer_SetError("Predecoded Unqueue buffer failed: %s", |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4900 alGetString(error) ); |
0 | 4901 error_flag--; |
4902 } | |
4903 | |
4904 } | |
4905 | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4906 /* Launch callback */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4907 Invoke_Channel_Done_Callback(i, AL_TRUE); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4908 |
0 | 4909 Clean_Channel(i); |
4910 /* Subtract counter */ | |
4911 Is_Playing_global--; | |
4912 | |
4913 | |
4914 /* We're done for this loop. | |
4915 * Go to next channel | |
4916 */ | |
4917 continue; | |
4918 } | |
4919 continue; | |
4920 } | |
4921 } /* End if decoded_all */ | |
4922 /* For streamed */ | |
4923 else | |
4924 { | |
4925 ALint buffers_processed; | |
4926 ALint buffers_still_queued; | |
4927 ALint current_buffer_id; | |
4928 | |
4929 ALuint unqueued_buffer_id; | |
4930 #if 0 | |
4931 /********* Remove this **********/ | |
4932 fprintf(stderr, "For Streamed\n"); | |
4933 | |
4934 alGetSourcei( | |
4935 ALmixer_Channel_List[i].alsource, | |
4936 AL_SOURCE_STATE, &state | |
4937 ); | |
4938 switch(state) { | |
4939 case AL_PLAYING: | |
4940 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4941 break; | |
4942 case AL_PAUSED: | |
4943 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4944 break; | |
4945 case AL_STOPPED: | |
4946 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4947 break; | |
4948 case AL_INITIAL: | |
4949 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4950 break; | |
4951 default: | |
4952 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4953 break; | |
4954 } | |
4955 /******** END REMOVE *******/ | |
4956 #endif | |
4957 /* Get the number of buffers still queued */ | |
4958 alGetSourcei( | |
4959 ALmixer_Channel_List[i].alsource, | |
4960 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4961 ); | |
4962 if((error = alGetError()) != AL_NO_ERROR) | |
4963 { | |
4964 fprintf(stderr, "51Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4965 alGetString(error)); |
0 | 4966 } |
4967 /* Get the number of buffers processed | |
4968 * so we know if we need to refill | |
4969 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4970 /* WARNING: It looks like Snow Leopard some times crashes on this call under x86_64 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4971 * typically when I suffer a lot of buffer underruns. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4972 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4973 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 4974 alGetSourcei( |
4975 ALmixer_Channel_List[i].alsource, | |
4976 AL_BUFFERS_PROCESSED, &buffers_processed | |
4977 ); | |
4978 if((error = alGetError()) != AL_NO_ERROR) | |
4979 { | |
4980 fprintf(stderr, "52Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4981 alGetString(error)); |
0 | 4982 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4983 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 4984 |
4985 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
4986 * I need this call to figure out which buffer OpenAL is currently playing. | |
4987 * It keeps returning an "Invalid Enum" error. | |
4988 * This is totally inane! It's a basic query. | |
4989 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
4990 * fix this behavior, even though all other distributions work fine with this. | |
4991 * The only workaround for this is for | |
4992 * a significant rewrite of my code which requires me to | |
4993 * duplicate the OpenAL queued buffers state with my own | |
4994 * code and try to derive what the current playing buffer is by indirect observation of | |
4995 * looking at buffers_processed. But of course this has a ton of downsides since my | |
4996 * queries do not give me perfect timing of what OpenAL is actually doing and | |
4997 * the fact that some of the distributions seem to have buffer queuing problems | |
4998 * with their query results (CoreAudio). This also means a ton of extra code | |
4999 * on my side. The lack of support of a 1 line call has required me to | |
5000 * implement yet another entire state machine. <sigh> | |
5001 */ | |
5002 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5003 /* Get the id to the current buffer playing */ | |
5004 alGetSourcei( | |
5005 ALmixer_Channel_List[i].alsource, | |
5006 AL_BUFFER, ¤t_buffer_id | |
5007 ); | |
5008 if((error = alGetError()) != AL_NO_ERROR) | |
5009 { | |
5010 fprintf(stderr, "53Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5011 alGetString(error)); |
0 | 5012 } |
5013 | |
5014 /* Before the hard stuff, check to see if the | |
5015 * current queued AL buffer has changed. | |
5016 * If it has, we should launch a data callback if | |
5017 * necessary | |
5018 */ | |
5019 if( ((ALuint)current_buffer_id) != | |
5020 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5021 { | |
5022 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5023 = (ALuint)current_buffer_id; | |
5024 | |
5025 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5026 } | |
5027 #else | |
5028 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5029 * And if one of the two are true: | |
5030 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5031 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5032 * a buffer underrun) | |
5033 */ | |
5034 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5035 && ( | |
5036 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5037 ) | |
5038 ) | |
5039 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5040 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5041 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5042 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5043 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5044 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5045 ALint buffers_unplayed_int = buffers_still_queued - buffers_processed; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5046 ALuint unplayed_buffers; |
1 | 5047 if(buffers_unplayed_int < 0) |
5048 { | |
5049 unplayed_buffers = 0; | |
5050 } | |
5051 else | |
5052 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5053 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5054 } |
0 | 5055 /* |
5056 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5057 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5058 */ | |
5059 /* We can't make any determinations solely based on the number of buffers_processed | |
5060 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5061 * buffers became processed in one loop, the following loop, we would have | |
5062 * at least that_many-1 buffers_processed (plus possible new processed). | |
5063 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5064 * because we would not actually reflect the current playing buffer. | |
5065 * So the solution seems to be to make sure our queue is the same size | |
5066 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5067 * as the current playing buffer. | |
5068 */ | |
5069 /* Also, we have a corner case. When we first start playing or if we have | |
5070 * a buffer underrun, we have not done a data callback. | |
5071 * In this case, we need to see if there is any new data in our queue | |
5072 * and if so, launch that data callback. | |
5073 */ | |
5074 /* Warning, this code risks the possibility of no data callback being fired if | |
5075 * the system is really late (or skipped buffers). | |
5076 */ | |
5077 | |
5078 /* First, let's syncronize our queue with the OpenAL queue */ | |
5079 #if 0 | |
5080 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5081 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5082 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5083 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5084 for(k=0; k<buffers_processed; k++) |
0 | 5085 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5086 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5087 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5088 if(0 == queue_ret_flag) |
0 | 5089 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5090 fprintf(stderr, "53 Error popping queue\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5091 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5092 } |
0 | 5093 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5094 /* We have several possibilities we need to handle: | |
5095 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5096 * 2) We were out of sync and need to do a new data callback on the new head. | |
5097 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5098 * fall in this block of code. (Don't do anything.) | |
5099 */ | |
5100 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5101 { | |
5102 if(my_queue_size > 0) | |
5103 { | |
5104 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5105 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5106 if(0 == current_buffer_id) | |
5107 { | |
5108 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5109 } | |
5110 /* | |
5111 else | |
5112 { | |
5113 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5114 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5115 } | |
5116 */ | |
5117 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5118 = (ALuint)current_buffer_id; | |
5119 | |
5120 #if 0 | |
5121 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5122 { | |
5123 ALuint real_id; | |
5124 alGetSourcei( | |
5125 ALmixer_Channel_List[i].alsource, | |
5126 AL_BUFFER, &real_id | |
5127 ); | |
5128 alGetError(); | |
5129 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5130 } | |
5131 #endif | |
5132 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5133 } | |
5134 else | |
5135 { | |
1 | 5136 /* |
0 | 5137 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5138 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5139 */ | |
0 | 5140 /* In this case, we might either be in an underrun or finished with playback */ |
5141 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5142 } | |
5143 } | |
5144 } | |
5145 #endif | |
5146 | |
5147 | |
5148 | |
5149 /* Just a test - remove | |
5150 if( ALmixer_Channel_List[i].loops > 0) | |
5151 { | |
5152 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5153 ALmixer_Channel_List[i].loops); | |
5154 } | |
5155 */ | |
5156 #if 0 | |
5157 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5158 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5159 #endif | |
5160 /* We've used up a buffer so we need to unqueue and replace */ | |
5161 /* Okay, it gets more complicated here: | |
5162 * We need to Queue more data | |
5163 * if buffers_processed > 0 or | |
5164 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5165 * but we don't do this if at EOF, | |
5166 * except when there is looping | |
5167 */ | |
5168 /* For this to work, we must rely on EVERYTHING | |
5169 * else to unset the EOF if there is looping. | |
5170 * Remember, even Play() must do this | |
5171 */ | |
5172 | |
5173 /* If not EOF, then we are still playing. | |
5174 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5175 * or buffers_process > 0 | |
5176 * in which case we queue up. | |
5177 * We also might find no buffers we need to fill, | |
5178 * in which case we just keep going | |
5179 */ | |
5180 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5181 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5182 ALuint bytes_returned; |
0 | 5183 /* We have a priority. We first must assign |
5184 * unused buffers in reserve. If there is nothing | |
5185 * left, then we may unqueue buffers. We can't | |
5186 * do it the other way around because we will | |
5187 * lose the pointer to the unqueued buffer | |
5188 */ | |
5189 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5190 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5191 { | |
1 | 5192 #if 0 |
0 | 5193 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5194 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5195 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5196 #endif |
0 | 5197 /* Going to add an unused packet. |
5198 * Grab next packet */ | |
5199 bytes_returned = GetMoreData( | |
5200 ALmixer_Channel_List[i].almixer_data, | |
5201 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5202 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5203 ); | |
5204 } | |
5205 /* For processed > 0 */ | |
5206 else if(buffers_processed > 0) | |
5207 { | |
5208 /* Unqueue only 1 buffer for now. | |
5209 * If there are more than one, | |
5210 * let the next Update pass deal with it | |
5211 * so we don't stall the program for too long. | |
5212 */ | |
5213 #if 0 | |
5214 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5215 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5216 fprintf(stderr, "Unqueuing a buffer\n"); | |
5217 #endif | |
5218 alSourceUnqueueBuffers( | |
5219 ALmixer_Channel_List[i].alsource, | |
5220 1, &unqueued_buffer_id | |
5221 ); | |
5222 if((error = alGetError()) != AL_NO_ERROR) | |
5223 { | |
5224 fprintf(stderr, "Error with unqueue: %s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5225 alGetString(error)); |
0 | 5226 ALmixer_SetError("Unqueue buffer failed: %s", |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5227 alGetString(error) ); |
0 | 5228 error_flag--; |
5229 } | |
5230 /* | |
5231 fprintf(stderr, "Right after unqueue..."); | |
5232 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5233 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5234 */ | |
5235 /* Grab unqueued packet */ | |
5236 bytes_returned = GetMoreData( | |
5237 ALmixer_Channel_List[i].almixer_data, | |
5238 unqueued_buffer_id); | |
5239 } | |
5240 /* We are still streaming, but currently | |
5241 * don't need to fill any buffers */ | |
5242 else | |
5243 { | |
5244 /* Might want to check state */ | |
5245 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5246 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5247 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5248 */ |
1 | 5249 #if 1 |
5250 /* Try not refetching the state here because I'm getting a duplicate | |
5251 buffer playback (hiccup) */ | |
0 | 5252 alGetSourcei( |
5253 ALmixer_Channel_List[i].alsource, | |
5254 AL_SOURCE_STATE, &state | |
5255 ); | |
1 | 5256 if((error = alGetError()) != AL_NO_ERROR) |
5257 { | |
5258 fprintf(stderr, "54bTesting error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5259 alGetString(error)); |
1 | 5260 } |
5261 /* Get the number of buffers processed | |
5262 */ | |
5263 alGetSourcei( | |
5264 ALmixer_Channel_List[i].alsource, | |
5265 AL_BUFFERS_PROCESSED, | |
5266 &buffers_processed | |
5267 ); | |
5268 if((error = alGetError()) != AL_NO_ERROR) | |
5269 { | |
5270 fprintf(stderr, "54cError, Can't get buffers_processed: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5271 alGetString(error)); |
1 | 5272 } |
5273 #endif | |
0 | 5274 if(AL_STOPPED == state) |
5275 { | |
5276 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5277 |
5278 /* Okay, here's another lately discovered problem: | |
5279 * I can't find it in the spec, but for at least some of the | |
5280 * implementations, if I call play on a stopped source that | |
5281 * has processed buffers, all those buffers get marked as unprocessed | |
5282 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5283 * processed, on resume, the earlier 24 buffers will get replayed, | |
5284 * causing a "hiccup" like sound in the playback. | |
5285 * To avoid this, I must unqueue all processed buffers before | |
5286 * calling play. But to complicate things, I need to worry about resyncing | |
5287 * the circular queue with this since I designed this thing | |
5288 * with some correlation between the two. However, I might | |
5289 * have already handled this, so I will try writing this code without | |
5290 * syncing for now. | |
5291 * There is currently an assumption that a buffer | |
5292 * was queued above so I actually have something | |
5293 * to play. | |
5294 */ | |
5295 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5296 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5297 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5298 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5299 #endif |
1 | 5300 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5301 { | |
5302 alSourceUnqueueBuffers( | |
5303 ALmixer_Channel_List[i].alsource, | |
5304 1, &unqueued_buffer_id | |
5305 ); | |
5306 if((error = alGetError()) != AL_NO_ERROR) | |
5307 { | |
5308 fprintf(stderr, "55aTesting error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5309 alGetString(error)); |
1 | 5310 error_flag--; |
5311 } | |
5312 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5313 #if 0 |
1 | 5314 fprintf(stderr, "After unqueue clear...:\n"); |
5315 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5316 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5317 /* My assertion: We are STOPPED but not EOF. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5318 * This means we have a buffer underrun. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5319 * We just cleared out the unqueued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5320 * So we need to reset the mixer_data to reflect we have |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5321 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5322 * We need to GetMoreData and then queue up the data. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5324 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5325 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5326 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5327 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5328 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5329 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5330 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5331 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5332 |
1 | 5333 if((error = alGetError()) != AL_NO_ERROR) |
5334 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5335 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_queued: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5336 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5337 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5338 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5339 fprintf(stderr, "buffer underrun: buffers_queued:%d\n", buffers_queued); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5340 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5341 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5342 /* Reset the number of buffers in use to 0 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5343 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5344 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5345 /* Get more data and put it in the first buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5346 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5347 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5348 ALmixer_Channel_List[i].almixer_data->buffer[0] |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5349 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5350 /* NOTE: We might want to look for EOF and handle it here. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5351 * Currently, I just let the next loop handle it which seems to be working. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5352 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5353 if(bytes_returned > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5354 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5355 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5356 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5357 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5358 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5359 &ALmixer_Channel_List[i].almixer_data->buffer[0] |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5360 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5361 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5362 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5363 fprintf(stderr, "56e alSourceQueueBuffers error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5364 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5365 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5366 /* Increment the number of buffers in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5367 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5368 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5369 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5370 /* We need to empty and update the circular buffer queue if it is in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5371 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5372 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5373 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5374 CircularQueueUnsignedInt_Clear(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5375 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5376 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5377 ALmixer_Channel_List[i].almixer_data->buffer[0] |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5378 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5379 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5380 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5381 fprintf(stderr, "56fSerious internal error: CircularQueue could not push into queue.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5382 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5383 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5384 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5385 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5386 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5387 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5388 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5389 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5390 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5391 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5393 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5394 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5395 } |
1 | 5396 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5397 |
0 | 5398 } |
5399 /* Let's escape to the next loop. | |
5400 * All code below this point is for queuing up | |
5401 */ | |
5402 /* | |
1 | 5403 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5404 */ | |
0 | 5405 continue; |
5406 } | |
5407 /* We now know we have to fill an available | |
5408 * buffer. | |
5409 */ | |
5410 | |
5411 /* In the previous branch, we just grabbed more data. | |
5412 * Let's check it to make sure it's okay, | |
5413 * and then queue it up | |
5414 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5415 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5416 #if 0 |
5417 if(-1 == bytes_returned) | |
5418 { | |
5419 /* Problem occurred...not sure what to do */ | |
5420 /* Go to next loop? */ | |
5421 error_flag--; | |
5422 /* Set the eof flag to force a quit so | |
5423 * we don't get stuck in an infinite loop | |
5424 */ | |
5425 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5426 continue; | |
5427 } | |
5428 #endif | |
5429 /* This is a special case where we've run | |
5430 * out of data. We should check for loops | |
5431 * and get more data. If there is no loop, | |
5432 * then do nothing and wait for future | |
5433 * update passes to handle the EOF. | |
5434 * The advantage of handling the loop here | |
5435 * instead of waiting for play to stop is | |
5436 * that we should be able to keep the buffer | |
5437 * filled. | |
5438 */ | |
5439 #if 0 | |
5440 else if(0 == bytes_returned) | |
5441 #endif | |
5442 if(0 == bytes_returned) | |
5443 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5444 /* |
0 | 5445 fprintf(stderr, "We got 0 bytes from reading. Checking for loops\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5446 */ |
0 | 5447 /* Check for loops */ |
5448 if( ALmixer_Channel_List[i].loops != 0 ) | |
5449 { | |
5450 /* We have to loop, so rewind | |
5451 * and fetch more data | |
5452 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5453 /* |
0 | 5454 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5455 */ |
0 | 5456 if(0 == Sound_Rewind( |
5457 ALmixer_Channel_List[i].almixer_data->sample)) | |
5458 { | |
5459 fprintf(stderr, "Rewinding failed\n"); | |
5460 ALmixer_SetError( Sound_GetError() ); | |
5461 ALmixer_Channel_List[i].loops = 0; | |
5462 error_flag--; | |
5463 /* We'll continue on because we do have some valid data */ | |
5464 continue; | |
5465 } | |
5466 /* Remember to reset the data->eof flag */ | |
5467 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5468 if(ALmixer_Channel_List[i].loops > 0) | |
5469 { | |
5470 ALmixer_Channel_List[i].loops--; | |
5471 } | |
5472 /* Try grabbing another packet now. | |
5473 * Since we may have already unqueued a | |
5474 * buffer, we don't want to lose it. | |
5475 */ | |
5476 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5477 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5478 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5479 /* |
0 | 5480 fprintf(stderr, "We got %d bytes from reading loop. Filling unused packet\n", bytes_returned); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5481 */ |
0 | 5482 /* Grab next packet */ |
5483 bytes_returned = GetMoreData( | |
5484 ALmixer_Channel_List[i].almixer_data, | |
5485 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5486 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5487 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5488 /* |
0 | 5489 fprintf(stderr, "We reread %d bytes into unused packet\n", bytes_returned); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5490 */ |
0 | 5491 } |
5492 /* Refilling unqueued packet */ | |
5493 else | |
5494 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5495 /* |
0 | 5496 fprintf(stderr, "We got %d bytes from reading loop. Filling unqueued packet\n", bytes_returned); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5497 */ |
0 | 5498 /* Grab next packet */ |
5499 bytes_returned = GetMoreData( | |
5500 ALmixer_Channel_List[i].almixer_data, | |
5501 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5502 /* |
0 | 5503 fprintf(stderr, "We reread %d bytes into unqueued packet\n", bytes_returned); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5504 */ |
0 | 5505 } |
5506 /* Another error check */ | |
5507 /* | |
5508 if(bytes_returned <= 0) | |
5509 */ | |
5510 if(0 == bytes_returned) | |
5511 { | |
5512 fprintf(stderr, "??????????ERROR\n"); | |
5513 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5514 /* Problem occurred...not sure what to do */ | |
5515 /* Go to next loop? */ | |
5516 error_flag--; | |
5517 /* Set the eof flag to force a quit so | |
5518 * we don't get stuck in an infinite loop | |
5519 */ | |
5520 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5521 continue; | |
5522 } | |
5523 /* We made it to the end. We still need | |
5524 * to BufferData, so let this branch | |
5525 * fall into the next piece of | |
5526 * code below which will handle that | |
5527 */ | |
5528 | |
5529 | |
5530 } /* END loop check */ | |
5531 else | |
5532 { | |
5533 /* No more loops to do. | |
5534 * EOF flag should be set. | |
5535 * Just go to next loop and | |
5536 * let things be handled correctly | |
5537 * in future update calls | |
5538 */ | |
1 | 5539 /* |
0 | 5540 fprintf(stderr, "SHOULD BE EOF\n"); |
5541 | |
5542 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5543 */ |
0 | 5544 continue; |
5545 } | |
5546 } /* END if bytes_returned == 0 */ | |
5547 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5548 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5549 */ | |
5550 /* Fall here */ | |
5551 /* Everything is normal. We aren't | |
5552 * at an EOF, but need to simply | |
5553 * queue more data. The data is already checked for good, | |
5554 * so queue it up */ | |
5555 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5556 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5557 { | |
5558 /* Keep count of how many buffers we have | |
5559 * to queue so we can return the value | |
5560 */ | |
5561 retval++; | |
1 | 5562 /* |
0 | 5563 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5564 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5565 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5566 */ |
0 | 5567 alSourceQueueBuffers( |
5568 ALmixer_Channel_List[i].alsource, | |
5569 1, | |
5570 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5571 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5572 ); | |
5573 if((error = alGetError()) != AL_NO_ERROR) | |
5574 { | |
5575 fprintf(stderr, "56Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5576 alGetString(error)); |
0 | 5577 } |
5578 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5579 * which buffer to show during callbacks (for things like | |
5580 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5581 * data structure. This code will be called only if | |
5582 * "access_data" was set, indicated by whether the queue is NULL. | |
5583 */ | |
5584 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5585 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5586 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5587 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5588 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5589 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5590 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5591 ); | |
5592 if(0 == queue_ret_flag) | |
5593 { | |
5594 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5595 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5596 } | |
5597 /* | |
5598 else | |
5599 { | |
5600 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5601 } | |
5602 */ | |
5603 } | |
5604 } | |
5605 /* for processed > 0 */ | |
5606 else | |
5607 { | |
5608 /* Keep count of how many buffers we have | |
5609 * to queue so we can return the value | |
5610 */ | |
5611 retval++; | |
5612 /* | |
5613 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5614 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5615 */ | |
5616 alSourceQueueBuffers( | |
5617 ALmixer_Channel_List[i].alsource, | |
5618 1, &unqueued_buffer_id); | |
5619 if((error = alGetError()) != AL_NO_ERROR) | |
5620 { | |
5621 ALmixer_SetError("Could not QueueBuffer: %s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5622 alGetString(error) ); |
0 | 5623 error_flag--; |
5624 continue; | |
5625 } | |
5626 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5627 * which buffer to show during callbacks (for things like | |
5628 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5629 * data structure. This code will be called only if | |
5630 * "access_data" was set, indicated by whether the queue is NULL. | |
5631 */ | |
5632 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5633 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5634 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5635 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5636 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5637 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5638 unqueued_buffer_id | |
5639 ); | |
5640 if(0 == queue_ret_flag) | |
5641 { | |
5642 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5643 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5644 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5645 #if 0 |
0 | 5646 else |
5647 { | |
5648 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5649 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5650 #endif |
0 | 5651 } |
5652 } | |
5653 /* If we used an available buffer queue, | |
5654 * then we need to update the number of them in use | |
5655 */ | |
5656 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5657 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5658 { | |
5659 /* Increment the number of buffers in use */ | |
5660 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5661 } | |
5662 /* Might want to check state */ | |
5663 /* In case the playback stopped, | |
5664 * we need to resume */ | |
1 | 5665 #if 1 |
5666 /* Try not refetching the state here because I'm getting a duplicate | |
5667 buffer playback (hiccup) */ | |
0 | 5668 alGetSourcei( |
5669 ALmixer_Channel_List[i].alsource, | |
5670 AL_SOURCE_STATE, &state | |
5671 ); | |
1 | 5672 if((error = alGetError()) != AL_NO_ERROR) |
5673 { | |
5674 fprintf(stderr, "57bTesting error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5675 alGetString(error)); |
1 | 5676 } |
5677 /* Get the number of buffers processed | |
5678 */ | |
5679 alGetSourcei( | |
5680 ALmixer_Channel_List[i].alsource, | |
5681 AL_BUFFERS_PROCESSED, | |
5682 &buffers_processed | |
5683 ); | |
5684 if((error = alGetError()) != AL_NO_ERROR) | |
5685 { | |
5686 fprintf(stderr, "57cError, Can't get buffers_processed: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5687 alGetString(error)); |
1 | 5688 } |
5689 #endif | |
0 | 5690 if(AL_STOPPED == state) |
5691 { | |
1 | 5692 /* |
0 | 5693 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5694 */ |
5695 /* Okay, here's another lately discovered problem: | |
5696 * I can't find it in the spec, but for at least some of the | |
5697 * implementations, if I call play on a stopped source that | |
5698 * has processed buffers, all those buffers get marked as unprocessed | |
5699 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5700 * processed, on resume, the earlier 24 buffers will get replayed, | |
5701 * causing a "hiccup" like sound in the playback. | |
5702 * To avoid this, I must unqueue all processed buffers before | |
5703 * calling play. But to complicate things, I need to worry about resyncing | |
5704 * the circular queue with this since I designed this thing | |
5705 * with some correlation between the two. However, I might | |
5706 * have already handled this, so I will try writing this code without | |
5707 * syncing for now. | |
5708 * There is currently an assumption that a buffer | |
5709 * was queued above so I actually have something | |
5710 * to play. | |
5711 */ | |
5712 ALint temp_count; | |
5713 /* | |
5714 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5715 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5716 */ | |
5717 | |
5718 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5719 { | |
5720 alSourceUnqueueBuffers( | |
5721 ALmixer_Channel_List[i].alsource, | |
5722 1, &unqueued_buffer_id | |
5723 ); | |
5724 if((error = alGetError()) != AL_NO_ERROR) | |
5725 { | |
5726 fprintf(stderr, "58aTesting error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5727 alGetString(error)); |
1 | 5728 error_flag--; |
5729 } | |
5730 } | |
5731 /* | |
5732 fprintf(stderr, "After unqueue clear...:\n"); | |
5733 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5734 */ | |
5735 | |
5736 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5737 if((error = alGetError()) != AL_NO_ERROR) | |
5738 { | |
5739 fprintf(stderr, "55Tbesting 8rror: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5740 alGetString(error)); |
1 | 5741 } |
0 | 5742 } |
5743 continue; | |
5744 } /* END if( ! eof) */ | |
5745 /* We have hit EOF in the SDL_Sound sample and there | |
5746 * are no more loops. However, there may still be | |
5747 * buffers in the OpenAL queue which still need to | |
5748 * be played out. The following body of code will | |
5749 * determine if play is still happening or | |
5750 * initiate the stop/cleanup sequenece. | |
5751 */ | |
5752 else | |
5753 { | |
5754 /* Let's continue to remove the used up | |
5755 * buffers as they come in. */ | |
5756 if(buffers_processed > 0) | |
5757 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5758 ALint temp_count; |
0 | 5759 /* Do as a for-loop because I don't want |
5760 * to have to create an array for the | |
5761 * unqueued_buffer_id's | |
5762 */ | |
5763 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5764 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5765 /* |
0 | 5766 fprintf(stderr, "unqueuing remainder, %d\n", temp_count); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5767 */ |
0 | 5768 alSourceUnqueueBuffers( |
5769 ALmixer_Channel_List[i].alsource, | |
5770 1, &unqueued_buffer_id | |
5771 ); | |
5772 if((error = alGetError()) != AL_NO_ERROR) | |
5773 { | |
5774 fprintf(stderr, "59Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5775 alGetString(error)); |
0 | 5776 } |
5777 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5778 /* |
0 | 5779 fprintf(stderr, "done unqueuing remainder for this loop, %d\n", temp_count); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5780 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5781 |
0 | 5782 /* Need to update counts since we removed everything. |
5783 * If we don't update the counts here, we end up in the | |
5784 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
5785 */ | |
5786 alGetSourcei( | |
5787 ALmixer_Channel_List[i].alsource, | |
5788 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5789 ); | |
5790 if((error = alGetError()) != AL_NO_ERROR) | |
5791 { | |
5792 fprintf(stderr, "5100Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5793 alGetString(error)); |
0 | 5794 } |
5795 /* Get the number of buffers processed | |
5796 * so we know if we need to refill | |
5797 */ | |
5798 alGetSourcei( | |
5799 ALmixer_Channel_List[i].alsource, | |
5800 AL_BUFFERS_PROCESSED, &buffers_processed | |
5801 ); | |
5802 if((error = alGetError()) != AL_NO_ERROR) | |
5803 { | |
5804 fprintf(stderr, "5200Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5805 alGetString(error)); |
0 | 5806 } |
5807 } | |
5808 | |
5809 | |
5810 /* Else if buffers_processed == 0 | |
5811 * and buffers_still_queued == 0. | |
5812 * then we check to see if the source | |
5813 * is still playing. Quit if stopped | |
5814 * We shouldn't need to worry about | |
5815 * looping because that should have | |
5816 * been handled above. | |
5817 */ | |
5818 if(0 == buffers_still_queued) | |
5819 { | |
5820 /* Make sure playback has stopped before | |
5821 * we shutdown. | |
5822 */ | |
5823 alGetSourcei( | |
5824 ALmixer_Channel_List[i].alsource, | |
5825 AL_SOURCE_STATE, &state | |
5826 ); | |
5827 if((error = alGetError()) != AL_NO_ERROR) | |
5828 { | |
5829 fprintf(stderr, "60Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5830 alGetString(error)); |
0 | 5831 } |
5832 if(AL_STOPPED == state) | |
5833 { | |
5834 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
5835 /* Playback has ended. | |
5836 * Loop if necessary, or launch callback | |
5837 * and clear channel (or clear channel and | |
5838 * then launch callback?) | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5839 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 5840 */ |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5841 |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5842 /* Launch callback */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5843 Invoke_Channel_Done_Callback(i, AL_TRUE); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5844 |
0 | 5845 Clean_Channel(i); |
5846 /* Subtract counter */ | |
5847 Is_Playing_global--; | |
5848 | |
5849 | |
5850 /* We're done for this loop. | |
5851 * Go to next channel | |
5852 */ | |
5853 continue; | |
5854 } | |
5855 } /* End end-playback */ | |
5856 else | |
5857 { | |
5858 /* Need to run out buffer */ | |
5859 #if 1 | |
5860 /* Might want to check state */ | |
5861 /* In case the playback stopped, | |
5862 * we need to resume */ | |
5863 alGetSourcei( | |
5864 ALmixer_Channel_List[i].alsource, | |
5865 AL_SOURCE_STATE, &state | |
5866 ); | |
5867 if((error = alGetError()) != AL_NO_ERROR) | |
5868 { | |
5869 fprintf(stderr, "61Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5870 alGetString(error)); |
0 | 5871 } |
5872 if(AL_STOPPED == state) | |
5873 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5874 /* |
0 | 5875 fprintf(stderr, "Shouldn't be here. %d Buffers still in queue, but play stopped. This might be correct though because race conditions could have caused the STOP to happen right after our other tests...Checking queue status...\n", buffers_still_queued); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5876 */ |
1 | 5877 /* |
0 | 5878 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5879 */ |
0 | 5880 /* Rather than force unqueuing the buffer, let's see if |
5881 * setting the buffer to none works (the OpenAL 1.0 | |
5882 * Reference Annotation suggests this should work). | |
5883 */ | |
5884 alSourcei(ALmixer_Channel_List[i].alsource, | |
5885 AL_BUFFER, AL_NONE); | |
5886 /* | |
5887 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5888 */ | |
5889 /* This doesn't work because in some cases, I think | |
5890 * it causes the sound to be replayed | |
5891 */ | |
5892 /* | |
5893 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
5894 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5895 */ | |
5896 } | |
5897 #endif | |
5898 } /* End trap section */ | |
5899 } /* End POST-EOF use-up buffer section */ | |
5900 } /* END Streamed section */ | |
5901 } /* END channel in use */ | |
5902 } /* END for-loop for each channel */ | |
5903 | |
5904 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
5905 alcProcessContext(alcGetCurrentContext()); | |
5906 if((error = alGetError()) != AL_NO_ERROR) | |
5907 { | |
5908 fprintf(stderr, "62Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5909 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5910 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5911 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5912 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5913 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5914 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5915 #endif |
0 | 5916 /* Return the number of errors */ |
5917 if(error_flag < 0) | |
5918 { | |
5919 return error_flag; | |
5920 } | |
5921 /* Return the number of buffers that were queued */ | |
5922 return retval; | |
5923 } | |
5924 | |
5925 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
5926 /* This is only here so we can call SDL_OpenAudio() */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5927 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 5928 { |
5929 } | |
5930 #endif | |
5931 | |
5932 | |
5933 | |
5934 | |
5935 #ifdef ENABLE_ALMIXER_THREADS | |
5936 /* We might need threads. We | |
5937 * must constantly poll OpenAL to find out | |
5938 * if sound is being streamed, if play has | |
5939 * ended, etc. Without threads, this must | |
5940 * be explicitly done by the user. | |
5941 * We could try to do it for them if we | |
5942 * finish the threads. | |
5943 */ | |
5944 | |
5945 static int Stream_Data_Thread_Callback(void* data) | |
5946 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5947 ALint retval; |
0 | 5948 |
5949 while(ALmixer_Initialized) | |
5950 { | |
5951 retval = Update_ALmixer(data); | |
5952 /* 0 means that nothing needed updating and | |
5953 * the function returned quickly | |
5954 */ | |
5955 if(0 == retval) | |
5956 { | |
5957 /* Let's be nice and make the thread sleep since | |
5958 * little work was done in update | |
5959 */ | |
5960 /* Make sure times are multiples of 10 | |
5961 * for optimal performance and accuracy in Linux | |
5962 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5963 ALmixer_Delay(10); |
0 | 5964 } |
5965 else | |
5966 { | |
5967 /* should I also be sleeping/yielding here? */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5968 ALmixer_Delay(0); |
0 | 5969 } |
5970 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5971 /* |
0 | 5972 fprintf(stderr, "Thread is closing\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5973 */ |
0 | 5974 return 0; |
5975 } | |
5976 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
5977 | |
5978 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5979 /* SDL/SDL_mixer returns -1 on error and 0 on success. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5980 * I actually prefer false/true conventions (SDL_Sound/OpenAL/GL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5981 * so SDL_mixer porting people beware. |
0 | 5982 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
5983 * means the SDL audio system will be disabled. It will not | |
5984 * be restored (in case SDL is not actually being used) so | |
5985 * the user will need to restart it if they need it after | |
5986 * OpenAL shuts down. | |
5987 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5988 ALboolean ALmixer_Init(ALuint frequency, ALint num_sources, ALuint refresh) |
0 | 5989 { |
5990 ALCdevice* dev; | |
5991 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5992 ALint i; |
0 | 5993 ALenum error; |
5994 ALuint* source; | |
5995 | |
5996 #ifdef USING_LOKI_AL_DIST | |
5997 /* The Loki dist requires that I set both the | |
5998 * device and context frequency values separately | |
5999 */ | |
6000 /* Hope this won't overflow */ | |
6001 char device_string[256]; | |
6002 #endif | |
6003 | |
6004 /* (Venting frustration) Damn it! Nobody bothered | |
6005 * documenting how you're supposed to use an attribute | |
6006 * list. In fact, the not even the Loki test program | |
6007 * writers seem to know because they use it inconsistently. | |
6008 * For example, how do you terminate that attribute list? | |
6009 * The Loki test code does it 3 different ways. They | |
6010 * set the last value to 0, or they set it to ALC_INVALID, | |
6011 * or they set two final values: ALC_INVALID, 0 | |
6012 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6013 * but with Creative Labs ALC_INVALID is -1. | |
6014 * So something's going to break. Loki's source | |
6015 * code says to terminate with ALC_INVALID. But I | |
6016 * don't know if that's really true, or it happens | |
6017 * to be a coinicidence because it's defined to 0. | |
6018 * Creative provides no source code, so I can't look at how | |
6019 * they terminate it. | |
6020 * So this is really, really ticking me off... | |
6021 * For now, I'm going to use ALC_INVALID. | |
6022 * (Update...after further review of the API spec, | |
6023 * it seems that a NULL terminated string is the correct | |
6024 * termination value to use, so 0 it is.) | |
6025 */ | |
6026 #if 0 | |
6027 ALint attrlist[] = { | |
6028 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6029 /* Don't know anything about these values. | |
6030 * Trust defaults? */ | |
6031 /* Supposed to be the refresh rate in Hz. | |
6032 * I think 15-120 are supposed to be good | |
6033 * values. Though I haven't gotten any effect except | |
6034 * for one strange instance on a Mac. But it was | |
6035 * unrepeatable. | |
6036 */ | |
6037 #if 0 | |
6038 ALC_REFRESH, 15, | |
6039 #endif | |
6040 /* Sync requires a alcProcessContext() call | |
6041 * for every cycle. By default, this is | |
6042 * not used and the value is AL_FALSE | |
6043 * because it will probably perform | |
6044 * pretty badly for me. | |
6045 */ | |
6046 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6047 ALC_SYNC, AL_TRUE, | |
6048 #else | |
6049 ALC_SYNC, AL_FALSE, | |
6050 #endif | |
6051 /* Looking at the API spec, it implies | |
6052 * that the list be a NULL terminated string | |
6053 * so it's probably not safe to use ALC_INVALID | |
6054 */ | |
6055 /* | |
6056 ALC_INVALID }; | |
6057 */ | |
6058 '\0'}; | |
6059 #endif | |
6060 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6061 * However, if no value is specified, I don't | |
6062 * want it in the list so I can get the OpenAL defaults | |
6063 */ | |
6064 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6065 ALsizei current_attrlist_index = 0; |
0 | 6066 |
6067 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6068 /* More problems: I'm getting bit by endian/signedness issues on | |
6069 * different platforms. I can find the endianess easily enough, | |
6070 * but I don't know how to determine what the correct signedness | |
6071 * is (if such a thing exists). I do know that if I try using | |
6072 * unsigned on OSX with an originally signed sample, I get | |
6073 * distortion. However, I don't have any native unsigned samples | |
6074 * to test. But I'm assuming that the platform must be in the | |
6075 * correct signedness no matter what. | |
6076 * I can either assume everybody is signed, or I can try to | |
6077 * determine the value. If I try to determine the values, | |
6078 * I think my only ability to figure it out will be to open | |
6079 * SDL_Audio, and read what the obtained settings were. | |
6080 * Then shutdown everything. However, I don't even know how | |
6081 * reliable this is. | |
6082 * Update: I think I resolved the issues...forgot to update | |
6083 * these comments when it happened. I should check the revision control | |
6084 * log... Anyway, I think the issue was partly related to me not | |
6085 * doing something correctly with the AudioInfo or some kind | |
6086 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6087 * revision control, I think I might have assumed that SDL_Sound would | |
6088 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6089 * and had to fill one out myself. | |
6090 */ | |
6091 SDL_AudioSpec desired; | |
6092 SDL_AudioSpec obtained; | |
6093 #endif | |
6094 | |
6095 | |
6096 /* Make sure ALmixer isn't already initialized */ | |
6097 if(ALmixer_Initialized) | |
6098 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6099 return AL_FALSE; |
0 | 6100 } |
6101 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6102 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6103 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6104 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6105 /* Note: The pool may have been created on previous Init's */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6106 /* I leave the pool allocated allocated in case the user wants |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6107 * to read the pool in case of a failure (such as in this function). |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6108 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6109 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6110 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6111 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6112 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6113 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6114 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6115 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6116 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6117 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6118 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6119 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6120 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6121 fprintf(stderr, "tError Test1: %s\n", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6122 fprintf(stderr, "tError Test2: %s\n", ALmixer_GetError()); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6123 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6124 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6125 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6126 |
0 | 6127 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6128 /* |
0 | 6129 attrlist[0] = ALC_FREQUENCY; |
6130 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6131 attrlist[2] = ALC_SYNC; | |
6132 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6133 attrlist[3] = ALC_TRUE; | |
6134 #else | |
6135 attrlist[3] = ALC_FALSE; | |
6136 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6137 */ |
0 | 6138 /* Set frequency value if it is not 0 */ |
6139 if(0 != frequency) | |
6140 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6141 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6142 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6143 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6144 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6145 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6146 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6147 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6148 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6149 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6150 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6151 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6152 #endif |
0 | 6153 |
6154 /* If the user specifies a refresh value, | |
6155 * make room for it | |
6156 */ | |
6157 if(0 != refresh) | |
6158 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6159 attrlist[current_attrlist_index] = (ALint)ALC_REFRESH; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6160 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6161 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6162 current_attrlist_index++; |
0 | 6163 } |
6164 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6165 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6166 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6167 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6168 |
0 | 6169 /* Initialize SDL_Sound */ |
6170 if(! Sound_Init() ) | |
6171 { | |
6172 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6173 return AL_FALSE; |
0 | 6174 } |
6175 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6176 /* Here is the paranoid check that opens | |
6177 * SDL audio in an attempt to find the correct | |
6178 * system values. | |
6179 */ | |
6180 /* Doesn't have to be the actual value I think | |
6181 * (as long as it doesn't influence format, in | |
6182 * which case I'm probably screwed anyway because OpenAL | |
6183 * may easily choose to do something else). | |
6184 */ | |
6185 desired.freq = 44100; | |
6186 desired.channels = 2; | |
6187 desired.format = AUDIO_S16SYS; | |
6188 desired.callback = my_dummy_audio_callback; | |
6189 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6190 { | |
6191 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6192 /* Now to get really paranoid, we should probably | |
6193 * also assume that the 8bit format is also the | |
6194 * same sign type and set that value | |
6195 */ | |
6196 if(AUDIO_S16SYS == obtained.format) | |
6197 { | |
6198 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6199 } | |
6200 /* Should be AUDIO_U16SYS */ | |
6201 else | |
6202 { | |
6203 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6204 } | |
6205 SDL_CloseAudio(); | |
6206 } | |
6207 else | |
6208 { | |
6209 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6210 */ | |
6211 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6212 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6213 } | |
6214 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6215 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6216 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6217 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6218 * causes OpenAL and SMPEG to conflict. For some reason | |
6219 * if SDL_Init on audio is active, then all the SMPEG | |
6220 * decoded sound comes out silent. Unfortunately, | |
6221 * Sound_Init() invokes SDL_Init on audio. I'm | |
6222 * not sure why it actually needs it... | |
6223 * But we'll attempt to disable it here after the | |
6224 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6225 */ | |
6226 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6227 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6228 |
0 | 6229 /* I'm told NULL will call the default string |
6230 * and hopefully do the right thing for each platform | |
6231 */ | |
6232 /* | |
6233 dev = alcOpenDevice( NULL ); | |
6234 */ | |
6235 /* Now I'm told I need to set both the device and context | |
6236 * to have the same sampling rate, so I must pass a string | |
6237 * to OpenDevice(). I don't know how portable these strings are. | |
6238 * I don't even know if the format for strings is | |
6239 * compatible | |
6240 * From the testattrib.c in the Loki test section | |
6241 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6242 */ | |
6243 | |
6244 #ifdef USING_LOKI_AL_DIST | |
6245 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6246 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6247 #else | |
6248 dev = alcOpenDevice( NULL ); | |
6249 #endif | |
6250 if(NULL == dev) | |
6251 { | |
6252 ALmixer_SetError("Cannot open sound device for OpenAL"); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6253 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6254 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6255 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6256 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6257 /* The ALC_FREQUENCY attribute is ignored with Apple's implementation. */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6258 /* This extension must be called before the context is created. */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6259 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6260 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6261 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6262 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6263 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6264 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6265 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate()); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6266 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6267 #endif |
0 | 6268 |
6269 context = alcCreateContext(dev, attrlist); | |
6270 if(NULL == context) | |
6271 { | |
6272 ALmixer_SetError("Cannot create a context OpenAL"); | |
6273 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6274 return AL_FALSE; |
0 | 6275 } |
6276 | |
6277 | |
6278 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6279 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6280 * According to Garin Hiebert, this is actually an inconsistency | |
6281 * in the Loki version. The function should return a boolean. | |
6282 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6283 * alcGetError(). | |
6284 */ | |
6285 /* clear the error */ | |
6286 alcGetError(dev); | |
6287 alcMakeContextCurrent(context); | |
6288 | |
6289 error = alcGetError(dev); | |
6290 if( (ALC_NO_ERROR != error) ) | |
6291 { | |
6292 ALmixer_SetError("Could not MakeContextCurrent"); | |
6293 alcDestroyContext(context); | |
6294 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6295 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6296 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6297 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6298 /* It looks like OpenAL won't let us ask it what |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6299 * the set frequency is, so we need to save our |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6300 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6301 * Update: J. Valenzuela just updated the Loki |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6302 * dist (2003/01/02) to handle this. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6303 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6304 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6305 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6306 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6307 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6308 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6309 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6310 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6311 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6312 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6313 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6314 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6315 |
0 | 6316 #if 0 |
6317 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6318 if(alcGetCurrentContext() != context) | |
6319 { | |
6320 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6321 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6322 * I think this is a bug in the OpenAL implementation. | |
6323 */ | |
6324 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6325 | |
6326 fprintf(stderr, "Making context current\n"); | |
6327 #ifndef __APPLE__ | |
6328 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6329 #else | |
6330 if(!alcMakeContextCurrent(context)) | |
6331 #endif | |
6332 { | |
6333 ALmixer_SetError("Could not MakeContextCurrent"); | |
6334 alcDestroyContext(context); | |
6335 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6336 return AL_FALSE; |
0 | 6337 } |
6338 } | |
6339 #endif | |
6340 | |
6341 | |
6342 /* #endif */ | |
6343 /* Saw this in the README with the OS X OpenAL distribution. | |
6344 * It looked interesting and simple, so I thought I might | |
6345 * try it out. | |
6346 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6347 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6348 * Audio format, the audio data passed to the | |
6349 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6350 * usage by removing an audio data conversion | |
6351 * (per source) at render timem at the expense of a larger memory footprint. | |
6352 * | |
6353 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6354 * setting will be applied to all subsequent | |
6355 * calls to alBufferData(). | |
6356 */ | |
6357 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6358 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6359 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6360 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6361 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6362 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6363 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6364 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6365 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6366 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6367 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6368 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6369 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6370 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6371 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6372 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6373 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6374 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6375 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6376 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6377 |
0 | 6378 #endif |
6379 | |
6380 | |
6381 | |
6382 | |
6383 ALmixer_Initialized = 1; | |
6384 | |
6385 if(num_sources <= 0) | |
6386 { | |
6387 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6388 } | |
6389 else | |
6390 { | |
6391 Number_of_Channels_global = num_sources; | |
6392 } | |
6393 Number_of_Reserve_Channels_global = 0; | |
6394 Is_Playing_global = 0; | |
6395 /* Set to Null in case system quit and was reinitialized */ | |
6396 Channel_Done_Callback = NULL; | |
6397 Channel_Done_Callback_Userdata = NULL; | |
6398 Channel_Data_Callback = NULL; | |
1 | 6399 Channel_Data_Callback_Userdata = NULL; |
0 | 6400 |
6401 /* Allocate memory for the list of channels */ | |
6402 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6403 if(NULL == ALmixer_Channel_List) | |
6404 { | |
6405 ALmixer_SetError("Out of Memory for Channel List"); | |
6406 alcDestroyContext(context); | |
6407 alcCloseDevice(dev); | |
6408 ALmixer_Initialized = 0; | |
6409 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6410 return AL_FALSE; |
0 | 6411 } |
6412 | |
6413 /* Allocate memory for the list of sources that map to the channels */ | |
6414 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6415 if(NULL == Source_Map_List) | |
6416 { | |
6417 ALmixer_SetError("Out of Memory for Source Map List"); | |
6418 free(ALmixer_Channel_List); | |
6419 alcDestroyContext(context); | |
6420 alcCloseDevice(dev); | |
6421 ALmixer_Initialized = 0; | |
6422 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6423 return AL_FALSE; |
0 | 6424 } |
6425 | |
6426 /* Create array that will hold the sources */ | |
6427 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6428 if(NULL == source) | |
6429 { | |
6430 ALmixer_SetError("Out of Memory for sources"); | |
6431 free(Source_Map_List); | |
6432 free(ALmixer_Channel_List); | |
6433 alcDestroyContext(context); | |
6434 alcCloseDevice(dev); | |
6435 ALmixer_Initialized = 0; | |
6436 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6437 return AL_FALSE; |
0 | 6438 } |
6439 | |
6440 /* Clear the error state */ | |
6441 alGetError(); | |
6442 /* Generate the OpenAL sources */ | |
6443 alGenSources(Number_of_Channels_global, source); | |
6444 if( (error=alGetError()) != AL_NO_ERROR) | |
6445 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6446 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6447 free(ALmixer_Channel_List); |
6448 free(Source_Map_List); | |
6449 alcDestroyContext(context); | |
6450 alcCloseDevice(dev); | |
6451 ALmixer_Initialized = 0; | |
6452 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6453 return AL_FALSE; |
0 | 6454 } |
6455 | |
6456 /* Initialize each channel and associate one source to one channel */ | |
6457 for(i=0; i<Number_of_Channels_global; i++) | |
6458 { | |
6459 if(0 == source[i]) | |
6460 { | |
6461 fprintf(stderr, "SDL_ALmixer serious problem. This OpenAL implementation allowed 0 to be a valid source id which is in conflict with assumptions made in this library.\n"); | |
6462 } | |
6463 | |
6464 Init_Channel(i); | |
6465 /* Keeping the source allocation out of the Init function | |
6466 * in case I want to reuse the Init | |
6467 * function for resetting data | |
6468 */ | |
6469 ALmixer_Channel_List[i].alsource = source[i]; | |
6470 /* Now also keep a copy of the source to channel mapping | |
6471 * in case we need to look up a channel from the source | |
6472 * instead of a source from a channel | |
6473 */ | |
6474 Source_Map_List[i].source = source[i]; | |
6475 Source_Map_List[i].channel = i; | |
6476 /* Clean the channel because there are some things that need to | |
6477 * be done that can't happen until the source is set | |
6478 */ | |
6479 Clean_Channel(i); | |
6480 } | |
6481 | |
6482 /* The Source_Map_List must be sorted by source for binary searches | |
6483 */ | |
6484 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6485 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6486 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6487 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6488 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6489 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6490 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6491 if(NULL == s_simpleLock) |
0 | 6492 { |
6493 /* SDL sets the error message already? */ | |
6494 free(source); | |
6495 free(ALmixer_Channel_List); | |
6496 free(Source_Map_List); | |
6497 alcDestroyContext(context); | |
6498 alcCloseDevice(dev); | |
6499 ALmixer_Initialized = 0; | |
6500 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6501 return AL_FALSE; |
0 | 6502 } |
6503 | |
6504 | |
6505 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6506 if(NULL == Stream_Thread_global) | |
6507 { | |
6508 /* SDL sets the error message already? */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6509 SDL_DestroyMutex(s_simpleLock); |
0 | 6510 free(source); |
6511 free(ALmixer_Channel_List); | |
6512 free(Source_Map_List); | |
6513 alcDestroyContext(context); | |
6514 alcCloseDevice(dev); | |
6515 ALmixer_Initialized = 0; | |
6516 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6517 return AL_FALSE; |
0 | 6518 } |
6519 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6520 /* |
0 | 6521 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6522 */ |
0 | 6523 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6524 | |
6525 /* We don't need this array any more because all the sources | |
6526 * are connected to channels | |
6527 */ | |
6528 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6529 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6530 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6531 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6532 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6533 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6534 { |
6535 ALCdevice* dev; | |
6536 ALCcontext* context; | |
6537 ALCenum error; | |
6538 | |
6539 #ifdef USING_LOKI_AL_DIST | |
6540 /* The Loki dist requires that I set both the | |
6541 * device and context frequency values separately | |
6542 */ | |
6543 /* Hope this won't overflow */ | |
6544 char device_string[256]; | |
6545 #endif | |
6546 | |
6547 /* (Venting frustration) Damn it! Nobody bothered | |
6548 * documenting how you're supposed to use an attribute | |
6549 * list. In fact, the not even the Loki test program | |
6550 * writers seem to know because they use it inconsistently. | |
6551 * For example, how do you terminate that attribute list? | |
6552 * The Loki test code does it 3 different ways. They | |
6553 * set the last value to 0, or they set it to ALC_INVALID, | |
6554 * or they set two final values: ALC_INVALID, 0 | |
6555 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6556 * but with Creative Labs ALC_INVALID is -1. | |
6557 * So something's going to break. Loki's source | |
6558 * code says to terminate with ALC_INVALID. But I | |
6559 * don't know if that's really true, or it happens | |
6560 * to be a coinicidence because it's defined to 0. | |
6561 * Creative provides no source code, so I can't look at how | |
6562 * they terminate it. | |
6563 * So this is really, really ticking me off... | |
6564 * For now, I'm going to use ALC_INVALID. | |
6565 * (Update...after further review of the API spec, | |
6566 * it seems that a NULL terminated string is the correct | |
6567 * termination value to use, so 0 it is.) | |
6568 */ | |
6569 #if 0 | |
6570 ALint attrlist[] = { | |
6571 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6572 /* Don't know anything about these values. | |
6573 * Trust defaults? */ | |
6574 /* Supposed to be the refresh rate in Hz. | |
6575 * I think 15-120 are supposed to be good | |
6576 * values. Though I haven't gotten any effect except | |
6577 * for one strange instance on a Mac. But it was | |
6578 * unrepeatable. | |
6579 */ | |
6580 #if 0 | |
6581 ALC_REFRESH, 15, | |
6582 #endif | |
6583 /* Sync requires a alcProcessContext() call | |
6584 * for every cycle. By default, this is | |
6585 * not used and the value is AL_FALSE | |
6586 * because it will probably perform | |
6587 * pretty badly for me. | |
6588 */ | |
6589 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6590 ALC_SYNC, AL_TRUE, | |
6591 #else | |
6592 ALC_SYNC, AL_FALSE, | |
6593 #endif | |
6594 /* Looking at the API spec, it implies | |
6595 * that the list be a NULL terminated string | |
6596 * so it's probably not safe to use ALC_INVALID | |
6597 */ | |
6598 /* | |
6599 ALC_INVALID }; | |
6600 */ | |
6601 '\0'}; | |
6602 #endif | |
6603 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6604 * However, if no value is specified, I don't | |
6605 * want it in the list so I can get the OpenAL defaults | |
6606 */ | |
6607 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6608 ALsizei current_attrlist_index = 0; |
0 | 6609 |
6610 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6611 /* More problems: I'm getting bit by endian/signedness issues on | |
6612 * different platforms. I can find the endianess easily enough, | |
6613 * but I don't know how to determine what the correct signedness | |
6614 * is (if such a thing exists). I do know that if I try using | |
6615 * unsigned on OSX with an originally signed sample, I get | |
6616 * distortion. However, I don't have any native unsigned samples | |
6617 * to test. But I'm assuming that the platform must be in the | |
6618 * correct signedness no matter what. | |
6619 * I can either assume everybody is signed, or I can try to | |
6620 * determine the value. If I try to determine the values, | |
6621 * I think my only ability to figure it out will be to open | |
6622 * SDL_Audio, and read what the obtained settings were. | |
6623 * Then shutdown everything. However, I don't even know how | |
6624 * reliable this is. | |
6625 * Update: I think I resolved the issues...forgot to update | |
6626 * these comments when it happened. I should check the revision control | |
6627 * log... Anyway, I think the issue was partly related to me not | |
6628 * doing something correctly with the AudioInfo or some kind | |
6629 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6630 * revision control, I think I might have assumed that SDL_Sound would | |
6631 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6632 * and had to fill one out myself. | |
6633 */ | |
6634 SDL_AudioSpec desired; | |
6635 SDL_AudioSpec obtained; | |
6636 #endif | |
6637 | |
6638 | |
6639 | |
6640 | |
6641 /* Make sure ALmixer isn't already initialized */ | |
6642 if(ALmixer_Initialized) | |
6643 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6644 return AL_FALSE; |
0 | 6645 } |
6646 | |
6647 /* Set the defaults */ | |
6648 attrlist[0] = ALC_FREQUENCY; | |
6649 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6650 attrlist[2] = ALC_SYNC; | |
6651 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6652 attrlist[3] = ALC_TRUE; | |
6653 #else | |
6654 attrlist[3] = ALC_FALSE; | |
6655 #endif | |
6656 /* Set frequency value if it is not 0 */ | |
6657 if(0 != frequency) | |
6658 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6659 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6660 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6661 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6662 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6663 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6664 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6665 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6666 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6667 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6668 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6669 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6670 #endif |
0 | 6671 |
6672 /* If the user specifies a refresh value, | |
6673 * make room for it | |
6674 */ | |
6675 if(0 != refresh) | |
6676 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6677 attrlist[current_attrlist_index] = (ALint)ALC_REFRESH; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6678 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6679 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6680 current_attrlist_index++; |
0 | 6681 } |
6682 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6683 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6684 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6685 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6686 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6687 |
0 | 6688 /* Initialize SDL_Sound */ |
6689 if(! Sound_Init() ) | |
6690 { | |
6691 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6692 return AL_FALSE; |
0 | 6693 } |
6694 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6695 /* Here is the paranoid check that opens | |
6696 * SDL audio in an attempt to find the correct | |
6697 * system values. | |
6698 */ | |
6699 /* Doesn't have to be the actual value I think | |
6700 * (as long as it doesn't influence format, in | |
6701 * which case I'm probably screwed anyway because OpenAL | |
6702 * may easily choose to do something else). | |
6703 */ | |
6704 desired.freq = 44100; | |
6705 desired.channels = 2; | |
6706 desired.format = AUDIO_S16SYS; | |
6707 desired.callback = my_dummy_audio_callback; | |
6708 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6709 { | |
6710 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6711 /* Now to get really paranoid, we should probably | |
6712 * also assume that the 8bit format is also the | |
6713 * same sign type and set that value | |
6714 */ | |
6715 if(AUDIO_S16SYS == obtained.format) | |
6716 { | |
6717 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6718 } | |
6719 /* Should be AUDIO_U16SYS */ | |
6720 else | |
6721 { | |
6722 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6723 } | |
6724 SDL_CloseAudio(); | |
6725 } | |
6726 else | |
6727 { | |
6728 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6729 */ | |
6730 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6731 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6732 } | |
6733 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6734 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6735 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6736 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6737 * causes OpenAL and SMPEG to conflict. For some reason | |
6738 * if SDL_Init on audio is active, then all the SMPEG | |
6739 * decoded sound comes out silent. Unfortunately, | |
6740 * Sound_Init() invokes SDL_Init on audio. I'm | |
6741 * not sure why it actually needs it... | |
6742 * But we'll attempt to disable it here after the | |
6743 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6744 */ | |
6745 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6746 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6747 |
0 | 6748 /* I'm told NULL will call the default string |
6749 * and hopefully do the right thing for each platform | |
6750 */ | |
6751 /* | |
6752 dev = alcOpenDevice( NULL ); | |
6753 */ | |
6754 /* Now I'm told I need to set both the device and context | |
6755 * to have the same sampling rate, so I must pass a string | |
6756 * to OpenDevice(). I don't know how portable these strings are. | |
6757 * I don't even know if the format for strings is | |
6758 * compatible | |
6759 * From the testattrib.c in the Loki test section | |
6760 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6761 */ | |
6762 | |
6763 #ifdef USING_LOKI_AL_DIST | |
6764 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6765 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6766 #else | |
6767 dev = alcOpenDevice( NULL ); | |
6768 #endif | |
6769 if(NULL == dev) | |
6770 { | |
6771 ALmixer_SetError("Cannot open sound device for OpenAL"); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6772 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6773 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6774 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6775 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6776 /* The ALC_FREQUENCY attribute is ignored with Apple's implementation. */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6777 /* This extension must be called before the context is created. */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6778 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6779 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6780 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6781 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6782 ALmixer_Frequency_global = (ALuint)Internal_alcMacOSXGetMixerOutputRate(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6783 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6784 fprintf(stderr, "Internal_alcMacOSXMixerOutputRate is: %lf", Internal_alcMacOSXGetMixerOutputRate()); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6785 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6786 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6787 |
0 | 6788 |
6789 context = alcCreateContext(dev, attrlist); | |
6790 if(NULL == context) | |
6791 { | |
6792 ALmixer_SetError("Cannot create a context OpenAL"); | |
6793 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6794 return AL_FALSE; |
0 | 6795 } |
6796 | |
6797 | |
6798 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6799 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6800 * According to Garin Hiebert, this is actually an inconsistency | |
6801 * in the Loki version. The function should return a boolean. | |
6802 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6803 * alcGetError(). | |
6804 */ | |
6805 /* clear the error */ | |
6806 alcGetError(dev); | |
6807 alcMakeContextCurrent(context); | |
6808 | |
6809 error = alcGetError(dev); | |
6810 if( (ALC_NO_ERROR != error) ) | |
6811 { | |
6812 ALmixer_SetError("Could not MakeContextCurrent"); | |
6813 alcDestroyContext(context); | |
6814 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6815 return AL_FALSE; |
0 | 6816 } |
6817 | |
6818 | |
6819 #if 0 | |
6820 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6821 if(alcGetCurrentContext() != context) | |
6822 { | |
6823 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6824 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6825 * I think this is a bug in the OpenAL implementation. | |
6826 */ | |
6827 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6828 | |
6829 fprintf(stderr, "Making context current\n"); | |
6830 #ifndef __APPLE__ | |
6831 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6832 #else | |
6833 if(!alcMakeContextCurrent(context)) | |
6834 #endif | |
6835 { | |
6836 ALmixer_SetError("Could not MakeContextCurrent"); | |
6837 alcDestroyContext(context); | |
6838 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6839 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6840 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6841 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6842 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6843 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6844 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6845 /* It looks like OpenAL won't let us ask it what |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6846 * the set frequency is, so we need to save our |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6847 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6848 * Update: J. Valenzuela just updated the Loki |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6849 * dist (2003/01/02) to handle this. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6850 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6851 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6852 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6853 alcGetIntegerv(dev, ALC_FREQUENCY, 1, &ALmixer_Frequency_global); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6854 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6855 fprintf(stderr, "alcGetIntegerv ALC_FREQUENCY is: %d", ALmixer_Frequency_global); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6856 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6857 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6858 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6859 |
0 | 6860 |
6861 /* Saw this in the README with the OS X OpenAL distribution. | |
6862 * It looked interesting and simple, so I thought I might | |
6863 * try it out. | |
6864 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6865 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6866 * Audio format, the audio data passed to the | |
6867 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6868 * usage by removing an audio data conversion | |
6869 * (per source) at render timem at the expense of a larger memory footprint. | |
6870 * | |
6871 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6872 * setting will be applied to all subsequent | |
6873 * calls to alBufferData(). | |
6874 */ | |
6875 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6876 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6877 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6878 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6879 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6880 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6881 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6882 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6883 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6884 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6885 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6886 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6887 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6888 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6889 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6890 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6891 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6892 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6893 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6894 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6895 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6896 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6897 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6898 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6899 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6900 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6901 ALboolean ALmixer_InitMixer(ALint num_sources) |
0 | 6902 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6903 ALint i; |
0 | 6904 ALenum error; |
6905 ALuint* source; | |
6906 | |
6907 | |
6908 ALmixer_Initialized = 1; | |
6909 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6910 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6911 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6912 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6913 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6914 /* Note: The pool may have been created on previous Init's */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6915 /* I leave the pool allocated allocated in case the user wants |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6916 * to read the pool in case of a failure (such as in this function). |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6917 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6918 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6919 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6920 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6921 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6922 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6923 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6924 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6925 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6926 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6927 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6928 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6929 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6930 fprintf(stderr, "tError Test1: %s\n", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6931 fprintf(stderr, "tError Test2: %s\n", ALmixer_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6932 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6933 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6934 |
0 | 6935 if(num_sources <= 0) |
6936 { | |
6937 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6938 } | |
6939 else | |
6940 { | |
6941 Number_of_Channels_global = num_sources; | |
6942 } | |
6943 Number_of_Reserve_Channels_global = 0; | |
6944 Is_Playing_global = 0; | |
6945 /* Set to Null in case system quit and was reinitialized */ | |
6946 Channel_Done_Callback = NULL; | |
6947 Channel_Done_Callback_Userdata = NULL; | |
6948 Channel_Data_Callback = NULL; | |
1 | 6949 Channel_Data_Callback_Userdata = NULL; |
0 | 6950 |
6951 /* Allocate memory for the list of channels */ | |
6952 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6953 if(NULL == ALmixer_Channel_List) | |
6954 { | |
6955 ALmixer_SetError("Out of Memory for Channel List"); | |
6956 ALmixer_Initialized = 0; | |
6957 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6958 return AL_FALSE; |
0 | 6959 } |
6960 | |
6961 /* Allocate memory for the list of sources that map to the channels */ | |
6962 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6963 if(NULL == Source_Map_List) | |
6964 { | |
6965 ALmixer_SetError("Out of Memory for Source Map List"); | |
6966 free(ALmixer_Channel_List); | |
6967 ALmixer_Initialized = 0; | |
6968 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6969 return AL_FALSE; |
0 | 6970 } |
6971 | |
6972 /* Create array that will hold the sources */ | |
6973 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6974 if(NULL == source) | |
6975 { | |
6976 ALmixer_SetError("Out of Memory for sources"); | |
6977 free(Source_Map_List); | |
6978 free(ALmixer_Channel_List); | |
6979 ALmixer_Initialized = 0; | |
6980 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6981 return AL_FALSE; |
0 | 6982 } |
6983 | |
6984 /* Clear the error state */ | |
6985 alGetError(); | |
6986 /* Generate the OpenAL sources */ | |
6987 alGenSources(Number_of_Channels_global, source); | |
6988 if( (error=alGetError()) != AL_NO_ERROR) | |
6989 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6990 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6991 free(ALmixer_Channel_List); |
6992 free(Source_Map_List); | |
6993 ALmixer_Initialized = 0; | |
6994 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6995 return AL_FALSE; |
0 | 6996 } |
6997 | |
6998 /* Initialize each channel and associate one source to one channel */ | |
6999 for(i=0; i<Number_of_Channels_global; i++) | |
7000 { | |
7001 Init_Channel(i); | |
7002 /* Keeping the source allocation out of the Init function | |
7003 * in case I want to reuse the Init | |
7004 * function for resetting data | |
7005 */ | |
7006 ALmixer_Channel_List[i].alsource = source[i]; | |
7007 /* Now also keep a copy of the source to channel mapping | |
7008 * in case we need to look up a channel from the source | |
7009 * instead of a source from a channel | |
7010 */ | |
7011 Source_Map_List[i].source = source[i]; | |
7012 Source_Map_List[i].channel = i; | |
7013 /* Clean the channel because there are some things that need to | |
7014 * be done that can't happen until the source is set | |
7015 */ | |
7016 Clean_Channel(i); | |
7017 } | |
7018 | |
7019 /* The Source_Map_List must be sorted by source for binary searches | |
7020 */ | |
7021 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7022 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7023 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7024 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7025 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7026 if(NULL == s_simpleLock) |
0 | 7027 { |
7028 /* SDL sets the error message already? */ | |
7029 free(source); | |
7030 free(ALmixer_Channel_List); | |
7031 free(Source_Map_List); | |
7032 ALmixer_Initialized = 0; | |
7033 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7034 return AL_FALSE; |
0 | 7035 } |
7036 | |
7037 | |
7038 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7039 if(NULL == Stream_Thread_global) | |
7040 { | |
7041 /* SDL sets the error message already? */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7042 SDL_DestroyMutex(s_simpleLock); |
0 | 7043 free(source); |
7044 free(ALmixer_Channel_List); | |
7045 free(Source_Map_List); | |
7046 ALmixer_Initialized = 0; | |
7047 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7048 return AL_FALSE; |
0 | 7049 } |
7050 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7051 /* |
0 | 7052 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7053 */ |
0 | 7054 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7055 | |
7056 /* We don't need this array any more because all the sources | |
7057 * are connected to channels | |
7058 */ | |
7059 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7060 return AL_TRUE; |
0 | 7061 } |
7062 | |
7063 | |
7064 | |
7065 /* Keep the return value void to allow easy use with | |
7066 * atexit() | |
7067 */ | |
7068 void ALmixer_Quit() | |
7069 { | |
7070 ALCcontext* context; | |
7071 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7072 ALint i; |
0 | 7073 |
7074 if( ! ALmixer_Initialized) | |
7075 { | |
7076 return; | |
7077 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7078 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7079 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7080 #endif |
0 | 7081 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7082 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7083 |
7084 /* This flag will cause the thread to terminate */ | |
7085 ALmixer_Initialized = 0; | |
7086 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7087 SDL_UnlockMutex(s_simpleLock); |
0 | 7088 SDL_WaitThread(Stream_Thread_global, NULL); |
7089 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7090 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7091 #endif |
0 | 7092 |
7093 /* Delete all the OpenAL sources */ | |
7094 for(i=0; i<Number_of_Channels_global; i++) | |
7095 { | |
7096 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7097 } | |
7098 /* Delete all the channels */ | |
7099 free(ALmixer_Channel_List); | |
7100 free(Source_Map_List); | |
7101 | |
7102 /* Reset the Number_of_Channels just in case somebody | |
7103 * tries using a ALmixer function. | |
7104 * I probably should put "Initialized" checks everywhere, | |
7105 * but I'm too lazy at the moment. | |
7106 */ | |
7107 Number_of_Channels_global = 0; | |
7108 | |
7109 context = alcGetCurrentContext(); | |
7110 if(NULL == context) | |
7111 { | |
7112 return; | |
7113 } | |
7114 /* Need to get the device before I close the context */ | |
7115 dev = alcGetContextsDevice(context); | |
7116 alcDestroyContext(context); | |
7117 | |
7118 if(NULL == dev) | |
7119 { | |
7120 return; | |
7121 } | |
7122 alcCloseDevice(dev); | |
7123 | |
7124 Sound_Quit(); | |
7125 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7126 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 /* Remember: ALmixer_SetError/GetError calls will not work while this is gone. */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7128 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7129 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7130 #endif |
0 | 7131 return; |
7132 } | |
7133 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7134 ALboolean ALmixer_IsInitialized() |
0 | 7135 { |
7136 return ALmixer_Initialized; | |
7137 } | |
7138 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7139 ALuint ALmixer_GetFrequency() |
0 | 7140 { |
7141 return ALmixer_Frequency_global; | |
7142 } | |
7143 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7144 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7145 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7146 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7147 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7148 return(&linked_mixver); |
7149 } | |
7150 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7151 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7152 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7153 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7154 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7155 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7156 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7157 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7158 return "Error: You should not call ALmixer_GetError while ALmixer is not initialized"; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7159 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7160 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7161 /* SDL returns empty strings instead of NULL */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7162 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7163 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7164 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7165 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7166 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7167 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7168 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7169 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7170 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7171 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7172 void ALmixer_SetError(const char* err_str, ...) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7173 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7174 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7175 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7176 fprintf(stderr, "Error: You should not call ALmixer_SetError while ALmixer is not initialized\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7177 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7178 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7179 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7180 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7181 // SDL_SetError which I'm emulating has no number parameter. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7182 TError_SetErrorv(s_ALmixerErrorPool, 1, err_str, argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7183 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7184 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7185 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7186 #endif |
0 | 7187 |
7188 | |
7189 | |
7190 | |
7191 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7192 void ALmixer_OutputAttributes() |
0 | 7193 { |
7194 ALint num_flags = 0; | |
7195 ALint* flags = 0; | |
7196 int i; | |
7197 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7198 | |
7199 | |
7200 printf("custom context\n"); | |
7201 | |
7202 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7203 sizeof num_flags, &num_flags ); | |
7204 | |
7205 printf("Number of Flags: %d\n", num_flags); | |
7206 | |
7207 if(num_flags) | |
7208 { | |
7209 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7210 | |
7211 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7212 sizeof num_flags * sizeof(ALint), | |
7213 flags ); | |
7214 } | |
7215 for(i = 0; i < num_flags-1; i += 2) | |
7216 { | |
7217 printf("key 0x%x : value %d\n", | |
7218 flags[i], flags[i+1]); | |
7219 } | |
7220 free(flags); | |
7221 } | |
7222 #endif | |
7223 | |
7224 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7225 void ALmixer_OutputDecoders() |
0 | 7226 { |
7227 Sound_Version sound_compile_version; | |
7228 Sound_Version sound_link_version; | |
7229 | |
7230 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7231 const Sound_DecoderInfo **i; | |
7232 const char **ext; | |
7233 FILE* stream = stdout; | |
7234 | |
7235 | |
7236 fprintf(stream, "SDL_sound Information:\n"); | |
7237 | |
7238 SOUND_VERSION(&sound_compile_version); | |
7239 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7240 sound_compile_version.major, | |
7241 sound_compile_version.minor, | |
7242 sound_compile_version.patch); | |
7243 | |
7244 Sound_GetLinkedVersion(&sound_link_version); | |
7245 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7246 sound_link_version.major, | |
7247 sound_link_version.minor, | |
7248 sound_link_version.patch); | |
7249 | |
7250 fprintf(stream, "Supported sound formats:\n"); | |
7251 if (rc == NULL) | |
7252 fprintf(stream, " * Apparently, NONE!\n"); | |
7253 else | |
7254 { | |
7255 for (i = rc; *i != NULL; i++) | |
7256 { | |
7257 fprintf(stream, " * %s\n", (*i)->description); | |
7258 | |
7259 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7260 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7261 | |
7262 fprintf(stream, " Written by %s.\n %s\n\n", | |
7263 (*i)->author, (*i)->url); | |
7264 } /* for */ | |
7265 } /* else */ | |
7266 | |
7267 fprintf(stream, "\n"); | |
7268 } | |
7269 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7270 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7271 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7272 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7273 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7274 FILE* stream = stdout; |
7275 | |
7276 fprintf(stream, "OpenAL Information:\n"); | |
7277 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7278 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7279 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7280 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7281 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7282 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7283 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7284 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7285 mixer_compile_version.major, | |
7286 mixer_compile_version.minor, | |
7287 mixer_compile_version.patch); | |
7288 | |
7289 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7290 mixer_link_version->major, | |
7291 mixer_link_version->minor, | |
7292 mixer_link_version->patch); | |
7293 | |
7294 fprintf(stream, "\tCompile flags: "); | |
7295 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7296 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7297 #endif | |
7298 #ifdef ENABLE_ALMIXER_THREADS | |
7299 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7300 #endif | |
7301 #ifdef ENABLE_ALC_SYNC | |
7302 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7303 #endif | |
7304 fprintf(stream, "\n"); | |
7305 } | |
7306 | |
7307 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7308 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7309 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7310 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7311 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7312 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7313 #endif |
0 | 7314 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7315 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7316 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7317 #endif |
0 | 7318 return retval; |
7319 } | |
7320 | |
7321 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7322 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7323 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7324 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7325 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7326 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7327 #endif |
0 | 7328 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7329 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7330 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7331 #endif |
0 | 7332 return retval; |
7333 } | |
7334 | |
7335 | |
7336 | |
7337 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7338 static ALmixer_Data* DoLoad(Sound_Sample* sample, ALuint buffersize, ALboolean decode_mode_is_predecoded, ALuint max_queue_buffers, ALuint num_startup_buffers, ALboolean access_data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7339 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7340 ALuint bytes_decoded; |
0 | 7341 ALmixer_Data* ret_data; |
7342 ALenum error; | |
7343 | |
7344 /* Allocate memory */ | |
7345 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7346 if (NULL == ret_data) | |
7347 { | |
7348 ALmixer_SetError("Out of memory"); | |
7349 return(NULL); | |
7350 } | |
7351 | |
7352 /* Initialize the data fields */ | |
7353 | |
7354 /* Set the Sound_Sample pointer */ | |
7355 ret_data->sample = sample; | |
7356 | |
7357 /* Flag the data to note that it is not in use */ | |
7358 ret_data->in_use = 0; | |
7359 | |
7360 /* Initialize remaining flags */ | |
7361 ret_data->total_time = -1; | |
7362 ret_data->eof = 0; | |
7363 | |
7364 /* Just initialize */ | |
7365 ret_data->num_buffers_in_use = 0; | |
7366 | |
7367 /* Just initialize */ | |
7368 ret_data->total_bytes = 0; | |
7369 | |
7370 /* Just initialize */ | |
7371 ret_data->loaded_bytes = 0; | |
7372 | |
7373 /* Set the max queue buffers (minimum must be 2) */ | |
7374 if(max_queue_buffers < 2) | |
7375 { | |
7376 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7377 } | |
7378 ret_data->max_queue_buffers = max_queue_buffers; | |
7379 /* Set up the start up buffers */ | |
7380 if(0 == num_startup_buffers) | |
7381 { | |
7382 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7383 } | |
7384 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7385 if(num_startup_buffers > max_queue_buffers) | |
7386 { | |
7387 num_startup_buffers = max_queue_buffers; | |
7388 } | |
7389 ret_data->num_startup_buffers = num_startup_buffers; | |
7390 | |
7391 ret_data->buffer_map_list = NULL; | |
7392 ret_data->current_buffer = 0; | |
7393 | |
7394 ret_data->circular_buffer_queue = NULL; | |
7395 | |
7396 /* Now decode and load the data into a data chunk */ | |
7397 /* Different cases for Streamed and Predecoded | |
7398 * Streamed might turn into a predecoded if buffersize | |
7399 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7400 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7401 { |
7402 bytes_decoded = Sound_Decode(sample); | |
7403 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7404 { | |
7405 ALmixer_SetError(Sound_GetError()); | |
7406 Sound_FreeSample(sample); | |
7407 free(ret_data); | |
7408 return NULL; | |
7409 } | |
7410 | |
7411 /* If no data, return an error */ | |
7412 if(0 == bytes_decoded) | |
7413 { | |
7414 ALmixer_SetError("File has no data"); | |
7415 Sound_FreeSample(sample); | |
7416 free(ret_data); | |
7417 return NULL; | |
7418 } | |
7419 | |
7420 /* Note, currently, my Ogg conservative modifications | |
7421 * prevent EOF from being detected in the first read | |
7422 * because of the weird packet behavior of ov_read(). | |
7423 * The EAGAIN will get set, but not the EOF. | |
7424 * I don't know the best way to handle this, | |
7425 * so for now, Ogg's can only be explicitly | |
7426 * predecoded. | |
7427 */ | |
7428 | |
7429 /* Correction: Since we no longer actually keep the | |
7430 * streamed data we read here (we rewind and throw | |
7431 * it away, and start over on Play), it is | |
7432 * safe to read another chunk to see if we've hit EOF | |
7433 */ | |
7434 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7435 { | |
7436 bytes_decoded = Sound_Decode(sample); | |
7437 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7438 { | |
7439 ALmixer_SetError(Sound_GetError()); | |
7440 Sound_FreeSample(sample); | |
7441 free(ret_data); | |
7442 return NULL; | |
7443 } | |
7444 } | |
7445 | |
7446 | |
7447 /* If we found an EOF, the entire file was | |
7448 * decoded, so we can treat it like one. | |
7449 */ | |
7450 | |
7451 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7452 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7453 /* |
0 | 7454 fprintf(stderr, "We got LUCKY! File is predecoded even though STREAM was requested\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7455 */ |
0 | 7456 ret_data->decoded_all = 1; |
7457 /* Need to keep this information around for | |
7458 * seek and rewind abilities. | |
7459 */ | |
7460 ret_data->total_bytes = bytes_decoded; | |
7461 /* For now, the loaded bytes is the same as total bytes, but | |
7462 * this could change during a seek operation | |
7463 */ | |
7464 ret_data->loaded_bytes = bytes_decoded; | |
7465 | |
7466 /* Let's compute the total playing time | |
7467 * SDL_sound does not yet provide this (we're working on | |
7468 * that at the moment...) | |
7469 */ | |
7470 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7471 | |
7472 /* Create one element in the buffer array for data for OpanAL */ | |
7473 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7474 if(NULL == ret_data->buffer) | |
7475 { | |
7476 ALmixer_SetError("Out of Memory"); | |
7477 Sound_FreeSample(sample); | |
7478 free(ret_data); | |
7479 return NULL; | |
7480 } | |
7481 /* Clear the error code */ | |
7482 alGetError(); | |
7483 /* Now generate an OpenAL buffer using that first element */ | |
7484 alGenBuffers(1, ret_data->buffer); | |
7485 if( (error = alGetError()) != AL_NO_ERROR) | |
7486 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7487 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7488 Sound_FreeSample(sample); |
7489 free(ret_data->buffer); | |
7490 free(ret_data); | |
7491 return NULL; | |
7492 } | |
7493 | |
7494 | |
7495 /* Now copy the data to the OpenAL buffer */ | |
7496 /* We can't just set a pointer because the API needs | |
7497 * its own copy to assist hardware acceleration */ | |
7498 alBufferData(ret_data->buffer[0], | |
7499 TranslateFormat(&sample->desired), | |
7500 sample->buffer, | |
7501 bytes_decoded, | |
7502 sample->desired.rate | |
7503 ); | |
7504 if( (error = alGetError()) != AL_NO_ERROR) | |
7505 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7506 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7507 Sound_FreeSample(sample); |
7508 alDeleteBuffers(1, ret_data->buffer); | |
7509 free(ret_data->buffer); | |
7510 free(ret_data); | |
7511 return NULL; | |
7512 } | |
7513 | |
7514 /* We should be done with the sample since it's all | |
7515 * predecoded. So we can free the memory */ | |
7516 | |
7517 /* Additional notes: | |
7518 * We need to keep data around in case Seek() is needed | |
7519 * or other Sound_AudioInfo is needed. | |
7520 * This can either be done by not deleting the sample, | |
7521 * or it can be done by dynamically recreating it | |
7522 * when we need it. | |
7523 */ | |
7524 /* Since OpenAL won't let us retrieve it | |
7525 * (aka dynamically), we have to keep the Sample | |
7526 * around because since the user requested | |
7527 * streamed and we offered predecoded, | |
7528 * we don't want to mess up the user who | |
7529 * was expecting seek support | |
7530 * So Don't Do anything | |
7531 */ | |
7532 /* | |
7533 if(0 == access_data) | |
7534 { | |
7535 Sound_FreeSample(sample); | |
7536 ret_data->sample = NULL; | |
7537 } | |
7538 */ | |
7539 /* Else, We keep a copy of the sample around. | |
7540 * so don't do anything. | |
7541 */ | |
7542 | |
7543 #if 0 | |
7544 #if defined(DISABLE_PREDECODED_SEEK) | |
7545 Sound_FreeSample(sample); | |
7546 ret_data->sample = NULL; | |
7547 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7548 Sound_FreeSample(sample); | |
7549 ret_data->sample = NULL; | |
7550 #else | |
7551 /* We keep a copy of the sample around. | |
7552 * so don't do anything. | |
7553 */ | |
7554 #endif | |
7555 #endif | |
7556 /* okay we're done here */ | |
7557 | |
7558 } | |
7559 /* Else, we need to stream the data, so we'll | |
7560 * create multple buffers for queuing */ | |
7561 else | |
7562 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7563 /* |
0 | 7564 fprintf(stderr, "Loading streamed data (not lucky)\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7565 */ |
0 | 7566 ret_data->decoded_all = 0; |
7567 | |
7568 /* This information is for predecoded. | |
7569 * Set to 0, since we don't know. | |
7570 */ | |
7571 ret_data->total_bytes = 0; | |
7572 | |
7573 /* Create buffers for data | |
7574 */ | |
7575 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7576 if(NULL == ret_data->buffer) | |
7577 { | |
7578 ALmixer_SetError("Out of Memory"); | |
7579 Sound_FreeSample(sample); | |
7580 free(ret_data); | |
7581 return NULL; | |
7582 } | |
7583 | |
7584 /* Clear the error code */ | |
7585 alGetError(); | |
7586 /* Now generate an OpenAL buffer using that first element */ | |
7587 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7588 if( (error = alGetError()) != AL_NO_ERROR) | |
7589 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7590 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7591 Sound_FreeSample(sample); |
7592 free(ret_data->buffer); | |
7593 free(ret_data); | |
7594 return NULL; | |
7595 } | |
7596 | |
7597 /* Redesign: Okay, because of the unqueuing problems and such, | |
7598 * I've decided to redesign where and how queuing is handled. | |
7599 * Before, everything was queued up here. However, this | |
7600 * placed a penalty on load and made performance inconsistent | |
7601 * when samples had to be rewound. It did make things easier | |
7602 * to queue because I could let OpenAL decide which buffer | |
7603 * needed to be queued next. | |
7604 * Now, I'm going to push off the queuing to the actual | |
7605 * Play() command. I'm going to add some book keeping, | |
7606 * and allow for additional buffers to be filled at later | |
7607 * times. | |
7608 */ | |
7609 | |
7610 | |
7611 /* So first of all, because of I already decoded the sample | |
7612 * for testing, I need to decide what to do with it. | |
7613 * The best thing would be be to alBufferData() it. | |
7614 * The problem is it may conflict with the rest of | |
7615 * the system because everything now assumes buffers | |
7616 * are entirely stripped (because of the unqueing | |
7617 * problem). | |
7618 * So it looks like I have to do the crappy thing | |
7619 * and throw away the data, and rewind. | |
7620 */ | |
7621 | |
7622 if(0 == Sound_Rewind(ret_data->sample)) | |
7623 { | |
7624 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7625 Sound_FreeSample(sample); | |
7626 free(ret_data->buffer); | |
7627 free(ret_data); | |
7628 return NULL; | |
7629 } | |
7630 | |
7631 | |
7632 /* If the user has selected access_data, we need to | |
7633 * keep copies of the queuing buffers around because | |
7634 * OpenAL won't let us access the data. | |
7635 * Allocate the memory for the buffers here | |
7636 * and initialize the albuffer-index map | |
7637 */ | |
7638 if(access_data) | |
7639 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7640 ALuint j; |
0 | 7641 /* Create buffers for data access |
7642 * Should be the same number as the number of queue buffers | |
7643 */ | |
1 | 7644 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 7645 if(NULL == ret_data->buffer_map_list) |
7646 { | |
7647 ALmixer_SetError("Out of Memory"); | |
7648 Sound_FreeSample(sample); | |
7649 free(ret_data->buffer); | |
7650 free(ret_data); | |
7651 return NULL; | |
7652 } | |
7653 | |
7654 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
7655 if(NULL == ret_data->circular_buffer_queue) | |
7656 { | |
7657 ALmixer_SetError("Out of Memory"); | |
7658 free(ret_data->buffer_map_list); | |
7659 Sound_FreeSample(sample); | |
7660 free(ret_data->buffer); | |
7661 free(ret_data); | |
7662 return NULL; | |
7663 } | |
7664 | |
7665 | |
7666 for(j=0; j<max_queue_buffers; j++) | |
7667 { | |
7668 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
7669 ret_data->buffer_map_list[j].index = j; | |
7670 ret_data->buffer_map_list[j].num_bytes = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7671 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 7672 if(NULL == ret_data->buffer_map_list[j].data) |
7673 { | |
7674 ALmixer_SetError("Out of Memory"); | |
7675 break; | |
7676 } | |
7677 } | |
7678 /* If an error happened, we have to clean up the memory */ | |
7679 if(j < max_queue_buffers) | |
7680 { | |
7681 fprintf(stderr, "################## Buffer allocation failed\n"); | |
7682 for( ; j>=0; j--) | |
7683 { | |
7684 free(ret_data->buffer_map_list[j].data); | |
7685 } | |
7686 free(ret_data->buffer_map_list); | |
7687 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
7688 Sound_FreeSample(sample); | |
7689 free(ret_data->buffer); | |
7690 free(ret_data); | |
7691 return NULL; | |
7692 } | |
7693 | |
7694 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
7695 */ | |
1 | 7696 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 7697 } /* End if access_data==true */ |
7698 | |
7699 | |
7700 } /* End of do stream */ | |
7701 } /* end of DECODE_STREAM */ | |
7702 /* User requested decode all (easy, nothing to figure out) */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7703 else if(AL_TRUE == decode_mode_is_predecoded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7704 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7705 #ifdef ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7706 /* SDL_sound (behind the scenes) seems to loop on buffer_size chunks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7707 * until the buffer is filled. It seems like we can |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7708 * do much better and precompute the size of the buffer |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7709 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7710 * WARNING: Due to the way SDL_sound is currently implemented, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7711 * this may waste a lot of memory up front. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7712 * SDL_sound seems to pre-create a buffer of the requested size, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7713 * but on DecodeAll, an entirely new buffer is created and |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7714 * everything is memcpy'd into the new buffer in read chunks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7715 * of the buffer_size. This means we need roughly twice the memory |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7716 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7717 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7718 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7719 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7720 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7721 size_t total_bytes = Compute_Total_Bytes_With_Frame_Padding(&sample->desired, (ALuint)sound_duration); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7722 int buffer_resize_succeeded = Sound_SetBufferSize(sample, total_bytes); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7723 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7724 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7725 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7726 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7727 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7728 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7729 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7730 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7731 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 7732 bytes_decoded = Sound_DecodeAll(sample); |
7733 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7734 { | |
7735 ALmixer_SetError(Sound_GetError()); | |
7736 Sound_FreeSample(sample); | |
7737 free(ret_data); | |
7738 return NULL; | |
7739 } | |
7740 | |
7741 /* If no data, return an error */ | |
7742 if(0 == bytes_decoded) | |
7743 { | |
7744 ALmixer_SetError("File has no data"); | |
7745 Sound_FreeSample(sample); | |
7746 free(ret_data); | |
7747 return NULL; | |
7748 } | |
7749 | |
7750 | |
7751 ret_data->decoded_all = 1; | |
7752 /* Need to keep this information around for | |
7753 * seek and rewind abilities. | |
7754 */ | |
7755 ret_data->total_bytes = bytes_decoded; | |
7756 /* For now, the loaded bytes is the same as total bytes, but | |
7757 * this could change during a seek operation | |
7758 */ | |
7759 ret_data->loaded_bytes = bytes_decoded; | |
7760 | |
7761 /* Let's compute the total playing time | |
7762 * SDL_sound does not yet provide this (we're working on | |
7763 * that at the moment...) | |
7764 */ | |
7765 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7766 | |
7767 /* Create one element in the buffer array for data for OpanAL */ | |
7768 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7769 if(NULL == ret_data->buffer) | |
7770 { | |
7771 ALmixer_SetError("Out of Memory"); | |
7772 Sound_FreeSample(sample); | |
7773 free(ret_data); | |
7774 return NULL; | |
7775 } | |
7776 /* Clear the error code */ | |
7777 alGetError(); | |
7778 /* Now generate an OpenAL buffer using that first element */ | |
7779 alGenBuffers(1, ret_data->buffer); | |
7780 if( (error = alGetError()) != AL_NO_ERROR) | |
7781 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7782 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7783 Sound_FreeSample(sample); |
7784 free(ret_data->buffer); | |
7785 free(ret_data); | |
7786 return NULL; | |
7787 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7788 /* |
0 | 7789 fprintf(stderr, "Actual rate=%d, desired=%d\n", sample->actual.rate, sample->desired.rate); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7790 */ |
0 | 7791 /* Now copy the data to the OpenAL buffer */ |
7792 /* We can't just set a pointer because the API needs | |
7793 * its own copy to assist hardware acceleration */ | |
7794 alBufferData(ret_data->buffer[0], | |
7795 TranslateFormat(&sample->desired), | |
7796 sample->buffer, | |
7797 bytes_decoded, | |
7798 sample->desired.rate | |
7799 ); | |
7800 if( (error = alGetError()) != AL_NO_ERROR) | |
7801 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7802 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7803 Sound_FreeSample(sample); |
7804 alDeleteBuffers(1, ret_data->buffer); | |
7805 free(ret_data->buffer); | |
7806 free(ret_data); | |
7807 return NULL; | |
7808 } | |
7809 | |
7810 /* We should be done with the sample since it's all | |
7811 * predecoded. So we can free the memory */ | |
7812 /* Need to keep around because Seek() needs it */ | |
7813 | |
7814 /* Additional notes: | |
7815 * We need to keep data around in case Seek() is needed | |
7816 * or other Sound_AudioInfo is needed. | |
7817 * This can either be done by not deleting the sample, | |
7818 * or it can be done by dynamically recreating it | |
7819 * when we need it. | |
7820 * Update: I think now it's up to the user by passing the | |
7821 * access_data flag. If they set the flag, then they get | |
7822 * data callbacks and seek support. If not, then they can | |
7823 * get all that stuff at the expense of keeping extra memory | |
7824 * around. | |
7825 */ | |
7826 if(0 == access_data) | |
7827 { | |
7828 Sound_FreeSample(sample); | |
7829 ret_data->sample = NULL; | |
7830 } | |
7831 | |
7832 /* Else, We keep a copy of the sample around. | |
7833 * so don't do anything. | |
7834 */ | |
7835 #if 0 | |
7836 #if defined(DISABLE_PREDECODED_SEEK) | |
7837 Sound_FreeSample(sample); | |
7838 ret_data->sample = NULL; | |
7839 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7840 Sound_FreeSample(sample); | |
7841 ret_data->sample = NULL; | |
7842 #else | |
7843 /* We keep a copy of the sample around. | |
7844 * so don't do anything. | |
7845 */ | |
7846 #endif | |
7847 #endif | |
7848 | |
7849 /* okay we're done here */ | |
7850 } | |
7851 else | |
7852 { | |
7853 /* Shouldn't get here */ | |
7854 ALmixer_SetError("Unknown decode mode"); | |
7855 Sound_FreeSample(sample); | |
7856 free(ret_data); | |
7857 return NULL; | |
7858 } | |
7859 | |
7860 return ret_data; | |
7861 } | |
7862 | |
7863 | |
7864 /* This will load a sample for us. Most of the uglyness is | |
7865 * error checking and the fact that streamed/predecoded files | |
7866 * must be treated differently. | |
7867 * I don't like the AudioInfo parameter. I removed it once, | |
7868 * but the system will fail on RAW samples because the user | |
7869 * must specify it, so I had to bring it back. | |
7870 * Remember I must close the rwops if there is an error before NewSample() | |
7871 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7872 ALmixer_Data* ALmixer_LoadSample_RW(ALmixer_RWops* rwops, const char* fileext, ALuint buffersize, ALboolean decode_mode_is_predecoded, ALuint max_queue_buffers, ALuint num_startup_buffers, ALboolean access_data) |
0 | 7873 { |
7874 Sound_Sample* sample = NULL; | |
7875 Sound_AudioInfo target; | |
7876 | |
7877 /* Initialize target values to defaults | |
7878 * 0 tells SDL_sound to use the "actual" values | |
7879 */ | |
7880 target.channels = 0; | |
7881 target.rate = 0; | |
7882 #if 0 | |
7883 /* This requires my new additions to SDL_sound. It will | |
7884 * convert the sample to the proper endian order. | |
7885 * If the actual is 8-bit, it will do unsigned, if | |
7886 * the actual is 16-bit, it will do signed. | |
7887 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7888 * in this way. | |
7889 */ | |
7890 target.format = AUDIO_U8S16SYS; | |
7891 #else | |
7892 target.format = AUDIO_S16SYS; | |
7893 #endif | |
7894 | |
7895 /* Set a default buffersize if needed */ | |
7896 if(0 == buffersize) | |
7897 { | |
7898 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
7899 } | |
7900 | |
7901 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
7902 if(NULL == sample) | |
7903 { | |
7904 ALmixer_SetError(Sound_GetError()); | |
7905 return NULL; | |
7906 } | |
7907 | |
1 | 7908 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7909 } |
7910 | |
7911 | |
7912 | |
7913 /* This will load a sample for us from | |
7914 * a file (instead of RWops). Most of the uglyness is | |
7915 * error checking and the fact that streamed/predecoded files | |
7916 * must be treated differently. | |
7917 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7918 ALmixer_Data* ALmixer_LoadSample(const char* filename, ALuint buffersize, ALboolean decode_mode_is_predecoded, ALuint max_queue_buffers, ALuint num_startup_buffers, ALboolean access_data) |
0 | 7919 { |
7920 Sound_Sample* sample = NULL; | |
7921 Sound_AudioInfo target; | |
7922 | |
7923 /* Initialize target values to defaults | |
7924 * 0 tells SDL_sound to use the "actual" values | |
7925 */ | |
7926 target.channels = 0; | |
7927 target.rate = 0; | |
7928 | |
7929 #if 0 | |
7930 /* This requires my new additions to SDL_sound. It will | |
7931 * convert the sample to the proper endian order. | |
7932 * If the actual is 8-bit, it will do unsigned, if | |
7933 * the actual is 16-bit, it will do signed. | |
7934 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7935 * in this way. | |
7936 */ | |
7937 target.format = AUDIO_U8S16SYS; | |
7938 #else | |
7939 target.format = AUDIO_S16SYS; | |
7940 #endif | |
7941 | |
7942 #if 0 | |
7943 /* Okay, here's a messy hack. The problem is that we need | |
7944 * to convert the sample to have the correct bitdepth, | |
7945 * endian order, and signedness values. | |
7946 * The bit depth is 8 or 16. | |
7947 * The endian order is the native order of the system. | |
7948 * The signedness depends on what the original value | |
7949 * of the sample. Unfortunately, we can't specify these | |
7950 * values until we after we already know what the original | |
7951 * values were for bitdepth and signedness. | |
7952 * So we must open the file once to get the values, | |
7953 * then close it, and then reopen it with the | |
7954 * correct desired target values. | |
7955 * I tried changing the sample->desired field after | |
7956 * the NewSample call, but it had no effect, so | |
7957 * it looks like it must be set on open. | |
7958 */ | |
7959 /* Pick a small buffersize for the first open to not | |
7960 * waste much time allocating memory */ | |
7961 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
7962 if(NULL == sample) | |
7963 { | |
7964 ALmixer_SetError(Sound_GetError()); | |
7965 return NULL; | |
7966 } | |
7967 | |
7968 bit_depth = GetBitDepth(sample->actual.format); | |
7969 signedness_value = GetSignednessValue(sample->actual.format); | |
7970 if(8 == bit_depth) | |
7971 { | |
7972 /* If 8 bit, then we don't have to worry about | |
7973 * endian issues. We can just use the actual format | |
7974 * value and it should do the right thing | |
7975 */ | |
7976 target.format = sample->actual.format; | |
7977 } | |
7978 else | |
7979 { | |
7980 /* We'll assume it's 16-bit, and if it's not | |
7981 * hopefully SDL_sound will return an error, | |
7982 * or let us convert to 16-bit | |
7983 */ | |
7984 /* Now we need to get the correct signedness */ | |
7985 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
7986 { | |
7987 /* Set to Unsigned 16-bit, system endian order */ | |
7988 target.format = AUDIO_U16SYS; | |
7989 } | |
7990 else | |
7991 { | |
7992 /* Again, we'll assume it's Signed 16-bit system order | |
7993 * or force the conversion and hope it works out | |
7994 */ | |
7995 target.format = AUDIO_S16SYS; | |
7996 } | |
7997 } | |
7998 | |
7999 /* Now we have the correct info. We need to close and reopen */ | |
8000 Sound_FreeSample(sample); | |
8001 #endif | |
8002 | |
8003 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8004 if(NULL == sample) | |
8005 { | |
8006 ALmixer_SetError(Sound_GetError()); | |
8007 return NULL; | |
8008 } | |
8009 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8010 /* |
0 | 8011 fprintf(stderr, "Correction test: Actual rate=%d, desired=%d, actual format=%d, desired format=%d\n", sample->actual.rate, sample->desired.rate, sample->actual.format, sample->desired.format); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8012 */ |
1 | 8013 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8014 } |
8015 | |
8016 | |
8017 /* This is a back door for RAW samples or if you need the | |
8018 * AudioInfo field. Use at your own risk. | |
8019 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8020 ALmixer_Data* ALmixer_LoadSample_RAW_RW(ALmixer_RWops* rwops, const char* fileext, ALmixer_AudioInfo* desired, ALuint buffersize, ALboolean decode_mode_is_predecoded, ALuint max_queue_buffers, ALuint num_startup_buffers, ALboolean access_data) |
0 | 8021 { |
8022 Sound_Sample* sample = NULL; | |
1 | 8023 Sound_AudioInfo sound_desired; |
8024 /* Rather than copying the data from struct to struct, I could just | |
8025 * cast the thing since the structs are meant to be identical. | |
8026 * But if SDL_sound changes it's implementation, bad things | |
8027 * will probably happen. (Or if I change my implementation and | |
8028 * forget about the cast, same bad scenario.) Since this is a load | |
8029 * function, performance of this is negligible. | |
8030 */ | |
8031 if(NULL == desired) | |
8032 { | |
8033 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8034 } | |
8035 else | |
8036 { | |
8037 sound_desired.format = desired->format; | |
8038 sound_desired.channels = desired->channels; | |
8039 sound_desired.rate = desired->rate; | |
8040 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8041 } | |
0 | 8042 if(NULL == sample) |
8043 { | |
8044 ALmixer_SetError(Sound_GetError()); | |
8045 return NULL; | |
8046 } | |
1 | 8047 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8048 } |
8049 | |
8050 | |
8051 | |
8052 | |
8053 /* This is a back door for RAW samples or if you need the | |
8054 * AudioInfo field. Use at your own risk. | |
8055 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8056 ALmixer_Data* ALmixer_LoadSample_RAW(const char* filename, ALmixer_AudioInfo* desired, ALuint buffersize, ALboolean decode_mode_is_predecoded, ALuint max_queue_buffers, ALuint num_startup_buffers, ALboolean access_data) |
0 | 8057 { |
8058 Sound_Sample* sample = NULL; | |
1 | 8059 Sound_AudioInfo sound_desired; |
8060 /* Rather than copying the data from struct to struct, I could just | |
8061 * cast the thing since the structs are meant to be identical. | |
8062 * But if SDL_sound changes it's implementation, bad things | |
8063 * will probably happen. (Or if I change my implementation and | |
8064 * forget about the cast, same bad scenario.) Since this is a load | |
8065 * function, performance of this is negligible. | |
8066 */ | |
8067 if(NULL == desired) | |
8068 { | |
8069 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8070 } | |
8071 else | |
8072 { | |
8073 sound_desired.format = desired->format; | |
8074 sound_desired.channels = desired->channels; | |
8075 sound_desired.rate = desired->rate; | |
8076 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8077 } | |
8078 | |
0 | 8079 if(NULL == sample) |
8080 { | |
8081 ALmixer_SetError(Sound_GetError()); | |
8082 return NULL; | |
8083 } | |
1 | 8084 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8085 } |
8086 | |
8087 | |
8088 | |
8089 | |
8090 void ALmixer_FreeData(ALmixer_Data* data) | |
8091 { | |
8092 ALenum error; | |
8093 if(NULL == data) | |
8094 { | |
8095 return; | |
8096 } | |
8097 | |
8098 if(data->decoded_all) | |
8099 { | |
8100 /* If access_data was enabled, then the Sound_Sample* | |
8101 * still exists. We need to free it | |
8102 */ | |
8103 if(data->sample != NULL) | |
8104 { | |
8105 Sound_FreeSample(data->sample); | |
8106 } | |
8107 alDeleteBuffers(1, data->buffer); | |
8108 if((error = alGetError()) != AL_NO_ERROR) | |
8109 { | |
8110 fprintf(stderr, "70Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8111 alGetString(error)); |
0 | 8112 } |
8113 | |
8114 } | |
8115 else | |
8116 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8117 ALuint i; |
0 | 8118 |
8119 /* Delete buffer copies if access_data was enabled */ | |
8120 if(data->buffer_map_list != NULL) | |
8121 { | |
8122 for(i=0; i<data->max_queue_buffers; i++) | |
8123 { | |
8124 free(data->buffer_map_list[i].data); | |
8125 } | |
8126 free(data->buffer_map_list); | |
8127 } | |
8128 if(data->circular_buffer_queue != NULL) | |
8129 { | |
8130 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8131 } | |
8132 | |
8133 Sound_FreeSample(data->sample); | |
8134 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
8135 if((error = alGetError()) != AL_NO_ERROR) | |
8136 { | |
8137 fprintf(stderr, "71Testing error: %s\n", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8138 alGetString(error)); |
0 | 8139 } |
8140 } | |
8141 free(data->buffer); | |
8142 free(data); | |
8143 } | |
8144 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8145 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8146 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8147 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8148 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8149 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8150 } |
0 | 8151 return data->total_time; |
8152 } | |
8153 | |
8154 /* This function will look up the source for the corresponding channel */ | |
8155 /* Must return 0 on error instead of -1 because of unsigned int */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8156 ALuint ALmixer_GetSource(ALint channel) |
0 | 8157 { |
8158 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8159 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8160 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8161 #endif |
0 | 8162 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8163 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8164 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8165 #endif |
0 | 8166 return retval; |
8167 } | |
8168 | |
8169 /* This function will look up the channel for the corresponding source */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8170 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8171 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8172 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8173 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8174 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8175 #endif |
0 | 8176 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8177 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8178 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8179 #endif |
0 | 8180 return retval; |
8181 } | |
8182 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8183 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8184 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8185 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8186 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8187 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8188 #endif |
0 | 8189 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8190 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8191 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8192 #endif |
0 | 8193 return retval; |
8194 } | |
8195 | |
8196 | |
8197 | |
8198 /* API update function. | |
8199 * It should return the number of buffers that were | |
8200 * queued during the call. The value might be | |
8201 * used to guage how long you might wait to | |
8202 * call the next update loop in case you are worried | |
8203 * about preserving CPU cycles. The idea is that | |
8204 * when a buffer is queued, there was probably some | |
8205 * CPU intensive looping which took awhile. | |
8206 * It's mainly provided as a convenience. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8207 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8208 * more accurate information. |
8209 * Returns a negative value if there was an error, | |
8210 * the value being the number of errors. | |
8211 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8212 ALint ALmixer_Update() |
0 | 8213 { |
8214 #ifdef ENABLE_ALMIXER_THREADS | |
8215 /* The thread will handle all updates by itself. | |
8216 * Don't allow the user to explicitly call update. | |
8217 */ | |
8218 return 0; | |
8219 #else | |
8220 return( Update_ALmixer(NULL) ); | |
8221 #endif | |
8222 } | |
8223 | |
8224 | |
8225 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8226 void ALmixer_SetPlaybackFinishedCallback(void (*playback_finished_callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data), void* user_data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8227 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8228 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8229 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8230 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8231 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8232 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8233 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8234 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8235 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8236 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8237 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8238 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8239 void ALmixer_SetPlaybackDataCallback(void (*playback_data_callback)(ALint which_chan, ALuint al_source, ALbyte* data, ALuint num_bytes, ALuint frequency, ALubyte channels, ALubyte bit_depth, ALboolean is_unsigned, ALboolean decode_mode_is_predecoded, ALuint length_in_msec, void* user_data), void* user_data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8240 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8241 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8242 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8243 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8244 Channel_Data_Callback = playback_data_callback; |
1 | 8245 Channel_Data_Callback_Userdata = user_data; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8246 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8247 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8248 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8249 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8250 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8251 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8252 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8253 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8254 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8255 ALint ALmixer_PlayChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8256 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8257 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8258 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8259 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8260 #endif |
0 | 8261 retval = Internal_PlayChannelTimed(channel, data, loops, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8262 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8263 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8264 #endif |
0 | 8265 return retval; |
8266 } | |
8267 | |
8268 | |
8269 /* In case the user wants to specify a source instead of a channel, | |
8270 * they may use this function. This function will look up the | |
8271 * source-to-channel map, and convert the call into a | |
8272 * PlayChannelTimed() function call. | |
8273 * Returns the channel it's being played on. | |
8274 * Note: If you are prefer this method, then you need to be careful | |
8275 * about using PlayChannel, particularly if you request the | |
8276 * first available channels because source and channels have | |
8277 * a one-to-one mapping in this API. It is quite easy for | |
8278 * a channel/source to already be in use because of this. | |
8279 * In this event, an error message will be returned to you. | |
8280 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8281 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8282 { |
8283 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8284 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8285 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8286 #endif |
0 | 8287 retval = Internal_PlaySourceTimed(source, data, loops, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8288 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8289 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8290 #endif |
0 | 8291 return retval; |
8292 } | |
8293 | |
8294 | |
8295 /* Will return the number of channels halted | |
8296 * or 0 for error | |
8297 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8298 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8300 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8301 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8302 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8303 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8304 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8305 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8306 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8307 #endif |
0 | 8308 return retval; |
8309 } | |
8310 | |
8311 /* Will return the number of channels halted | |
8312 * or 0 for error | |
8313 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8314 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8316 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8317 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8318 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8319 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8320 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8321 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8322 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8323 #endif |
0 | 8324 return retval; |
8325 } | |
8326 | |
8327 | |
8328 /* This will rewind the SDL_Sound sample for streamed | |
8329 * samples and start buffering up the data for the next | |
8330 * playback. This may require samples to be halted | |
8331 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8332 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8333 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8334 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8335 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8336 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8337 #endif |
0 | 8338 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8339 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8340 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8341 #endif |
0 | 8342 return retval; |
8343 } | |
8344 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8345 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8346 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8347 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8348 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8349 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8350 #endif |
0 | 8351 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8352 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8353 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8354 #endif |
0 | 8355 return retval; |
8356 } | |
8357 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8358 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8359 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8360 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8361 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8362 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8363 #endif |
0 | 8364 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8365 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8366 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8367 #endif |
0 | 8368 return retval; |
8369 } | |
8370 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8371 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8372 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8373 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8374 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8375 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8376 #endif |
0 | 8377 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8378 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8379 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8380 #endif |
0 | 8381 return retval; |
8382 } | |
8383 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8384 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8385 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8386 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8387 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8388 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8389 #endif |
0 | 8390 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8391 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8392 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8393 #endif |
0 | 8394 return retval; |
8395 } | |
8396 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8397 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8398 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8399 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8400 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8401 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8402 #endif |
0 | 8403 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8404 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8405 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8406 #endif |
0 | 8407 return retval; |
8408 } | |
8409 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8410 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8411 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8412 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8413 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8414 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8415 #endif |
0 | 8416 retval = Internal_ResumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8417 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8418 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8419 #endif |
0 | 8420 return retval; |
8421 } | |
8422 | |
8423 /* Might consider setting eof to 0 as a "feature" | |
8424 * This will allow seek to end to stay there because | |
8425 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8426 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8427 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8428 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8429 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8430 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8431 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8432 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8433 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8434 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8435 #endif |
0 | 8436 return retval; |
8437 } | |
8438 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8439 ALint ALmixer_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8440 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8441 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8442 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8443 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8444 #endif |
0 | 8445 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8446 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8447 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8448 #endif |
0 | 8449 return retval; |
8450 } | |
8451 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8452 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8453 { |
8454 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8455 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8456 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8457 #endif |
0 | 8458 retval = Internal_FadeInSourceTimed(source, data, loops, fade_ticks, expire_ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8459 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8460 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8461 #endif |
0 | 8462 return retval; |
8463 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8464 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8465 ALint ALmixer_FadeOutChannel(ALint channel, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8466 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8467 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8468 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8469 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8470 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8471 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8472 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8473 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8474 #endif |
0 | 8475 return retval; |
8476 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8477 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8478 ALint ALmixer_FadeOutSource(ALuint source, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8479 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8480 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8481 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8482 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8483 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8484 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8485 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8486 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8487 #endif |
0 | 8488 return retval; |
8489 } | |
8490 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8491 ALint ALmixer_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8492 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8493 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8494 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8495 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8496 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8497 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8498 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8499 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8500 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8501 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8502 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8503 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8504 ALint ALmixer_FadeSource(ALuint source, ALuint ticks, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8506 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8507 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8508 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8509 #endif |
0 | 8510 retval = Internal_FadeSource(source, ticks, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8511 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8512 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8513 #endif |
0 | 8514 return retval; |
8515 } | |
8516 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8517 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8518 ALboolean ALmixer_SetVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8519 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8520 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8521 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8522 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8523 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8524 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8525 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8526 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8527 #endif |
0 | 8528 return retval; |
8529 } | |
8530 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 ALboolean ALmixer_SetVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8532 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8535 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8536 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8537 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8538 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8539 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8540 #endif |
0 | 8541 return retval; |
8542 } | |
8543 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8544 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8545 { |
8546 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8547 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8548 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8549 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8550 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8551 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8552 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8553 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8554 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8555 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8556 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8557 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8560 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8561 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8562 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8563 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8565 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8566 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8567 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8568 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8569 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8570 ALboolean ALmixer_SetMaxVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8573 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8574 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8576 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8577 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8578 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8580 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8581 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8582 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8583 ALboolean ALmixer_SetMaxVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8584 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8585 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8586 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8587 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8588 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8589 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8590 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8591 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8592 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8593 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8594 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8595 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8596 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8597 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8598 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8599 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8600 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 #endif |
0 | 8602 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8603 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8604 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8605 #endif |
0 | 8606 return retval; |
8607 } | |
8608 | |
8609 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
8610 { | |
8611 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8612 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8613 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8614 #endif |
0 | 8615 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8616 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8617 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8618 #endif |
0 | 8619 return retval; |
8620 } | |
8621 | |
8622 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8623 ALboolean ALmixer_SetMinVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8625 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8626 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8627 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 #endif |
0 | 8629 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8631 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 #endif |
0 | 8633 return retval; |
8634 } | |
8635 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 ALboolean ALmixer_SetMinVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8637 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8638 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8639 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8640 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 #endif |
0 | 8642 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8643 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8644 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 #endif |
0 | 8646 return retval; |
8647 } | |
8648 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 8650 { |
8651 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8652 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8653 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8654 #endif |
0 | 8655 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8656 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8657 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8658 #endif |
0 | 8659 return retval; |
8660 } | |
8661 | |
8662 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
8663 { | |
8664 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8665 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8666 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8667 #endif |
0 | 8668 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8670 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #endif |
0 | 8672 return retval; |
8673 } | |
8674 | |
8675 | |
8676 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8677 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8678 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8679 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8680 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8681 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8682 #endif |
0 | 8683 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8684 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8685 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 #endif |
0 | 8687 return retval; |
8688 } | |
8689 | |
8690 ALfloat ALmixer_GetMasterVolume() | |
8691 { | |
8692 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8693 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8694 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8695 #endif |
0 | 8696 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8697 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8698 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 #endif |
0 | 8700 return retval; |
8701 } | |
8702 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8703 ALint ALmixer_ExpireChannel(ALint channel, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 #endif |
0 | 8709 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8710 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8711 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 #endif |
0 | 8713 return retval; |
8714 } | |
8715 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8716 ALint ALmixer_ExpireSource(ALuint source, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8717 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8719 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8720 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8721 #endif |
0 | 8722 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8723 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8725 #endif |
0 | 8726 return retval; |
8727 } | |
8728 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8729 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8730 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 #endif |
0 | 8735 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8736 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8738 #endif |
0 | 8739 return retval; |
8740 } | |
8741 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8742 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8744 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8749 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8750 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8751 #endif |
0 | 8752 return retval; |
8753 } | |
8754 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8755 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8756 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8762 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 #endif |
0 | 8766 return retval; |
8767 } | |
8768 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8769 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8778 #endif |
0 | 8779 return retval; |
8780 } | |
8781 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8782 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8783 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8784 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8788 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8789 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8790 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8791 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8792 #endif |
0 | 8793 return retval; |
8794 } | |
8795 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8796 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8797 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8798 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8799 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8800 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8801 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8802 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8803 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8804 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8805 #endif |
0 | 8806 return retval; |
8807 } | |
8808 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8809 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8810 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8811 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8812 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8813 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8818 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 #endif |
0 | 8820 return retval; |
8821 } | |
8822 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8823 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8824 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8825 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8826 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8827 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8828 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8829 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8830 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8831 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8832 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8833 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8834 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8835 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8836 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8837 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8838 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8839 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8840 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8841 #endif |
0 | 8842 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8843 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8844 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8845 #endif |
0 | 8846 return retval; |
8847 } | |
8848 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8849 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8851 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 #endif |
0 | 8855 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8856 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8858 #endif |
0 | 8859 return retval; |
8860 } | |
8861 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8862 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 8863 { |
8864 if(NULL == data) | |
8865 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8866 return AL_FALSE; |
1 | 8867 } |
8868 return data->decoded_all; | |
8869 } | |
8870 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8871 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8872 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8873 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8874 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8875 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8876 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8877 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8879 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8880 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8881 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8882 |